|
30 | 30 | import static jdk.graal.compiler.bytecode.Bytecodes.INVOKESPECIAL;
|
31 | 31 | import static jdk.graal.compiler.bytecode.Bytecodes.INVOKESTATIC;
|
32 | 32 | import static jdk.graal.compiler.bytecode.Bytecodes.INVOKEVIRTUAL;
|
| 33 | +import static jdk.graal.compiler.hotspot.HotSpotReplacementsImpl.isGraalClass; |
33 | 34 | import static jdk.graal.compiler.java.StableMethodNameFormatter.isMethodHandle;
|
34 | 35 |
|
35 | 36 | import java.lang.reflect.Proxy;
|
|
48 | 49 | import jdk.graal.compiler.core.common.CompilerProfiler;
|
49 | 50 | import jdk.graal.compiler.debug.DebugContext;
|
50 | 51 | import jdk.graal.compiler.debug.GraalError;
|
| 52 | +import jdk.graal.compiler.hotspot.meta.HotSpotGraalConstantFieldProvider; |
51 | 53 | import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxy;
|
52 | 54 | import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxyBase;
|
53 | 55 | import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilerProfilerProxy;
|
|
66 | 68 | import jdk.graal.compiler.hotspot.replaycomp.proxy.SignatureProxy;
|
67 | 69 | import jdk.graal.compiler.hotspot.replaycomp.proxy.SpeculationLogProxy;
|
68 | 70 | import jdk.graal.compiler.java.LambdaUtils;
|
| 71 | +import jdk.graal.compiler.options.ExcludeFromJacocoGeneratedReport; |
69 | 72 | import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
|
70 | 73 | import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
|
71 | 74 | import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
|
@@ -703,6 +706,7 @@ public static CompilerInterfaceDeclarations build() {
|
703 | 706 | }
|
704 | 707 | return List.of();
|
705 | 708 | })
|
| 709 | + .setFallbackInvocationHandler(HotSpotResolvedObjectTypeProxy.isInstanceMethod, CompilerInterfaceDeclarations::objectTypeIsInstanceFallback) |
706 | 710 | .register(declarations);
|
707 | 711 | // Must come after HotSpotResolvedObjectType. Needed for HotSpotResolvedPrimitiveType.
|
708 | 712 | new RegistrationBuilder<>(HotSpotResolvedJavaType.class)
|
@@ -921,4 +925,27 @@ private static ResolvedJavaType javaLangObjectSupplier(Object proxy, Compilation
|
921 | 925 | MetaAccessProvider metaAccess = (MetaAccessProvider) singletonObjects.get(MetaAccessProvider.class);
|
922 | 926 | return metaAccess.lookupJavaType(Object.class);
|
923 | 927 | }
|
| 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 | + } |
924 | 951 | }
|
0 commit comments