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

8269268: JDWP: Properly fix thread lookup assert in findThread() #4580

Closed
wants to merge 3 commits into from

Conversation

plummercj
Copy link
Contributor

@plummercj plummercj commented Jun 24, 2021

Re-enable the assert that was disabled (with some overhead) by JDK-8265683. Explanation is in the CR and also in comments included with the changes.

I tested by running vmTestbase/nsk/jdb/suspend/suspend001/suspend001.java and vmTestbase/nsk/jdb/wherei/wherei001/wherei001.java 100's of times, and did not see any failures. I also verified the original issue was still reproducible by temporarily not setting gdata->handlingVMDeath = JNI_TRUE, which did trigger the assert as expected.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8269268: JDWP: Properly fix thread lookup assert in findThread()

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4580/head:pull/4580
$ git checkout pull/4580

Update a local copy of the PR:
$ git checkout pull/4580
$ git pull https://git.openjdk.java.net/jdk pull/4580/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4580

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4580.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 24, 2021

👋 Welcome back cjplummer! 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 Jun 24, 2021
@openjdk
Copy link

openjdk bot commented Jun 24, 2021

@plummercj 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 Jun 24, 2021
@mlbridge
Copy link

mlbridge bot commented Jun 24, 2021

Webrevs

Comment on lines 1242 to 1243
/* Setting this flag is needed for a very special case. See the reference in findThread(). */
gdata->handlingVMDeath = JNI_TRUE;
Copy link
Member

Choose a reason for hiding this comment

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

Is this used to communicate across different threads? If so then it needs to be at least volatile, but a more forceful memory-barrier may be needed on some platforms. I can't tell in what context findThread will be called after this has been set to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had an answer typed up for you, but I realized I need to think some things through a bit more, and it's getting late. I'll look into it some more tomorrow.

@plummercj
Copy link
Contributor Author

There are two threads to consider here. The one that VM_DEATH was received on and the thread that reads JDWP commands from the debugger. For the latter, a VM.Resume command has been received. The debugger does this as the test wraps up, allowing all debuggee threads to resume and the debugeee to exit. VM.resume() calls threadControl_resumeAll(), which calls commonResumeList(), which walks the runningThreads list to build an array of jthreads that need to be resumed. This array is passed to JVMTI ResumeThreadList(). Any time after this point a VM_DEATH can be triggered since the debuggee main thread calls System.exit() and does not wait for all the threads it creates to exit first (no join is done). The VM_DEATH event leads to clearing all the JVMTI callbacks, so the debug agent is no longer notified of THREAD_END events as the other threads created by the debuggee exit. This leads to threads still being on runningThreads, even though they have exited and had their TLS cleared by JVMTI. Keep in mind we are still in commonResumeList() when all this is happening. After calling JVMTI ResumeThreadList(), it then walks that same array of jthreads that were resumed, doing a findThread() on each. This is done mainly so it can update the suspendCount the ThreadNodes. This is when the assert was getting triggered. Some of the debuggee threads had already exited and had their TLS cleared, but were still in runningThreads since the THREAD_END was never received. The fix is to not assert (and instead look up the thread in runningThreads) if we are dealing with a VM_DEATH event.

You mentioned gdata->handlingVMDeath should be volatile. I will fix that. I also think I will rename it to gdata->jvmtiCallBacksCleared. There is no need to ever set it back false, so I will remove that line of code. Once true, we know the vm is exiting anyway, and the callbacks will never be setup again. Also, I'm going to set it true before actually clearing the callbacks rather than after. Doing it early is fine. In fact if it was always true, findThread() would still work, but just be slower.

As far as any other synchronizing or memory barriers being needed, I'm a bit unclear on that part. The only thing that matters is that gdata->jvmtiCallBacksCleared being set true is visible to other threads before the callbacks get cleared. It seems the call to SetEventCallbacks() should ensure this.

@openjdk
Copy link

openjdk bot commented Jun 25, 2021

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

8269268: JDWP: Properly fix thread lookup assert in findThread()

Reviewed-by: kevinw, amenkov, 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 61 new commits pushed to the master branch:

  • e9b2c05: 8269409: Post JEP 411 refactoring: core-libs with maximum covering > 10K
  • d0d26f5: 8269433: Remove effectively unused ReferenceProcessor::_enqueuing_is_done
  • 29bc381: 8268902: Testing for threadObj != NULL is unnecessary in suspend handshake
  • 87ff277: 8269222: Incorrect number of workers reported for reference processing
  • 4d2412e: 8269122: The use of "extern const" for Register definitions generates poor code
  • f45be15: 8269003: Update the java manpage for JDK 18
  • a29953d: Merge
  • d9cb068: 8258746: illegal access to global field _jvmci_old_thread_counters by terminated thread causes crash
  • 6eb734a: 8266269: Lookup::accessClass fails with IAE when accessing an arrayClass with a protected inner class as component class
  • 3d0d27c: 8269351: Proxy::newProxyInstance and MethodHandleProxies::asInterfaceInstance should reject sealed interfaces
  • ... and 51 more: https://git.openjdk.java.net/jdk/compare/7621fa37efb2739b953da1cda87dca4762b5bd0c...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 Jun 25, 2021
Copy link
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.

LGTM.
I like the way it is fixed.
Thanks,
Serguei

@plummercj
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 29, 2021

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

  • 7a23c9c: 8260540: serviceability/jdwp/AllModulesCommandTest.java failed with "Debuggee error: 'ERROR: transport error 202: bind failed: Address already in use'"
  • c1e2a29: 8263640: hs_err improvement: handle class path longer than O_BUFLEN
  • bb42d75: 8269417: Minor clarification on NonblockingQueue utility
  • e238cbd: 8269530: runtime/ParallelLoad/ParallelSuperTest.java timeout
  • 3f2c372: 8269126: Rename G1AllowPreventiveGC option to G1UsePreventiveGC
  • a977157: 8261579: AArch64: Support for weaker memory ordering in Atomic
  • ee1e202: 8268821: Split systemDictionaryShared.cpp
  • 03d54e6: Merge
  • 5624069: 8269426: Rename test/jdk/java/lang/invoke/t8150782 to accessClassAndFindClass
  • 09bb846: 8267952: async logging supports to dynamically change tags and decorators
  • ... and 65 more: https://git.openjdk.java.net/jdk/compare/7621fa37efb2739b953da1cda87dca4762b5bd0c...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Jun 29, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 29, 2021
@openjdk
Copy link

openjdk bot commented Jun 29, 2021

@plummercj Pushed as commit 7ca753b.

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

@dholmes-ora
Copy link
Member

Just to follow up:

As far as any other synchronizing or memory barriers being needed, I'm a bit unclear on that part. The only thing that matters is that gdata->jvmtiCallBacksCleared being set true is visible to other threads before the callbacks get cleared. It seems the call to SetEventCallbacks() should ensure this.

In practice this should be fine as SetEventCallbacks acquires a monitor/mutex; and findThread is also called while holding a monitor, so although different monitors, in practice the acquire/release semantics should make this work. Additionally the complexity of the interaction between the two threads involved will introduce other synchronization actions.

@plummercj plummercj deleted the 8269268_jdwp-tls-assert branch December 13, 2021 19:08
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
5 participants