Skip to content

Conversation

@mrserb
Copy link
Member

@mrserb mrserb commented Apr 20, 2025

At some point, java.awt.Color.createContext() was marked as synchronized to support caching of a ColorPaintContext instance. The cache was later removed, but the synchronized modifier remained. Since there is no shared mutable state anymore, the synchronization is no longer necessary and can be safely removed.

Note: This code path is rarely executed because a special optimization was introduced in SunGraphics2D.setPaint. As a result, unless a custom wrapper around the Color class is used, the Color.createContext() method is typically bypassed during rendering.

Two tests are added:

  • ColorPaintContextBasicTest: Checks if different image types (BufferedImage and VolatileImage) produce the same results when using different ways to fill the image (setColor, setPaint, and custom Paint). This test intentionally uses a custom Paint implementation to bypass the optimization and ensure that Color.createContext() is invoked verifying its correct behavior.
  • ColorPaintContextStateTrackerTest: Checks that the raster used in ColorPaintContext.getRaster() can be properly cached in video memory and we do not need to call icr.markDirty() in ColorPaintContext.getRaster()

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
  • Change requires CSR request JDK-8356113 to be approved

Issues

  • JDK-8355078: java.awt.Color.createContext() uses unnecessary synchronization (Bug - P5)
  • JDK-8356113: java.awt.Color.createContext() uses unnecessary synchronization (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24771

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 20, 2025

👋 Welcome back serb! 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.

@mrserb
Copy link
Member Author

mrserb commented Apr 20, 2025

/csr

@openjdk
Copy link

openjdk bot commented Apr 20, 2025

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

8355078: java.awt.Color.createContext() uses unnecessary synchronization

Reviewed-by: prr

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 csr Pull request needs approved CSR before integration label Apr 20, 2025
@openjdk
Copy link

openjdk bot commented Apr 20, 2025

@mrserb has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@mrserb please create a CSR request for issue JDK-8355078 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@openjdk
Copy link

openjdk bot commented Apr 20, 2025

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

  • client

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 client client-libs-dev@openjdk.org label Apr 20, 2025
@liach
Copy link
Member

liach commented Apr 20, 2025

Is a CSR requested for the access flags change? Some method flags, notably native or synchronized, are not part of the API specificaion and not rendered, and thus can be changed without CSR reviews. For example, the javadoc for this particular method does not include the synchronized modifier.

protected ColorPaintContext(int color, ColorModel cm) {
private final int color;
private volatile WritableRaster savedTile;

Copy link
Member Author

Choose a reason for hiding this comment

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

Since ColorPaintContext is no longer cached within the Color class, it's unlikely that this object will be accessed by multiple threads in typical JDK usage. Therefore, the synchronized modifier has been removed from the getRaster() method. However, to ensure thread safety in the rare case where a ColorPaintContext instance is shared across threads (if app decides to do so for some reason), the savedTile field has been declared as volatile.

@mrserb mrserb marked this pull request as ready for review May 3, 2025 03:31
@openjdk openjdk bot added the rfr Pull request is ready for review label May 3, 2025
@mlbridge
Copy link

mlbridge bot commented May 3, 2025

Webrevs

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels May 12, 2025
@mrserb
Copy link
Member Author

mrserb commented May 19, 2025

/integrate

@openjdk
Copy link

openjdk bot commented May 19, 2025

Going to push as commit 890456f.
Since your change was applied there have been 24 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 May 19, 2025
@openjdk openjdk bot closed this May 19, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 19, 2025
@openjdk
Copy link

openjdk bot commented May 19, 2025

@mrserb Pushed as commit 890456f.

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

@mrserb mrserb deleted the colorctx branch May 19, 2025 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client client-libs-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants