Skip to content
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

8310628: GcInfoBuilder.c missing JNI Exception checks #14613

Closed

Conversation

kevinjwalls
Copy link
Contributor

@kevinjwalls kevinjwalls commented Jun 22, 2023

JNI calls were identified, where we do not check for a pending Exception afterwards.

(JDK-8162530 cleaned up up some of these kind of issues some years back, but more were found.)

I tested a code change to manually create an Exception before some of the new ExceptionCheck calls, and this is correctly recognised, we see an Exception thrown by the native getLastGcInfo0, e.g.

java.lang.NullPointerException: XXX Test Exception
at jdk.management/com.sun.management.internal.GcInfoBuilder.getLastGcInfo0(Native Method)
at jdk.management/com.sun.management.internal.GcInfoBuilder.getLastGcInfo(GcInfoBuilder.java:77)
at jdk.management/com.sun.management.internal.GarbageCollectorExtImpl.getLastGcInfo(GarbageCollectorExtImpl.java:69)
at LastGCInfo.main(LastGCInfo.java:53)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
at java.base/java.lang.Thread.run(Thread.java:1570)

Tested with all of test/jdk/com/sun/management including test/jdk/com/sun/management/GarbageCollectorMXBean/LastGCInfo.java


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-8310628: GcInfoBuilder.c missing JNI Exception checks (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14613

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 22, 2023

👋 Welcome back kevinw! 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

openjdk bot commented Jun 22, 2023

@kevinjwalls The following labels will be automatically applied to this pull request:

  • jmx
  • serviceability

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added serviceability serviceability-dev@openjdk.org jmx jmx-dev@openjdk.org labels Jun 22, 2023
@kevinjwalls kevinjwalls marked this pull request as ready for review June 22, 2023 11:06
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 22, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 22, 2023

Webrevs

Copy link
Member

@mlchung mlchung left a comment

Choose a reason for hiding this comment

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

Looks fine. It may worth refactoring the code to set an element in an utility method.

    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
    if ((*env)->ExceptionCheck(env)) {
        return;
    }
    (*env)->SetObjectArrayElement(env, array, index, obj);

@kevinjwalls
Copy link
Contributor Author

Looks fine. It may worth refactoring the code to set an element in an utility method.

    jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
    if ((*env)->ExceptionCheck(env)) {
        return;
    }
    (*env)->SetObjectArrayElement(env, array, index, obj);

Thanks Mandy,

I would suggest to just do this simple change as it seems most likely to be correct. We are here because a tool found the missing exception checks, not because this code is looked at by people frequently. I think the common helper method might be more complex than what we have here.

This file rarely changes, these methods here haven't changed in forever.
There was the previous JNI exception change in this file in 2017, affecting other methods.
There are a couple of other changes in the file, also affecting other methods, and then it's the initial load in jdk8 in 2007 and probably they are the same before that.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Seems fine to me.

Thanks.

@openjdk
Copy link

openjdk bot commented Jun 23, 2023

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

8310628: GcInfoBuilder.c missing JNI Exception checks

Reviewed-by: mchung, dholmes

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 16 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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 23, 2023
@kevinjwalls
Copy link
Contributor Author

Thanks David and Mandy for the Reviews!

@kevinjwalls
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 23, 2023

Going to push as commit a9c0a0f.
Since your change was applied there have been 17 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 23, 2023
@openjdk openjdk bot closed this Jun 23, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 23, 2023
@openjdk
Copy link

openjdk bot commented Jun 23, 2023

@kevinjwalls Pushed as commit a9c0a0f.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated jmx jmx-dev@openjdk.org serviceability serviceability-dev@openjdk.org
3 participants