Skip to content

Commit f3e6db4

Browse files
committed
Add isInstance fallback for jargraal replay of libgraal compilations.
1 parent a592796 commit f3e6db4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static jdk.graal.compiler.bytecode.Bytecodes.INVOKESPECIAL;
3131
import static jdk.graal.compiler.bytecode.Bytecodes.INVOKESTATIC;
3232
import static jdk.graal.compiler.bytecode.Bytecodes.INVOKEVIRTUAL;
33+
import static jdk.graal.compiler.hotspot.HotSpotReplacementsImpl.isGraalClass;
3334
import static jdk.graal.compiler.java.StableMethodNameFormatter.isMethodHandle;
3435

3536
import java.lang.reflect.Proxy;
@@ -48,6 +49,7 @@
4849
import jdk.graal.compiler.core.common.CompilerProfiler;
4950
import jdk.graal.compiler.debug.DebugContext;
5051
import jdk.graal.compiler.debug.GraalError;
52+
import jdk.graal.compiler.hotspot.meta.HotSpotGraalConstantFieldProvider;
5153
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxy;
5254
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxyBase;
5355
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilerProfilerProxy;
@@ -66,6 +68,7 @@
6668
import jdk.graal.compiler.hotspot.replaycomp.proxy.SignatureProxy;
6769
import jdk.graal.compiler.hotspot.replaycomp.proxy.SpeculationLogProxy;
6870
import jdk.graal.compiler.java.LambdaUtils;
71+
import jdk.graal.compiler.options.ExcludeFromJacocoGeneratedReport;
6972
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
7073
import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
7174
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
@@ -703,6 +706,7 @@ public static CompilerInterfaceDeclarations build() {
703706
}
704707
return List.of();
705708
})
709+
.setFallbackInvocationHandler(HotSpotResolvedObjectTypeProxy.isInstanceMethod, CompilerInterfaceDeclarations::objectTypeIsInstanceFallback)
706710
.register(declarations);
707711
// Must come after HotSpotResolvedObjectType. Needed for HotSpotResolvedPrimitiveType.
708712
new RegistrationBuilder<>(HotSpotResolvedJavaType.class)
@@ -921,4 +925,27 @@ private static ResolvedJavaType javaLangObjectSupplier(Object proxy, Compilation
921925
MetaAccessProvider metaAccess = (MetaAccessProvider) singletonObjects.get(MetaAccessProvider.class);
922926
return metaAccess.lookupJavaType(Object.class);
923927
}
928+
929+
/**
930+
* Implements a fallback for {@link HotSpotResolvedObjectType#isInstance} calls performed by
931+
* {@link HotSpotGraalConstantFieldProvider} when replaying a libgraal compilation on jargraal.
932+
* <p>
933+
* The provider performs checks like {@code getHotSpotVMConfigType().isInstance(receiver)},
934+
* which use snippet types on libgraal and HotSpot types on jargraal. Replay on jargraal needs
935+
* to answer these queries when the receiver and argument are HotSpot proxies.
936+
*/
937+
@SuppressWarnings("unused")
938+
@ExcludeFromJacocoGeneratedReport("related to replay of libgraal compilations on jargraal")
939+
private static boolean objectTypeIsInstanceFallback(Object proxy, CompilationProxy.SymbolicMethod method, Object[] args, EconomicMap<Class<?>, Object> singletonObjects) {
940+
HotSpotResolvedObjectType receiverType = (HotSpotResolvedObjectType) proxy;
941+
if (!(args[0] instanceof HotSpotObjectConstant objectConstant)) {
942+
return false;
943+
}
944+
HotSpotResolvedObjectType constantType = objectConstant.getType();
945+
if (isGraalClass(receiverType) && !isGraalClass(constantType)) {
946+
// Assumes that only a Graal class can subtype a Graal class.
947+
return false;
948+
}
949+
return receiverType.isAssignableFrom(constantType);
950+
}
924951
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/proxy/HotSpotResolvedJavaTypeProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public final boolean isAssignableFrom(ResolvedJavaType other) {
241241
return (boolean) handle(isAssignableFromMethod, isAssignableFromInvokable, other);
242242
}
243243

244-
private static final SymbolicMethod isInstanceMethod = method("isInstance", JavaConstant.class);
244+
public static final SymbolicMethod isInstanceMethod = method("isInstance", JavaConstant.class);
245245
private static final InvokableMethod isInstanceInvokable = (receiver, args) -> ((HotSpotResolvedJavaType) receiver).isInstance((JavaConstant) args[0]);
246246

247247
@Override

0 commit comments

Comments
 (0)