changeset 3430:4e47e55dd717

6927458: font system should cache transient strikes with weak references. Reviewed-by: igor, jgodinez
author prr
date Thu, 23 Dec 2010 21:58:12 -0800
parents 417acb7e8fa1
children 99c540ac926c
files src/share/classes/sun/font/Font2D.java
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/font/Font2D.java	Thu Dec 23 15:28:59 2010 -0800
+++ b/src/share/classes/sun/font/Font2D.java	Thu Dec 23 21:58:12 2010 -0800
@@ -343,7 +343,21 @@
             }
             strike = createStrike(desc);
             //StrikeCache.addStrike();
-            strikeRef = StrikeCache.getStrikeRef(strike);
+            /* If we are creating many strikes on this font which
+             * involve non-quadrant rotations, or more general
+             * transforms which include shears, then force the use
+             * of weak references rather than soft references.
+             * This means that it won't live much beyond the next GC,
+             * which is what we want for what is likely a transient strike.
+             */
+            int txType = desc.glyphTx.getType();
+            if (txType == AffineTransform.TYPE_GENERAL_TRANSFORM ||
+                (txType & AffineTransform.TYPE_GENERAL_ROTATION) != 0 &&
+                strikeCache.size() > 10) {
+                strikeRef = StrikeCache.getStrikeRef(strike, true);
+            } else {
+                strikeRef = StrikeCache.getStrikeRef(strike);
+            }
             strikeCache.put(desc, strikeRef);
             //strike.lastlookupTime = System.currentTimeMillis();
             lastFontStrike = new SoftReference(strike);