Skip to content

Commit d19698f

Browse files
committed
Use ReportUtils and reportsPath for inferred dynamic access logging.
1 parent c7894e3 commit d19698f

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dynamicaccessinference/DynamicAccessInferenceLog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ public String toString() {
120120
}
121121

122122
public void toJson(JsonBuilder.ObjectBuilder builder) throws IOException {
123-
try (JsonBuilder.ArrayBuilder foldContextBuilder = builder.append("foldContext").array()) {
123+
try (JsonBuilder.ArrayBuilder inliningContextBuilder = builder.append("inliningContext").array()) {
124124
for (StackTraceElement element : callStack) {
125-
foldContextBuilder.append(element);
125+
inliningContextBuilder.append(element);
126126
}
127127
}
128128
builder.append("targetMethod", targetMethod.format("%H.%n(%p)"));

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dynamicaccessinference/DynamicAccessInferenceLoggingFeature.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
package com.oracle.svm.hosted.dynamicaccessinference;
2626

2727
import java.io.IOException;
28-
import java.nio.file.Path;
2928
import java.util.List;
3029

3130
import org.graalvm.collections.Pair;
3231
import org.graalvm.nativeimage.ImageSingletons;
3332

33+
import com.oracle.graal.pointsto.reports.ReportUtils;
34+
import com.oracle.svm.core.SubstrateOptions;
3435
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3536
import com.oracle.svm.core.feature.InternalFeature;
3637
import com.oracle.svm.core.option.HostedOptionKey;
@@ -47,14 +48,14 @@
4748
public 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

Comments
 (0)