changeset 7832:dadd43e02a79

8017580: Crash in font loading code on Linux (due to use of reflection) Reviewed-by: bae, vadim
author prr
date Mon, 19 Aug 2013 03:58:47 -0700
parents b44ce67c0565
children 0c950b2be7ab
files src/share/native/sun/font/sunFont.c src/share/native/sun/font/sunfontids.h
diffstat 2 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/sun/font/sunFont.c	Fri Aug 16 15:57:28 2013 +0400
+++ b/src/share/native/sun/font/sunFont.c	Mon Aug 19 03:58:47 2013 -0700
@@ -71,13 +71,17 @@
 void initLCDGammaTables();
 
 /* placeholder for extern variable */
+static int initialisedFontIDs = 0;
 FontManagerNativeIDs sunFontIDs;
 
-JNIEXPORT void JNICALL
-Java_sun_font_SunFontManager_initIDs
-    (JNIEnv *env, jclass cls) {
+static void initFontIDs(JNIEnv *env) {
 
-     jclass tmpClass = (*env)->FindClass(env, "sun/font/TrueTypeFont");
+     jclass tmpClass;
+
+     if (initialisedFontIDs) {
+        return;
+     }
+     tmpClass = (*env)->FindClass(env, "sun/font/TrueTypeFont");
      sunFontIDs.ttReadBlockMID =
          (*env)->GetMethodID(env, tmpClass, "readBlock",
                              "(Ljava/nio/ByteBuffer;II)I");
@@ -173,9 +177,20 @@
          (*env)->GetFieldID(env, tmpClass, "lcdSubPixPos", "Z");
 
      initLCDGammaTables();
+
+     initialisedFontIDs = 1;
 }
 
-JNIEXPORT FontManagerNativeIDs getSunFontIDs() {
+JNIEXPORT void JNICALL
+Java_sun_font_SunFontManager_initIDs
+    (JNIEnv *env, jclass cls) {
+
+    initFontIDs(env);
+}
+
+JNIEXPORT FontManagerNativeIDs getSunFontIDs(JNIEnv *env) {
+
+    initFontIDs(env);
     return sunFontIDs;
 }
 
--- a/src/share/native/sun/font/sunfontids.h	Fri Aug 16 15:57:28 2013 +0400
+++ b/src/share/native/sun/font/sunfontids.h	Mon Aug 19 03:58:47 2013 -0700
@@ -84,7 +84,7 @@
 /* Note: we share variable in the context of fontmanager lib
    but we need access method to use it from separate rasterizer lib */
 extern FontManagerNativeIDs sunFontIDs;
-JNIEXPORT FontManagerNativeIDs getSunFontIDs();
+JNIEXPORT FontManagerNativeIDs getSunFontIDs(JNIEnv* env);
 
 #ifdef  __cplusplus
 }