Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8356113

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

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P5 P5
    • 25
    • client-libs
    • None
    • 2d
    • source, binary, behavioral
    • minimal
    • Removing the synchronized modifier from Color.createContext() has no impact on existing callers, as the method does not access any shared mutable state.
    • Java API
    • SE

      Summary

      At some point java.awt.Color.createContext() was marked as synchronized to support caching of a ColorPaintContext instance. Although the caching logic was removed, the synchronized modifier remained in place.

      Problem

      The method is still marked as synchronized despite no longer accessing shared mutable state. This introduces unnecessary synchronization overhead which can degrade performance in multi-threaded rendering scenarios.

      Solution

      Drop the "synchronized" keyword from the java.awt.Color#createContext() method to reduce the overhead of the method in multi-core environments.

      Specification

      java/awt/Color.java
      
      -    public synchronized PaintContext createContext(ColorModel cm, Rectangle r,
      -                                                   Rectangle2D r2d,
      -                                                   AffineTransform xform,
      -                                                   RenderingHints hints) {
      +    public PaintContext createContext(ColorModel cm, Rectangle r,
      +                                      Rectangle2D r2d, AffineTransform xform,
      +                                      RenderingHints hints) {

            serb Sergey Bylokhov
            serb Sergey Bylokhov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: