Skip to content

8176567: nsk/jdi/ReferenceType/instances/instances002: TestFailure: Unexpected size of referenceType.instances(nsk.share.jdi.TestInterfaceImplementer1): 11, expected: 10 #6943

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

Closed
wants to merge 2 commits into from

Conversation

plummercj
Copy link
Contributor

@plummercj plummercj commented Jan 2, 2022

The test is failing because it is detecting an extra instance of TestClass1. The test (the debugger side) first tells the debuggee to create 10 instances of TestClass1. The debugger then uses JDI ClassType.newInstance() to create 100 more instances. It then resumes the debuggee and uses RefrenceType.instances() to find out how many instances of TestClass1 are reachable. Since the 100 created by ClassType.newInstance() should not have any references keeping them live, the answer should be 10, but sometimes it ends up being 11, so there is an extra instance.

I determined that this extra instance is always the last of the 100 that are created with ClassType.newInstance(). It uses the JDI/JDWP invoker interface. I found the following code in the debug agent invoker.c to be the problem:

    if (!detached) {
        outStream_initReply(&out, id);
        (void)outStream_writeValue(env, &out, tag, returnValue);
        (void)outStream_writeObjectTag(env, &out, exc);
        (void)outStream_writeObjectRef(env, &out, exc);
        outStream_sendReply(&out);
    }
…
    if (mustReleaseReturnValue && returnValue.l != NULL) {
        tossGlobalRef(env, &returnValue.l);
    }

The first block is responsible for sending the reply to the debugger for the JDI ClassType.newInstance() call. returnValue is a JNI global ref to the object that was just created, and tossGlobalRef() frees it after the reply packet has been sent. The problem is that once the reply packet has been received by the debugger (for the 100th TestClass1 allocation), it resumes the debuggee and issues the ReferenceType.instances() call. This might be handled by the debug agent before it ever gets to the tossGlobalRef() call. So there will still be a reference to the 100th TestClass1 object.

The fix is to call tossGlobalRef() after we are done with returnValue, but before sending out the packet. We are done with returnValue once the outStream_writeValue() call has been made. I decided to handle exc (the exception object) in the same manner. Although no tests were failing as a result of releasing it after sending the reply, I think you could write a test that triggered an exception and verified that the exception was not still considered live after doing the resume.

Regarding any concerns you might have for moving tossGlobalRef() code from outside the if (!detached) to inside, if you follow the logic of this function you'll see that mustReleaseReturnValue can only be set true if detached is false. You'll also see that exc can only be non-null if detached is false. Thus these two tossGlobalRef() calls were only ever made when detached was false, and that remains true after my changes.

Regarding any concerns you might have for making the tossGlobalRef() calls outside of the locks, the locking is a remnant from when the exception and returnValue fields were referenced directly out of the InvokeRequest struct, which could be accessed by other threads. That is no longer the case after changes were made for JDK-8181419, which copied the fields into local variables. This code actually has been subject to a pretty long bug tail. See the last couple of long comments by me in JDK-8176567 for details.


Progress

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

Issue

  • JDK-8176567: nsk/jdi/ReferenceType/instances/instances002: TestFailure: Unexpected size of referenceType.instances(nsk.share.jdi.TestInterfaceImplementer1): 11, expected: 10

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6943

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 2, 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
Copy link

openjdk bot commented Jan 2, 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 Jan 2, 2022
@plummercj plummercj marked this pull request as ready for review January 3, 2022 01:37
@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 3, 2022
@mlbridge
Copy link

mlbridge bot commented Jan 3, 2022

Webrevs

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.

The fix looks good to me. Nice analysis!

Thanks,
Serguei

@openjdk
Copy link

openjdk bot commented Jan 4, 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:

8176567: nsk/jdi/ReferenceType/instances/instances002: TestFailure: Unexpected size of referenceType.instances(nsk.share.jdi.TestInterfaceImplementer1): 11, expected: 10

Reviewed-by: 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 205 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 Jan 4, 2022
@plummercj
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 18, 2022

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

openjdk bot commented Jan 18, 2022

@plummercj Pushed as commit 46fd683.

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

@plummercj plummercj deleted the 8176567-invoker_result branch January 26, 2022 05:52
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