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

Loading

@openjdk openjdk bot added the core-libs label Dec 26, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Dec 26, 2020

@kimbarrett
The core-libs label was successfully added.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Dec 26, 2020

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

Loading

@kimbarrett kimbarrett marked this pull request as ready for review Dec 26, 2020
@openjdk openjdk bot added the rfr label Dec 26, 2020
@mlbridge
Copy link

@mlbridge mlbridge bot commented Dec 26, 2020

Loading

@plevart
Copy link
Contributor

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

Loading

@mlbridge
Copy link

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

Loading

Copy link
Contributor

@rkennke rkennke left a comment

Looks good to me!

Loading

@openjdk
Copy link

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

Loading

@openjdk openjdk bot added the ready label Jan 19, 2021
Copy link
Contributor

@plevart plevart left a comment

This looks good.

Loading

Copy link
Member

@mlchung mlchung left a comment

Looks good.

Loading

@kimbarrett
Copy link
Author

@kimbarrett kimbarrett commented Jan 19, 2021

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

Loading

@kimbarrett
Copy link
Author

@kimbarrett kimbarrett commented Jan 19, 2021

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

Loading

@openjdk
Copy link

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

Loading

@kimbarrett
Copy link
Author

@kimbarrett kimbarrett commented Jan 19, 2021

/integrate

Loading

@openjdk openjdk bot closed this Jan 19, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Jan 19, 2021
@openjdk
Copy link

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

Loading

@kimbarrett kimbarrett deleted the fix_discovered_type branch Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants