Skip to content

8316439: Several jvmti tests fail with -Xcheck:jni#30711

Open
shivshah-oracle wants to merge 1 commit intoopenjdk:masterfrom
shivshah-oracle:JDK-8316439-xcheck-jni
Open

8316439: Several jvmti tests fail with -Xcheck:jni#30711
shivshah-oracle wants to merge 1 commit intoopenjdk:masterfrom
shivshah-oracle:JDK-8316439-xcheck-jni

Conversation

@shivshah-oracle
Copy link
Copy Markdown
Contributor

@shivshah-oracle shivshah-oracle commented Apr 13, 2026

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8316439: Several jvmti tests fail with -Xcheck:jni (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30711/head:pull/30711
$ git checkout pull/30711

Update a local copy of the PR:
$ git checkout pull/30711
$ git pull https://git.openjdk.org/jdk.git pull/30711/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30711

View PR using the GUI difftool:
$ git pr show -t 30711

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30711.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 13, 2026

👋 Welcome back shivshah-oracle! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 13, 2026

@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:

8316439: Several jvmti tests fail with -Xcheck:jni

Reviewed-by: cjplummer, epavlova, lmesnik, sspitsyn

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 master branch:

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 /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the serviceability serviceability-dev@openjdk.org label Apr 13, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 13, 2026

@shivshah-oracle The following label will be automatically applied to this pull request:

  • serviceability

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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 13, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 13, 2026

Webrevs

@@ -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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this just end up getting an exception that we never handle anywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 13, 2026
@katyapav
Copy link
Copy Markdown
Member

The fix looks good, all nsk/jvmti and nsk/aod tests passed on linux, windows and macos, approve.

Comment on lines +116 to +117
if (jni->ExceptionCheck()) {
jni->ExceptionClear();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@sspitsyn sspitsyn Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +130 to +131
if (jni->ExceptionCheck()) {
jni->ExceptionClear();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Copy Markdown
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good modulo a suggestion from David.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

6 participants