Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/font/NativeStrikeDisposer.java
32287 views
/*1* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.font;2627/*28* This keeps track of data that needs to be cleaned up once a29* strike is freed.30* a) The native memory that is the glyph image cache.31* b) removing the "desc" key from the strike's map.32* This is safe to do because this disposer is invoked only when the33* reference object has been cleared, which means the value indexed by34* this key is just an empty reference object.35* It is possible that a new FontStrike has been created that would36* be referenced by the same (equals) key. If it is placed in the map37* before this disposer is executed, then we do not want to remove that38* object. We should only remove an object where the value is null.39* So we first verify that the key still points to a cleared reference.40* Updates to the map thus need to be synchronized.41*42* A WeakHashmap will automatically clean up, but we might maintain a43* reference to the "desc" key in the FontStrike (value) which would44* prevent the keys from being discarded. And since the strike is the only45* place is likely we would maintain such a strong reference, then the map46* entries would be removed much more promptly than we need.47*/4849class NativeStrikeDisposer extends FontStrikeDisposer {5051long pNativeScalerContext;5253public NativeStrikeDisposer(Font2D font2D, FontStrikeDesc desc,54long pContext, int[] images) {55super(font2D, desc, 0L, images);56pNativeScalerContext = pContext;57}5859public NativeStrikeDisposer(Font2D font2D, FontStrikeDesc desc,60long pContext, long[] images) {61super(font2D, desc, 0L, images);62pNativeScalerContext = pContext;63}6465public NativeStrikeDisposer(Font2D font2D, FontStrikeDesc desc,66long pContext) {67super(font2D, desc, 0L);68pNativeScalerContext = pContext;69}7071public NativeStrikeDisposer(Font2D font2D, FontStrikeDesc desc) {72super(font2D, desc);73}7475public synchronized void dispose() {76if (!disposed) {77if (pNativeScalerContext != 0L) {78freeNativeScalerContext(pNativeScalerContext);79}80super.dispose();81}82}8384private native void freeNativeScalerContext(long pContext);85}868788