RFR: 8273581: Change the mechanism by which JDK loads the platform-specific FontManager class [v3]

Sergey Bylokhov serb at openjdk.java.net
Sat Sep 18 23:11:51 UTC 2021


On Fri, 17 Sep 2021 12:42:51 GMT, Alexander Scherbatiy <alexsch at openjdk.org> wrote:

>> src/java.desktop/share/classes/sun/font/FontManagerFactory.java line 55:
>> 
>>> 53:      */
>>> 54:     @SuppressWarnings("removal")
>>> 55:     public static synchronized FontManager getInstance() {
>> 
>> Just an idea, since the method became so small can we use DLC here instead of synchronised static method?
>
> The method `FontManagerFactory.getInstance()` is updated to use DLC.
> 
> I used synchronization on FontManagerFactory.class in the first check to be consistent with the previous behavior where synchronization was on the `FontManagerFactory.getInstance()` method.
> 
> What about to use a static nested class singleton? It could look like:
> 
> public final class FontManagerFactory {
> 
>     public static FontManager getInstance() {
>         return FontManagerHolder.instance;
>     }
> 
>     private static class FontManagerHolder {
>         private static final FontManager instance = PlatformFontInfo.createFontManager();
>     }
> }

The SunFontManager constructor and its subclasses seem too big, and potentially throw some exceptions and this will ruin the holder idiom since all subsequent calls to this method will fail.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5517



More information about the client-libs-dev mailing list