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

8132984: incorrect type for Reference.discovered #1897

Closed
wants to merge 5 commits into from

Conversation

kimbarrett
Copy link

@kimbarrett kimbarrett commented Dec 26, 2020

Please review this change which fixes the type of the private
Reference.discovered field. It was Reference, but that's wrong because
it can be any Reference object.

I've changed it to Reference and let that flow through, updating some other variables that were previously somewhat incorrectly typed (usually with an Object type parameter). The interesting change is to the ReferenceQueue.enqueue parameter, which is now also Reference.

This ultimately end up with a provably safe and correct, but uncheckable,
cast in ReferenceQueue.enqueue.

An alternative might be to use a raw type for the discovered field, but I
think that ends up with more @SuppressWarnings of various flavors. I think
the unbounded wildcard approach is clearer and cleaner.

Note that all of the pending list handling, including the discovered field,
could be moved into a non-public, non-generic, sealed(?) base class of
Reference. The pending list handling has nothing to do with the generic
parameter T.

Testing:
mach5 tier1 and tier4 (tier4 is where vmTestbase_vm_gc_ref tests are run)

/label core-libs
/summary Use unbounded wildcard placeholders and final safe but unchecked cast.


Progress

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

Issue

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/1897/head:pull/1897
$ git checkout pull/1897

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 26, 2020

👋 Welcome back kbarrett! 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 core-libs core-libs-dev@openjdk.org label Dec 26, 2020
@openjdk
Copy link

openjdk bot commented Dec 26, 2020

@kimbarrett
The core-libs label was successfully added.

@openjdk
Copy link

openjdk bot commented Dec 26, 2020

@kimbarrett Setting summary to Use unbounded wildcard placeholders and final safe but unchecked cast.

@kimbarrett kimbarrett marked this pull request as ready for review December 26, 2020 03:45
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 26, 2020
@mlbridge
Copy link

mlbridge bot commented Dec 26, 2020

Webrevs

@plevart
Copy link
Contributor

plevart commented Jan 18, 2021

Hi Kim,

If you introduce a private method in Reference:

    private void enqueueFromPending() {
        var q = queue;
        if (q != ReferenceQueue.NULL) q.enqueue(this);
    }

...and use it Reference.processPendingReferences while loop like this:

            if (ref instanceof Cleaner) {
                ...
            } else {
                ref.enqueueFromPending();
            }

Then you can keep the signature of ReferenceQueue.enqueue(Reference<? extends T> r) and no unchecked casts are needed there.

But what you have is OK and much better than what was before.

@mlbridge
Copy link

mlbridge bot commented Jan 18, 2021

Mailing list message from Kim Barrett on core-libs-dev:

On Jan 18, 2021, at 12:28 PM, Peter Levart <plevart at openjdk.java.net> wrote:
If you introduce a private method in Reference:

private void enqueueFromPending() {
var q = queue;
if (q != ReferenceQueue.NULL) q.enqueue(this);
}

...and use it Reference.processPendingReferences while loop like this:

       if \(ref instanceof Cleaner\) \{
           \.\.\.
       \} else \{
           ref\.enqueueFromPending\(\)\;
       \}

Then you can keep the signature of `ReferenceQueue.enqueue(Reference<? extends T> r)` and no unchecked casts are needed there.

Nice! And this reverts all changes to ReferenceQueue.java

But what you have is OK and much better than what was before.

Thanks, but I?m going to take your improvement. I?ll update the PR once I?ve re-run some tests.

Copy link
Contributor

@rkennke rkennke 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 to me!

@openjdk
Copy link

openjdk bot commented Jan 19, 2021

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

8132984: incorrect type for Reference.discovered

Use unbounded wildcard placeholders, plus a new helper to get back to the Reference<T> domain.

Reviewed-by: rkennke, plevart, rriggs, mchung

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 19, 2021
Copy link
Contributor

@plevart plevart left a comment

Choose a reason for hiding this comment

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

This looks good.

Copy link
Member

@mlchung mlchung 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.

@kimbarrett
Copy link
Author

Thanks @plevart , @rkennke , @RogerRiggs , and @mlchung for reviews.

@kimbarrett
Copy link
Author

/summary Use unbounded wildcard placeholders, plus a new helper to get back to the Reference domain.

@openjdk
Copy link

openjdk bot commented Jan 19, 2021

@kimbarrett Updating existing summary to Use unbounded wildcard placeholders, plus a new helper to get back to the Reference<T> domain.

@kimbarrett
Copy link
Author

/integrate

@openjdk openjdk bot closed this Jan 19, 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 Jan 19, 2021
@openjdk
Copy link

openjdk bot commented Jan 19, 2021

@kimbarrett Pushed as commit 33dcc00.

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

@kimbarrett kimbarrett deleted the fix_discovered_type branch January 19, 2021 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
5 participants