diff --git a/src/java.desktop/macosx/classes/sun/font/CStrike.java b/src/java.desktop/macosx/classes/sun/font/CStrike.java index 69b53433c4f17..4b0ac9fd8d322 100644 --- a/src/java.desktop/macosx/classes/sun/font/CStrike.java +++ b/src/java.desktop/macosx/classes/sun/font/CStrike.java @@ -39,7 +39,7 @@ private static native long createNativeStrikePtr(long nativeFontPtr, int fmHint); // Disposes the native strike - private static native void disposeNativeStrikePtr(long nativeStrikePtr); + static native void disposeNativeStrikePtr(long nativeStrikePtr); // Creates a StrikeMetrics from the underlying native system fonts private static native StrikeMetrics getFontMetrics(long nativeStrikePtr); @@ -70,14 +70,11 @@ private static native void getNativeGlyphImageBounds(long nativeStrikePtr, private AffineTransform invDevTx; private final GlyphInfoCache glyphInfoCache; private final GlyphAdvanceCache glyphAdvanceCache; - private long nativeStrikePtr; + private final long nativeStrikePtr; CStrike(final CFont font, final FontStrikeDesc inDesc) { nativeFont = font; desc = inDesc; - glyphInfoCache = new GlyphInfoCache(font, desc); - glyphAdvanceCache = new GlyphAdvanceCache(); - disposer = glyphInfoCache; // Normally the device transform should be the identity transform // for screen operations. The device transform only becomes @@ -92,12 +89,18 @@ private static native void getNativeGlyphImageBounds(long nativeStrikePtr, // so we won't worry about it. } } + nativeStrikePtr = initNativeStrikePtr(); // after setting up invDevTx + glyphInfoCache = new GlyphInfoCache(font, desc, nativeStrikePtr); + glyphAdvanceCache = new GlyphAdvanceCache(); + disposer = glyphInfoCache; } public long getNativeStrikePtr() { - if (nativeStrikePtr != 0) { - return nativeStrikePtr; - } + return nativeStrikePtr; + } + + public long initNativeStrikePtr() { + long nativeStrikePtr = 0L; final double[] glyphTx = new double[6]; desc.glyphTx.getMatrix(glyphTx); @@ -136,16 +139,6 @@ public long getNativeStrikePtr() { return nativeStrikePtr; } - @Override - @SuppressWarnings("removal") - protected synchronized void finalize() throws Throwable { - if (nativeStrikePtr != 0) { - disposeNativeStrikePtr(nativeStrikePtr); - } - nativeStrikePtr = 0; - } - - @Override public int getNumGlyphs() { return nativeFont.getNumGlyphs(); @@ -379,8 +372,8 @@ private static final class GlyphInfoCache extends CStrikeDisposer { private SparseBitShiftingTwoLayerArray secondLayerCache; private HashMap generalCache; - GlyphInfoCache(final Font2D nativeFont, final FontStrikeDesc desc) { - super(nativeFont, desc); + GlyphInfoCache(final Font2D nativeFont, final FontStrikeDesc desc, long pScalerContext) { + super(nativeFont, desc, pScalerContext); firstLayerCache = new long[FIRST_LAYER_SIZE]; } diff --git a/src/java.desktop/macosx/classes/sun/font/CStrikeDisposer.java b/src/java.desktop/macosx/classes/sun/font/CStrikeDisposer.java index f032d716e905a..c37209c83967f 100644 --- a/src/java.desktop/macosx/classes/sun/font/CStrikeDisposer.java +++ b/src/java.desktop/macosx/classes/sun/font/CStrikeDisposer.java @@ -48,7 +48,7 @@ */ class CStrikeDisposer extends FontStrikeDisposer { - long pNativeScalerContext; + private final long pNativeScalerContext; public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc, long pContext, int[] images) @@ -73,19 +73,18 @@ public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc, public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc) { super(font2D, desc); + pNativeScalerContext = 0L; } @Override public synchronized void dispose() { if (!disposed) { if (pNativeScalerContext != 0L) { - freeNativeScalerContext(pNativeScalerContext); + CStrike.disposeNativeStrikePtr(pNativeScalerContext); } super.dispose(); } } - private native void freeNativeScalerContext(long pContext); - protected static native void removeGlyphInfoFromCache(long glyphInfo); }