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

8295375: debug agent class tracking should not piggy back on the cbClassPrepare() callback #10776

Closed
wants to merge 1 commit into from

Conversation

plummercj
Copy link
Contributor

@plummercj plummercj commented Oct 20, 2022

The debug agent needs to keep track of all loaded classes, and also be notified when they are unloaded. It tracks classes loading by getting CLASS_PREPARE events and it tracks their unloading by tagging them, which triggers OBJECT_FREE events when they are unloaded. The tagging and OBJECT_FREE events are handled by a separate JVMTIEnv from the one that does main event handling, mostly in support of the attached debugger. However, the CLASS_PREPARE events are piggy backed on the main event handler. As a result, we have this special check in filterAndHandleEvent():

    /* We must keep track of all classes prepared to know what's unloaded */
    if (evinfo->ei == EI_CLASS_PREPARE) {
        classTrack_addPreparedClass(env, evinfo->clazz);
    }

We also have to always keep CLASS_PREPARE events enabled on the main event handler, even if the debugger is not requesting them. The main event handler has a lot of overhead that isn't necessary when simply wanting to use the CLASS_PREPARE event for class tracking.

Another downside of this piggy backing is it causes problems for addressing JDK-8295376, which is attempting to not track virtual threads when the debugger is not attached (no VIRTUAL_THREAD_START and VIRTUAL_THREAD_END events). The problem is when the debugger is not attached and a CLASS_PREPARE event comes in on a virtual thread, the debug agent unnecessarily creates a ThreadNode for it. Since there won't be a corresponding VIRTUAL_THREAD_END event when the virtual thread is destroyed (as long as the debugger is not attached), the debug agent ends up keeping this ThreadNode around even after the thread is gone. This usually eventually leads to an assert.

The fix for this is pretty simple. We already have the separate JVMTIEnv that the class tracker uses to handle OBJECT_FREE. This is easily purposed to also handle CLASS_PREPARE events. By doing so we can get rid of the special CLASS_PREPARE code above in filterAndHandleEvent(), and we also only need to enable CLASS_PREPARE events for the main event handler when a debugger is attached and is requesting them.


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-8295375: debug agent class tracking should not piggy back on the cbClassPrepare() callback

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10776

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

Using diff file

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

@@ -1265,7 +1265,6 @@ enableEvents(HandlerNode *node)
case EI_THREAD_END:
case EI_VM_INIT:
case EI_VM_DEATH:
case EI_CLASS_PREPARE:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since CLASS_PREPARE is no longer globally and permanently enabled, we remove it from this list so the code below can enable it as needed based on whether or not the debugger as requested CLASS_PREPARE events.

Comment on lines -549 to -553
/* We must keep track of all classes prepared to know what's unloaded */
if (evinfo->ei == EI_CLASS_PREPARE) {
classTrack_addPreparedClass(env, evinfo->clazz);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer need this hack here since the class tracking code now installs its own CLASS_PREPARE event handler.

Comment on lines -1512 to -1516
error = threadControl_setEventMode(JVMTI_ENABLE,
EI_CLASS_PREPARE, NULL);
if (error != JVMTI_ERROR_NONE) {
EXIT_ERROR(error,"Can't enable class prepare events");
}
Copy link
Contributor Author

@plummercj plummercj Oct 20, 2022

Choose a reason for hiding this comment

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

We no longer permanently enable CLASS_PREPARE events here. It's now done in classTrack.c, and only impacts the JVMTIEnv that is used for class tracking.

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 20, 2022

👋 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 changed the title 8295375 8295375: debug agent class tracking should not piggy back on the cbClassPrepare() callback Oct 20, 2022
@openjdk
Copy link

openjdk bot commented Oct 20, 2022

@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 Oct 20, 2022
@plummercj plummercj marked this pull request as ready for review October 20, 2022 03:13
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 20, 2022
@mlbridge
Copy link

mlbridge bot commented Oct 20, 2022

Webrevs

@openjdk
Copy link

openjdk bot commented Oct 20, 2022

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

8295375: debug agent class tracking should not piggy back on the cbClassPrepare() callback

Reviewed-by: 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 21 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 Oct 20, 2022
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.

Good simplification.
Thanks,
Serguei

@plummercj
Copy link
Contributor Author

Thank you Alex and Serguei!

/integrate

@openjdk
Copy link

openjdk bot commented Oct 21, 2022

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

  • f41711e: 8295650: JFR: jfr scrub should warn if an event type doesn't exist
  • 0c13d66: 8295530: Update Zlib Data Compression Library to Version 1.2.13
  • 15bebf9: 8295666: Linux x86 build fails after 8292591
  • 5064718: 8294460: CodeSection::alignment checks for CodeBuffer::SECT_STUBS incorrectly
  • 8b010e0: 8030616: sun/management/jmxremote/bootstrap/RmiBootstrapTest fails intermittently with cannot find a free port
  • b35922b: 8295714: GHA ::set-output is deprecated and will be removed
  • dfd2d83: 8295657: SA: Allow larger object alignments
  • a345df2: 8280131: jcmd reports "Module jdk.jfr not found." when "jdk.management.jfr" is missing
  • ef62b61: 8295703: RISC-V: Remove implicit noreg temp register arguments in MacroAssembler
  • 6240431: 8295697: Resolve conflicts between serviceability/jvmti and nsk/jvmti shared code
  • ... and 19 more: https://git.openjdk.org/jdk/compare/8d4c077218748d37617fc1bdb537a165706a5849...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 21, 2022

@plummercj Pushed as commit 2181042.

💡 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 serviceability serviceability-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

3 participants