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

8295810: cleanup debug agent removeThread() api #10828

Closed
wants to merge 1 commit into from

Conversation

plummercj
Copy link
Contributor

@plummercj plummercj commented Oct 22, 2022

The implementation of removeThread() is currently:

static void
removeThread(JNIEnv *env, ThreadList *list, jthread thread)
{
    ThreadNode *node;

    node = findThread(list, thread);
    if (node != NULL) {
        removeNode(list, node);
        clearThread(env, node);
    }
}

However, currently all callers already have the ThreadNode*, so they end up calling like the following:

removeThread(env, list, node->thread);

So we go from a ThreadNode* to a jthread, only to do a findThread() to get the ThreadNode* again. Also, the list is stored in the ThreadNode. removeThread() can instead be implemented as:

static void
removeThread(JNIEnv *env, ThreadNode *node)
{
  JDI_ASSERT(node != NULL);
  removeNode(node->list, node);
  clearThread(env, node);
}

This is faster, although not by as much as you might think. TLS is used to map a jthread to a ThreadNode*, so the findThread() call is actually already pretty fast. The exception is when dealing with the otherThreads list. These threads have not yet been started, so TLS cannot be used, but it is rare for threads to appear on this list. Still, this is a good cleanup to do, and should be a bit faster.

This cleanup was initially implemented as part of the work for JDK-8295376, but is being split out.


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

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10828

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 22, 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 8295810 8295810: cleanup debug agent removeThread() api Oct 22, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 22, 2022
@openjdk
Copy link

openjdk bot commented Oct 22, 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 22, 2022
@mlbridge
Copy link

mlbridge bot commented Oct 22, 2022

Webrevs

Copy link
Contributor

@kevinjwalls kevinjwalls left a comment

Choose a reason for hiding this comment

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

Looks like a good simplification.
As ThreadNode knows what ThreadList it is on there was no reason to be checking which list to remove from.

@@ -319,6 +319,7 @@ removeNode(ThreadList *list, ThreadNode *node)
ThreadNode *prev;
ThreadNode *next;

JDI_ASSERT(list == node->list);

Choose a reason for hiding this comment

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

"list" argument is redundant
I suggest to drop it and replace this assert with
ThreadList *list == node->list;

Copy link
Contributor

Choose a reason for hiding this comment

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

I was almost to suggest the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I did the assert to first convince myself that this would always be the case. I was thinking it would be good to leave as-is until we get a full round of testing first. Are you ok if I file an RFE instead?

Choose a reason for hiding this comment

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

There are only 2 calls of removeNode and I don't see risk here. But fell free to file separate RFE

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Alex that there should not be any risk here.
But I'm okay if filing a separate RFE is more convenient to you.

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 filed JDK-8295810. Thanks for the reviews!

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.

I support the suggestion from Alex on the redundant "list" argument.
Otherwise, it looks good.
Thanks,
Serguei

@openjdk
Copy link

openjdk bot commented Oct 24, 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:

8295810: cleanup debug agent removeThread() api

Reviewed-by: kevinw, sspitsyn, amenkov

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 58 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 24, 2022
@plummercj
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 25, 2022

Going to push as commit 6289600.
Since your change was applied there have been 64 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 Oct 25, 2022
@openjdk openjdk bot closed this Oct 25, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 25, 2022
@openjdk
Copy link

openjdk bot commented Oct 25, 2022

@plummercj Pushed as commit 6289600.

💡 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
4 participants