diff -r 13588c901957 -r 9cf78a70fa4f src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotReplacementsImpl.java --- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotReplacementsImpl.java Thu Oct 17 20:27:44 2019 +0100 +++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotReplacementsImpl.java Thu Oct 17 20:53:35 2019 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,6 +41,7 @@ import org.graalvm.compiler.graph.NodeSourcePosition; import org.graalvm.compiler.hotspot.meta.HotSpotWordOperationPlugin; import org.graalvm.compiler.hotspot.word.HotSpotOperation; +import org.graalvm.compiler.nodes.Cancellable; import org.graalvm.compiler.nodes.Invoke; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; @@ -91,7 +92,7 @@ } @Override - public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug) { + public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, Cancellable cancellable) { boolean useEncodedGraphs = UseEncodedGraphs.getValue(debug.getOptions()); if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) { HotSpotReplacementsImpl replacements = (HotSpotReplacementsImpl) providers.getReplacements(); @@ -101,13 +102,13 @@ if (useEncodedGraphs) { replacements.registerMethodSubstitution(msp, method, ROOT_COMPILATION, debug.getOptions()); } - StructuredGraph methodSubstitution = replacements.getMethodSubstitution(msp, method, ROOT_COMPILATION, StructuredGraph.AllowAssumptions.YES, debug.getOptions()); + StructuredGraph methodSubstitution = replacements.getMethodSubstitution(msp, method, ROOT_COMPILATION, StructuredGraph.AllowAssumptions.YES, cancellable, debug.getOptions()); methodSubstitution.resetDebug(debug); return methodSubstitution; } return null; } - return super.getIntrinsicGraph(method, compilationId, debug); + return super.getIntrinsicGraph(method, compilationId, debug, cancellable); } @Override @@ -122,7 +123,7 @@ } // This assumes the normal path creates the graph using // GraphBuilderConfiguration.getSnippetDefault with omits exception edges - StructuredGraph subst = getMethodSubstitution(msPlugin, targetMethod, INLINE_AFTER_PARSING, StructuredGraph.AllowAssumptions.NO, options); + StructuredGraph subst = getMethodSubstitution(msPlugin, targetMethod, INLINE_AFTER_PARSING, StructuredGraph.AllowAssumptions.NO, null, options); return subst; } } @@ -207,6 +208,7 @@ return super.getSnippet(method, recursiveEntry, args, trackNodeSourcePosition, replaceePosition, options); } + @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) { @@ -218,11 +220,15 @@ if (getEncodedSnippets() == null) { throw GraalError.shouldNotReachHere("encoded snippets not found"); } - StructuredGraph graph = getEncodedSnippets().getEncodedSnippet(method, this, args, allowAssumptions, options); - if (graph == null) { - throw GraalError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)")); + // 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); + if (graph == null) { + throw GraalError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)")); + } + return graph; } - return graph; } } else { assert registeredSnippets == null || registeredSnippets.contains(method) : "Asking for snippet method that was never registered: " + method.format("%H.%n(%p)"); @@ -232,7 +238,7 @@ @Override public StructuredGraph getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context, - StructuredGraph.AllowAssumptions allowAssumptions, OptionValues options) { + StructuredGraph.AllowAssumptions allowAssumptions, Cancellable cancellable, OptionValues options) { boolean useEncodedGraphs = UseEncodedGraphs.getValue(options); if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) { if (!IS_IN_NATIVE_IMAGE) { @@ -242,7 +248,7 @@ if (getEncodedSnippets() == null) { throw GraalError.shouldNotReachHere("encoded snippets not found"); } - return getEncodedSnippets().getMethodSubstitutionGraph(plugin, original, this, context, allowAssumptions, options); + return getEncodedSnippets().getMethodSubstitutionGraph(plugin, original, this, context, allowAssumptions, cancellable, options); } return null; }