From 5119e6d87a022547362afa52d8dd3093d6d47b80 Mon Sep 17 00:00:00 2001
From: Phil Race <prr@openjdk.org>
Date: Thu, 23 Dec 2010 21:58:12 -0800
Subject: [PATCH] 6927458: font system should cache transient strikes with weak
 references

Reviewed-by: igor, jgodinez
---
 jdk/src/share/classes/sun/font/Font2D.java | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/jdk/src/share/classes/sun/font/Font2D.java b/jdk/src/share/classes/sun/font/Font2D.java
index 3fab32c8434..b78292722b5 100644
--- a/jdk/src/share/classes/sun/font/Font2D.java
+++ b/jdk/src/share/classes/sun/font/Font2D.java
@@ -343,7 +343,21 @@ public abstract class Font2D {
             }
             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);