--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotReplacementsImpl.java Thu Oct 31 14:23:06 2019 -0700
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotReplacementsImpl.java Thu Oct 31 16:54:16 2019 -0700
@@ -72,26 +72,40 @@
replacements.getDefaultReplacementBytecodeProvider(), replacements.target);
}
+ public void maybeInitializeEncoder(OptionValues options) {
+ if (IS_BUILDING_NATIVE_IMAGE || UseEncodedGraphs.getValue(options)) {
+ synchronized (HotSpotReplacementsImpl.class) {
+ if (snippetEncoder == null) {
+ snippetEncoder = new SymbolicSnippetEncoder(this);
+ }
+ }
+ }
+ }
+
@Override
public Class<? extends GraphBuilderPlugin> getIntrinsifyingPlugin(ResolvedJavaMethod method) {
return method.getAnnotation(HotSpotOperation.class) != null ? HotSpotWordOperationPlugin.class : super.getIntrinsifyingPlugin(method);
}
@Override
- public void registerMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context, OptionValues options) {
- if (!IS_IN_NATIVE_IMAGE) {
- if (IS_BUILDING_NATIVE_IMAGE || UseEncodedGraphs.getValue(options)) {
- synchronized (HotSpotReplacementsImpl.class) {
- if (snippetEncoder == null) {
- snippetEncoder = new SymbolicSnippetEncoder(this);
- }
- snippetEncoder.registerMethodSubstitution(plugin, original, context, options);
- }
- }
+ public void registerMethodSubstitution(MethodSubstitutionPlugin plugin) {
+ if (snippetEncoder != null) {
+ snippetEncoder.registerMethodSubstitution(plugin);
}
}
@Override
+ public void registerConditionalPlugin(InvocationPlugin plugin) {
+ if (snippetEncoder != null) {
+ snippetEncoder.registerConditionalPlugin(plugin);
+ }
+ }
+
+ public void checkRegistered(MethodSubstitutionPlugin plugin) {
+ snippetEncoder.checkRegistered(plugin);
+ }
+
+ @Override
public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, Cancellable cancellable) {
boolean useEncodedGraphs = UseEncodedGraphs.getValue(debug.getOptions());
if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) {
@@ -99,8 +113,9 @@
InvocationPlugin plugin = replacements.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method);
if (plugin instanceof MethodSubstitutionPlugin) {
MethodSubstitutionPlugin msp = (MethodSubstitutionPlugin) plugin;
- if (useEncodedGraphs) {
- replacements.registerMethodSubstitution(msp, method, ROOT_COMPILATION, debug.getOptions());
+ if (!IS_IN_NATIVE_IMAGE && useEncodedGraphs) {
+ replacements.maybeInitializeEncoder(debug.getOptions());
+ replacements.registerMethodSubstitution(msp);
}
StructuredGraph methodSubstitution = replacements.getMethodSubstitution(msp, method, ROOT_COMPILATION, StructuredGraph.AllowAssumptions.YES, cancellable, debug.getOptions());
methodSubstitution.resetDebug(debug);
@@ -119,7 +134,8 @@
if (plugin instanceof MethodSubstitutionPlugin && (!plugin.inlineOnly() || invokeBci >= 0)) {
MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
if (!IS_IN_NATIVE_IMAGE && useEncodedGraphs) {
- registerMethodSubstitution(msPlugin, targetMethod, INLINE_AFTER_PARSING, options);
+ maybeInitializeEncoder(options);
+ registerMethodSubstitution(msPlugin);
}
// This assumes the normal path creates the graph using
// GraphBuilderConfiguration.getSnippetDefault with omits exception edges
@@ -155,9 +171,6 @@
assert registeredSnippets.add(method) : "Cannot register snippet twice: " + method.format("%H.%n(%p)");
if (IS_BUILDING_NATIVE_IMAGE || UseEncodedGraphs.getValue(options)) {
synchronized (HotSpotReplacementsImpl.class) {
- if (snippetEncoder == null) {
- snippetEncoder = new SymbolicSnippetEncoder(this);
- }
snippetEncoder.registerSnippet(method, original, receiver, trackNodeSourcePosition, options);
}
}
@@ -169,7 +182,10 @@
snippetRegistrationClosed = true;
}
- private static SymbolicSnippetEncoder.EncodedSnippets getEncodedSnippets() {
+ private static SymbolicSnippetEncoder.EncodedSnippets getEncodedSnippets(OptionValues options) {
+ if (!IS_IN_NATIVE_IMAGE && snippetEncoder != null) {
+ snippetEncoder.encode(options);
+ }
return encodedSnippets;
}
@@ -210,20 +226,15 @@
@SuppressWarnings("try")
private StructuredGraph getEncodedSnippet(ResolvedJavaMethod method, Object[] args, StructuredGraph.AllowAssumptions allowAssumptions, OptionValues options) {
- boolean useEncodedGraphs = UseEncodedGraphs.getValue(options);
- if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) {
+ if (IS_IN_NATIVE_IMAGE || UseEncodedGraphs.getValue(options)) {
synchronized (HotSpotReplacementsImpl.class) {
- if (!IS_IN_NATIVE_IMAGE) {
- snippetEncoder.encode(options);
- }
-
- if (getEncodedSnippets() == null) {
+ if (getEncodedSnippets(options) == null) {
throw GraalError.shouldNotReachHere("encoded snippets not found");
}
// Snippets graphs can contain foreign object reference and
// outlive a single compilation.
try (CompilationContext scope = HotSpotGraalServices.enterGlobalCompilationContext()) {
- StructuredGraph graph = getEncodedSnippets().getEncodedSnippet(method, this, args, allowAssumptions, options);
+ StructuredGraph graph = getEncodedSnippets(options).getEncodedSnippet(method, this, args, allowAssumptions, options);
if (graph == null) {
throw GraalError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)"));
}
@@ -239,16 +250,11 @@
@Override
public StructuredGraph getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context,
StructuredGraph.AllowAssumptions allowAssumptions, Cancellable cancellable, OptionValues options) {
- boolean useEncodedGraphs = UseEncodedGraphs.getValue(options);
- if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) {
- if (!IS_IN_NATIVE_IMAGE) {
- snippetEncoder.encode(options);
- }
-
- if (getEncodedSnippets() == null) {
+ if (IS_IN_NATIVE_IMAGE || UseEncodedGraphs.getValue(options)) {
+ if (getEncodedSnippets(options) == null) {
throw GraalError.shouldNotReachHere("encoded snippets not found");
}
- return getEncodedSnippets().getMethodSubstitutionGraph(plugin, original, this, context, allowAssumptions, cancellable, options);
+ return getEncodedSnippets(options).getMethodSubstitutionGraph(plugin, original, this, context, allowAssumptions, cancellable, options);
}
return null;
}