Skip to content

Commit f1b321e

Browse files
committed
Disallow encoded snippet cache replacements when replay is a possibility.
1 parent f3e6db4 commit f1b321e

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/replaycomp/test/ReplayCompilationTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
import org.graalvm.collections.EconomicMap;
4040
import org.graalvm.collections.EconomicSet;
41+
import org.junit.AfterClass;
42+
import org.junit.BeforeClass;
4143
import org.junit.Test;
4244

4345
import com.oracle.truffle.api.Truffle;
@@ -46,6 +48,7 @@
4648
import jdk.graal.compiler.core.CompilationWrapper;
4749
import jdk.graal.compiler.core.GraalCompilerOptions;
4850
import jdk.graal.compiler.core.test.GraalCompilerTest;
51+
import jdk.graal.compiler.debug.DebugCloseable;
4952
import jdk.graal.compiler.debug.DebugOptions;
5053
import jdk.graal.compiler.debug.GlobalMetrics;
5154
import jdk.graal.compiler.debug.LogStream;
@@ -54,9 +57,11 @@
5457
import jdk.graal.compiler.hotspot.CompilerConfigurationFactory;
5558
import jdk.graal.compiler.hotspot.HotSpotGraalCompiler;
5659
import jdk.graal.compiler.hotspot.HotSpotGraalCompilerFactory;
60+
import jdk.graal.compiler.hotspot.HotSpotReplacementsImpl;
5761
import jdk.graal.compiler.hotspot.replaycomp.CompilerInterfaceDeclarations;
5862
import jdk.graal.compiler.hotspot.replaycomp.ReplayCompilationRunner;
5963
import jdk.graal.compiler.options.OptionValues;
64+
import jdk.graal.compiler.phases.util.Providers;
6065
import jdk.graal.compiler.runtime.RuntimeProvider;
6166
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
6267
import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
@@ -69,6 +74,25 @@
6974
* Tests for compilation recording and replay.
7075
*/
7176
public class ReplayCompilationTest extends GraalCompilerTest {
77+
/**
78+
* A separate encoded snippet scope is necessary in case the global encoded snippets have cache
79+
* replacements.
80+
*/
81+
private static DebugCloseable snippetScope;
82+
83+
@BeforeClass
84+
public static void setup() {
85+
Providers providers = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders();
86+
HotSpotReplacementsImpl replacements = (HotSpotReplacementsImpl) providers.getReplacements();
87+
snippetScope = replacements.suppressEncodedSnippets();
88+
replacements.encode(getInitialOptions());
89+
}
90+
91+
@AfterClass
92+
public static void teardown() {
93+
snippetScope.close();
94+
}
95+
7296
private static int[] lengthsSquared(List<String> strings) {
7397
return strings.stream().mapToInt(String::length).map(i -> i * i).toArray();
7498
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/EncodedSnippets.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import jdk.graal.compiler.core.common.type.StampPair;
4848
import jdk.graal.compiler.core.common.type.SymbolicJVMCIReference;
4949
import jdk.graal.compiler.debug.DebugContext;
50+
import jdk.graal.compiler.debug.DebugOptions;
5051
import jdk.graal.compiler.debug.GraalError;
5152
import jdk.graal.compiler.nodeinfo.Verbosity;
5253
import jdk.graal.compiler.nodes.ConstantNode;
@@ -250,12 +251,14 @@ StructuredGraph getEncodedSnippet(ResolvedJavaMethod method, ResolvedJavaMethod
250251
declaringClass = replacements.getProviders().getMetaAccess().lookupJavaType(Object.class);
251252
}
252253
/*
253-
* If this is a recorded/replayed compilation, we must not mutate the snippet objects. This
254-
* ensures we record all relevant operations during recording and no proxies are stored in
255-
* the snippet objects during replay.
254+
* If there is a possibility of a recorded/replayed compilation, we must not mutate the
255+
* snippet objects. During recording, this ensures that we record all relevant operations
256+
* and the cached objects are resolved to proxies. During replay, this ensures that no
257+
* proxies are stored in the snippet objects.
256258
*/
257259
boolean allowCacheReplacements = replacements.getProviders().getReplayCompilationSupport() == null &&
258-
GraalCompilerOptions.CompilationFailureAction.getValue(options) != CompilationWrapper.ExceptionAction.Diagnose;
260+
GraalCompilerOptions.CompilationFailureAction.getValue(options) != CompilationWrapper.ExceptionAction.Diagnose &&
261+
!DebugOptions.RecordForReplay.hasBeenSet(options);
259262
SymbolicEncodedGraph encodedGraph = new SymbolicEncodedGraph(snippetEncoding, startOffset, snippetObjects, allowCacheReplacements,
260263
snippetNodeClasses, data.originalMethod, declaringClass);
261264
return decodeSnippetGraph(encodedGraph, method, original, replacements, args, allowAssumptions, options, true);

0 commit comments

Comments
 (0)