< prev index next >
src/java.desktop/share/classes/sun/font/GlyphList.java
Print this page
*** 26,35 ****
--- 26,36 ----
package sun.font;
import java.awt.Font;
import java.awt.font.GlyphVector;
import java.awt.font.FontRenderContext;
+ import java.util.concurrent.atomic.AtomicBoolean;
import sun.java2d.loops.FontInfo;
/*
* This class represents a list of actual renderable glyphs.
* It can be constructed from a number of text sources, representing
*** 149,160 ****
* GlyphList is checked out for a long time (or never returned?) then
* we would end up always creating new ones. That situation should not
* occur and if it did, it would just lead to some extra garbage being
* created.
*/
! private static GlyphList reusableGL = new GlyphList();
! private static boolean inUse;
void ensureCapacity(int len) {
/* Note len must not be -ve! only setFromChars should be capable
* of passing down a -ve len, and this guards against it.
--- 150,161 ----
* GlyphList is checked out for a long time (or never returned?) then
* we would end up always creating new ones. That situation should not
* occur and if it did, it would just lead to some extra garbage being
* created.
*/
! private static final GlyphList reusableGL = new GlyphList();
! private static final AtomicBoolean inUse = new AtomicBoolean();
void ensureCapacity(int len) {
/* Note len must not be -ve! only setFromChars should be capable
* of passing down a -ve len, and this guards against it.
*** 182,230 ****
// private GlyphList(int arraylen) {
// ensureCapacity(arraylen);
// }
public static GlyphList getInstance() {
! /* The following heuristic is that if the reusable instance is
! * in use, it probably still will be in a micro-second, so avoid
! * synchronising on the class and just allocate a new instance.
! * The cost is one extra boolean test for the normal case, and some
! * small number of cases where we allocate an extra object when
! * in fact the reusable one would be freed very soon.
! */
! if (inUse) {
! return new GlyphList();
} else {
- synchronized(GlyphList.class) {
- if (inUse) {
return new GlyphList();
- } else {
- inUse = true;
- return reusableGL;
- }
- }
}
}
/* In some cases the caller may be able to estimate the size of
* array needed, and it will usually be long enough. This avoids
* the unnecessary reallocation that occurs if our default
* values are too small. This is useful because this object
* will be discarded so the re-allocation overhead is high.
*/
// public static GlyphList getInstance(int sz) {
! // if (inUse) {
! // return new GlyphList(sz);
! // } else {
! // synchronized(GlyphList.class) {
! // if (inUse) {
! // return new GlyphList();
! // } else {
! // inUse = true;
// return reusableGL;
! // }
! // }
// }
// }
/* GlyphList is in an invalid state until setFrom* method is called.
* After obtaining a new GlyphList it is the caller's responsibility
--- 183,210 ----
// private GlyphList(int arraylen) {
// ensureCapacity(arraylen);
// }
public static GlyphList getInstance() {
! if (inUse.compareAndSet(false, true)) {
! return reusableGL;
} else {
return new GlyphList();
}
}
/* In some cases the caller may be able to estimate the size of
* array needed, and it will usually be long enough. This avoids
* the unnecessary reallocation that occurs if our default
* values are too small. This is useful because this object
* will be discarded so the re-allocation overhead is high.
*/
// public static GlyphList getInstance(int sz) {
! // if (inUse.compareAndSet(false, true) {
// return reusableGL;
! // } else {
! // return new GlyphList(sz);
// }
// }
/* GlyphList is in an invalid state until setFrom* method is called.
* After obtaining a new GlyphList it is the caller's responsibility
*** 421,431 ****
if (graybits != null && graybits.length > MAXGRAYLENGTH) {
graybits = null;
}
usePositions = false;
strikelist = null; // remove reference to the strike list
! inUse = false;
}
}
/* The value here is for use by the rendering engine as it reflects
* the number of glyphs in the array to be blitted. Surrogates pairs
--- 401,411 ----
if (graybits != null && graybits.length > MAXGRAYLENGTH) {
graybits = null;
}
usePositions = false;
strikelist = null; // remove reference to the strike list
! inUse.set(false);
}
}
/* The value here is for use by the rendering engine as it reflects
* the number of glyphs in the array to be blitted. Surrogates pairs
< prev index next >