Skip to content

Commit f1cf96d

Browse files
committed
[GR-61098] Make TrackDynamicAccess experimental and make Dynamic Access data structures public
PullRequest: graal/19756
2 parents 16a0a50 + 5d0781e commit f1cf96d

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ public static boolean hasDumpRuntimeCompiledMethodsSupport() {
15761576
return !Platform.includedIn(Platform.WINDOWS.class) && ConcealedOptions.DumpRuntimeCompiledMethods.getValue();
15771577
}
15781578

1579-
@Option(help = "file:doc-files/TrackDynamicAccessHelp.txt")//
1579+
@Option(help = "file:doc-files/TrackDynamicAccessHelp.txt", stability = OptionStability.EXPERIMENTAL)//
15801580
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> TrackDynamicAccess = new HostedOptionKey<>(
15811581
AccumulatingLocatableMultiOptionValue.Strings.buildWithCommaDelimiter());
15821582

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/TrackDynamicAccessHelp.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ The analysis is limited to the provided comma-separated list of class-path entri
33
If any dynamic access calls are found, a "dynamic-access" directory is created in the native image output,
44
and the calls are serialized in "dynamic-access/<entry-name>/[reflection-calls.json][resource-calls.json]".
55

6-
Usage: -H:TrackDynamicAccess=[all|none|to-console|path=<cp-entry>|module=<module>|package=<package>][,...]
6+
Usage: -H:TrackDynamicAccess=[all|none|to-console|no-dump|path=<cp-entry>|module=<module>|package=<package>][,...]
77

88
The flag can be used in following ways:
99
1. -H:TrackDynamicAccess=all reports all dynamic access calls made across the entire project
@@ -12,7 +12,8 @@ The flag can be used in following ways:
1212
4. -H:TrackDynamicAccess=package=<package> reports all dynamic access calls made from the specified package
1313
5. -H:TrackDynamicAccess=none disables all previous selections for dynamic access detection
1414
6. -H:TrackDynamicAccess=to-console outputs all detected dynamic access calls to the console
15-
7. A comma-separated list of the previous cases. For example, -H:TrackDynamicAccess=path=<cp-entry>,module=<module>,package=<package>
15+
7. -H:TrackDynamicAccess=no-dump disables the serialization of detected dynamic access calls
16+
8. A comma-separated list of the previous cases. For example, -H:TrackDynamicAccess=path=<cp-entry>,module=<module>,package=<package>
1617

1718
Example of the option usage:
1819

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
@AutomaticallyRegisteredFeature
7272
public final class DynamicAccessDetectionFeature implements InternalFeature {
7373

74-
private record MethodsByAccessKind(Map<DynamicAccessDetectionPhase.DynamicAccessKind, CallLocationsByMethod> methodsByAccessKind) {
74+
public record MethodsByAccessKind(Map<DynamicAccessDetectionPhase.DynamicAccessKind, CallLocationsByMethod> methodsByAccessKind) {
7575
MethodsByAccessKind() {
7676
this(new ConcurrentSkipListMap<>());
7777
}
@@ -85,7 +85,7 @@ public CallLocationsByMethod getCallLocationsByMethod(DynamicAccessDetectionPhas
8585
}
8686
}
8787

88-
private record CallLocationsByMethod(Map<String, ConcurrentLinkedQueue<String>> callLocationsByMethod) {
88+
public record CallLocationsByMethod(Map<String, ConcurrentLinkedQueue<String>> callLocationsByMethod) {
8989
CallLocationsByMethod() {
9090
this(new ConcurrentSkipListMap<>());
9191
}
@@ -113,6 +113,7 @@ public ConcurrentLinkedQueue<String> getMethodCallLocations(String methodName) {
113113
private static final String OUTPUT_DIR_NAME = "dynamic-access";
114114
private static final String TRACK_NONE = "none";
115115
private static final String TO_CONSOLE = "to-console";
116+
private static final String NO_DUMP = "no-dump";
116117

117118
private UnmodifiableEconomicSet<String> sourceEntries; // Class path entries and module or
118119
// package names
@@ -122,6 +123,7 @@ public ConcurrentLinkedQueue<String> getMethodCallLocations(String methodName) {
122123
private final OptionValues hostedOptionValues = HostedOptionValues.singleton();
123124

124125
private boolean printToConsole;
126+
private boolean dumpJsonFiles = true;
125127

126128
public DynamicAccessDetectionFeature() {
127129
callsBySourceEntry = new ConcurrentSkipListMap<>();
@@ -169,7 +171,7 @@ private void printReportForEntry(String entry) {
169171
}
170172
}
171173

172-
public static Path getOrCreateDirectory(Path directory) throws IOException {
174+
private static Path getOrCreateDirectory(Path directory) throws IOException {
173175
if (Files.exists(directory)) {
174176
if (!Files.isDirectory(directory)) {
175177
throw new NoSuchFileException(directory.toString(), null,
@@ -225,7 +227,9 @@ private static String toMethodJson(DynamicAccessDetectionPhase.DynamicAccessKind
225227
public void reportDynamicAccess() {
226228
for (String entry : sourceEntries) {
227229
if (callsBySourceEntry.containsKey(entry)) {
228-
dumpReportForEntry(entry);
230+
if (dumpJsonFiles) {
231+
dumpReportForEntry(entry);
232+
}
229233
if (printToConsole) {
230234
printReportForEntry(entry);
231235
}
@@ -299,10 +303,13 @@ public void afterRegistration(AfterRegistrationAccess access) {
299303

300304
AccumulatingLocatableMultiOptionValue.Strings options = SubstrateOptions.TrackDynamicAccess.getValue();
301305
for (String optionValue : options.values()) {
302-
if (optionValue.equals(TO_CONSOLE)) {
303-
printToConsole = true;
304-
} else if (optionValue.equals(TRACK_NONE)) {
305-
printToConsole = false;
306+
switch (optionValue) {
307+
case TO_CONSOLE -> printToConsole = true;
308+
case NO_DUMP -> dumpJsonFiles = false;
309+
case TRACK_NONE -> {
310+
printToConsole = false;
311+
dumpJsonFiles = true;
312+
}
306313
}
307314
}
308315

@@ -324,8 +331,8 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
324331
}
325332

326333
private static String dynamicAccessPossibleOptions() {
327-
return String.format("[%s, %s, %s, %s]",
328-
TRACK_ALL, TRACK_NONE, TO_CONSOLE, IncludeOptionsSupport.possibleExtendedOptions());
334+
return String.format("[%s, %s, %s, %s, %s]",
335+
TRACK_ALL, TRACK_NONE, TO_CONSOLE, NO_DUMP, IncludeOptionsSupport.possibleExtendedOptions());
329336
}
330337

331338
public static void parseDynamicAccessOptions(EconomicMap<OptionKey<?>, Object> hostedValues, NativeImageClassLoaderSupport classLoaderSupport) {
@@ -340,8 +347,8 @@ public static void parseDynamicAccessOptions(EconomicMap<OptionKey<?>, Object> h
340347
switch (option) {
341348
case TRACK_ALL -> classLoaderSupport.setTrackAllDynamicAccess(valueWithOrigin);
342349
case TRACK_NONE -> classLoaderSupport.clearDynamicAccessSelectors();
343-
case TO_CONSOLE -> {
344-
// This option is parsed later in the afterRegistration hook
350+
case TO_CONSOLE, NO_DUMP -> {
351+
// These options are parsed later in the afterRegistration hook
345352
}
346353
default -> parseIncludeSelector(optionArgument, valueWithOrigin, classLoaderSupport.getDynamicAccessSelectors(), IncludeOptionsSupport.ExtendedOption.parse(option),
347354
dynamicAccessPossibleOptions());

0 commit comments

Comments
 (0)