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

JDK-8263467: Incorrect double-checked locking in sun.java2d.CRenderer #2948

Closed
wants to merge 2 commits into from

Conversation

shipilev
Copy link
Contributor

@shipilev shipilev commented Mar 11, 2021

SonarCloud reports multiple incorrect double-checked locking cases in sun.java2d.CRenderer. For example:

  Arc2D arcToShape;

  ...
            if (arcToShape == null) {
                synchronized (this) {
                    if (arcToShape == null) {
                        arcToShape = new Arc2D.Float();
                    }
                }
            }

Arc2D contains fields that are not final. arcToShape is not volatile. This makes it an incorrect DCL.
This code is used by Mac OS, do it would probably blow up some time later on M1.

This is the candidate fix that preserves the semantics. I am doing this fix blindly so far, without testing on real Mac OS. But maybe there is no need to do any of this, because the setter methods overwrite the contents of all these objects under their own sync. So, maybe we can just allocate those objects without DCL-backed caching and pass them in?


Progress

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

Issue

  • JDK-8263467: Incorrect double-checked locking in sun.java2d.CRenderer

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2948

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

Using diff file

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Mar 11, 2021

👋 Welcome back shade! 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 rfr label Mar 11, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Mar 11, 2021

@shipilev The following label will be automatically applied to this pull request:

  • 2d

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 2d label Mar 11, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Mar 11, 2021

Webrevs

@mrserb
Copy link
Member

@mrserb mrserb commented Mar 12, 2021

I guess "Incorrect double-checked" is a too strict description of this code, it just tried to eliminate the creation of one object and do not care about the content of that object, since it is immediately overridden.

I think It will be more clear to just eliminate this DCL since overhead and code complexity seems too much to just cache five objects.

Probably it was important in past(jdk6 and below) when this renderer was used for onscreen rendering. Currently, it is used for printing(if actually used at all).

@shipilev
Copy link
Contributor Author

@shipilev shipilev commented Mar 12, 2021

Ok, I removed the "DCL" from that code and used the objects directly. AFAICS, synchronization is redundant on those local objects. What would be a good test for this change?

@mrserb
Copy link
Member

@mrserb mrserb commented Mar 15, 2021

Ok, I removed the "DCL" from that code and used the objects directly. AFAICS, synchronization is redundant on those local objects. What would be a good test for this change?

I guess that synchronization became redundant because the field was moved to the local var. But before that, it guarded the method in question for multithreaded access and that was not part of the DCL. So it will be better to return those fields back.

As the test I have run all automated tests and some manual tests, none of them triggered this code.

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Apr 21, 2021

@shipilev This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@shipilev
Copy link
Contributor Author

@shipilev shipilev commented Apr 21, 2021

Not now, bot.

prrace
prrace approved these changes May 6, 2021
Copy link
Contributor

@prrace prrace left a comment

LGTM

@openjdk
Copy link

@openjdk openjdk bot commented May 6, 2021

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

8263467: Incorrect double-checked locking in sun.java2d.CRenderer

Reviewed-by: prr, azvegint

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

  • 3af4efd: 8265291: Error in Javadoc for doAccessibleAction API in AccessibleJSlider class
  • be4f25b: 8266369: (se) Add wepoll based Selector
  • ff77ca8: 8266675: Optimize IntHashTable for encapsulation and ease of use
  • 04fad70: 8266765: [BACKOUT] JDK-8255493 Support for pre-generated java.lang.invoke classes in CDS dynamic archive
  • 0790e60: 8196743: jstatd doesn't see new Java processes inside Docker container
  • c6aa8f1: 8232644: bugs in serialized-form.html
  • b5b3119: 8266589: (fs) Improve performance of Files.copy() on macOS using copyfile(3)
  • 947d69d: 8265042: javadoc HTML files not generated for types nested in records
  • 946b0fe: 8266645: javac should not check for sealed supertypes in intersection types
  • 74fecc0: 8266503: [UL] Make Decorations safely copy-able and reduce their size
  • ... and 919 more: https://git.openjdk.java.net/jdk/compare/7ed46bd02e66415f3a9ce03b93e4469f9277aff5...master

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 label May 6, 2021
@mrserb
Copy link
Member

@mrserb mrserb commented May 8, 2021

I guess that synchronization became redundant because the field was moved to the local var. But before that, it guarded the method in question for multithreaded access and that was not part of the DCL. So it will be better to return those fields back.

Is not approved yet, see above.

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Jun 5, 2021

@shipilev This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Jul 3, 2021

@shipilev This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2d ready rfr
4 participants