Skip to content

Commit 2376d67

Browse files
committed
Revert "[GR-69070] Improve replayability with different compiler options"
This reverts commit a0e665e, reversing changes made to f23bb72.
1 parent 9479d28 commit 2376d67

18 files changed

+267
-379
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public GlobalMetrics getMetricValues() {
172172
throw new GraalError("No backend available for host architecture \"%s\"", hostArchitecture);
173173
}
174174
if (replayCompilationSupport != null) {
175-
factory = replayCompilationSupport.decorateBackendFactory(factory, jvmciRuntime);
175+
factory = replayCompilationSupport.decorateBackendFactory(factory);
176176
}
177177
hostBackend = registerBackend(factory.createBackend(this, compilerConfiguration, jvmciRuntime, null));
178178
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import jdk.graal.compiler.graph.NodeMap;
6363
import jdk.graal.compiler.graph.NodeSourcePosition;
6464
import jdk.graal.compiler.hotspot.meta.HotSpotProviders;
65-
import jdk.graal.compiler.hotspot.replaycomp.proxy.HotSpotResolvedObjectTypeProxy;
6665
import jdk.graal.compiler.hotspot.stubs.AbstractForeignCallStub;
6766
import jdk.graal.compiler.hotspot.stubs.ForeignCallStub;
6867
import jdk.graal.compiler.hotspot.word.HotSpotWordTypes;
@@ -533,8 +532,6 @@ private synchronized EncodedSnippets encodeSnippets(DebugContext debug, Economic
533532
lookupSnippetType(SnippetTemplate.SnippetInfo.class);
534533
lookupSnippetType(ForeignCallStub.class);
535534
lookupSnippetType(HotSpotSpeculationLog.HotSpotSpeculation.class);
536-
// Needed to pass constant type parameters to snippets when recording/replaying.
537-
lookupSnippetType(HotSpotResolvedObjectTypeProxy.class);
538535

539536
registerAbstractForeignCallStubInfo();
540537

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/CompilationProxies.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,4 @@ public interface CompilationProxies {
7373
* @return a debug closeable object representing the debug context
7474
*/
7575
DebugCloseable withDebugContext(DebugContext debugContext);
76-
77-
/**
78-
* Enters the context of a method compilation.
79-
*
80-
* @return a scope for the context
81-
*/
82-
DebugCloseable enterCompilationContext();
8376
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/CompilerInterfaceDeclarations.java

Lines changed: 82 additions & 119 deletions
Large diffs are not rendered by default.

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/HotSpotProxyBackendFactory.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import jdk.graal.compiler.hotspot.meta.HotSpotHostForeignCallsProvider;
3333
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
3434
import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
35-
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
3635
import jdk.vm.ci.meta.Constant;
3736
import jdk.vm.ci.meta.JavaConstant;
3837
import jdk.vm.ci.meta.MemoryAccessProvider;
@@ -49,12 +48,11 @@ class HotSpotProxyBackendFactory implements HotSpotBackendFactoryDecorators {
4948

5049
private final ReplayCompilationSupport replayCompilationSupport;
5150

52-
private final HotSpotJVMCIRuntime jvmciRuntime;
51+
private MetaAccessProvider metaAccessProviderProxy;
5352

54-
HotSpotProxyBackendFactory(CompilationProxies proxies, ReplayCompilationSupport replayCompilationSupport, HotSpotJVMCIRuntime jvmciRuntime) {
53+
HotSpotProxyBackendFactory(CompilationProxies proxies, ReplayCompilationSupport replayCompilationSupport) {
5554
this.proxies = proxies;
5655
this.replayCompilationSupport = replayCompilationSupport;
57-
this.jvmciRuntime = jvmciRuntime;
5856
}
5957

6058
@Override
@@ -64,13 +62,14 @@ public void afterJVMCIProvidersCreated() {
6462
* mirrors. We must identify the local mirrors before initialization continues to avoid
6563
* creating duplicate proxies for equivalent local mirrors.
6664
*/
67-
replayCompilationSupport.findLocalMirrors(jvmciRuntime);
65+
replayCompilationSupport.findLocalMirrors();
6866
}
6967

7068
@Override
7169
public MetaAccessProvider decorateMetaAccessProvider(MetaAccessProvider metaAccess) {
7270
// Do not record snippet types in libgraal - decorate the JVMCI meta access only.
73-
return new HotSpotSnippetMetaAccessProvider((MetaAccessProvider) proxies.proxify(metaAccess));
71+
metaAccessProviderProxy = (MetaAccessProvider) proxies.proxify(metaAccess);
72+
return new HotSpotSnippetMetaAccessProvider(metaAccessProviderProxy);
7473
}
7574

7675
@Override
@@ -80,7 +79,7 @@ public HotSpotConstantReflectionProvider decorateConstantReflectionProvider(HotS
8079
return new DecoratedConstantReflectionProvider(delegate);
8180
}
8281

83-
private static final class DecoratedConstantReflectionProvider extends HotSpotConstantReflectionProvider {
82+
private final class DecoratedConstantReflectionProvider extends HotSpotConstantReflectionProvider {
8483
private final HotSpotConstantReflectionProvider delegate;
8584

8685
private DecoratedConstantReflectionProvider(HotSpotConstantReflectionProvider delegate) {
@@ -143,7 +142,7 @@ public ResolvedJavaType asJavaType(Constant constant) {
143142
* Avoid recording an operation with the snippet constant, which is not
144143
* serializable.
145144
*/
146-
return objectConstant.asObject(ResolvedJavaType.class);
145+
return metaAccessProviderProxy.lookupJavaType(objectConstant.asObject(Object.class).getClass());
147146
} else {
148147
return delegate.asJavaType(constant);
149148
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/RecordedOperationPersistence.java

Lines changed: 43 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,6 @@ private interface RecursiveDeserializer {
144144
Object deserialize(Object json, ProxyFactory proxyFactory) throws DeserializationException;
145145

146146
Object deserialize(Object json, ProxyFactory proxyFactory, String tag) throws DeserializationException;
147-
148-
/**
149-
* Sets the {@link Architecture} parsed by this deserializer.
150-
*
151-
* @param arch the architecture
152-
*/
153-
void setArchitecture(Architecture arch);
154-
155-
/**
156-
* Gets the {@link Architecture} parsed by this deserializer.
157-
*
158-
* @return the architecture
159-
*/
160-
Architecture getArchitecture();
161147
}
162148

163149
private sealed interface ObjectSerializer {
@@ -819,6 +805,7 @@ public Object deserialize(EconomicMap<String, Object> json, RecursiveDeserialize
819805
}
820806

821807
private static final class RegisterSerializer implements ObjectSerializer {
808+
822809
@Override
823810
public Class<?> clazz() {
824811
return Register.class;
@@ -833,17 +820,20 @@ public String tag() {
833820
public void serialize(Object instance, JsonBuilder.ObjectBuilder objectBuilder, RecursiveSerializer serializer) throws IOException {
834821
Register register = (Register) instance;
835822
objectBuilder.append("number", register.number);
823+
objectBuilder.append("name", register.name);
824+
objectBuilder.append("encoding", register.encoding);
825+
objectBuilder.append("catName", register.getRegisterCategory().toString());
826+
objectBuilder.append("containsRef", register.mayContainReference());
836827
}
837828

838829
@Override
839-
public Object deserialize(EconomicMap<String, Object> json, RecursiveDeserializer deserializer, ProxyFactory proxyFactory) throws DeserializationException {
830+
public Object deserialize(EconomicMap<String, Object> json, RecursiveDeserializer deserializer, ProxyFactory proxyFactory) {
840831
int number = (int) json.get("number");
841-
for (Register register : deserializer.getArchitecture().getRegisters()) {
842-
if (register.number == number) {
843-
return register;
844-
}
845-
}
846-
throw new DeserializationException(this, json, "Register not found");
832+
String name = (String) json.get("name");
833+
int encoding = (int) json.get("encoding");
834+
String catName = (String) json.get("catName");
835+
boolean containsRef = (boolean) json.get("containsRef");
836+
return new Register(number, encoding, name, new Register.RegisterCategory(catName, containsRef));
847837
}
848838
}
849839

@@ -1697,14 +1687,12 @@ public void serialize(Object instance, JsonBuilder.ObjectBuilder objectBuilder,
16971687
public Object deserialize(EconomicMap<String, Object> json, RecursiveDeserializer deserializer, ProxyFactory proxyFactory) throws DeserializationException {
16981688
String name = (String) json.get("name");
16991689
EnumSet<?> features = (EnumSet<?>) deserializer.deserialize(json.get("features"), proxyFactory);
1700-
Architecture architecture = switch (name) {
1690+
return switch (name) {
17011691
case "AMD64" -> new AMD64((EnumSet<AMD64.CPUFeature>) features);
17021692
case "riscv64" -> new RISCV64((EnumSet<RISCV64.CPUFeature>) features);
17031693
case "aarch64" -> new AArch64((EnumSet<AArch64.CPUFeature>) features);
17041694
default -> throw new IllegalStateException("Unexpected value: " + name);
17051695
};
1706-
deserializer.setArchitecture(architecture);
1707-
return architecture;
17081696
}
17091697
}
17101698

@@ -1944,55 +1932,41 @@ public void dump(RecordedCompilationUnit compilationUnit, JsonWriter writer) thr
19441932
recursiveSerializer.serialize(compilationUnit, writer.valueBuilder(), RecordedCompilationUnitSerializer.TAG);
19451933
}
19461934

1947-
private RecursiveDeserializer createRecursiveDeserializer() {
1948-
return new RecursiveDeserializer() {
1949-
@Override
1950-
@SuppressWarnings("unchecked")
1951-
public Object deserialize(Object json, ProxyFactory proxyFactory) throws DeserializationException {
1952-
if (json instanceof EconomicMap<?, ?>) {
1953-
EconomicMap<String, Object> map = (EconomicMap<String, Object>) json;
1954-
String tag = (String) map.get("tag");
1955-
if (tag == null) {
1956-
throw new IllegalArgumentException("The JSON map does not contain a tag: " + map);
1957-
}
1958-
ObjectSerializer deserializer = tagSerializers.get(tag);
1959-
if (deserializer == null) {
1960-
throw new IllegalArgumentException("No deserializer registered for tag " + tag);
1961-
}
1962-
return deserializer.deserialize(map, this, proxyFactory);
1963-
} else {
1964-
return json;
1935+
private final RecursiveDeserializer recursiveDeserializer = new RecursiveDeserializer() {
1936+
@Override
1937+
@SuppressWarnings("unchecked")
1938+
public Object deserialize(Object json, ProxyFactory proxyFactory) throws DeserializationException {
1939+
if (json instanceof EconomicMap<?, ?>) {
1940+
EconomicMap<String, Object> map = (EconomicMap<String, Object>) json;
1941+
String tag = (String) map.get("tag");
1942+
if (tag == null) {
1943+
throw new IllegalArgumentException("The JSON map does not contain a tag: " + map);
19651944
}
1966-
}
1967-
1968-
@Override
1969-
@SuppressWarnings("unchecked")
1970-
public Object deserialize(Object json, ProxyFactory proxyFactory, String tag) throws DeserializationException {
1971-
if (json instanceof EconomicMap<?, ?>) {
1972-
EconomicMap<String, Object> map = (EconomicMap<String, Object>) json;
1973-
ObjectSerializer deserializer = tagSerializers.get(tag);
1974-
if (deserializer == null) {
1975-
throw new IllegalArgumentException("No deserializer registered for tag " + tag);
1976-
}
1977-
return deserializer.deserialize(map, this, proxyFactory);
1978-
} else {
1979-
throw new IllegalArgumentException("Expected a map.");
1945+
ObjectSerializer deserializer = tagSerializers.get(tag);
1946+
if (deserializer == null) {
1947+
throw new IllegalArgumentException("No deserializer registered for tag " + tag);
19801948
}
1949+
return deserializer.deserialize(map, this, proxyFactory);
1950+
} else {
1951+
return json;
19811952
}
1953+
}
19821954

1983-
private Architecture architecture;
1984-
1985-
@Override
1986-
public void setArchitecture(Architecture arch) {
1987-
architecture = arch;
1988-
}
1989-
1990-
@Override
1991-
public Architecture getArchitecture() {
1992-
return architecture;
1955+
@Override
1956+
@SuppressWarnings("unchecked")
1957+
public Object deserialize(Object json, ProxyFactory proxyFactory, String tag) throws DeserializationException {
1958+
if (json instanceof EconomicMap<?, ?>) {
1959+
EconomicMap<String, Object> map = (EconomicMap<String, Object>) json;
1960+
ObjectSerializer deserializer = tagSerializers.get(tag);
1961+
if (deserializer == null) {
1962+
throw new IllegalArgumentException("No deserializer registered for tag " + tag);
1963+
}
1964+
return deserializer.deserialize(map, this, proxyFactory);
1965+
} else {
1966+
throw new IllegalArgumentException("Expected a map.");
19931967
}
1994-
};
1995-
}
1968+
}
1969+
};
19961970

19971971
/**
19981972
* Loads a recorded compilation unit from the given reader.
@@ -2005,6 +1979,6 @@ public Architecture getArchitecture() {
20051979
*/
20061980
public RecordedCompilationUnit load(Reader source, ProxyFactory proxyFactory) throws IOException, DeserializationException {
20071981
JsonParser parser = new JsonParser(source);
2008-
return (RecordedCompilationUnit) createRecursiveDeserializer().deserialize(parser.parse(), proxyFactory, RecordedCompilationUnitSerializer.TAG);
1982+
return (RecordedCompilationUnit) recursiveDeserializer.deserialize(parser.parse(), proxyFactory, RecordedCompilationUnitSerializer.TAG);
20091983
}
20101984
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/RecordingCompilationProxies.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ public List<OperationRecorder.RecordedOperation> collectOperationsForSerializati
139139
return recorder.getCurrentRecordedOperations();
140140
}
141141

142-
@Override
142+
/**
143+
* Enters the context of a method compilation for the current compilation thread.
144+
*
145+
* @return a scope for the context
146+
*/
143147
public DebugCloseable enterCompilationContext() {
144148
return recorder.enterCompilationContext();
145149
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/ReplayCompilationProxies.java

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
import jdk.graal.compiler.debug.GlobalMetrics;
4242
import jdk.graal.compiler.debug.GraalError;
4343
import jdk.graal.compiler.debug.TimerKey;
44-
import jdk.graal.compiler.hotspot.CompilationContext;
45-
import jdk.graal.compiler.hotspot.HotSpotGraalServices;
4644
import jdk.graal.compiler.hotspot.Platform;
4745
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxy;
4846
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxyBase;
@@ -51,10 +49,7 @@
5149
import jdk.graal.compiler.options.OptionType;
5250
import jdk.graal.compiler.options.OptionValues;
5351
import jdk.vm.ci.code.TargetDescription;
54-
import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
55-
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
5652
import jdk.vm.ci.meta.Constant;
57-
import jdk.vm.ci.meta.MetaAccessProvider;
5853

5954
//JaCoCo Exclude
6055

@@ -71,7 +66,7 @@
7166
* memory usage low, which is important when replaying many compilations on libgraal and
7267
* benchmarking compile time.
7368
* <p>
74-
* It is necessary to call {@link #findLocalMirrors} after the operations are loaded and JVMCI
69+
* It is necessary to call {@link #findLocalMirrors()} after the operations are loaded and JVMCI
7570
* providers are created. The local mirrors may be required during a replayed compilation to query
7671
* information from the local VM, which is needed for snippet parsing.
7772
*
@@ -148,11 +143,6 @@ public void setLocalMirror(Object newLocalMirror) {
148143
*/
149144
private final EconomicMap<Class<?>, Object> singletonObjects;
150145

151-
/**
152-
* The host meta access provider.
153-
*/
154-
private MetaAccessProvider hostMetaAccess;
155-
156146
/**
157147
* Proxifies and unproxifies composite objects.
158148
*/
@@ -224,17 +214,6 @@ public DebugCloseable withDebugContext(DebugContext debugContext) {
224214
};
225215
}
226216

227-
@Override
228-
public DebugCloseable enterCompilationContext() {
229-
// The handles created during replay are cached across compilations.
230-
CompilationContext context = HotSpotGraalServices.enterGlobalCompilationContext();
231-
if (context == null) {
232-
return DebugCloseable.VOID_CLOSEABLE;
233-
} else {
234-
return context::close;
235-
}
236-
}
237-
238217
/**
239218
* Loads the recorded operations from a collection.
240219
*
@@ -351,17 +330,14 @@ private static Object intern(Object object, EconomicMap<Object, Object> internPo
351330
* <p>
352331
* During snippet parsing, the compiler may discover a JVMCI object which has no matching proxy.
353332
* For such objects, local-only proxies are created using {@link #proxify(Object)}.
354-
*
355-
* @param jvmciRuntime the JVMCI runtime
356333
*/
357-
public void findLocalMirrors(HotSpotJVMCIRuntime jvmciRuntime) {
358-
HotSpotConstantReflectionProvider constantReflection = (HotSpotConstantReflectionProvider) singletonObjects.get(HotSpotConstantReflectionProvider.class);
334+
public void findLocalMirrors() {
359335
var cursor = createdProxies.getEntries();
360336
while (cursor.advance()) {
361337
CompilationProxy proxy = cursor.getKey();
362338
CompilerInterfaceDeclarations.Registration registration = declarations.findRegistrationForInstance(proxy);
363339
if (registration.mirrorLocator() != null) {
364-
Object localMirror = registration.mirrorLocator().findLocalMirror(proxy, hostMetaAccess, constantReflection, jvmciRuntime);
340+
Object localMirror = registration.mirrorLocator().findLocalMirror(proxy, singletonObjects);
365341
if (localMirror != null) {
366342
Object previousProxy = localMirrorToProxy.put(localMirror, proxy);
367343
GraalError.guarantee(previousProxy == null, "there must be at most one proxy instance for an object");
@@ -426,9 +402,6 @@ public CompilationProxy proxify(Object input) {
426402
localMirrorToProxy.put(input, proxy);
427403
if (registration.singleton()) {
428404
singletonObjects.put(registration.clazz(), input);
429-
if (input instanceof MetaAccessProvider metaAccess) {
430-
hostMetaAccess = metaAccess;
431-
}
432405
}
433406
return proxy;
434407
}
@@ -488,13 +461,13 @@ public CompilationProxy createProxy(CompilerInterfaceDeclarations.Registration r
488461
if (proxyInfo.localMirror == null) {
489462
CompilerInterfaceDeclarations.OperationResultSupplier handler = registration.findFallbackHandler(method);
490463
if (handler != null) {
491-
return proxyMapper.proxifyRecursive(handler.apply(proxy, method, args, hostMetaAccess));
464+
return proxyMapper.proxifyRecursive(handler.apply(proxy, method, args, singletonObjects));
492465
}
493466
}
494467
GraalError.guarantee(proxyInfo.localMirror != null, "a proxy with passthrough strategy must have a local mirror or fallback handler");
495468
return callback.invoke(proxyInfo.localMirror, args);
496469
} else if (strategy == CompilerInterfaceDeclarations.MethodStrategy.DefaultValue) {
497-
return proxyMapper.proxifyRecursive(registration.findDefaultValue(proxy, method, args, hostMetaAccess));
470+
return proxyMapper.proxifyRecursive(registration.findDefaultValue(proxy, method, args, singletonObjects));
498471
}
499472
Object result = findResult(proxyInfo, method, args);
500473
if (result != SpecialResultMarker.NO_RESULT_MARKER) {
@@ -522,7 +495,7 @@ public CompilationProxy createProxy(CompilerInterfaceDeclarations.Registration r
522495
}
523496
CompilerInterfaceDeclarations.OperationResultSupplier handler = registration.findFallbackHandler(method);
524497
if (handler != null) {
525-
return proxyMapper.proxifyRecursive(handler.apply(proxy, method, args, hostMetaAccess));
498+
return proxyMapper.proxifyRecursive(handler.apply(proxy, method, args, singletonObjects));
526499
}
527500
if (args != null) {
528501
for (Object arg : args) {
@@ -534,7 +507,7 @@ public CompilationProxy createProxy(CompilerInterfaceDeclarations.Registration r
534507
if (divergenceIsFailure) {
535508
failOnDivergence(proxy, proxyInfo, method, args);
536509
}
537-
return proxyMapper.proxifyRecursive(registration.findDefaultValue(proxy, method, args, hostMetaAccess));
510+
return proxyMapper.proxifyRecursive(registration.findDefaultValue(proxy, method, args, singletonObjects));
538511
}
539512
});
540513
if (registration.singleton()) {

0 commit comments

Comments
 (0)