changeset 3422:b0f9760f3103

7007299: FileFontStrike appears not to be threadsafe? Reviewed-by: igor, jgodinez
author prr
date Wed, 22 Dec 2010 13:32:58 -0800
parents 0125062d65b6
children 1513ccf103a9
files src/share/classes/sun/font/FileFontStrike.java
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/font/FileFontStrike.java	Mon Dec 20 10:38:55 2010 +0300
+++ b/src/share/classes/sun/font/FileFontStrike.java	Wed Dec 22 13:32:58 2010 -0800
@@ -58,7 +58,7 @@
     private static final int SEGINTARRAY   = 3;
     private static final int SEGLONGARRAY  = 4;
 
-    private int glyphCacheFormat = UNINITIALISED;
+    private volatile int glyphCacheFormat = UNINITIALISED;
 
     /* segmented arrays are blocks of 256 */
     private static final int SEGSHIFT = 8;
@@ -522,32 +522,33 @@
     }
 
     /* Called only from synchronized code or constructor */
-    private void initGlyphCache() {
+    private synchronized void initGlyphCache() {
 
         int numGlyphs = mapper.getNumGlyphs();
-
+        int tmpFormat = UNINITIALISED;
         if (segmentedCache) {
             int numSegments = (numGlyphs + SEGSIZE-1)/SEGSIZE;
             if (longAddresses) {
-                glyphCacheFormat = SEGLONGARRAY;
+                tmpFormat = SEGLONGARRAY;
                 segLongGlyphImages = new long[numSegments][];
                 this.disposer.segLongGlyphImages = segLongGlyphImages;
              } else {
-                 glyphCacheFormat = SEGINTARRAY;
+                 tmpFormat = SEGINTARRAY;
                  segIntGlyphImages = new int[numSegments][];
                  this.disposer.segIntGlyphImages = segIntGlyphImages;
              }
         } else {
             if (longAddresses) {
-                glyphCacheFormat = LONGARRAY;
+                tmpFormat = LONGARRAY;
                 longGlyphImages = new long[numGlyphs];
                 this.disposer.longGlyphImages = longGlyphImages;
             } else {
-                glyphCacheFormat = INTARRAY;
+                tmpFormat = INTARRAY;
                 intGlyphImages = new int[numGlyphs];
                 this.disposer.intGlyphImages = intGlyphImages;
             }
         }
+        glyphCacheFormat = tmpFormat;
     }
 
     float getGlyphAdvance(int glyphCode) {