Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Changed signature of createJNITrampoline to use computed index instea…
Browse files Browse the repository at this point in the history
…d of nonVirtual boolean. Removed comments about broken feature in sub methods
  • Loading branch information
Zeavee committed Feb 21, 2022
1 parent 71723e0 commit 1988cb7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public BasePhase<CoreProviders> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public static int getNewThreadStatus(CallTargetNode callTarget) {

public abstract BasePhase<CoreProviders> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand Down

0 comments on commit 1988cb7

Please sign in to comment.