Skip to content

Commit

Permalink
new jni getContextFast
Browse files Browse the repository at this point in the history
  • Loading branch information
weixlu committed Jul 8, 2024
1 parent 66495b3 commit d91872e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions make/hotspot/symbols/symbols-unix
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ JVM_GetProtectionDomain
JVM_GetProxyUnpark
JVM_GetSimpleBinaryName
JVM_GetStackAccessControlContext
Java_com_alibaba_sparklib_Library_getContextFast
JVM_GetSystemPackage
JVM_GetSystemPackages
JVM_GetTemporaryDirectory
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/include/jvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@ JVM_DoPrivileged(JNIEnv *env, jclass cls,
JNIEXPORT jobject JNICALL
JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls);

JNIEXPORT jobject JNICALL
Java_com_alibaba_sparklib_Library_getContextFast(JNIEnv *env, jclass cls);

JNIEXPORT jobject JNICALL
JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls);

Expand Down
23 changes: 23 additions & 0 deletions src/hotspot/share/prims/jvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,29 @@ class RegisterArrayForGC {
}
};

JVM_ENTRY(jobject, Java_com_alibaba_sparklib_Library_getContextFast(JNIEnv *env, jclass cls))
JVMWrapper("Java_com_alibaba_sparklib_Library_getContextFast");

Handle privileged_context(thread, NULL);
if (thread->privileged_stack_top()) {
intptr_t* privileged_frame_id = thread->privileged_stack_top()->frame_id();
vframeStream vfst(thread);
for(; !vfst.at_end(); vfst.next()) {
if (privileged_frame_id == vfst.frame_id()) {
privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context());
if (privileged_context.is_null()) {
oop dummy = java_security_AccessControlContext::create(objArrayHandle(), true, Handle(thread, NULL), CHECK_NULL);
privileged_context = Handle(thread, dummy);
}
break;
}
}
}

oop result = privileged_context.not_null() ? privileged_context() :
java_lang_Thread::inherited_access_control_context(thread->threadObj());
return JNIHandles::make_local(env, result);
JVM_END

JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls))
JVMWrapper("JVM_GetStackAccessControlContext");
Expand Down

0 comments on commit d91872e

Please sign in to comment.