[OpenJDK 2D-Dev] RFR: 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe
Sergey Bylokhov
serb at openjdk.java.net
Sun Mar 7 19:36:15 UTC 2021
On Sun, 28 Feb 2021 03:50:13 GMT, liach <github.com+7806504+liach at openjdk.org> wrote:
>> src/java.desktop/share/classes/sun/font/SunFontManager.java line 1452:
>>
>>> 1450: if (platformFontMap == null) {
>>> 1451: platformFontMap = populateHardcodedFileNameMap();
>>> 1452: SunFontManager.platformFontMap = platformFontMap;
>>
>> I am not sure it is enough for "thread-safe initialization". The "platformFontMap" might not be null, but its content can be broken/incomplete at this point.
>
> https://github.com/openjdk/jdk/pull/2691#issuecomment-784367127
>
> In short, previously platformFontMap references were field set/gets and may be inconsistent due to concurrency. It is now moved to a local variable; also the map modifications have been moved to fields to avoid concurrency issues with hash map as far as I can see.
One thread may create the local platformFontMap, then set the static SunFontManager.platformFontMap field, and then initialize the platformFontMap or mix these operations. The second thread may see non-null SunFontManager.platformFontMap which is not still initialized.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2762
More information about the 2d-dev
mailing list