8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe
------------- Commit messages: - [PATCH] Thread-safe initialization of SunFontManager.platformFontMap - [PATCH] Thread-safe initialization of SunFontManager.platformFontMap Changes: https://git.openjdk.java.net/jdk/pull/2762/files Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2762&range=00 Issue: https://bugs.openjdk.java.net/browse/JDK-8263138 Stats: 7 lines in 1 file changed: 3 ins; 0 del; 4 mod Patch: https://git.openjdk.java.net/jdk/pull/2762.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/2762/head:pull/2762 PR: https://git.openjdk.java.net/jdk/pull/2762 |
On Sat, 27 Feb 2021 18:33:52 GMT, Andrey Turbanov <[hidden email]> wrote:
> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe The bug: https://bugs.openjdk.java.net/browse/JDK-8263138 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. ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
On Sun, 7 Mar 2021 03:32:01 GMT, Sergey Bylokhov <[hidden email]> wrote:
>> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe > > The bug: https://bugs.openjdk.java.net/browse/JDK-8263138 I don't know why making this volatile is doing anything. Let's discuss this further. ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
In reply to this post by Sergey Bylokhov-2
On Sat, 27 Feb 2021 22:30:18 GMT, Sergey Bylokhov <[hidden email]> wrote:
>> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe > > 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. ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
On Sun, 28 Feb 2021 03:50:13 GMT, liach <[hidden email]> 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 |
On Sun, 28 Feb 2021 04:56:07 GMT, Sergey Bylokhov <[hidden email]> wrote:
>> 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. Made `volatile` to guarantee memory visibility if thread saw non-null value. ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
On Sun, 28 Feb 2021 08:47:22 GMT, Andrey Turbanov <[hidden email]> wrote:
>> 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. > > Made `volatile` to guarantee memory visibility if thread saw non-null value. I don't have any other questions, will file a bug and run the tests. ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
In reply to this post by Andrey Turbanov-2
On Sat, 27 Feb 2021 18:33:52 GMT, Andrey Turbanov <[hidden email]> wrote:
> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe Marked as reviewed by aivanov (Reviewer). ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
On Tue, 9 Mar 2021 20:56:15 GMT, Alexey Ivanov <[hidden email]> wrote:
>> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe > > Marked as reviewed by aivanov (Reviewer). > I don't know why making this volatile is doing anything. > Let's discuss this further. It will prevent the possibility that one thread will store the non-null value to the SunFontManager.platformFontMap and only after that complete initialization of object stored in that field due to code optimizations. It is similar to the volatile DCL: see "broken multithreaded version" example: https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
In reply to this post by Andrey Turbanov-2
On Sat, 27 Feb 2021 18:33:52 GMT, Andrey Turbanov <[hidden email]> wrote:
> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe Marked as reviewed by kizune (Reviewer). ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
In reply to this post by Andrey Turbanov-2
On Sat, 27 Feb 2021 18:33:52 GMT, Andrey Turbanov <[hidden email]> wrote:
> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe Marked as reviewed by serb (Reviewer). ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
On Wed, 10 Mar 2021 23:13:09 GMT, Sergey Bylokhov <[hidden email]> wrote:
>> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe > > Marked as reviewed by serb (Reviewer). @prrace Do you have any objections to integrating this change? ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
In reply to this post by Andrey Turbanov-2
On Sat, 27 Feb 2021 18:33:52 GMT, Andrey Turbanov <[hidden email]> wrote:
> 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe This pull request has now been integrated. Changeset: ab66d699 Author: Andrey Turbanov <[hidden email]> Committer: Sergey Bylokhov <[hidden email]> URL: https://git.openjdk.java.net/jdk/commit/ab66d699 Stats: 7 lines in 1 file changed: 3 ins; 0 del; 4 mod 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe Reviewed-by: aivanov, kizune, serb ------------- PR: https://git.openjdk.java.net/jdk/pull/2762 |
Free forum by Nabble | Edit this page |