Skip to content

Commit f610693

Browse files
committed
Options to include metadata for module or classpath
1 parent d7d4ddb commit f610693

File tree

6 files changed

+151
-32
lines changed

6 files changed

+151
-32
lines changed

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ At runtime, premain runtime options are set along with main class' arguments in
2424
* (GR-60081) Native Image now targets `armv8.1-a` by default on AArch64. Use `-march=compatibility` for best compatibility or `-march=native` for best performance if the native executable is deployed on the same machine or on a machine with the same CPU features. To list all available machine types, use `-march=list`.
2525
* (GR-60234) Remove `"customTargetConstructorClass"` field from the serialization JSON metadata. All possible constructors are now registered by default when registering a type for serialization. `RuntimeSerialization.registerWithTargetConstructorClass` is now deprecated.
2626
* (GR-60237) Include serialization JSON reachability metadata as part of reflection metadata by introducing the `"serializable"` flag for reflection entries.
27+
* (GR-54953) Add options `-H:IncludeAllMetadataForClassPathEntry`, `-H:+IncludeAllForClassPath`, and `-H:IncludeAllMetadataForModule` for bulk inclusion of reachability metadata.
2728

2829
## GraalVM for JDK 23 (Internal Version 24.1.0)
2930
* (GR-51520) The old class initialization strategy, which was deprecated in GraalVM for JDK 22, is removed. The option `StrictImageHeap` no longer has any effect.

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/ClassInclusionPolicy.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,17 @@ public void setBigBang(BigBang bb) {
5656
this.bb = bb;
5757
}
5858

59+
public static boolean isClassIncludedBase(Class<?> cls) {
60+
Class<?> enclosingClass = cls.getEnclosingClass();
61+
return !Feature.class.isAssignableFrom(cls) && !AnnotationAccess.isAnnotationPresent(cls, TargetClass.class) && (enclosingClass == null || isClassIncludedBase(enclosingClass));
62+
}
63+
5964
/**
6065
* Determine if the given class needs to be included in the image according to the policy.
6166
*/
6267
public boolean isClassIncluded(Class<?> cls) {
6368
Class<?> enclosingClass = cls.getEnclosingClass();
64-
return !Feature.class.isAssignableFrom(cls) && !AnnotationAccess.isAnnotationPresent(cls, TargetClass.class) && (enclosingClass == null || isClassIncluded(enclosingClass));
69+
return isClassIncludedBase(cls) && (enclosingClass == null || isClassIncluded(enclosingClass));
6570
}
6671

6772
/**

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,16 +1301,29 @@ public enum ReportingMode {
13011301
@Option(help = "Include all classes, methods, and fields from given modules", type = OptionType.Debug) //
13021302
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllFromModule = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
13031303

1304+
@Option(help = "Include all classes, methods, fields, and resources from a given module for dynamic access", type = OptionType.Debug) //
1305+
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllMetadataForModule = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
1306+
13041307
@Option(help = "Include all classes, methods, fields, and resources from given paths", type = OptionType.Debug) //
13051308
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllFromPath = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
13061309

13071310
@Option(help = "Include all classes, methods and fields from the given packages", type = OptionType.Debug) //
13081311
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllFromPackage = new HostedOptionKey<>(
13091312
AccumulatingLocatableMultiOptionValue.Strings.buildWithCommaDelimiter());
13101313

1314+
@Option(help = "Include all classes, methods and fields from the given packages for dynamic access", type = OptionType.Debug) //
1315+
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllMetadataFromPackage = new HostedOptionKey<>(
1316+
AccumulatingLocatableMultiOptionValue.Strings.buildWithCommaDelimiter());
1317+
1318+
@Option(help = "Include all classes, methods, fields, and resources from given paths for dynamic access", type = OptionType.Debug) //
1319+
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> IncludeAllMetadataForClassPathEntry = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
1320+
13111321
@Option(help = "Include all classes, methods, fields, and resources from the class path", type = OptionType.Debug) //
13121322
public static final HostedOptionKey<Boolean> IncludeAllFromClassPath = new HostedOptionKey<>(false);
13131323

1324+
@Option(help = "Include all classes, methods, fields, and resources for dynamic access for the whole classpath", type = OptionType.Debug) //
1325+
public static final HostedOptionKey<Boolean> IncludeAllMetadataForClassPath = new HostedOptionKey<>(false);
1326+
13141327
public static boolean includeAll() {
13151328
return IncludeAllFromModule.hasBeenSet() || IncludeAllFromPath.hasBeenSet() || IncludeAllFromPackage.hasBeenSet() || IncludeAllFromClassPath.hasBeenSet();
13161329
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public void collectResources(ResourceCollector resourceCollector) {
116116

117117
/* Collect remaining resources from classpath */
118118
classLoaderSupport.classpath().stream().parallel().forEach(classpathFile -> {
119-
boolean includeCurrent = classLoaderSupport.getJavaPathsToInclude().contains(classpathFile) || classLoaderSupport.includeAllFromClassPath();
119+
boolean includeCurrent = classLoaderSupport.getJavaPathsToInclude().contains(classpathFile) || classLoaderSupport.includeAllFromClassPath() ||
120+
classLoaderSupport.getPathsToIncludeMetadata().contains(classpathFile) || classLoaderSupport.isIncludeAllMetadataFromClassPath();
120121
try {
121122
if (Files.isDirectory(classpathFile)) {
122123
scanDirectory(classpathFile, resourceCollector, includeCurrent);
@@ -132,7 +133,8 @@ public void collectResources(ResourceCollector resourceCollector) {
132133
private void collectResourceFromModule(ResourceCollector resourceCollector, ResourceLookupInfo info) {
133134
ModuleReference moduleReference = info.resolvedModule.reference();
134135
try (ModuleReader moduleReader = moduleReference.open()) {
135-
boolean includeCurrent = classLoaderSupport.getJavaModuleNamesToInclude().contains(info.resolvedModule().name());
136+
boolean includeCurrent = classLoaderSupport.getModuleNamesToInclude().contains(info.resolvedModule().name()) ||
137+
classLoaderSupport.getModuleNamesToIncludeMetadata().contains(info.resolvedModule().name());
136138
List<ConditionalResource> resourcesFound = new ArrayList<>();
137139
moduleReader.list().forEach(resourceName -> {
138140
var conditionsWithOrigins = shouldIncludeEntry(info.module, resourceCollector, resourceName, moduleReference.location().orElse(null), includeCurrent);

0 commit comments

Comments
 (0)