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

JDK-8317920: JDWP-agent sends broken exception event with onthrow option #16145

Closed

Conversation

parttimenerd
Copy link
Contributor

@parttimenerd parttimenerd commented Oct 11, 2023

Fix onthrow issue by passing the event info to the initialize method.

This prevents jdb from receiving a broken exception event and throwing an internal NullPointerException, upon attaching to the JDWP-agent.


Progress

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

Issue

  • JDK-8317920: JDWP-agent sends broken exception event with onthrow option (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16145

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 11, 2023

👋 Welcome back jbechberger! 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 openjdk bot added the rfr Pull request is ready for review label Oct 11, 2023
@openjdk
Copy link

openjdk bot commented Oct 11, 2023

@parttimenerd 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 serviceability serviceability-dev@openjdk.org label Oct 11, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 11, 2023

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk
Copy link

openjdk bot commented Oct 11, 2023

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

8317920: JDWP-agent sends broken exception event with onthrow option

Reviewed-by: clanger, cjplummer

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 154 new commits pushed to the master branch:

  • 4812cab: 8316587: Use ArraysSupport.vectorizedHashCode in Utf8EntryImpl
  • bd02cfd: 8318540: make test cannot run .jasm tests directly
  • bd3bc2c: 8317350: Move code cache purging out of CodeCache::UnloadingScope
  • 292aad2: 8316436: ContinuationWrapper uses unhandled nullptr oop
  • 387504c: 8317575: AArch64: C2_MacroAssembler::fast_lock uses rscratch1 for cmpxchg result
  • d9ce525: 8318150: StaticProxySelector.select should not throw NullPointerExceptions
  • c46a54e: 8312777: notifyJvmtiMount before notifyJvmtiUnmount
  • 8f5f440: 8317692: jcmd GC.heap_dump performance regression after JDK-8292818
  • 684b91e: 8315064: j.text.ChoiceFormat provides no specification on quoting behavior
  • 1740950: 8314901: AES-GCM interleaved implementation using AVX2 instructions
  • ... and 144 more: https://git.openjdk.org/jdk/compare/ad7a8e86e0334390f87ae44cf749d2b47f1409a1...master

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 Oct 11, 2023
@plummercj
Copy link
Contributor

/reviewers 2

@plummercj
Copy link
Contributor

Do you have a test case for this?

@openjdk
Copy link

openjdk bot commented Oct 11, 2023

@plummercj
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Oct 11, 2023
@parttimenerd
Copy link
Contributor Author

No. But if neccessary I could write one analogous to the OnJcmdTest, using jdb to check that no NullPointerException occurs in the JDI exception receiving code. This should test the current problem pretty reliably without too much effort.

@plummercj
Copy link
Contributor

It would be good if you could do that. Also, can you provide a backtrace for the NPE in the JBS issue.

@plummercj
Copy link
Contributor

Also, does onthrow ever work, or is it completely broken? If it is completely broken I'd be curious as to when/how this happened.

@parttimenerd
Copy link
Contributor Author

I can confirm that it doesn't work properly in JDK 8, I have to check older JDKs.

But it kind of worked, because it started a debugging session after the specified exception had been thrown. It just didn't send a proper exception event. It's definitely a useful feature.

@plummercj
Copy link
Contributor

So with 8 there is no NPE? Maybe JDI or jdb used to do something different and just swallowed exception event. Seeing the NPE stack trace would help determine what has changed to cause this behavior difference.

@parttimenerd
Copy link
Contributor Author

There is an NPE on JDK 8. The onthrow option doesn't work properly there too. The bug is in the code since it is on GitHub. The stack trace in JDB looks exactly the same in JDK 8 as in JDK 21.

@plummercj
Copy link
Contributor

So when you said "But it kind of worked", you were referring to both JDK 8 and current JDK, and were just pointing out that it did start the debugging session.

I'd still like to see the NPE stack trace.

@parttimenerd
Copy link
Contributor Author

Sorry, I forgot to put the NPE somewhere. Here the NPE of JDB:

Exception in thread "event-handler" java.lang.NullPointerException: Cannot invoke "com.sun.jdi.ObjectReference.referenceType()" because the return value of "com.sun.jdi.event.ExceptionEvent.exception()" is null
        at jdk.jdi/com.sun.tools.example.debug.tty.TTY.exceptionEvent(TTY.java:171)
        at jdk.jdi/com.sun.tools.example.debug.tty.EventHandler.exceptionEvent(EventHandler.java:295)
        at jdk.jdi/com.sun.tools.example.debug.tty.EventHandler.handleEvent(EventHandler.java:133)
        at jdk.jdi/com.sun.tools.example.debug.tty.EventHandler.run(EventHandler.java:78)
        at java.base/java.lang.Thread.run(Thread.java:1583)

@plummercj
Copy link
Contributor

Ok. I think overall the changes look good. I'd still like to see a test. Also, I'd like to see the jdb output after the fix. Maybe include the list output when jdb stops for the exception. It looks like jdb will print the name of the exception object and also the location where it will be caught, and I assume list will show you where it was thrown (although I think if this info is wrong in the ExceptionEvent, a jdb user would not notice so jdb it instead getting it from the current Thread info).

@parttimenerd
Copy link
Contributor Author

parttimenerd commented Oct 16, 2023

After the fix (see https://mostlynerdless.de/blog/2023/10/11/jdwp-onthrow-and-a-mysterious-error/):

➜ jdb -attach 5005
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
> 
Exception occurred: Ex (to be caught at: OnThrowAndJCmd.main(), line=7 bci=18)"thread=main", OnThrowAndJCmd.main(), line=6 bci=17
6                throw new Ex("");

main[1] list
2    
3        public static void main(String[] args) throws InterruptedException {
4            System.out.println("Hello world!");
5            try {
6 =>             throw new Ex("");
7            } catch (Ex e) {
8                System.out.println("Caught");
9            }
10            try {
11                throw new Ex("");
main[1] 

The problem started appearing with JDK 1.5.

I'm currently working on a test case and hope to add it in the next few hours.

@parttimenerd
Copy link
Contributor Author

I added a minimal test case which starts a debugging session for a basic program and attaches to it via JDI to check that the JDWP-agent throws an exception event with non-null properties. The case fails for the current master and succeeds with this PR.

test/jdk/com/sun/jdi/JdwpOnThrowTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/jdi/JdwpOnThrowTest.java Show resolved Hide resolved
test/jdk/com/sun/jdi/ThrowCaughtException.java Outdated Show resolved Hide resolved
test/jdk/com/sun/jdi/JdwpOnThrowTest.java Outdated Show resolved Hide resolved
Copy link
Contributor

@plummercj plummercj left a comment

Choose a reason for hiding this comment

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

Overall the changes look good except one minor comment typo I noted. I'd like to first run this through our CI testing to make sure there are no issues.

test/jdk/com/sun/jdi/JdwpOnThrowTest.java Outdated Show resolved Hide resolved
Co-authored-by: Chris Plummer <chris.plummer@oracle.com>
Copy link
Contributor

@plummercj plummercj left a comment

Choose a reason for hiding this comment

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

Changes look good. I'm approving, but I think also @RealCLanger should re-review since a lot has changed since his review, including the addition of the test.

test/jdk/com/sun/jdi/JdwpOnThrowTest.java Show resolved Hide resolved
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 18, 2023
test/jdk/com/sun/jdi/JdwpOnThrowTest.java Show resolved Hide resolved
test/jdk/com/sun/jdi/lib/jdb/Debuggee.java Outdated Show resolved Hide resolved
test/jdk/com/sun/jdi/ThrowCaughtException.java Outdated Show resolved Hide resolved
test/jdk/com/sun/jdi/lib/jdb/Debuggee.java Show resolved Hide resolved
test/jdk/com/sun/jdi/JdwpOnThrowTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/jdi/JdwpOnThrowTest.java Show resolved Hide resolved
test/jdk/com/sun/jdi/JdwpOnThrowTest.java Outdated Show resolved Hide resolved
@RealCLanger
Copy link
Contributor

Changes look good. I'm approving, but I think also @RealCLanger should re-review since a lot has changed since his review, including the addition of the test.

Thanks @plummercj for checking that so thoroughly, I couldn't do that. I only have a few minor suggestions for cleanups.

Copy link
Contributor

@RealCLanger RealCLanger 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, just a few last minor flaws. 😉

test/jdk/com/sun/jdi/JdwpOnThrowTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/jdi/OnThrowTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/jdi/ThrowCaughtException.java Outdated Show resolved Hide resolved
Copy link
Contributor

@RealCLanger RealCLanger 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 to me now.

@parttimenerd
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 20, 2023

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

  • cd25d1a: 8318296: Move Space::initialize to ContiguousSpace
  • 744f206: 8318525: Atomic gtest should run as TEST_VM to access VM capabilities
  • 8099261: 8318489: Remove unused alignment_unit and alignment_offset
  • 138437f: 8314438: NMT: Performance benchmarks are needed to have a baseline for comparison of improvements
  • 4812cab: 8316587: Use ArraysSupport.vectorizedHashCode in Utf8EntryImpl
  • bd02cfd: 8318540: make test cannot run .jasm tests directly
  • bd3bc2c: 8317350: Move code cache purging out of CodeCache::UnloadingScope
  • 292aad2: 8316436: ContinuationWrapper uses unhandled nullptr oop
  • 387504c: 8317575: AArch64: C2_MacroAssembler::fast_lock uses rscratch1 for cmpxchg result
  • d9ce525: 8318150: StaticProxySelector.select should not throw NullPointerExceptions
  • ... and 148 more: https://git.openjdk.org/jdk/compare/ad7a8e86e0334390f87ae44cf749d2b47f1409a1...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 20, 2023

@parttimenerd Pushed as commit 8f4ebd8.

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

@parttimenerd
Copy link
Contributor Author

/backport jdk21u

@openjdk
Copy link

openjdk bot commented Oct 20, 2023

@parttimenerd the backport was successfully created on the branch parttimenerd-backport-8f4ebd89 in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 8f4ebd89 from the openjdk/jdk repository.

The commit being backported was authored by Johannes Bechberger on 20 Oct 2023 and was reviewed by Christoph Langer and Chris Plummer.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:

$ git fetch https://github.com/openjdk-bots/jdk21u.git parttimenerd-backport-8f4ebd89:parttimenerd-backport-8f4ebd89
$ git checkout parttimenerd-backport-8f4ebd89
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u.git parttimenerd-backport-8f4ebd89

@parttimenerd
Copy link
Contributor Author

/backport jdk17u

@openjdk
Copy link

openjdk bot commented Oct 20, 2023

@parttimenerd Could not automatically backport 8f4ebd89 to openjdk/jdk17u due to conflicts in the following files:

  • test/jdk/com/sun/jdi/lib/jdb/Debuggee.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b parttimenerd-backport-8f4ebd89

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 8f4ebd892148f2c23fd11672a10aaf787a0be2eb

# Backport the commit
$ git cherry-pick --no-commit 8f4ebd892148f2c23fd11672a10aaf787a0be2eb
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 8f4ebd892148f2c23fd11672a10aaf787a0be2eb'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u with the title Backport 8f4ebd892148f2c23fd11672a10aaf787a0be2eb.

@RealCLanger
Copy link
Contributor

/backport jdk17u

This is the wrong repo. For jdk17 you have to got to jdk17u-dev.

@parttimenerd
Copy link
Contributor Author

Oh, thank you.

@parttimenerd
Copy link
Contributor Author

/backport jdk17u-dev

@openjdk
Copy link

openjdk bot commented Oct 20, 2023

@parttimenerd Could not automatically backport 8f4ebd89 to openjdk/jdk17u-dev due to conflicts in the following files:

  • test/jdk/com/sun/jdi/lib/jdb/Debuggee.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b parttimenerd-backport-8f4ebd89

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 8f4ebd892148f2c23fd11672a10aaf787a0be2eb

# Backport the commit
$ git cherry-pick --no-commit 8f4ebd892148f2c23fd11672a10aaf787a0be2eb
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 8f4ebd892148f2c23fd11672a10aaf787a0be2eb'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport 8f4ebd892148f2c23fd11672a10aaf787a0be2eb.

@openjdk
Copy link

openjdk bot commented Oct 23, 2023

@parttimenerd Could not automatically backport 8f4ebd89 to openjdk/jdk11u due to conflicts in the following files:

  • test/jdk/com/sun/jdi/lib/jdb/Debuggee.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b parttimenerd-backport-8f4ebd89

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 8f4ebd892148f2c23fd11672a10aaf787a0be2eb

# Backport the commit
$ git cherry-pick --no-commit 8f4ebd892148f2c23fd11672a10aaf787a0be2eb
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 8f4ebd892148f2c23fd11672a10aaf787a0be2eb'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u with the title Backport 8f4ebd892148f2c23fd11672a10aaf787a0be2eb.

@parttimenerd
Copy link
Contributor Author

/backport jdk11u-dev

@openjdk
Copy link

openjdk bot commented Oct 23, 2023

@parttimenerd Could not automatically backport 8f4ebd89 to openjdk/jdk11u-dev due to conflicts in the following files:

  • test/jdk/com/sun/jdi/lib/jdb/Debuggee.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b parttimenerd-backport-8f4ebd89

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 8f4ebd892148f2c23fd11672a10aaf787a0be2eb

# Backport the commit
$ git cherry-pick --no-commit 8f4ebd892148f2c23fd11672a10aaf787a0be2eb
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 8f4ebd892148f2c23fd11672a10aaf787a0be2eb'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 8f4ebd892148f2c23fd11672a10aaf787a0be2eb.

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 serviceability serviceability-dev@openjdk.org
4 participants