commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dynamic-portable-native-sync-1.patch


From: Steven Augart
Subject: dynamic-portable-native-sync-1.patch
Date: Sat, 19 Jun 2004 20:20:03 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7b) Gecko/20040421

OK to commit?

--
Steven Augart

Jikes RVM, a free, open source, Virtual Machine:
http://oss.software.ibm.com/jikesrvm
This patch makes the portable-native-sync no longer need build-time
configuration.  Instead, we configure it at run-time.  Build-time sets
the defaults.

Please commit it with the following ChangeLog entry: 

2004-06-19  Steven Augart  <address@hidden>

        * gnu/java/awtk/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. 
        

Index: configure.ac
===================================================================
RCS file: /cvsroot/classpath/classpath/configure.ac,v
retrieving revision 1.32
diff -I*.class -u -r1.32 configure.ac
--- configure.ac        19 Jun 2004 19:51:12 -0000      1.32
+++ configure.ac        20 Jun 2004 00:19:01 -0000
@@ -274,11 +274,15 @@
 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)  ;;
                 *)   
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c,v
retrieving revision 1.18
diff -I*.class -u -r1.18 gnu_java_awt_peer_gtk_GtkMainThread.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c   6 Jun 2004 
04:14:13 -0000       1.18
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c   20 Jun 2004 
00:19:01 -0000
@@ -65,13 +65,20 @@
 
 GtkWindowGroup *global_gtk_window_group;
 
-/*
+static void init_glib_threads(JNIEnv *, jint);
+
+/**
  * Call gtk_init.  It is very important that this happen before any other
  * gtk calls.
+ *
+ * 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.
  */
 
 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;
@@ -95,16 +102,7 @@
 #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();
@@ -198,6 +196,37 @@
   global_gtk_window_group = gtk_window_group_new ();
 }
 
+
+/** 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.  (In a
+    subsequent release, the config.h macro can 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.
  */ 
Index: include/gnu_java_awt_peer_gtk_GtkMainThread.h
===================================================================
RCS file: 
/cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_GtkMainThread.h,v
retrieving revision 1.3
diff -I*.class -u -r1.3 gnu_java_awt_peer_gtk_GtkMainThread.h
--- include/gnu_java_awt_peer_gtk_GtkMainThread.h       28 May 2004 17:27:53 
-0000      1.3
+++ include/gnu_java_awt_peer_gtk_GtkMainThread.h       20 Jun 2004 00:19:01 
-0000
@@ -10,7 +10,7 @@
 {
 #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
Index: gnu/java/awt/peer/gtk/GtkMainThread.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkMainThread.java,v
retrieving revision 1.11
diff -I*.class -u -r1.11 GtkMainThread.java
--- gnu/java/awt/peer/gtk/GtkMainThread.java    22 Jan 2002 22:26:56 -0000      
1.11
+++ gnu/java/awt/peer/gtk/GtkMainThread.java    20 Jun 2004 00:19:01 -0000
@@ -43,7 +43,15 @@
   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 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();
Index: doc/vmintegration.texinfo
===================================================================
RCS file: /cvsroot/classpath/classpath/doc/vmintegration.texinfo,v
retrieving revision 1.11
diff -I*.class -u -r1.11 vmintegration.texinfo
--- doc/vmintegration.texinfo   6 Jun 2004 04:36:54 -0000       1.11
+++ doc/vmintegration.texinfo   20 Jun 2004 00:19:01 -0000
@@ -261,7 +261,7 @@
 done.  No harm will come, as long as you follow the guidelines in the
 @pxref{Initialization} section.
 
address@hidden: this is written in anticipation of 1.2 support and does not
address@hidden: this is written in anticipation of Java 1.2 support and does not
 apply just yet.}
 
 @item Top-level Exception Handler @*
@@ -321,12 +321,43 @@
 @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 address@hidden 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
address@hidden:@i{n} threading. 
+
+Historically, enabling the Java threading primitives had been done at
+build time, by configuring classpath with the
address@hidden 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
address@hidden  A VM that wants
+GLIB to use the Java threading primitives should modify
address@hidden()} to include code like the
+following:
+
address@hidden
+static void insertSystemProperties(Properties @var{p}) 
address@hidden example
+...
address@hidden
address@hidden("gnu.classpath.awt.gtk.portable.native.sync", "true");
address@hidden example
+
+So, the configure option
address@hidden is deprecated, and should go away in a
+subsequent release of GNU Classpath.
 
 @bye
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]