src/share/classes/sun/font/FileFont.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 142      *
 143      * It also appears desirable to remove all the entries from the
 144      * cache so no other code will pick them up. But we can't just
 145      * 'delete' them as code may be using them. And simply dropping
 146      * the reference to the cache will make the reference objects
 147      * unreachable and so they will not get disposed.
 148      * Since a strike may hold (via java arrays) native pointers to many
 149      * rasterised glyphs, this would be a memory leak.
 150      * The solution is :
 151      * - to move all the entries to another map where they
 152      *   are no longer locatable
 153      * - update FontStrikeDisposer to be able to distinguish which
 154      * map they are held in via a boolean flag
 155      * Since this isn't expected to be anything other than an extremely
 156      * rare maybe it is not worth doing this last part.
 157      */
 158     synchronized void deregisterFontAndClearStrikeCache() {
 159         SunFontManager fm = SunFontManager.getInstance();
 160         fm.deRegisterBadFont(this);
 161 
 162         for (Reference strikeRef : strikeCache.values()) {
 163             if (strikeRef != null) {
 164                 /* NB we know these are all FileFontStrike instances
 165                  * because the cache is on this FileFont
 166                  */
 167                 FileFontStrike strike = (FileFontStrike)strikeRef.get();
 168                 if (strike != null && strike.pScalerContext != 0L) {
 169                     scaler.invalidateScalerContext(strike.pScalerContext);
 170                 }
 171             }
 172         }
 173         if (scaler != null) {
 174             scaler.dispose();
 175         }
 176         scaler = FontScaler.getNullScaler();
 177     }
 178 
 179     StrikeMetrics getFontMetrics(long pScalerContext) {
 180         try {
 181             return getScaler().getFontMetrics(pScalerContext);
 182         } catch (FontScalerException fe) {


 244     protected abstract FontScaler getScaler();
 245 
 246     protected long getUnitsPerEm() {
 247         return getScaler().getUnitsPerEm();
 248     }
 249 
 250     private static class CreatedFontFileDisposerRecord
 251         implements DisposerRecord {
 252 
 253         File fontFile = null;
 254         CreatedFontTracker tracker;
 255 
 256         private CreatedFontFileDisposerRecord(File file,
 257                                               CreatedFontTracker tracker) {
 258             fontFile = file;
 259             this.tracker = tracker;
 260         }
 261 
 262         public void dispose() {
 263             java.security.AccessController.doPrivileged(
 264                  new java.security.PrivilegedAction() {
 265                       public Object run() {
 266                           if (fontFile != null) {
 267                               try {
 268                                   if (tracker != null) {
 269                                       tracker.subBytes((int)fontFile.length());
 270                                   }
 271                                   /* REMIND: is it possible that the file is
 272                                    * still open? It will be closed when the
 273                                    * font2D is disposed but could this code
 274                                    * execute first? If so the file would not
 275                                    * be deleted on MS-windows.
 276                                    */
 277                                   fontFile.delete();
 278                                   /* remove from delete on exit hook list : */
 279                                   // FIXME: still need to be refactored
 280                                   SunFontManager.getInstance().tmpFontFiles.remove(fontFile);
 281                               } catch (Exception e) {
 282                               }
 283                           }
 284                           return null;


   1 /*
   2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 142      *
 143      * It also appears desirable to remove all the entries from the
 144      * cache so no other code will pick them up. But we can't just
 145      * 'delete' them as code may be using them. And simply dropping
 146      * the reference to the cache will make the reference objects
 147      * unreachable and so they will not get disposed.
 148      * Since a strike may hold (via java arrays) native pointers to many
 149      * rasterised glyphs, this would be a memory leak.
 150      * The solution is :
 151      * - to move all the entries to another map where they
 152      *   are no longer locatable
 153      * - update FontStrikeDisposer to be able to distinguish which
 154      * map they are held in via a boolean flag
 155      * Since this isn't expected to be anything other than an extremely
 156      * rare maybe it is not worth doing this last part.
 157      */
 158     synchronized void deregisterFontAndClearStrikeCache() {
 159         SunFontManager fm = SunFontManager.getInstance();
 160         fm.deRegisterBadFont(this);
 161 
 162         for (Reference<FontStrike> strikeRef : strikeCache.values()) {
 163             if (strikeRef != null) {
 164                 /* NB we know these are all FileFontStrike instances
 165                  * because the cache is on this FileFont
 166                  */
 167                 FileFontStrike strike = (FileFontStrike)strikeRef.get();
 168                 if (strike != null && strike.pScalerContext != 0L) {
 169                     scaler.invalidateScalerContext(strike.pScalerContext);
 170                 }
 171             }
 172         }
 173         if (scaler != null) {
 174             scaler.dispose();
 175         }
 176         scaler = FontScaler.getNullScaler();
 177     }
 178 
 179     StrikeMetrics getFontMetrics(long pScalerContext) {
 180         try {
 181             return getScaler().getFontMetrics(pScalerContext);
 182         } catch (FontScalerException fe) {


 244     protected abstract FontScaler getScaler();
 245 
 246     protected long getUnitsPerEm() {
 247         return getScaler().getUnitsPerEm();
 248     }
 249 
 250     private static class CreatedFontFileDisposerRecord
 251         implements DisposerRecord {
 252 
 253         File fontFile = null;
 254         CreatedFontTracker tracker;
 255 
 256         private CreatedFontFileDisposerRecord(File file,
 257                                               CreatedFontTracker tracker) {
 258             fontFile = file;
 259             this.tracker = tracker;
 260         }
 261 
 262         public void dispose() {
 263             java.security.AccessController.doPrivileged(
 264                  new java.security.PrivilegedAction<Object>() {
 265                       public Object run() {
 266                           if (fontFile != null) {
 267                               try {
 268                                   if (tracker != null) {
 269                                       tracker.subBytes((int)fontFile.length());
 270                                   }
 271                                   /* REMIND: is it possible that the file is
 272                                    * still open? It will be closed when the
 273                                    * font2D is disposed but could this code
 274                                    * execute first? If so the file would not
 275                                    * be deleted on MS-windows.
 276                                    */
 277                                   fontFile.delete();
 278                                   /* remove from delete on exit hook list : */
 279                                   // FIXME: still need to be refactored
 280                                   SunFontManager.getInstance().tmpFontFiles.remove(fontFile);
 281                               } catch (Exception e) {
 282                               }
 283                           }
 284                           return null;