[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    Re: [OpenJDK 2D-Dev] Thread safety of SunFontManager.platformFontMap
From:       Philip Race <philip.race () oracle ! com>
Date:       2021-02-22 18:18:45
Message-ID: f0e9401d-be86-21fc-9c8a-949f0f7266ea () oracle ! com
[Download RAW message or body]

The map is not expected to be updated after it has been created so it 
should not need synchronized access.
There are a couple of exceptions where it is being updated when some 
file that
is supposed to be there can't be found - a scenario that apparently 
hasn't been
an issue in the 10 years this code has been in use.
So the removal is an optimisation that could be revisited.

-phil.

On 2/22/21 4:40 AM, Andrey Turbanov wrote:
>
> Hello.
> I recently found suspicious field (with SpotBugs help) in class 
> SunFontManager:
>
>     static HashMap<String, FamilyDescription> platformFontMap;
>
> This HashMap is accessed (read and write) in a method
> sun.font.SunFontManager#findFontFromPlatformMap. As I see there is no
> synchronization when this HashMap is accessed.
> This method can be called from client code with this simple stack trace:
>
>       at 
> sun.font.SunFontManager.findFontFromPlatformMap(SunFontManager.java:1508)
>       at sun.font.SunFontManager.findFont2D(SunFontManager.java:2069)
>       at java.awt.Font.getFont2D(Font.java:500)
>       at java.awt.Font.getPSName(Font.java:1416)
>
> I wonder if this unsynchronized access is expected. Looks like it can
> break things when accessed from multiple threads simultaneously.
> Do I miss something? Is it done this way, because Font objects are
> supposed to be accessed from a single thread only?
>
> Andrey Turbanov


[Attachment #3 (text/html)]

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    The map is not expected to be updated after it has been created so
    it should not need synchronized access.<br>
    There are a couple of exceptions where it is being updated when some
    file that<br>
    is supposed to be there can't be found - a scenario that apparently
    hasn't been<br>
    an issue in the 10 years this code has been in use.<br>
    So the removal is an optimisation that could be revisited.<br>
    <br>
    -phil.<br>
    <br>
    <div class="moz-cite-prefix">On 2/22/21 4:40 AM, Andrey Turbanov
      wrote:<br>
    </div>
    <blockquote type="cite" \
cite="mid:CAF+DQ5df=xwGx_U+6+q1gP=fvo8O+oZESwQfHW1peu=1shxjkQ@mail.gmail.com">  
      <div dir="auto">
        <div class="gmail_quote" dir="auto">
          <div dir="ltr" class="gmail_attr"><br>
          </div>
          Hello.<br>
          I recently found suspicious field (with SpotBugs help) in
          class SunFontManager:<br>
          <br>
          &nbsp; &nbsp; static HashMap&lt;String, FamilyDescription&gt;
          platformFontMap;<br>
          <br>
          This HashMap is accessed (read and write) in a method<br>
          sun.font.SunFontManager#findFontFromPlatformMap. As I see
          there is no<br>
          synchronization when this HashMap is accessed.<br>
          This method can be called from client code with this simple
          stack trace:<br>
          <br>
          &nbsp; &nbsp; &nbsp; at
sun.font.SunFontManager.findFontFromPlatformMap(SunFontManager.java:1508)<br>
          &nbsp; &nbsp; &nbsp; at
          sun.font.SunFontManager.findFont2D(SunFontManager.java:2069)<br>
          &nbsp; &nbsp; &nbsp; at java.awt.Font.getFont2D(Font.java:500)<br>
          &nbsp; &nbsp; &nbsp; at java.awt.Font.getPSName(Font.java:1416)<br>
          <br>
          I wonder if this unsynchronized access is expected. Looks like
          it can<br>
          break things when accessed from multiple threads
          simultaneously.<br>
          Do I miss something? Is it done this way, because Font objects
          are<br>
          supposed to be accessed from a single thread only?<br>
          <br>
          Andrey Turbanov<br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic