2525package com .oracle .svm .hosted .dynamicaccessinference ;
2626
2727import java .io .IOException ;
28- import java .nio .file .Path ;
2928import java .util .List ;
3029
3130import org .graalvm .collections .Pair ;
3231import org .graalvm .nativeimage .ImageSingletons ;
3332
33+ import com .oracle .graal .pointsto .reports .ReportUtils ;
34+ import com .oracle .svm .core .SubstrateOptions ;
3435import com .oracle .svm .core .feature .AutomaticallyRegisteredFeature ;
3536import com .oracle .svm .core .feature .InternalFeature ;
3637import com .oracle .svm .core .option .HostedOptionKey ;
4748public class DynamicAccessInferenceLoggingFeature implements InternalFeature {
4849
4950 static class Options {
50- @ Option (help = "Specify the .json log file location for inferred dynamic accesses ." , stability = OptionStability .EXPERIMENTAL )//
51- static final HostedOptionKey <String > LogDynamicAccessInference = new HostedOptionKey <>(null );
51+ @ Option (help = "Log inferred dynamic access invocations ." , stability = OptionStability .EXPERIMENTAL )//
52+ static final HostedOptionKey <Boolean > LogDynamicAccessInference = new HostedOptionKey <>(false );
5253 }
5354
5455 private DynamicAccessInferenceLog log ;
5556
5657 private static boolean isEnabled () {
57- return Options .LogDynamicAccessInference .getValue () != null || shouldWarnForNonStrictFolding ();
58+ return Options .LogDynamicAccessInference .getValue () || shouldWarnForNonStrictFolding ();
5859 }
5960
6061 @ Override
@@ -70,9 +71,8 @@ public void afterRegistration(AfterRegistrationAccess access) {
7071
7172 @ Override
7273 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 ();
7676 }
7777 if (shouldWarnForNonStrictFolding ()) {
7878 warnForNonStrictFolding ();
@@ -81,18 +81,21 @@ public void afterAnalysis(AfterAnalysisAccess access) {
8181 log .seal ();
8282 }
8383
84- private void dump ( String location ) {
84+ private void dumpLog ( ) {
8585 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+ }
9194 }
95+ } catch (IOException e ) {
96+ throw new RuntimeException (e );
9297 }
93- } catch (IOException e ) {
94- throw new RuntimeException (e );
95- }
98+ });
9699 }
97100
98101 private static boolean shouldWarnForNonStrictFolding () {
0 commit comments