--- old/src/solaris/native/sun/awt/awt_UNIXToolkit.c 2013-09-23 21:01:15.991135498 +0400 +++ new/src/solaris/native/sun/awt/awt_UNIXToolkit.c 2013-09-23 21:01:15.859135502 +0400 @@ -67,7 +67,7 @@ Java_sun_awt_UNIXToolkit_load_1gtk(JNIEnv *env, jclass klass) { #ifndef HEADLESS - return (jboolean)gtk2_load(); + return (jboolean)gtk2_load(env); #else return JNI_FALSE; #endif /* !HEADLESS */ --- old/src/solaris/native/sun/awt/gtk2_interface.c 2013-09-23 21:01:16.415135490 +0400 +++ new/src/solaris/native/sun/awt/gtk2_interface.c 2013-09-23 21:01:16.267135492 +0400 @@ -81,7 +81,7 @@ static void *gtk2_libhandle = NULL; static void *gthread_libhandle = NULL; -static gboolean flag_g_thread_get_initialized = FALSE; + static jmp_buf j; /* Widgets */ @@ -502,7 +502,7 @@ fp_gtk_g_slist_length = dl_symbol("g_slist_length"); } -gboolean gtk2_load() +gboolean gtk2_load(JNIEnv *env) { gboolean result; int i; @@ -810,16 +810,23 @@ io_handler = XSetIOErrorHandler(NULL); if (fp_gtk_check_version(2, 2, 0) == NULL) { - // Init the thread system to use GLib in a thread-safe mode - if (!flag_g_thread_get_initialized) { - flag_g_thread_get_initialized = TRUE; + jclass class = (*env)->FindClass(env, "sun/misc/GThreadHelper"); + jmethodID mid_isInitializationNeeded = (*env)->GetStaticMethodID(env, class, "isInitializationNeeded", "()Z"); + jmethodID mid_lock = (*env)->GetStaticMethodID(env, class, "lock", "()V"); + jmethodID mid_unlock = (*env)->GetStaticMethodID(env, class, "unlock", "()V"); + jmethodID mid_initFinished = (*env)->GetStaticMethodID(env, class, "initFinished", "()V"); + // Init the thread system to use GLib in a thread-safe mode + (*env)->CallStaticVoidMethod(env, class, mid_lock); + if ((*env)->CallStaticBooleanMethod(env, class, mid_isInitializationNeeded)) { fp_g_thread_init(NULL); //According the GTK documentation, gdk_threads_init() should be //called before gtk_init() or gtk_init_check() fp_gdk_threads_init(); + (*env)->CallStaticVoidMethod(env, class, mid_initFinished); } + (*env)->CallStaticVoidMethod(env, class, mid_unlock); } result = (*fp_gtk_init_check)(NULL, NULL); --- old/src/solaris/native/sun/awt/gtk2_interface.h 2013-09-23 21:01:16.887135478 +0400 +++ new/src/solaris/native/sun/awt/gtk2_interface.h 2013-09-23 21:01:16.747135482 +0400 @@ -663,7 +663,7 @@ * effect and returns success. * Returns FALSE on failure and TRUE on success. */ -gboolean gtk2_load(); +gboolean gtk2_load(JNIEnv *env); /* * Loads fp_gtk_show_uri function pointer. This initialization is --- old/src/solaris/native/sun/xawt/awt_Desktop.c 2013-09-23 21:01:17.315135469 +0400 +++ new/src/solaris/native/sun/xawt/awt_Desktop.c 2013-09-23 21:01:17.187135473 +0400 @@ -42,7 +42,7 @@ return JNI_TRUE; } - if (gtk2_load() && gtk2_show_uri_load()) { + if (gtk2_load(env) && gtk2_show_uri_load()) { gtk_has_been_loaded = TRUE; return JNI_TRUE; } else if (gnome_load()) { --- /dev/null 2013-09-23 13:00:00.231764993 +0400 +++ new/src/solaris/classes/sun/misc/GThreadHelper.java 2013-09-23 21:01:17.575135463 +0400 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package sun.misc; + +import java.util.concurrent.locks.ReentrantLock; + +/** + * This class is used to prevent multiple calling of g_thread_init (). + * + * Since version 2.24 of GLib, calling g_thread_init () multiple times is + * allowed, but for older versions it will crash. There are two ways to + * find out if g_thread_init() has been called: + * g_thread_get_initialized (), but it was introduced in 2.20 + * g_thread_supported (), but it is a macro and cannot be loaded with dlsym. + * + * usage: + *
+ * lock();
+ * if (isInitializationNeeded) {
+ *     //call to g_thread_init();
+ *     initFinished();
+ * }
+ * unlock();
+ * 
+ */ +public final class GThreadHelper { + + private static final ReentrantLock LOCK = new ReentrantLock(); + private static volatile boolean isGThreadInitialized = false; + + static void lock() { + LOCK.lock(); + } + + static void unlock() { + LOCK.unlock(); + } + + /** + * MUST be called under LOCK + * @return {@code true} if g_thread_init() has not been called + */ + static boolean isInitializationNeeded() { + return !isGThreadInitialized; + } + + /** + * MUST be called under LOCK + * Call this method only after g_thread_init() call. + */ + static void initFinished() { + isGThreadInitialized = true; + } +}