Skip to content

Commit

Permalink
WIP, make spring petclinic work
Browse files Browse the repository at this point in the history
  • Loading branch information
vjovanov committed Jan 14, 2025
1 parent f610693 commit b7393b2
Show file tree
Hide file tree
Showing 23 changed files with 158 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static void registerAllDeclaredMethods(Class<?> declaringClass) {
* @since 23.0
*/
public static void registerAllConstructors(Class<?> declaringClass) {
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllConstructorsQuery(ConfigurationCondition.alwaysTrue(), true, declaringClass);
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllConstructorsQuery(ConfigurationCondition.alwaysTrue(), false, declaringClass);
}

/**
Expand All @@ -211,7 +211,7 @@ public static void registerAllConstructors(Class<?> declaringClass) {
* @since 23.0
*/
public static void registerAllDeclaredConstructors(Class<?> declaringClass) {
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredConstructorsQuery(ConfigurationCondition.alwaysTrue(), true, declaringClass);
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredConstructorsQuery(ConfigurationCondition.alwaysTrue(), false, declaringClass);
}

/**
Expand All @@ -221,7 +221,7 @@ public static void registerAllDeclaredConstructors(Class<?> declaringClass) {
* @since 23.0
*/
public static void registerAllFields(Class<?> declaringClass) {
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllFieldsQuery(ConfigurationCondition.alwaysTrue(), declaringClass);
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllFields(ConfigurationCondition.alwaysTrue(), declaringClass);
}

/**
Expand All @@ -231,7 +231,7 @@ public static void registerAllFields(Class<?> declaringClass) {
* @since 23.0
*/
public static void registerAllDeclaredFields(Class<?> declaringClass) {
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredFieldsQuery(ConfigurationCondition.alwaysTrue(), declaringClass);
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredFields(ConfigurationCondition.alwaysTrue(), declaringClass);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Arrays;

public interface ReflectionRegistry {
// TODO thread this true behind MRE flag
default void register(ConfigurationCondition condition, Class<?>... classes) {
Arrays.stream(classes).forEach(clazz -> register(condition, false, clazz));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public interface RuntimeReflectionSupport extends ReflectionRegistry {

void registerAllDeclaredMethodsQuery(ConfigurationCondition condition, boolean queriedOnly, Class<?> clazz);

void registerAllFieldsQuery(ConfigurationCondition condition, Class<?> clazz);
void registerAllFields(ConfigurationCondition condition, Class<?> clazz);

void registerAllDeclaredFieldsQuery(ConfigurationCondition condition, Class<?> clazz);
void registerAllDeclaredFields(ConfigurationCondition condition, Class<?> clazz);

void registerAllConstructorsQuery(ConfigurationCondition condition, boolean queriedOnly, Class<?> clazz);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.api.replacements.Fold;

Expand All @@ -57,7 +58,7 @@ public void setBigBang(BigBang bb) {
}

public static boolean isClassIncludedBase(Class<?> cls) {
Class<?> enclosingClass = cls.getEnclosingClass();
Class<?> enclosingClass = ReflectionUtil.linkageSafeQuery(cls, null, Class::getEnclosingClass);
return !Feature.class.isAssignableFrom(cls) && !AnnotationAccess.isAnnotationPresent(cls, TargetClass.class) && (enclosingClass == null || isClassIncludedBase(enclosingClass));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ public void onTypeInstantiated(AnalysisType type) {
/* Register the type as instantiated with all its super types. */

assert type.isInstantiated() : type;
AnalysisError.guarantee(type.isArray() || (type.isInstanceClass() && !type.isAbstract()));
AnalysisError.guarantee(type.isArray() || (type.isInstanceClass() && !type.isAbstract()), "Type %s must be either an array, or a non abstract instance class", type.getName());

TypeState typeState = TypeState.forExactType(this, type, true);
TypeState typeStateNonNull = TypeState.forExactType(this, type, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TypeResult<ConfigurationType> resolveType(UnresolvedConfigurationConditio
}

@Override
public void registerType(UnresolvedConfigurationCondition condition, ConfigurationType type) {
public void registerType(UnresolvedConfigurationCondition condition, ConfigurationType type, boolean registerMetadata) {
VMError.guarantee(condition.equals(type.getCondition()), "condition is already a part of the type");
configuration.add(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ public enum ReportingMode {
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllFromModule = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());

@Option(help = "Include all classes, methods, fields, and resources from a given module for dynamic access", type = OptionType.Debug) //
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllMetadataForModule = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> EnableDynamicAccessForModule = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());

@Option(help = "Include all classes, methods, fields, and resources from given paths", type = OptionType.Debug) //
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllFromPath = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
Expand All @@ -1312,17 +1312,17 @@ public enum ReportingMode {
AccumulatingLocatableMultiOptionValue.Strings.buildWithCommaDelimiter());

@Option(help = "Include all classes, methods and fields from the given packages for dynamic access", type = OptionType.Debug) //
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllMetadataFromPackage = new HostedOptionKey<>(
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> EnableDynamicAccessForPackage = new HostedOptionKey<>(
AccumulatingLocatableMultiOptionValue.Strings.buildWithCommaDelimiter());

@Option(help = "Include all classes, methods, fields, and resources from given paths for dynamic access", type = OptionType.Debug) //
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllMetadataForClassPathEntry = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> EnableDynamicAccessForClassPathEntry = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());

@Option(help = "Include all classes, methods, fields, and resources from the class path", type = OptionType.Debug) //
public static final HostedOptionKey<Boolean> IncludeAllFromClassPath = new HostedOptionKey<>(false);

@Option(help = "Include all classes, methods, fields, and resources for dynamic access for the whole classpath", type = OptionType.Debug) //
public static final HostedOptionKey<Boolean> IncludeAllMetadataForClassPath = new HostedOptionKey<>(false);
public static final HostedOptionKey<Boolean> EnableDynamicAccess = new HostedOptionKey<>(false);

public static boolean includeAll() {
return IncludeAllFromModule.hasBeenSet() || IncludeAllFromPath.hasBeenSet() || IncludeAllFromPackage.hasBeenSet() || IncludeAllFromClassPath.hasBeenSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected void parseClass(EconomicMap<String, Object> data) {

C queryCondition = isType ? conditionResolver.alwaysTrue() : condition;
T clazz = result.get();
delegate.registerType(conditionResult.get(), clazz);
delegate.registerType(conditionResult.get(), clazz, false);

registerIfNotDefault(data, false, clazz, "allDeclaredConstructors", () -> delegate.registerDeclaredConstructors(condition, false, clazz));
registerIfNotDefault(data, false, clazz, "allPublicConstructors", () -> delegate.registerPublicConstructors(condition, false, clazz));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface ReflectionConfigurationParserDelegate<C, T> {

TypeResult<T> resolveType(C condition, ConfigurationTypeDescriptor typeDescriptor, boolean allowPrimitives);

void registerType(C condition, T type);
void registerType(C condition, T type, boolean registerMetadata);

void registerPublicClasses(C condition, T type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void parseClass(EconomicMap<String, Object> data) {

C queryCondition = conditionResolver.alwaysTrue();
T clazz = result.get();
delegate.registerType(conditionResult.get(), clazz);
delegate.registerType(conditionResult.get(), clazz, true);

delegate.registerDeclaredClasses(queryCondition, clazz);
delegate.registerRecordComponents(queryCondition, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static com.oracle.svm.core.MissingRegistrationUtils.throwMissingRegistrationErrors;

import java.lang.reflect.Modifier;
import java.util.EnumSet;
import java.util.Objects;

Expand Down Expand Up @@ -154,7 +155,7 @@ public void registerNegativeQuery(ConfigurationCondition condition, String class

@Platforms(Platform.HOSTED_ONLY.class)
public void registerUnsafeAllocated(ConfigurationCondition condition, Class<?> clazz) {
if (!clazz.isArray()) {
if (!clazz.isArray() && !clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers())) {
var conditionSet = unsafeInstantiatedClasses.putIfAbsent(clazz, RuntimeConditionSet.createHosted(condition));
if (conditionSet != null) {
conditionSet.addCondition(condition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public void collectResources(ResourceCollector resourceCollector) {

/* Collect remaining resources from classpath */
classLoaderSupport.classpath().stream().parallel().forEach(classpathFile -> {
boolean includeCurrent = classLoaderSupport.getJavaPathsToInclude().contains(classpathFile) || classLoaderSupport.includeAllFromClassPath() ||
classLoaderSupport.getPathsToIncludeMetadata().contains(classpathFile) || classLoaderSupport.isIncludeAllMetadataFromClassPath();
boolean includeCurrent = classLoaderSupport.getPathsToInclude().contains(classpathFile) || classLoaderSupport.includeAllFromClassPath() ||
classLoaderSupport.getClassPathEntriesToEnableDynamicAccess().contains(classpathFile) || classLoaderSupport.isEnableDynamicAccessForClassPath();
try {
if (Files.isDirectory(classpathFile)) {
scanDirectory(classpathFile, resourceCollector, includeCurrent);
Expand All @@ -134,7 +134,7 @@ private void collectResourceFromModule(ResourceCollector resourceCollector, Reso
ModuleReference moduleReference = info.resolvedModule.reference();
try (ModuleReader moduleReader = moduleReference.open()) {
boolean includeCurrent = classLoaderSupport.getModuleNamesToInclude().contains(info.resolvedModule().name()) ||
classLoaderSupport.getModuleNamesToIncludeMetadata().contains(info.resolvedModule().name());
classLoaderSupport.getModuleNamesToEnableDynamicAccess().contains(info.resolvedModule().name());
List<ConditionalResource> resourcesFound = new ArrayList<>();
moduleReader.list().forEach(resourceName -> {
var conditionsWithOrigins = shouldIncludeEntry(info.module, resourceCollector, resourceName, moduleReference.location().orElse(null), includeCurrent);
Expand Down
Loading

0 comments on commit b7393b2

Please sign in to comment.