Skip to content

Commit b22165b

Browse files
committed
Remove PreParseCallbackSupport/PreParseCallback and fix class and option naming.
1 parent d820f11 commit b22165b

13 files changed

+93
-134
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,6 @@ protected void setupNativeImage(String imageName, OptionValues options, Map<Meth
945945
ImageSingletons.add(ClassLoaderSupport.class, classLoaderSupport);
946946
ImageSingletons.add(LinkAtBuildTimeSupport.class, new LinkAtBuildTimeSupport(loader, classLoaderSupport));
947947
ImageSingletons.add(ObservableImageHeapMapProvider.class, new ObservableImageHeapMapProviderImpl());
948-
ImageSingletons.add(PreParseCallbackSupport.class, new PreParseCallbackSupport());
949948

950949
ClassInitializationSupport classInitializationSupport = new ClassInitializationSupport(originalMetaAccess, loader);
951950
ImageSingletons.add(RuntimeClassInitializationSupport.class, classInitializationSupport);

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

Lines changed: 0 additions & 58 deletions
This file was deleted.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
import java.util.regex.Pattern;
5858
import java.util.stream.Collectors;
5959

60-
import com.oracle.svm.hosted.strictconstantanalysis.ConstantExpressionRegistry;
61-
import com.oracle.svm.hosted.strictconstantanalysis.InferredDynamicAccessLoggingFeature;
62-
import com.oracle.svm.hosted.strictconstantanalysis.StrictConstantAnalysisFeature;
6360
import org.graalvm.nativeimage.ImageSingletons;
6461
import org.graalvm.nativeimage.hosted.RuntimeResourceAccess;
6562
import org.graalvm.nativeimage.impl.ConfigurationCondition;
@@ -95,6 +92,9 @@
9592
import com.oracle.svm.core.util.VMError;
9693
import com.oracle.svm.hosted.classinitialization.ClassInitializationSupport;
9794
import com.oracle.svm.hosted.config.ConfigurationParserUtils;
95+
import com.oracle.svm.hosted.dynamicaccessinference.ConstantExpressionRegistry;
96+
import com.oracle.svm.hosted.dynamicaccessinference.DynamicAccessInferenceLoggingFeature;
97+
import com.oracle.svm.hosted.dynamicaccessinference.StrictDynamicAccessInferenceFeature;
9898
import com.oracle.svm.hosted.imagelayer.HostedImageLayerBuildingSupport;
9999
import com.oracle.svm.hosted.jdk.localization.LocalizationFeature;
100100
import com.oracle.svm.hosted.reflect.NativeImageConditionResolver;
@@ -717,7 +717,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
717717
String resource = SubstrateGraphBuilderPlugins.asConstantObject(b, String.class, arg);
718718
return processInferredResourceAccess(b, targetMethod, reason, resolveResourceName, clazz, resource);
719719
};
720-
return StrictConstantAnalysisFeature.tryToInfer(strictModeRoutine, graphModeRoutine);
720+
return StrictDynamicAccessInferenceFeature.tryToInfer(strictModeRoutine, graphModeRoutine);
721721
}
722722
});
723723
}
@@ -731,7 +731,7 @@ private static boolean processInferredResourceAccess(GraphBuilderContext b, Reso
731731
throw VMError.shouldNotReachHere(e);
732732
}
733733
b.add(ReachabilityRegistrationNode.create(() -> RuntimeResourceAccess.addResource(clazz.getModule(), resourceName), reason));
734-
InferredDynamicAccessLoggingFeature.logRegistration(b, reason, targetMethod, clazz, new Object[]{resource});
734+
DynamicAccessInferenceLoggingFeature.logRegistration(b, reason, targetMethod, clazz, new Object[]{resource});
735735
return true;
736736
}
737737
return false;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializerGraphBuilderPhase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
package com.oracle.svm.hosted.classinitialization;
2626

27-
import com.oracle.svm.hosted.PreParseCallbackSupport;
27+
import com.oracle.svm.hosted.dynamicaccessinference.StrictDynamicAccessInferenceSupport;
2828
import com.oracle.svm.hosted.phases.SharedGraphBuilderPhase;
2929

3030
import jdk.graal.compiler.java.BytecodeParser;
@@ -74,7 +74,7 @@ protected BytecodeParser createBytecodeParser(StructuredGraph graph, BytecodePar
7474
static class ClassInitializerBytecodeParser extends SharedBytecodeParser {
7575
ClassInitializerBytecodeParser(GraphBuilderPhase.Instance graphBuilderInstance, StructuredGraph graph, BytecodeParser parent, ResolvedJavaMethod method, int entryBCI,
7676
IntrinsicContext intrinsicContext) {
77-
super(graphBuilderInstance, graph, parent, method, entryBCI, intrinsicContext, true, false, PreParseCallbackSupport.singleton());
77+
super(graphBuilderInstance, graph, parent, method, entryBCI, intrinsicContext, true, false, StrictDynamicAccessInferenceSupport.singleton());
7878
}
7979
}
8080
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.hosted.strictconstantanalysis;
25+
package com.oracle.svm.hosted.dynamicaccessinference;
2626

2727
import java.lang.invoke.MethodHandles;
2828
import java.lang.invoke.MethodType;
@@ -66,7 +66,7 @@
6666
/**
6767
* A bytecode-level constant expression analyzer for use in contexts which can affect native image
6868
* execution semantics, such as build-time folding of reflective calls
69-
* {@link StrictConstantAnalysisFeature}.
69+
* {@link StrictDynamicAccessInferenceFeature}.
7070
* <p>
7171
* The analyzer builds {@link AbstractFrame abstract frames} for each bytecode instruction of the
7272
* analyzed method. The {@link ConstantExpressionAnalyzer.Value abstract values} in stored in the
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.hosted.strictconstantanalysis;
25+
package com.oracle.svm.hosted.dynamicaccessinference;
2626

2727
import java.util.Map;
2828
import java.util.concurrent.ConcurrentHashMap;
@@ -42,6 +42,9 @@
4242
import jdk.vm.ci.meta.JavaKind;
4343
import jdk.vm.ci.meta.ResolvedJavaMethod;
4444

45+
/**
46+
* Holds information on constant expressions as inferred by {@link ConstantExpressionAnalyzer}.
47+
*/
4548
public class ConstantExpressionRegistry {
4649

4750
public static ConstantExpressionRegistry singleton() {
@@ -53,6 +56,10 @@ public static ConstantExpressionRegistry singleton() {
5356
*/
5457
private static final Object NULL_MARKER = new Object();
5558

59+
/**
60+
* Maps method and BCI pairs into abstract frames which represent the execution frame right
61+
* before the corresponding bytecode instruction.
62+
*/
5663
private Map<Pair<ResolvedJavaMethod, Integer>, AbstractFrame<ConstantExpressionAnalyzer.Value>> registry;
5764
private boolean isSealed;
5865

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.hosted.strictconstantanalysis;
25+
package com.oracle.svm.hosted.dynamicaccessinference;
2626

2727
import java.io.IOException;
2828
import java.nio.file.Path;
@@ -54,11 +54,11 @@
5454
import jdk.vm.ci.meta.ResolvedJavaMethod;
5555

5656
@AutomaticallyRegisteredFeature
57-
public class InferredDynamicAccessLoggingFeature implements InternalFeature {
57+
public class DynamicAccessInferenceLoggingFeature implements InternalFeature {
5858

5959
static class Options {
6060
@Option(help = "Specify the .json log file location for inferred dynamic accesses.", stability = OptionStability.EXPERIMENTAL)//
61-
static final HostedOptionKey<String> InferredDynamicAccessLog = new HostedOptionKey<>(null);
61+
static final HostedOptionKey<String> DynamicAccessInferenceLog = new HostedOptionKey<>(null);
6262
}
6363

6464
private static Queue<LogEntry> log = new ConcurrentLinkedQueue<>();
@@ -85,7 +85,7 @@ private static void logEntry(GraphBuilderContext b, ParsingReason reason, Suppli
8585
}
8686

8787
private static boolean isEnabled() {
88-
return Options.InferredDynamicAccessLog.getValue() != null || shouldWarnForNonStrictFolding();
88+
return Options.DynamicAccessInferenceLog.getValue() != null || shouldWarnForNonStrictFolding();
8989
}
9090

9191
@Override
@@ -95,7 +95,7 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
9595

9696
@Override
9797
public void afterAnalysis(AfterAnalysisAccess access) {
98-
String logLocation = Options.InferredDynamicAccessLog.getValue();
98+
String logLocation = Options.DynamicAccessInferenceLog.getValue();
9999
if (logLocation != null) {
100100
dump(logLocation);
101101
}
@@ -124,7 +124,7 @@ private static void dump(String location) {
124124
}
125125

126126
private static boolean shouldWarnForNonStrictFolding() {
127-
return StrictConstantAnalysisFeature.Options.StrictConstantAnalysis.getValue() == StrictConstantAnalysisFeature.Options.Mode.Warn;
127+
return StrictDynamicAccessInferenceFeature.Options.StrictDynamicAccessInference.getValue() == StrictDynamicAccessInferenceFeature.Options.Mode.Warn;
128128
}
129129

130130
private static void warnForNonStrictFolding() {
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.hosted.strictconstantanalysis;
25+
package com.oracle.svm.hosted.dynamicaccessinference;
2626

2727
import java.lang.invoke.MethodType;
2828
import java.lang.reflect.Field;
@@ -38,7 +38,6 @@
3838
import com.oracle.svm.core.feature.InternalFeature;
3939
import com.oracle.svm.core.option.HostedOptionKey;
4040
import com.oracle.svm.hosted.FeatureImpl;
41-
import com.oracle.svm.hosted.PreParseCallbackSupport;
4241
import com.oracle.svm.util.ReflectionUtil;
4342

4443
import jdk.graal.compiler.options.Option;
@@ -89,7 +88,7 @@
8988
* </ul>
9089
*/
9190
@AutomaticallyRegisteredFeature
92-
public class StrictConstantAnalysisFeature implements InternalFeature {
91+
public class StrictDynamicAccessInferenceFeature implements InternalFeature {
9392

9493
public static class Options {
9594

@@ -105,27 +104,28 @@ public enum Mode {
105104
"Disable" (default): Disable the strict mode and fall back to the optimization dependent analysis for inferrable dynamic calls;
106105
"Warn": Fold both the calls inferred with the strict mode analysis and the optimization dependant analysis, but print a warning for non-strict call folding;
107106
"Enforce": Fold only the calls inferred by the strict analysis mode.""", stability = OptionStability.EXPERIMENTAL)//
108-
public static final HostedOptionKey<Mode> StrictConstantAnalysis = new HostedOptionKey<>(Mode.Disable);
107+
public static final HostedOptionKey<Mode> StrictDynamicAccessInference = new HostedOptionKey<>(Mode.Disable);
109108
}
110109

111110
public static boolean isActive() {
112-
return Options.StrictConstantAnalysis.getValue() != Options.Mode.Disable;
111+
return Options.StrictDynamicAccessInference.getValue() != Options.Mode.Disable;
113112
}
114113

115114
@Override
116-
public boolean isInConfiguration(IsInConfigurationAccess a) {
115+
public boolean isInConfiguration(IsInConfigurationAccess access) {
117116
return isActive();
118117
}
119118

120119
@Override
121120
public void afterRegistration(AfterRegistrationAccess access) {
122121
FeatureImpl.AfterRegistrationAccessImpl accessImpl = (FeatureImpl.AfterRegistrationAccessImpl) access;
123122

123+
ConstantExpressionAnalyzer analyzer = new ConstantExpressionAnalyzer(GraalAccess.getOriginalProviders(), accessImpl.getImageClassLoader());
124124
ConstantExpressionRegistry registry = new ConstantExpressionRegistry();
125-
ImageSingletons.add(ConstantExpressionRegistry.class, registry);
125+
StrictDynamicAccessInferenceSupport support = new StrictDynamicAccessInferenceSupport(analyzer, registry);
126126

127-
ConstantExpressionAnalyzer analyzer = new ConstantExpressionAnalyzer(GraalAccess.getOriginalProviders(), accessImpl.getImageClassLoader());
128-
PreParseCallbackSupport.singleton().addCallback((method, intrinsicContext) -> registry.analyzeAndStore(analyzer, method, intrinsicContext));
127+
ImageSingletons.add(ConstantExpressionRegistry.class, registry);
128+
ImageSingletons.add(StrictDynamicAccessInferenceSupport.class, support);
129129
}
130130

131131
@Override
@@ -169,7 +169,7 @@ public void afterAnalysis(AfterAnalysisAccess access) {
169169
*/
170170
public static boolean tryToInfer(Predicate<ConstantExpressionRegistry> strictModeRoutine, BooleanSupplier graphModeRoutine, ResolvedJavaMethod targetMethod,
171171
Predicate<ResolvedJavaMethod> strictModeTarget) {
172-
Options.Mode analysisMode = Options.StrictConstantAnalysis.getValue();
172+
Options.Mode analysisMode = Options.StrictDynamicAccessInference.getValue();
173173
boolean isTarget = strictModeTarget.test(targetMethod);
174174
if (analysisMode != Options.Mode.Disable && isTarget) {
175175
ConstantExpressionRegistry registry = ConstantExpressionRegistry.singleton();

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/PreParseCallback.java renamed to substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dynamicaccessinference/StrictDynamicAccessInferenceSupport.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,32 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.hosted;
25+
package com.oracle.svm.hosted.dynamicaccessinference;
26+
27+
import org.graalvm.nativeimage.ImageSingletons;
2628

2729
import jdk.graal.compiler.nodes.graphbuilderconf.IntrinsicContext;
2830
import jdk.vm.ci.meta.ResolvedJavaMethod;
2931

30-
/**
31-
* Callback executed at the start of method parsing. It is executed before any bytecode parser
32-
* invocation plugin, and can as such be used to collect information from the method that the
33-
* plugins may rely on.
34-
*/
35-
public interface PreParseCallback {
32+
public class StrictDynamicAccessInferenceSupport {
33+
34+
public static StrictDynamicAccessInferenceSupport singleton() {
35+
if (StrictDynamicAccessInferenceFeature.isActive()) {
36+
return ImageSingletons.lookup(StrictDynamicAccessInferenceSupport.class);
37+
} else {
38+
return null;
39+
}
40+
}
41+
42+
private final ConstantExpressionAnalyzer analyzer;
43+
private final ConstantExpressionRegistry registry;
44+
45+
public StrictDynamicAccessInferenceSupport(ConstantExpressionAnalyzer analyzer, ConstantExpressionRegistry registry) {
46+
this.analyzer = analyzer;
47+
this.registry = registry;
48+
}
3649

37-
/**
38-
* Execute the callback for {@code method}. {@code IntrinsicContext} is null if no intrinsic is
39-
* currently being processed.
40-
*/
41-
void execute(ResolvedJavaMethod method, IntrinsicContext intrinsicContext);
50+
public void analyze(ResolvedJavaMethod method, IntrinsicContext intrinsicContext) {
51+
registry.analyzeAndStore(analyzer, method, intrinsicContext);
52+
}
4253
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/AnalysisGraphBuilderPhase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import com.oracle.graal.pointsto.infrastructure.OriginalMethodProvider;
3434
import com.oracle.graal.pointsto.meta.AnalysisMethod;
3535
import com.oracle.svm.core.bootstrap.BootstrapMethodConfiguration;
36-
import com.oracle.svm.hosted.PreParseCallbackSupport;
3736
import com.oracle.svm.hosted.SVMHost;
3837
import com.oracle.svm.hosted.code.SubstrateCompilationDirectives;
38+
import com.oracle.svm.hosted.dynamicaccessinference.StrictDynamicAccessInferenceSupport;
3939
import com.oracle.svm.util.ModuleSupport;
4040

4141
import jdk.graal.compiler.core.common.type.StampFactory;
@@ -93,7 +93,7 @@ public AnalysisGraphBuilderPhase(CoreProviders providers,
9393

9494
@Override
9595
protected BytecodeParser createBytecodeParser(StructuredGraph graph, BytecodeParser parent, ResolvedJavaMethod method, int entryBCI, IntrinsicContext intrinsicContext) {
96-
return new AnalysisBytecodeParser(this, graph, parent, method, entryBCI, intrinsicContext, hostVM, true, PreParseCallbackSupport.singleton());
96+
return new AnalysisBytecodeParser(this, graph, parent, method, entryBCI, intrinsicContext, hostVM, true, StrictDynamicAccessInferenceSupport.singleton());
9797
}
9898

9999
public static class AnalysisBytecodeParser extends SharedBytecodeParser {
@@ -102,8 +102,8 @@ public static class AnalysisBytecodeParser extends SharedBytecodeParser {
102102

103103
@SuppressWarnings("this-escape")
104104
protected AnalysisBytecodeParser(GraphBuilderPhase.Instance graphBuilderInstance, StructuredGraph graph, BytecodeParser parent, ResolvedJavaMethod method, int entryBCI,
105-
IntrinsicContext intrinsicContext, SVMHost hostVM, boolean explicitExceptionEdges, PreParseCallbackSupport preParseCallbacks) {
106-
super(graphBuilderInstance, graph, parent, method, entryBCI, intrinsicContext, explicitExceptionEdges, preParseCallbacks);
105+
IntrinsicContext intrinsicContext, SVMHost hostVM, boolean explicitExceptionEdges, StrictDynamicAccessInferenceSupport strictDynamicAccessInferenceSupport) {
106+
super(graphBuilderInstance, graph, parent, method, entryBCI, intrinsicContext, explicitExceptionEdges, strictDynamicAccessInferenceSupport);
107107
this.hostVM = hostVM;
108108
}
109109

0 commit comments

Comments
 (0)