8154546: Retire sun.misc.GThreadHelper
authorprr
Thu, 12 May 2016 09:16:17 -0700
changeset 38412 96e1d2c5d435
parent 38411 39056b8055ca
child 38413 d9e49b45fd7d
8154546: Retire sun.misc.GThreadHelper Reviewed-by: serb, chegar, kcr
jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk2_interface.c
jdk/src/jdk.unsupported/unix/classes/sun/misc/GThreadHelper.java
--- a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk2_interface.c	Tue May 10 16:08:21 2016 +0530
+++ b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk2_interface.c	Thu May 12 09:16:17 2016 -0700
@@ -817,52 +817,22 @@
     io_handler = XSetIOErrorHandler(NULL);
 
     if (fp_gtk_check_version(2, 2, 0) == NULL) {
-        jclass clazz = (*env)->FindClass(env, "sun/misc/GThreadHelper");
-        jmethodID mid_getAndSetInitializationNeededFlag =
-                (*env)->GetStaticMethodID(env, clazz, "getAndSetInitializationNeededFlag", "()Z");
-        jmethodID mid_lock = (*env)->GetStaticMethodID(env, clazz, "lock", "()V");
-        jmethodID mid_unlock = (*env)->GetStaticMethodID(env, clazz, "unlock", "()V");
-
-        // Init the thread system to use GLib in a thread-safe mode
-        (*env)->CallStaticVoidMethod(env, clazz, mid_lock);
-        if ((*env)->ExceptionCheck(env)) {
-            AWT_UNLOCK();
-            return FALSE;
-        }
 
         // Calling g_thread_init() multiple times leads to crash on GLib < 2.24
         // We can use g_thread_get_initialized () but it is available only for
-        // GLib >= 2.20. We rely on GThreadHelper for GLib < 2.20.
+        // GLib >= 2.20.
         gboolean is_g_thread_get_initialized = FALSE;
         if (GLIB_CHECK_VERSION(2, 20, 0)) {
             is_g_thread_get_initialized = fp_g_thread_get_initialized();
         }
 
-        if (!(*env)->CallStaticBooleanMethod(env, clazz, mid_getAndSetInitializationNeededFlag)) {
-            if (!is_g_thread_get_initialized) {
-                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();
+        if (!is_g_thread_get_initialized) {
+            fp_g_thread_init(NULL);
         }
-        jthrowable pendExcpn = NULL;
-        // Exception raised during mid_getAndSetInitializationNeededFlag
-        // call is saved and error handling is done
-        // after unlock method is called
-        if ((pendExcpn = (*env)->ExceptionOccurred(env)) != NULL) {
-            (*env)->ExceptionClear(env);
-        }
-        (*env)->CallStaticVoidMethod(env, clazz, mid_unlock);
-        if (pendExcpn != NULL) {
-            (*env)->Throw(env, pendExcpn);
-        }
-        // check if any exception occured during mid_unlock call
-        if ((*env)->ExceptionCheck(env)) {
-            AWT_UNLOCK();
-            return FALSE;
-        }
+
+        //According the GTK documentation, gdk_threads_init() should be
+        //called before gtk_init() or gtk_init_check()
+        fp_gdk_threads_init();
     }
     result = (*fp_gtk_init_check)(NULL, NULL);
 
--- a/jdk/src/jdk.unsupported/unix/classes/sun/misc/GThreadHelper.java	Tue May 10 16:08:21 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-/*
- * 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 ()
- * and gdk_thread_init ().
- *
- * Since version 2.24 of GLib, calling g_thread_init () multiple times is
- * allowed, but it will crash for older versions. 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:
- * <pre>
- * lock();
- * try {
- *    if (!getAndSetInitializationNeededFlag()) {
- *        //call to g_thread_init();
- *        //call to gdk_thread_init();
- *    }
- * } finally {
- *    unlock();
- * }
- * </pre>
- */
-public final class GThreadHelper {
-
-    private static final ReentrantLock LOCK = new ReentrantLock();
-    private static boolean isGThreadInitialized = false;
-
-    /**
-     * Acquires the lock.
-     */
-    public static void lock() {
-        LOCK.lock();
-    }
-
-    /**
-     * Releases the lock.
-     */
-    public static void unlock() {
-        LOCK.unlock();
-    }
-
-    /**
-     * Gets current value of initialization flag and sets it to {@code true}.
-     * MUST be called under the lock.
-     *
-     * A return value of {@code false} indicates that the calling code
-     * should call the g_thread_init() and gdk_thread_init() functions
-     * before releasing the lock.
-     *
-     * @return {@code true} if initialization has been completed.
-     */
-    public static boolean getAndSetInitializationNeededFlag() {
-        boolean ret = isGThreadInitialized;
-        isGThreadInitialized = true;
-        return ret;
-    }
-}