diff options
author | Steven Augart <augart@watson.ibm.com> | 2004-07-07 04:26:37 +0000 |
---|---|---|
committer | Steven Augart <augart@watson.ibm.com> | 2004-07-07 04:26:37 +0000 |
commit | 6f9fb9019f12ed9d9568b5e05476a1097ed14cae (patch) | |
tree | 711cd8351031ef0b5d7adda7c0d110eafe117976 | |
parent | ed5ae0808a4393675deb8cb479470038d4b0d965 (diff) | |
download | classpath-6f9fb9019f12ed9d9568b5e05476a1097ed14cae.tar.gz |
2004-07-07 Steven Augart <augart@watson.ibm.com>
* gnu/java/awt/peer/gtk/GtkMainThread.java (run): Pass the value of
the gnu.classpath.awt.gtk.portable.native.sync system property to C.
* configure.ac: Correct description of PORTABLE_NATIVE_SYNC
config.h definition.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c,
include/gnu_java_awt_peer_gtk_GtkMainThread.h
(Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit): New argument,
portableNativeSync. Delegate PORTABLE_NATIVE_SYNC work to
init_glib_threads.
(init_glib_threads): New function.
* doc/vmintegration.texinfo (VM Threading Model): Explain the
gnu.classpath.awt.gtk.portable.native.sync system property.
* NEWS: Mention the gnu.classpath.awt.gtk.portable.native.sync
new system property.
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | NEWS | 12 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | doc/vmintegration.texinfo | 40 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkMainThread.java | 25 | ||||
-rw-r--r-- | include/gnu_java_awt_peer_gtk_GtkMainThread.h | 2 | ||||
-rw-r--r-- | native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c | 53 |
7 files changed, 136 insertions, 23 deletions
@@ -1,3 +1,24 @@ +2004-07-07 Steven Augart <augart@watson.ibm.com> + + * gnu/java/awt/peer/gtk/GtkMainThread.java (run): Pass the value of + the gnu.classpath.awt.gtk.portable.native.sync system property to C. + + * configure.ac: Correct description of PORTABLE_NATIVE_SYNC + config.h definition. + + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c, + include/gnu_java_awt_peer_gtk_GtkMainThread.h + (Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit): New argument, + portableNativeSync. Delegate PORTABLE_NATIVE_SYNC work to + init_glib_threads. + (init_glib_threads): New function. + + * doc/vmintegration.texinfo (VM Threading Model): Explain the + gnu.classpath.awt.gtk.portable.native.sync system property. + + * NEWS: Mention the gnu.classpath.awt.gtk.portable.native.sync + new system property. + 2004-07-06 Patrik Reali <reali@acm.org> * doc/www.gnu.org/newsitems.txt: mail about emacs with GNU Classpath @@ -1,13 +1,19 @@ New in release 0.10 (in preparation) -* Fixed the code enabled by the --portable-native-sync configure option; it - had been broken since Classpath release 0.06, when we upgraded to GTK+2. +* Fixed the "portable native sync" code; it had been broken since + Classpath release 0.06, when we upgraded to GTK+2. Explanation: Classpath's AWT peers use GTK+. GTK+ uses GLIB. GLIB by default uses the platform's native threading model -- pthreads in most cases. If the Java runtime doesn't use the native threading model, then you should specify --portable-native-sync when configuring Classpath, so that GLIB will - use the Java threading primitives instead. + use the Java threading primitives instead. (For a superior alternative, + see below.) + +* The VM can set the system property + gnu.classpath.awt.gtk.portable.native.sync instead of using the + --portable-native-sync configure-type option. See + doc/vmintegration.texinfo for details. * We intend that the next release of GNU Classpath will require the VM to provide JNI 1.2. Classpath currently uses only JNI 1.1, except for diff --git a/configure.ac b/configure.ac index 0223f4a0f..54c2e330c 100644 --- a/configure.ac +++ b/configure.ac @@ -274,11 +274,15 @@ dnl ----------------------------------------------------------- CLASSPATH_ENABLE_GJDOC dnl ----------------------------------------------------------- +dnl This sets the build-time default, which can now be overridden +dnl by setting the system property gnu.classpath.awt.gtk.portable.native.sync +dnl to "true" or "false". +dnl ----------------------------------------------------------- AC_ARG_ENABLE([portable-native-sync], [AS_HELP_STRING(--enable-portable-native-sync,synchronize VM threads portably)], [case "${enableval}" in yes) - AC_DEFINE(PORTABLE_NATIVE_SYNC, 1, [Define to 1 if you want to synchronize VM threads portably]) + AC_DEFINE(PORTABLE_NATIVE_SYNC, 1, [Define if you want to synchronize VM threads portably by default; undef otherwise]) ;; no) ;; *) diff --git a/doc/vmintegration.texinfo b/doc/vmintegration.texinfo index ad8853405..456a0fade 100644 --- a/doc/vmintegration.texinfo +++ b/doc/vmintegration.texinfo @@ -310,7 +310,7 @@ Classpath places a few requirements on the VM that uses it. Classpath currently uses only JNI 1.1, except for one JNI 1.2 function in the JNI Invocation API: GetEnv(). And GetEnv() is only used in the ---portable-native-sync code, so it's only actually used by Jikes RVM +``portable native sync'' code, so it's only actually used by Jikes RVM and Kaffe. A future direction will probably be to require that all VMs provide @@ -321,12 +321,42 @@ mailing list. @comment node-name, next, previous, up @section VM Threading Model -Classpath's AWT peers use GTK+. GTK+ uses GLIB. GLIB by default uses -the platform's native threading model -- pthreads in most cases. +Classpath's AWT peers use GTK+. GTK+ uses GLIB. Normally, Classpath +will initialize GLIB's @dfn{gthreads} to use +the platform's native threading model@footnote{The native threading +model is pthreads on Linux and AIX, the two platforms Classpath +currently runs on.} If the Java runtime doesn't use the native threading model, then you -should specify --portable-native-sync when configuring Classpath, so -that GLIB will use the Java threading primitives instead. +will want Classpath to tell GLIB to use the Java threading primitives +instead. Otherwise, GLIB would use the native threading model to +perform operations such as creating thread-local data, and that just +doesn't work on systems (such as Kaffe in some configurations, and +such as Jikes RVM) that use @i{m}:@i{n} threading. + +Historically, enabling the Java threading primitives had been done at +build time, by configuring classpath with the +@option{--portable-native-sync} option. This had bad consequences, +though -- it meant that the prebuild GNU Classpath package distributed +with Debian GNU/Linux would not be usable with VMs that could +otherwise have used it. Instead, we encourage +the use of the Java system property +@code{gnu.classpath.awt.gtk.portable.native.sync}. A VM that wants +GLIB to use the Java threading primitives should modify +@code{VMRuntime.insertSystemProperties()} to include code like the +following: + +@example +static void insertSystemProperties(Properties @var{p}) +@end example +... +@example +@var{p}.put("gnu.classpath.awt.gtk.portable.native.sync", "true"); +@end example + +So, the configure option +@option{--portable-native-sync} is deprecated, and should go away in a +subsequent release of GNU Classpath. @bye diff --git a/gnu/java/awt/peer/gtk/GtkMainThread.java b/gnu/java/awt/peer/gtk/GtkMainThread.java index 6efa84101..e591d2dfa 100644 --- a/gnu/java/awt/peer/gtk/GtkMainThread.java +++ b/gnu/java/awt/peer/gtk/GtkMainThread.java @@ -43,7 +43,15 @@ public class GtkMainThread extends GtkGenericPeer implements Runnable private static Thread mainThread = null; private static Object mainThreadLock = new Object(); - static native void gtkInit(); + /** + * Call gtk_init. It is very important that this happen before any other + * gtk calls. + * + * @param portableNativeSync 1 if the Java property + * gnu.classpath.awt.gtk.portable.native.sync is set to "true". 0 if it is + * set to "false". -1 if unset. + */ + static native void gtkInit(int portableNativeSync); native void gtkMain(); public GtkMainThread() @@ -67,9 +75,22 @@ public class GtkMainThread extends GtkGenericPeer implements Runnable public void run() { + /* Pass the value of the gnu.classpath.awt.gtk.portable.native.sync system + * property to C. */ + int portableNativeSync; + String portNatSyncProp = + System.getProperty("gnu.classpath.awt.gtk.portable.native.sync"); + + if (portNatSyncProp == null) + portableNativeSync = -1; // unset + else if (Boolean.valueOf(portNatSyncProp).booleanValue()) + portableNativeSync = 1; // true + else + portableNativeSync = 0; // false + synchronized (this) { - gtkInit(); + gtkInit(portableNativeSync); notify(); } gtkMain(); diff --git a/include/gnu_java_awt_peer_gtk_GtkMainThread.h b/include/gnu_java_awt_peer_gtk_GtkMainThread.h index 799cb74c9..31bc579d5 100644 --- a/include/gnu_java_awt_peer_gtk_GtkMainThread.h +++ b/include/gnu_java_awt_peer_gtk_GtkMainThread.h @@ -10,7 +10,7 @@ extern "C" { #endif -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass, jint); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkMain (JNIEnv *env, jobject); #ifdef __cplusplus diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c index 8a452b029..3b4c76018 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c @@ -65,6 +65,8 @@ JNIEnv *gdk_env; GtkWindowGroup *global_gtk_window_group; +static void init_glib_threads(JNIEnv *, jint); + double dpi_conversion_factor; static void init_dpi_conversion_factor (); @@ -74,10 +76,17 @@ static void dpi_changed_cb (GtkSettings *settings, /* * Call gtk_init. It is very important that this happen before any other * gtk calls. + * + * The portableNativeSync argument may have the values: + * 1 if the Java property gnu.classpath.awt.gtk.portable.native.sync + * is set to "true". + * 0 if it is set to "false" + * -1 if unset. */ JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) +Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz, + jint portableNativeSync) { int argc = 1; char **argv; @@ -101,16 +110,7 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) #endif argv[1] = NULL; - /* until we have JDK 1.2 JNI, assume we have a VM with threads that - match what GLIB was compiled for */ -#ifdef PORTABLE_NATIVE_SYNC - (*env)->GetJavaVM( env, &the_vm ); - g_thread_init ( &portable_native_sync_jni_functions ); - /* Debugging progress message; uncomment if needed: */ - /* printf("called gthread init\n"); */ -#else - g_thread_init ( NULL ); -#endif + init_glib_threads(env, portableNativeSync); /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */ gdk_threads_init(); @@ -206,6 +206,37 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) init_dpi_conversion_factor (); } + +/** Initialize GLIB's threads properly, based on the value of the + gnu.classpath.awt.gtk.portable.native.sync Java system property. If + that's unset, use the PORTABLE_NATIVE_SYNC config.h macro. (TODO: + In some release following 0.10, that config.h macro will go away.) + */ +static void +init_glib_threads(JNIEnv *env, jint portableNativeSync) +{ + if (portableNativeSync < 0) + { +#ifdef PORTABLE_NATIVE_SYNC /* Default value, if not set by the Java system + property */ + portableNativeSync = 1; +#else + portableNativeSync = 0; +#endif + } + + (*env)->GetJavaVM( env, &the_vm ); + if (portableNativeSync) + g_thread_init ( &portable_native_sync_jni_functions ); + else + g_thread_init ( NULL ); + + /* Debugging progress message; uncomment if needed: */ + /* printf("called gthread init\n"); */ +} + + + /* * Run gtk_main and block. */ |