Skip to content

Commit

Permalink
Merge pull request #2 from JornVernee/No_JNI_Comments_v2
Browse files Browse the repository at this point in the history
Address Coleen's review comments on "Don't use JNI when generating native wrappers"
  • Loading branch information
mcimadamore authored Oct 22, 2020
2 parents 21f5087 + fb355ad commit 0c89229
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/cpu/aarch64/foreign_globals_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool ABIDescriptor::is_volatile_reg(FloatRegister reg) const {
#define INTEGER_TYPE 0
#define VECTOR_TYPE 1

const ABIDescriptor ForeignGlobals::parseABIDescriptor_impl(jobject jabi) const {
const ABIDescriptor ForeignGlobals::parse_abi_descriptor_impl(jobject jabi) const {
oop abi_oop = JNIHandles::resolve_non_null(jabi);
ABIDescriptor abi;

Expand All @@ -64,7 +64,7 @@ const ABIDescriptor ForeignGlobals::parseABIDescriptor_impl(jobject jabi) const
return abi;
}

const BufferLayout ForeignGlobals::parseBufferLayout_impl(jobject jlayout) const {
const BufferLayout ForeignGlobals::parse_buffer_layout_impl(jobject jlayout) const {
oop layout_oop = JNIHandles::resolve_non_null(jlayout);
BufferLayout layout;

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/aarch64/universalNativeInvoker_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class ProgrammableInvokerGenerator : public StubCodeGenerator {

jlong ProgrammableInvoker::generate_adapter(jobject jabi, jobject jlayout) {
ResourceMark rm;
const ABIDescriptor abi = ForeignGlobals::parseABIDescriptor(jabi);
const BufferLayout layout = ForeignGlobals::parseBufferLayout(jlayout);
const ABIDescriptor abi = ForeignGlobals::parse_abi_descriptor(jabi);
const BufferLayout layout = ForeignGlobals::parse_buffer_layout(jlayout);

BufferBlob* _invoke_native_blob = BufferBlob::create("invoke_native_blob", native_invoker_size);

Expand Down
14 changes: 4 additions & 10 deletions src/hotspot/cpu/aarch64/universalUpcallHandler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ static void upcall_helper(jobject rec, address buff) {
&args, thread);
}

static address generate_upcall_stub(jobject rec, const ABIDescriptor& abi,
const BufferLayout& layout) {
addres ProgrammableUpcallHandler::generate_upcall_stub(jobject rec, jobject jabi, jobject jlayout) {
ResourceMark rm;
const ABIDescriptor abi = ForeignGlobals::parse_abi_descriptor(jabi);
const BufferLayout layout = ForeignGlobals::parse_buffer_layout(jlayout);

CodeBuffer buffer("upcall_stub", 1024, upcall_stub_size);

MacroAssembler* _masm = new MacroAssembler(&buffer);
Expand Down Expand Up @@ -183,11 +185,3 @@ static address generate_upcall_stub(jobject rec, const ABIDescriptor& abi,

return blob->code_begin();
}

jlong ProgrammableUpcallHandler::generate_upcall_stub(jobject rec, jobject jabi, jobject jlayout) {
ResourceMark rm;
const ABIDescriptor abi = ForeignGlobals::parseABIDescriptor(jabi);
const BufferLayout layout = ForeignGlobals::parseBufferLayout(jlayout);

return (jlong) ::generate_upcall_stub(rec, abi, layout);
}
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/foreign_globals_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool ABIDescriptor::is_volatile_reg(XMMRegister reg) const {
#define VECTOR_TYPE 1
#define X87_TYPE 2

const ABIDescriptor ForeignGlobals::parseABIDescriptor_impl(jobject jabi) const {
const ABIDescriptor ForeignGlobals::parse_abi_descriptor_impl(jobject jabi) const {
oop abi_oop = JNIHandles::resolve_non_null(jabi);
ABIDescriptor abi;

Expand All @@ -66,7 +66,7 @@ const ABIDescriptor ForeignGlobals::parseABIDescriptor_impl(jobject jabi) const
return abi;
}

const BufferLayout ForeignGlobals::parseBufferLayout_impl(jobject jlayout) const {
const BufferLayout ForeignGlobals::parse_buffer_layout_impl(jobject jlayout) const {
oop layout_oop = JNIHandles::resolve_non_null(jlayout);
BufferLayout layout;

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/universalNativeInvoker_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ class ProgrammableInvokerGenerator : public StubCodeGenerator {

jlong ProgrammableInvoker::generate_adapter(jobject jabi, jobject jlayout) {
ResourceMark rm;
const ABIDescriptor abi = ForeignGlobals::parseABIDescriptor(jabi);
const BufferLayout layout = ForeignGlobals::parseBufferLayout(jlayout);
const ABIDescriptor abi = ForeignGlobals::parse_abi_descriptor(jabi);
const BufferLayout layout = ForeignGlobals::parse_buffer_layout(jlayout);

BufferBlob* _invoke_native_blob = BufferBlob::create("invoke_native_blob", native_invoker_size);

Expand Down
13 changes: 4 additions & 9 deletions src/hotspot/cpu/x86/universalUpcallHandler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ static void upcall_helper(jobject rec, address buff) {
JavaCalls::call_static(&result, upcall_info.upcall_method.klass, upcall_info.upcall_method.name, upcall_info.upcall_method.sig, &args, thread);
}

static address generate_upcall_stub(jobject rec, const ABIDescriptor& abi, const BufferLayout& layout) {
address ProgrammableUpcallHandler::generate_upcall_stub(jobject rec, jobject jabi, jobject jlayout) {
ResourceMark rm;
const ABIDescriptor abi = ForeignGlobals::parse_abi_descriptor(jabi);
const BufferLayout layout = ForeignGlobals::parse_buffer_layout(jlayout);

CodeBuffer buffer("upcall_stub", 1024, upcall_stub_size);

MacroAssembler* _masm = new MacroAssembler(&buffer);
Expand Down Expand Up @@ -235,11 +238,3 @@ static address generate_upcall_stub(jobject rec, const ABIDescriptor& abi, const

return blob->code_begin();
}

jlong ProgrammableUpcallHandler::generate_upcall_stub(jobject rec, jobject jabi, jobject jlayout) {
ResourceMark rm;
const ABIDescriptor abi = ForeignGlobals::parseABIDescriptor(jabi);
const BufferLayout layout = ForeignGlobals::parseBufferLayout(jlayout);

return (jlong) ::generate_upcall_stub(rec, abi, layout);
}
16 changes: 8 additions & 8 deletions src/hotspot/share/prims/foreign_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@

#define FOREIGN_ABI "jdk/internal/foreign/abi/"

int ForeignGlobals::field_offset(InstanceKlass* cls, const char* fieldname, Symbol* sigsym) {
Symbol* fieldnamesym = SymbolTable::new_symbol(fieldname, (int)strlen(fieldname));
static int field_offset(InstanceKlass* cls, const char* fieldname, Symbol* sigsym) {
TempNewSymbol fieldnamesym = SymbolTable::new_symbol(fieldname, (int)strlen(fieldname));
fieldDescriptor fd;
bool success = cls->find_field(fieldnamesym, sigsym, false, &fd);
assert(success, "Field not found");
return fd.offset();
}

InstanceKlass* ForeignGlobals::find_InstanceKlass(const char* name, TRAPS) {
Symbol* sym = SymbolTable::new_symbol(name, (int)strlen(name));
static InstanceKlass* find_InstanceKlass(const char* name, TRAPS) {
TempNewSymbol sym = SymbolTable::new_symbol(name, (int)strlen(name));
Klass* k = SystemDictionary::resolve_or_null(sym, Handle(), Handle(), THREAD);
assert(k != nullptr, "Can not find class: %s", name);
return InstanceKlass::cast(k);
Expand All @@ -51,11 +51,11 @@ const ForeignGlobals& ForeignGlobals::instance() {
return globals;
}

const ABIDescriptor ForeignGlobals::parseABIDescriptor(jobject jabi) {
return instance().parseABIDescriptor_impl(jabi);
const ABIDescriptor ForeignGlobals::parse_abi_descriptor(jobject jabi) {
return instance().parse_abi_descriptor_impl(jabi);
}
const BufferLayout ForeignGlobals::parseBufferLayout(jobject jlayout) {
return instance().parseBufferLayout_impl(jlayout);
const BufferLayout ForeignGlobals::parse_buffer_layout(jobject jlayout) {
return instance().parse_buffer_layout_impl(jlayout);
}

ForeignGlobals::ForeignGlobals() {
Expand Down
11 changes: 4 additions & 7 deletions src/hotspot/share/prims/foreign_globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,11 @@ class ForeignGlobals {
template<typename T, typename Func>
void loadArray(objArrayOop jarray, int type_index, GrowableArray<T>& array, Func converter) const;

int field_offset(InstanceKlass* cls, const char* fieldname, Symbol* sigsym);
InstanceKlass* find_InstanceKlass(const char* name, TRAPS);

const ABIDescriptor parseABIDescriptor_impl(jobject jabi) const;
const BufferLayout parseBufferLayout_impl(jobject jlayout) const;
const ABIDescriptor parse_abi_descriptor_impl(jobject jabi) const;
const BufferLayout parse_buffer_layout_impl(jobject jlayout) const;
public:
static const ABIDescriptor parseABIDescriptor(jobject jabi);
static const BufferLayout parseBufferLayout(jobject jlayout);
static const ABIDescriptor parse_abi_descriptor(jobject jabi);
static const BufferLayout parse_buffer_layout(jobject jlayout);
};

#endif // SHARE_PRIMS_FOREIGN_GLOBALS
8 changes: 4 additions & 4 deletions src/hotspot/share/prims/nativeEntryPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include "runtime/interfaceSupport.inline.hpp"
#include "code/vmreg.hpp"

JVM_LEAF(jlong, NEP_vmStorageToVMReg(JNIEnv* env, jclass _unused, jint type, jint index))
JNI_LEAF(jlong, NEP_vmStorageToVMReg(JNIEnv* env, jclass _unused, jint type, jint index))
return VMRegImpl::vmStorageToVMReg(type, index)->value();
JVM_END
JNI_END

#define CC (char*) /*cast a literal from (const char*)*/
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
Expand All @@ -37,8 +37,8 @@ static JNINativeMethod NEP_methods[] = {
{CC "vmStorageToVMReg", CC "(II)J", FN_PTR(NEP_vmStorageToVMReg)},
};

JVM_LEAF(void, JVM_RegisterNativeEntryPointMethods(JNIEnv *env, jclass NEP_class))
JNI_LEAF(void, JVM_RegisterNativeEntryPointMethods(JNIEnv *env, jclass NEP_class))
int status = env->RegisterNatives(NEP_class, NEP_methods, sizeof(NEP_methods)/sizeof(JNINativeMethod));
guarantee(status == JNI_OK && !env->ExceptionOccurred(),
"register jdk.internal.invoke.NativeEntryPoint natives");
JVM_END
JNI_END
12 changes: 6 additions & 6 deletions src/hotspot/share/prims/universalNativeInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ void ProgrammableInvoker::invoke_native(ProgrammableStub stub, address buff, Jav
assert(thread->thread_state() == _thread_in_vm, "thread state is: %d", thread->thread_state());
}

JVM_ENTRY(void, PI_invokeNative(JNIEnv* env, jclass _unused, jlong adapter_stub, jlong buff))
JNI_ENTRY(void, PI_invokeNative(JNIEnv* env, jclass _unused, jlong adapter_stub, jlong buff))
assert(thread->thread_state() == _thread_in_vm, "thread state is: %d", thread->thread_state());
ProgrammableStub stub = (ProgrammableStub) adapter_stub;
address c = (address) buff;
ProgrammableInvoker::invoke_native(stub, c, thread);
JVM_END
JNI_END

JVM_ENTRY(jlong, PI_generateAdapter(JNIEnv* env, jclass _unused, jobject abi, jobject layout))
JNI_ENTRY(jlong, PI_generateAdapter(JNIEnv* env, jclass _unused, jobject abi, jobject layout))
return ProgrammableInvoker::generate_adapter(abi, layout);
JVM_END
JNI_END

#define CC (char*) /*cast a literal from (const char*)*/
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
Expand All @@ -60,8 +60,8 @@ static JNINativeMethod PI_methods[] = {
{CC "generateAdapter", CC "(" FOREIGN_ABI "/ABIDescriptor;" FOREIGN_ABI "/BufferLayout;" ")J", FN_PTR(PI_generateAdapter)}
};

JVM_LEAF(void, JVM_RegisterProgrammableInvokerMethods(JNIEnv *env, jclass PI_class))
JNI_LEAF(void, JVM_RegisterProgrammableInvokerMethods(JNIEnv *env, jclass PI_class))
int status = env->RegisterNatives(PI_class, PI_methods, sizeof(PI_methods)/sizeof(JNINativeMethod));
guarantee(status == JNI_OK && !env->ExceptionOccurred(),
"register jdk.internal.foreign.abi.programmable.ProgrammableInvoker natives");
JVM_END
JNI_END
10 changes: 5 additions & 5 deletions src/hotspot/share/prims/universalUpcallHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
#include "runtime/jniHandles.inline.hpp"
#include "runtime/interfaceSupport.inline.hpp"

JVM_ENTRY(jlong, PUH_AllocateUpcallStub(JNIEnv *env, jobject rec, jobject abi, jobject buffer_layout))
JNI_ENTRY(jlong, PUH_AllocateUpcallStub(JNIEnv *env, jobject rec, jobject abi, jobject buffer_layout))
Handle receiver(THREAD, JNIHandles::resolve(rec));
jobject global_rec = JNIHandles::make_global(receiver);
return ProgrammableUpcallHandler::generate_upcall_stub(global_rec, abi, buffer_layout);
JVM_END
return (jlong) ProgrammableUpcallHandler::generate_upcall_stub(global_rec, abi, buffer_layout);
JNI_END

#define CC (char*) /*cast a literal from (const char*)*/
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
Expand All @@ -45,8 +45,8 @@ static JNINativeMethod PUH_methods[] = {
/**
* This one function is exported, used by NativeLookup.
*/
JVM_LEAF(void, JVM_RegisterProgrammableUpcallHandlerMethods(JNIEnv *env, jclass PUH_class))
JNI_LEAF(void, JVM_RegisterProgrammableUpcallHandlerMethods(JNIEnv *env, jclass PUH_class))
int status = env->RegisterNatives(PUH_class, PUH_methods, sizeof(PUH_methods)/sizeof(JNINativeMethod));
guarantee(status == JNI_OK && !env->ExceptionOccurred(),
"register jdk.internal.foreign.abi.ProgrammableUpcallHandler natives");
JVM_END
JNI_END
2 changes: 1 addition & 1 deletion src/hotspot/share/prims/universalUpcallHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

class ProgrammableUpcallHandler : AllStatic {
public:
static jlong generate_upcall_stub(jobject rec, jobject abi, jobject buffer_layout);
static address generate_upcall_stub(jobject rec, jobject abi, jobject buffer_layout);
};

#endif // SHARE_VM_PRIMS_UNIVERSALUPCALLHANDLER_HPP

0 comments on commit 0c89229

Please sign in to comment.