24
24
*/
25
25
package com .oracle .svm .hosted ;
26
26
27
+ import com .oracle .graal .pointsto .meta .AnalysisMetaAccess ;
27
28
import com .oracle .graal .pointsto .reports .ReportUtils ;
28
29
import com .oracle .svm .core .BuildArtifacts ;
29
30
import com .oracle .svm .core .SubstrateOptions ;
@@ -73,16 +74,16 @@ public final class DynamicAccessDetectionFeature implements InternalFeature {
73
74
74
75
// We use a ConcurrentSkipListMap, as opposed to a ConcurrentHashMap, to maintain
75
76
// order of methods by access kind.
76
- public record MethodsByAccessKind (Map <DynamicAccessDetectionPhase .DynamicAccessKind , CallLocationsByMethod > methodsByAccessKind ) {
77
+ public record MethodsByAccessKind (Map <DynamicAccessDetectionSupport .DynamicAccessKind , CallLocationsByMethod > methodsByAccessKind ) {
77
78
MethodsByAccessKind () {
78
79
this (new ConcurrentSkipListMap <>());
79
80
}
80
81
81
- public Set <DynamicAccessDetectionPhase .DynamicAccessKind > getAccessKinds () {
82
+ public Set <DynamicAccessDetectionSupport .DynamicAccessKind > getAccessKinds () {
82
83
return methodsByAccessKind .keySet ();
83
84
}
84
85
85
- public CallLocationsByMethod getCallLocationsByMethod (DynamicAccessDetectionPhase .DynamicAccessKind accessKind ) {
86
+ public CallLocationsByMethod getCallLocationsByMethod (DynamicAccessDetectionSupport .DynamicAccessKind accessKind ) {
86
87
return methodsByAccessKind .getOrDefault (accessKind , new CallLocationsByMethod ());
87
88
}
88
89
}
@@ -137,7 +138,7 @@ public static DynamicAccessDetectionFeature instance() {
137
138
return ImageSingletons .lookup (DynamicAccessDetectionFeature .class );
138
139
}
139
140
140
- public void addCall (String entry , DynamicAccessDetectionPhase .DynamicAccessKind accessKind , String call , String callLocation ) {
141
+ public void addCall (String entry , DynamicAccessDetectionSupport .DynamicAccessKind accessKind , String call , String callLocation ) {
141
142
MethodsByAccessKind entryContent = callsBySourceEntry .computeIfAbsent (entry , _ -> new MethodsByAccessKind ());
142
143
CallLocationsByMethod methodCallLocations = entryContent .methodsByAccessKind ().computeIfAbsent (accessKind , _ -> new CallLocationsByMethod ());
143
144
ConcurrentSkipListSet <String > callLocations = methodCallLocations .callLocationsByMethod ().computeIfAbsent (call , _ -> new ConcurrentSkipListSet <>());
@@ -163,7 +164,7 @@ public static String getEntryName(String path) {
163
164
private void printReportForEntry (String entry ) {
164
165
System .out .println ("Dynamic method usage detected in " + entry + ":" );
165
166
MethodsByAccessKind methodsByAccessKind = getMethodsByAccessKind (entry );
166
- for (DynamicAccessDetectionPhase .DynamicAccessKind accessKind : methodsByAccessKind .getAccessKinds ()) {
167
+ for (DynamicAccessDetectionSupport .DynamicAccessKind accessKind : methodsByAccessKind .getAccessKinds ()) {
167
168
System .out .println (" " + accessKind + " calls detected:" );
168
169
CallLocationsByMethod methodCallLocations = methodsByAccessKind .getCallLocationsByMethod (accessKind );
169
170
for (String call : methodCallLocations .getMethods ()) {
@@ -196,7 +197,7 @@ private void dumpReportForEntry(String entry) {
196
197
MethodsByAccessKind methodsByAccessKind = getMethodsByAccessKind (entry );
197
198
Path reportDirectory = NativeImageGenerator .generatedFiles (hostedOptionValues )
198
199
.resolve (OUTPUT_DIR_NAME );
199
- for (DynamicAccessDetectionPhase .DynamicAccessKind accessKind : methodsByAccessKind .getAccessKinds ()) {
200
+ for (DynamicAccessDetectionSupport .DynamicAccessKind accessKind : methodsByAccessKind .getAccessKinds ()) {
200
201
Path entryDirectory = getOrCreateDirectory (reportDirectory .resolve (getEntryName (entry )));
201
202
Path targetPath = entryDirectory .resolve (accessKind .fileName );
202
203
ReportUtils .report ("Dynamic Access Detection Report" , targetPath ,
@@ -209,7 +210,7 @@ private void dumpReportForEntry(String entry) {
209
210
}
210
211
}
211
212
212
- private static void generateDynamicAccessReport (PrintWriter writer , DynamicAccessDetectionPhase .DynamicAccessKind accessKind , MethodsByAccessKind methodsByAccessKind ) {
213
+ private static void generateDynamicAccessReport (PrintWriter writer , DynamicAccessDetectionSupport .DynamicAccessKind accessKind , MethodsByAccessKind methodsByAccessKind ) {
213
214
writer .println ("{" );
214
215
String methodsJson = methodsByAccessKind .getCallLocationsByMethod (accessKind ).getMethods ().stream ()
215
216
.map (methodName -> toMethodJson (accessKind , methodName , methodsByAccessKind ))
@@ -218,7 +219,7 @@ private static void generateDynamicAccessReport(PrintWriter writer, DynamicAcces
218
219
writer .println ("}" );
219
220
}
220
221
221
- private static String toMethodJson (DynamicAccessDetectionPhase .DynamicAccessKind accessKind , String methodName , MethodsByAccessKind methodsByAccessKind ) {
222
+ private static String toMethodJson (DynamicAccessDetectionSupport .DynamicAccessKind accessKind , String methodName , MethodsByAccessKind methodsByAccessKind ) {
222
223
String locationsJson = methodsByAccessKind .getCallLocationsByMethod (accessKind )
223
224
.getMethodCallLocations (methodName ).stream ()
224
225
.map (location -> " \" " + location + "\" " )
@@ -321,10 +322,17 @@ public void afterRegistration(AfterRegistrationAccess access) {
321
322
});
322
323
}
323
324
325
+ @ Override
326
+ public void beforeAnalysis (BeforeAnalysisAccess access ) {
327
+ AnalysisMetaAccess metaAccess = ((FeatureImpl .BeforeAnalysisAccessImpl ) access ).getMetaAccess ();
328
+ DynamicAccessDetectionSupport dynamicAccessDetectionSupport = new DynamicAccessDetectionSupport (metaAccess );
329
+ ImageSingletons .add (DynamicAccessDetectionSupport .class , dynamicAccessDetectionSupport );
330
+ }
331
+
324
332
@ Override
325
333
public void beforeCompilation (BeforeCompilationAccess access ) {
326
334
DynamicAccessDetectionFeature .instance ().reportDynamicAccess ();
327
- DynamicAccessDetectionPhase . clearMethodSignatures ();
335
+ DynamicAccessDetectionSupport . instance (). clear ();
328
336
foldEntries .clear ();
329
337
}
330
338
0 commit comments