<Swing Dev> RFR: <swing-dev> [Regression] Switch of Gnome theme ends up in deadlocked UI

Jayashree Sk1 jayashreesk at in.ibm.com
Wed Aug 26 07:37:38 UTC 2020


Hello,

Please review the fix for the following issue:
https://bugs.openjdk.java.net/browse/JDK-8244088


The scenario is:
Every-time we tried to switch a Gnome theme, Java ended up n deadlocked UI.
This regression was introduced (by below patches) while Providing GTK3 support in
Java
Java8: 8207322: Backport GTK3 support on Linux to 8u
JDK11 : 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux

Here for GTK3's g_main_context_iteration they have included an extra lock which
was causing a deadlock and also the JNDI corresponding module is defined using a
single parameter causing the hang in XToolkit_waitForEvents


So the fix is in 2 parts:
1) In Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1switch_1theme () method
we wrap the g_main_context_iteration (ie, gtk->flush_event_loop() ) with
gdk_threads_enter/gdk_threads_exit while g_main_context_iteration itself takes
care of locks.

-> Remove the extra lock

2) The definition of g_main_context_iteration in new “gtk3_interface.h” was
wrongly written with a single parameter, like :
static gboolean (*fp_g_main_context_iteration)(GMainContext *context);
instead of https://developer.gnome.org/glib/stable/glib-The-Main-Event-
Loop.html#g-main-context-iteration
gboolean            g_main_context_iteration            (GMainContext *context,
                                                         gboolean may_block);

-> When the above definition was corrected, we stopped seeing the hang during
polling.


The proposed changeset is:

--- old/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c 2020-08-25
16:57:34.000000000 +0530
   1 of 2 26/08/20, 11:21 am
https://mail.notes.na.collabserv.com/data2/126/21004100.nsf/0/...
+++ new/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c 2020-08-25
16:57:34.000000000 +0530
@@ -703,7 +703,7 @@
  */
 static void flush_gtk_event_loop()
 {
-    while((*fp_g_main_context_iteration)(NULL));
+    while((*fp_g_main_context_iteration)(NULL, FALSE));
} /*

--- old/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.h 2020-08-25
16:57:36.000000000 +0530
+++ new/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.h 2020-08-25
16:57:35.000000000 +0530
@@ -396,7 +396,7 @@
                                        const gchar *first_property_name,
                                        ...);
-static gboolean (*fp_g_main_context_iteration)(GMainContext *context);
+static gboolean (*fp_g_main_context_iteration)(GMainContext *context, gboolean
may_block);
 static gboolean (*fp_g_str_has_prefix)(const gchar *str, const gchar *prefix);
 static gchar** (*fp_g_strsplit)(const gchar *string, const gchar *delimiter,
            gint max_tokens);


--- old/src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c 2020-08-25
16:57:37.000000000 +0530
+++ new/src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c 2020-08-25
16:57:37.000000000 +0530
@@ -346,10 +346,8 @@
 JNIEXPORT void JNICALL
Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1switch_1theme(
         JNIEnv *env, jobject this)
 {
-    // Note that flush_gtk_event_loop takes care of locks (7053002)
-    gtk->gdk_threads_enter();
+    // Note that gtk->flush_event_loop takes care of locks (7053002)
     gtk->flush_event_loop();
-    gtk->gdk_threads_leave();
} /*


Thanks 
Jay



More information about the swing-dev mailing list