Skip to content

8210765: Remove finalize method in CStrike.java #26397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions src/java.desktop/macosx/classes/sun/font/CStrike.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -379,8 +372,8 @@ private static final class GlyphInfoCache extends CStrikeDisposer {
private SparseBitShiftingTwoLayerArray secondLayerCache;
private HashMap<Integer, Long> 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];
}

Expand Down
7 changes: 3 additions & 4 deletions src/java.desktop/macosx/classes/sun/font/CStrikeDisposer.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
class CStrikeDisposer extends FontStrikeDisposer {

long pNativeScalerContext;
private final long pNativeScalerContext;

public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc,
long pContext, int[] images)
Expand All @@ -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);
}