8316439: Several jvmti tests fail with -Xcheck:jni#30711
8316439: Several jvmti tests fail with -Xcheck:jni#30711shivshah-oracle wants to merge 1 commit intoopenjdk:masterfrom
Conversation
|
👋 Welcome back shivshah-oracle! A progress list of the required criteria for merging this PR into |
|
@shivshah-oracle This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 219 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@plummercj, @katyapav, @lmesnik, @dholmes-ora, @sspitsyn) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
@shivshah-oracle The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
| @@ -191,7 +194,7 @@ Java_nsk_jvmti_PopFrame_popframe007_getRes(JNIEnv *env, jclass cls) { | |||
| JNIEXPORT void JNICALL | |||
| Java_nsk_jvmti_PopFrame_popframe007_B(JNIEnv *env, jclass cls) { | |||
| if (mid != nullptr) { | |||
| env->CallStaticVoidMethod(cls, mid); | |||
| env->CallStaticVoidMethod(testThreadClass, mid); | |||
There was a problem hiding this comment.
Did this just end up getting an exception that we never handle anywhere?
There was a problem hiding this comment.
On debug builds with -Xcheck:jni, it catches the class/method ID mismatch and aborts with a fatal error before the call even executes. Without -Xcheck:jni, the behavior is undefined per the JNI spec. It could silently leave a pending exception or produce incorrect results.
|
The fix looks good, all nsk/jvmti and nsk/aod tests passed on linux, windows and macos, approve. |
| if (jni->ExceptionCheck()) { | ||
| jni->ExceptionClear(); |
There was a problem hiding this comment.
If this code returns to Java (I can't tell easily) then we should not clear the exception. Otherwise we should use ExceptionDescribe as you do below so that we know that something has gone wrong in the test.
There was a problem hiding this comment.
If this code returns to Java (I can't tell easily) then we should not clear the exception.
It is in the ClassFileLoadHook callback (posting a CFLH event), so this code should eventually return to Java. Was the original error reported by -Xcheck:jni that the exception has not been cleared?
Update:
This is an assert:
# assert(!_thread->is_pending_jni_exception_check()) failed: Pending JNI Exception Check
class ThreadToNativeFromVM : public ThreadStateTransition {
public:
ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
assert(!thread->owns_locks(), "must release all locks when leaving VM");
transition_from_vm(thread, _thread_in_native);
}
~ThreadToNativeFromVM() {
transition_from_native(_thread, _thread_in_vm);
assert(!_thread->is_pending_jni_exception_check(), "Pending JNI Exception Check"); **<== HERE!!!**
// We don't need to clear_walkable because it will happen automagically when we return to java
}
};
So, the transition is from native to VM first. It is where we do not except pending exceptions with -Xcheck:jni. So, we probably should use ExceptionDescribe as you suggested.
| if (jni->ExceptionCheck()) { | ||
| jni->ExceptionClear(); |
sspitsyn
left a comment
There was a problem hiding this comment.
Looks good modulo a suggestion from David.
Fixed three test files that fail with -Xcheck:jni on debug builds:
popframe007.cpp: CallStaticVoidMethod in native B() was called with the declaring class (popframe007) instead of TestThread where the method ID belongs. Stored TestThread class as a global ref in getReady() and used it in B()
aod.cpp: nsk_aod_agentLoaded() and nsk_aod_agentFinished() call CallStaticVoidMethod without checking for pending exceptions. Added nsk_aod_checkJNIException wrapper that describes, clears, and fails on unexpected exceptions. Fixes all 13 AttachOnDemand tests
retransform003.cpp: ClassFileLoadHook callback calls CallObjectMethod and CallStaticObjectMethod without checking for pending exceptions. Added ExceptionCheck/ExceptionClear after both calls
bi02t001 and bi03t001 pass without changes, NMT corruption issue from JDK 22 appears resolved on JDK 27
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30711/head:pull/30711$ git checkout pull/30711Update a local copy of the PR:
$ git checkout pull/30711$ git pull https://git.openjdk.org/jdk.git pull/30711/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 30711View PR using the GUI difftool:
$ git pr show -t 30711Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30711.diff
Using Webrev
Link to Webrev Comment