25
25
package com .oracle .svm .hosted .dynamicaccessinference ;
26
26
27
27
import java .io .IOException ;
28
- import java .nio .file .Path ;
29
28
import java .util .List ;
30
29
31
30
import org .graalvm .collections .Pair ;
32
31
import org .graalvm .nativeimage .ImageSingletons ;
33
32
33
+ import com .oracle .graal .pointsto .reports .ReportUtils ;
34
+ import com .oracle .svm .core .SubstrateOptions ;
34
35
import com .oracle .svm .core .feature .AutomaticallyRegisteredFeature ;
35
36
import com .oracle .svm .core .feature .InternalFeature ;
36
37
import com .oracle .svm .core .option .HostedOptionKey ;
@@ -48,7 +49,7 @@ public class DynamicAccessInferenceLoggingFeature implements InternalFeature {
48
49
49
50
static class Options {
50
51
@ Option (help = "Specify the .json log file location for inferred dynamic accesses." , stability = OptionStability .EXPERIMENTAL )//
51
- static final HostedOptionKey <String > LogDynamicAccessInference = new HostedOptionKey <>(null );
52
+ static final HostedOptionKey <Boolean > LogDynamicAccessInference = new HostedOptionKey <>(false );
52
53
}
53
54
54
55
private DynamicAccessInferenceLog log ;
@@ -70,9 +71,8 @@ public void afterRegistration(AfterRegistrationAccess access) {
70
71
71
72
@ Override
72
73
public void afterAnalysis (AfterAnalysisAccess access ) {
73
- String logLocation = Options .LogDynamicAccessInference .getValue ();
74
- if (logLocation != null ) {
75
- dump (logLocation );
74
+ if (Options .LogDynamicAccessInference .getValue ()) {
75
+ dumpLog ();
76
76
}
77
77
if (shouldWarnForNonStrictFolding ()) {
78
78
warnForNonStrictFolding ();
@@ -81,18 +81,21 @@ public void afterAnalysis(AfterAnalysisAccess access) {
81
81
log .seal ();
82
82
}
83
83
84
- private void dump ( String location ) {
84
+ private void dumpLog ( ) {
85
85
assert !log .isSealed () : "Attempt to access sealed log" ;
86
- try (JsonWriter out = new JsonPrettyWriter (Path .of (location ));
87
- JsonBuilder .ArrayBuilder arrayBuilder = out .arrayBuilder ()) {
88
- for (DynamicAccessInferenceLog .LogEntry entry : log .getEntries ()) {
89
- try (JsonBuilder .ObjectBuilder objectBuilder = arrayBuilder .nextEntry ().object ()) {
90
- entry .toJson (objectBuilder );
86
+ String reportsPath = SubstrateOptions .reportsPath ();
87
+ ReportUtils .report ("inferred dynamic access invocations" , reportsPath , "dynamic_access_inference" , "json" , (writer ) -> {
88
+ try (JsonWriter out = new JsonPrettyWriter (writer );
89
+ JsonBuilder .ArrayBuilder arrayBuilder = out .arrayBuilder ()) {
90
+ for (DynamicAccessInferenceLog .LogEntry entry : log .getEntries ()) {
91
+ try (JsonBuilder .ObjectBuilder objectBuilder = arrayBuilder .nextEntry ().object ()) {
92
+ entry .toJson (objectBuilder );
93
+ }
91
94
}
95
+ } catch (IOException e ) {
96
+ throw new RuntimeException (e );
92
97
}
93
- } catch (IOException e ) {
94
- throw new RuntimeException (e );
95
- }
98
+ });
96
99
}
97
100
98
101
private static boolean shouldWarnForNonStrictFolding () {
0 commit comments