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

8295303: cleanup debug agent's confusing use of EI_GC_FINISH #10887

Closed
wants to merge 4 commits into from

Conversation

plummercj
Copy link
Contributor

@plummercj plummercj commented Oct 27, 2022

This PR renamed EI_GC_FINISH to EI_CLASS_UNLOAD and does some other minor cleanups related to EI_GC_FINISH.

The debug agent deals with 3 types of events: JVMTI (per the spec), JDWP (per the spec), and an event indexing that the debug agent refers to as EI (Event Index) events. We have the following EI_GC_FINISH event. The indexing is into the array of jdwp event handlers which are created when the debugger sends an EventRequest command.

Note there is no EI_CLASS_UNLOAD event that maps to the JDWP CLASS_UNLOAD event, but instead we have:

EI_GC_FINISH = 8,

And these are the mappings between EI_GC_FINISH and JDWP and JVMTI events

  case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
      return EI_GC_FINISH;

  case JDWP_EVENT(CLASS_UNLOAD):
      return EI_GC_FINISH;

  index2jvmti[EI_GC_FINISH - EI_min] = JVMTI_EVENT_GARBAGE_COLLECTION_FINISH;

  index2jdwp[EI_GC_FINISH - EI_min] = JDWP_EVENT(CLASS_UNLOAD);

So there is this odd relationship between EI_GC_FINISH and the JDWP CLASS_UNLOAD event. Note that JVMTI does not have a CLASS_UNLOAD (except for unused support in the extension mechanism), and JDWP has no GC_FINISH event.

This relationship between EI_GC_FINISH and the JDWP CLASS_UNLOAD events stems from the fact that at one point JVMTI_EVENT_GARBAGE_COLLECTION_FINISH was used to trigger the synthesizing all of JDWP CLASS_UNLOAD events for classes that unloaded during the last GC. That is no longer the case, and instead each time a JVMTI OBJECT_FREE event is triggered for a Class instance, the JDWP CLASS_UNLOAD is generated.

Since JDWP CLASS_UNLOAD maps to EI_GC_FINISH, we have the following:

node = getHandlerChain(EI_GC_FINISH)->first;

By looking at this line of code, you would never guess that this is how you fetch the event handler chain for JDWP CLASS_UNLOAD EventRequests, but it is.

To clean this up I renamed EI_GC_FINISH to EI_CLASS_UNLOAD. However, that still leaves the EI_GC_FINISH to JVMTI_EVENT_GARBAGE_COLLECTION_FINISH mapping to deal with. It's not needed anymore. When we get a JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, this is all we ever do with it:

static void JNICALL
cbGarbageCollectionFinish(jvmtiEnv *jvmti_env)
{
    LOG_CB(("cbGarbageCollectionFinish"));
    ++garbageCollected;
    LOG_MISC(("END cbGarbageCollectionFinish"));
}

So the event is not passed around at all, and doesn't trigger other events or mapping to a JDWP event. It is never used as an "event index". This means jvmti2EventIndex should assert if it is ever passed in, since following mapping should never be needed:

        case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
            return EI_GC_FINISH; 

This is accomplished by simply deleting the above code, and failing through to the default error handling code.

Also no longer needed is the following entry:

index2jvmti[EI_GC_FINISH          -EI_min] = JVMTI_EVENT_GARBAGE_COLLECTION_FINISH

For this we just assign the entry to 0, which will result in an error if the entry is ever referenced.


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-8295303: cleanup debug agent's confusing use of EI_GC_FINISH

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10887

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 27, 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 8295303 8295303: cleanup debug agent's confusing use of EI_GC_FINISH Oct 27, 2022
@openjdk
Copy link

openjdk bot commented Oct 27, 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 27, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 3, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 3, 2022

Webrevs

* GARBAGE_COLLECTION_FINISH is special since it is not tied to any handlers or an EI,
* so it cannot be setup using threadControl_setEventMode(). Use JVMTI API directly.
*/
error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventNotificationMode)

Choose a reason for hiding this comment

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

Please add space after the comma:
error = JVMTI_FUNC_PTR(gdata->jvmti, SetEventNotificationMode)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Omitting the space is consistent with other uses of JVMTI_FUNC_PTR.

if ( i < EI_min || i > EI_max ) {
EXIT_ERROR(AGENT_ERROR_INVALID_INDEX,"bad EventIndex");
jdwpEvent event = 0;
if (ei >= EI_min || ei >= EI_max) {

Choose a reason for hiding this comment

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

Should be "(ei >= EI_min && ei <= EI_max"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

if ( i < EI_min || i > EI_max ) {
EXIT_ERROR(AGENT_ERROR_INVALID_INDEX,"bad EventIndex");
jvmtiEvent event = 0;
if (ei >= EI_min || ei >= EI_max) {

Choose a reason for hiding this comment

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

Should be "(ei >= EI_min && ei <= EI_max"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@openjdk
Copy link

openjdk bot commented Nov 8, 2022

@plummercj this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout 8295303_gc_finish
git fetch https://git.openjdk.org/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Nov 8, 2022
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Nov 8, 2022
@@ -232,6 +232,7 @@ eventText(int i)
CASE_RETURN_TEXT(EI_THREAD_START)
CASE_RETURN_TEXT(EI_THREAD_END)
CASE_RETURN_TEXT(EI_CLASS_PREPARE)
CASE_RETURN_TEXT(EI_CLASS_UNLOAD)
CASE_RETURN_TEXT(EI_CLASS_LOAD)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Would it be a little better to place it after EI_CLASS_UNLOAD?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you mean put EI_CLASS_UNLOAD after EI_CLASS_LOAD, I tried to keep the current ordering. If you look in util.h (bottom of this page), it used to have:

        EI_CLASS_PREPARE        =  7,
        EI_GC_FINISH            =  8,
        EI_CLASS_LOAD           =  9,

and now it has:

        EI_CLASS_PREPARE        =  7,
        EI_CLASS_UNLOAD         =  8,
        EI_CLASS_LOAD           =  9,

There are a couple of other places where this ordering is preserved and I tried to be consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, thanks.
It makes sense then.

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.

Looks good.
Thanks,
Serguei

@openjdk
Copy link

openjdk bot commented Nov 8, 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:

8295303: cleanup debug agent's confusing use of EI_GC_FINISH

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

  • 0ee25de: 8296504: Memory leak in G1PLABAllocator::PLABData
  • dd5d4df: 8295658: G1: Refactor G1SegmentedArray to indicate that it is an allocator
  • cf65605: 8296445: C++ syntax error in jdwpTransport.h
  • 1169dc0: 8296447: RISC-V: Make the operands order of vrsub_vx/vrsub_vi consistent with RVV 1.0 spec

Please see this link for an up-to-date comparison between the source branch of this pull request and 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 Nov 8, 2022
@plummercj
Copy link
Contributor Author

Thanks Alex and Serguei!

/integrate

@openjdk
Copy link

openjdk bot commented Nov 8, 2022

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

  • 0ee25de: 8296504: Memory leak in G1PLABAllocator::PLABData
  • dd5d4df: 8295658: G1: Refactor G1SegmentedArray to indicate that it is an allocator
  • cf65605: 8296445: C++ syntax error in jdwpTransport.h
  • 1169dc0: 8296447: RISC-V: Make the operands order of vrsub_vx/vrsub_vi consistent with RVV 1.0 spec

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 8, 2022

@plummercj Pushed as commit 74f2b16.

💡 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