From 1988cb7a9e355fe80664f2308886b35f765aed6e Mon Sep 17 00:00:00 2001 From: Sacha Coppey Date: Mon, 21 Feb 2022 10:50:39 +0100 Subject: [PATCH] Changed signature of createJNITrampoline to use computed index instead of nonVirtual boolean. Removed comments about broken feature in sub methods --- .../svm/core/graal/aarch64/SubstrateAArch64Backend.java | 6 ++---- .../svm/core/graal/amd64/SubstrateAMD64Backend.java | 6 ++---- .../src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java | 8 ++++---- .../oracle/svm/core/graal/llvm/SubstrateLLVMBackend.java | 6 +++--- .../com/oracle/svm/core/graal/code/SubstrateBackend.java | 4 ++-- .../oracle/svm/jni/hosted/JNICallTrampolineMethod.java | 2 +- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64Backend.java b/substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64Backend.java index 30e28b83056..3d3e78e4eef 100755 --- a/substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64Backend.java +++ b/substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64Backend.java @@ -1053,16 +1053,14 @@ public RegisterAllocationConfig newRegisterAllocationConfig(RegisterConfig regis @Override public CompilationResult createJNITrampolineMethod(ResolvedJavaMethod method, CompilationIdentifier identifier, - int threadIsolateOffset, boolean nonVirtual, int methodObjEntryPointOffset, + int threadIdIndex, int threadIsolateOffset, int methodIdIndex, int methodObjEntryPointOffset, CallingConvention callingConvention) { RegisterValue threadArg = null; if (SubstrateOptions.SpawnIsolates.getValue()) { threadArg = (RegisterValue) callingConvention.getArgument(0); // JNIEnv - // NOTE: GR-17030: JNI is currently broken in the single-threaded, multi-isolate - // case. Fixing this also requires changes to how trampolines are generated. } - RegisterValue methodIdArg = (RegisterValue) callingConvention.getArgument(nonVirtual ? 3 : 2); + RegisterValue methodIdArg = (RegisterValue) callingConvention.getArgument(methodIdIndex); CompilationResult result = new CompilationResult(identifier); AArch64MacroAssembler asm = new AArch64MacroAssembler(getTarget()); diff --git a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java index 25eb00ac0c4..fd9b73a3d89 100644 --- a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java +++ b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java @@ -1155,15 +1155,13 @@ public void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod i @Override public CompilationResult createJNITrampolineMethod(ResolvedJavaMethod method, CompilationIdentifier identifier, - int threadIsolateOffset, boolean nonVirtual, int methodObjEntryPointOffset, CallingConvention callingConvention) { + int threadIdIndex, int threadIsolateOffset, int methodIdIndex, int methodObjEntryPointOffset, CallingConvention callingConvention) { RegisterValue threadArg = null; if (SubstrateOptions.SpawnIsolates.getValue()) { threadArg = (RegisterValue) callingConvention.getArgument(0); // JNIEnv - // NOTE: GR-17030: JNI is currently broken in the single-threaded, multi-isolate - // case. Fixing this also requires changes to how trampolines are generated. } - RegisterValue methodIdArg = (RegisterValue) callingConvention.getArgument(nonVirtual ? 3 : 2); + RegisterValue methodIdArg = (RegisterValue) callingConvention.getArgument(methodIdIndex); CompilationResult result = new CompilationResult(identifier); AMD64Assembler asm = new AMD64Assembler(getTarget()); diff --git a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java index 4b91669b9f2..775d5062b5f 100644 --- a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java +++ b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/LLVMGenerator.java @@ -1016,7 +1016,7 @@ LLVMValueRef createJNIWrapper(LLVMValueRef callee, boolean nativeABI, int numArg return transitionWrapper; } - void createJNITrampoline(int threadIsolateOffset, int methodIdArg, int methodObjEntryPointOffset) { + void createJNITrampoline(int threadIdIndex, int threadIsolateOffset, int methodIdIndex, int methodObjEntryPointOffset) { builder.setFunctionAttribute(Attribute.Naked); LLVMBasicBlockRef block = builder.appendBasicBlock("main"); @@ -1028,14 +1028,14 @@ void createJNITrampoline(int threadIsolateOffset, int methodIdArg, int methodObj LLVMValueRef jumpAddressAddress; if (SubstrateOptions.SpawnIsolates.getValue()) { - LLVMValueRef thread = builder.getFunctionParam(0); + LLVMValueRef thread = builder.getFunctionParam(threadIdIndex); LLVMValueRef heapBaseAddress = builder.buildGEP(builder.buildIntToPtr(thread, builder.rawPointerType()), builder.constantInt(threadIsolateOffset)); LLVMValueRef heapBase = builder.buildLoad(heapBaseAddress, builder.rawPointerType()); - LLVMValueRef methodId = builder.getFunctionParam(methodIdArg); + LLVMValueRef methodId = builder.getFunctionParam(methodIdIndex); LLVMValueRef methodBase = builder.buildGEP(builder.buildIntToPtr(heapBase, builder.rawPointerType()), builder.buildPtrToInt(methodId)); jumpAddressAddress = builder.buildGEP(methodBase, builder.constantInt(methodObjEntryPointOffset)); } else { - LLVMValueRef methodBase = builder.getFunctionParam(methodIdArg); + LLVMValueRef methodBase = builder.getFunctionParam(methodIdIndex); jumpAddressAddress = builder.buildGEP(builder.buildIntToPtr(methodBase, builder.rawPointerType()), builder.constantInt(methodObjEntryPointOffset)); } LLVMValueRef jumpAddress = builder.buildLoad(jumpAddressAddress, builder.rawPointerType()); diff --git a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/SubstrateLLVMBackend.java b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/SubstrateLLVMBackend.java index 3832e36a785..e3fcd99afb4 100644 --- a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/SubstrateLLVMBackend.java +++ b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/SubstrateLLVMBackend.java @@ -76,14 +76,14 @@ public BasePhase newAddressLoweringPhase(CodeCacheProvider codeCa } @Override - public CompilationResult createJNITrampolineMethod(ResolvedJavaMethod method, CompilationIdentifier identifier, int threadIsolateOffset, - boolean nonVirtual, int methodObjEntryPointOffset, CallingConvention callingConvention) { + public CompilationResult createJNITrampolineMethod(ResolvedJavaMethod method, CompilationIdentifier identifier, int threadIdIndex, int threadIsolateOffset, + int methodIdIndex, int methodObjEntryPointOffset, CallingConvention callingConvention) { CompilationResult result = new CompilationResult(identifier); result.setMethods(method, Collections.emptySet()); LLVMGenerator generator = new LLVMGenerator(getProviders(), result, null, method, 0); - generator.createJNITrampoline(threadIsolateOffset, nonVirtual ? 3 : 2, methodObjEntryPointOffset); + generator.createJNITrampoline(threadIdIndex, threadIsolateOffset, methodIdIndex, methodObjEntryPointOffset); byte[] bitcode = generator.getBitcode(); result.setTargetCode(bitcode, bitcode.length); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateBackend.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateBackend.java index a22f26fa764..90bdee3076e 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateBackend.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateBackend.java @@ -151,8 +151,8 @@ public static int getNewThreadStatus(CallTargetNode callTarget) { public abstract BasePhase newAddressLoweringPhase(CodeCacheProvider codeCache); - public abstract CompilationResult createJNITrampolineMethod(ResolvedJavaMethod method, CompilationIdentifier identifier, int threadIsolateOffset, - boolean nonVirtual, int methodObjEntryPointOffset, CallingConvention callingConvention); + public abstract CompilationResult createJNITrampolineMethod(ResolvedJavaMethod method, CompilationIdentifier identifier, int threadIdIndex, int threadIsolateOffset, + int methodIdIndex, int methodObjEntryPointOffset, CallingConvention callingConvention); /** * Returns whether the backend can fold the stack overflow check into the method prologue for diff --git a/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNICallTrampolineMethod.java b/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNICallTrampolineMethod.java index ef42fb96301..cbdad2595f9 100644 --- a/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNICallTrampolineMethod.java +++ b/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/hosted/JNICallTrampolineMethod.java @@ -130,7 +130,7 @@ public CompileFunction createCustomCompileFunction() { CallingConvention callingConvention = backend.getCodeCache().getRegisterConfig().getCallingConvention( SubstrateCallingConventionKind.Native.toType(true), returnType, parameters.toArray(new JavaType[0]), backend); - return backend.createJNITrampolineMethod(method, identifier, threadIsolateOffset, nonVirtual, getFieldOffset(providers), callingConvention); + return backend.createJNITrampolineMethod(method, identifier, 0, threadIsolateOffset, nonVirtual ? 3 : 2, getFieldOffset(providers), callingConvention); }; }