-
Notifications
You must be signed in to change notification settings - Fork 936
Avoid JVM crash by deleting JNI refs after calling GetMethodDeclaringClass #981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/flightRecorder.cpp
Outdated
} | ||
|
||
jvmtiEnv* jvmti = VM::jvmti(); | ||
JNIEnv* jni = VM::jni(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VM::jni()
is not an expensive call, but it's not free either - not a trivial getter like VM::jvmti()
.
So, I'd create JNIEnv*
once in Lookup
constructor and cache it as a field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, cached JNIEnv
.
src/frameName.cpp
Outdated
char* method_sig = NULL; | ||
|
||
jvmtiEnv* jvmti = VM::jvmti(); | ||
JNIEnv* jni = VM::jni(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above: obtain JNIEnv*
once in FrameName
constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cached as above.
fe2f917
to
340786f
Compare
_thread_names_lock(thread_names_lock), | ||
_thread_names(thread_names) | ||
_thread_names(thread_names), | ||
_jni(VM::jni()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be the same problem with native apps as above.
I suggest simply returning NULL
from VM::jni()
if _vm == NULL
.
} | ||
|
||
if (method_class) { | ||
_jni->DeleteLocalRef(method_class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @krk ,
After investigating why the call to DeleteLocalRef
is added here(cannot completely fix the problem), I think we can fix the problem in OpenJDK upstream.
Do you plan to fix it? If not, we will file an issue at OpenJDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created a backport into 17 for JDK-8268364 at openjdk/jdk17u-dev#2839. Do you propose a different fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you propose a different fix?
If I understand correctly, the call to 'DeleteLocalRef' here is to reduce the possibility of a crash. That crash is actually a bug in JDK and not fixed by JDK-8268364. So we should file a new issue in OpenJDK to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@D-D-H You are right: DeleteLocalRef
is a cheap way to significantly decrease possibility of a crash, but fixing the root cause in OpenJDK is still highly desirable. I think it makes sense to integrate this change anyway, before the proper fix is released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My colleague Liang created an issue for this problem:
Issue: https://bugs.openjdk.org/browse/JDK-8339725
PR: https://git.openjdk.org/jdk/pull/20907
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks!
I ran the reproducer. The stack trace in The crash in #974 on These are two different issues and need to be treated differently.
Am i right ? |
Yes, there are two crashes, but they are both parts of the same issue. |
This is a partial fix, complementing JDK-8268364.
This is a partial fix for #974, complementing JDK-8268364.
How has this been tested?
Backported JDK-8268364 into Java 17 and tested with reproducer at gist: