Use monitorenter/exit only with threads.
authortwisti <none@none>
Wed, 22 Dec 2004 10:47:13 +0000 (10:47 +0000)
committertwisti <none@none>
Wed, 22 Dec 2004 10:47:13 +0000 (10:47 +0000)
src/native/jni.c
src/vm/builtin.c
src/vm/builtin.h
src/vm/jit/jit.c
src/vm/loader.c

index 2ab13a32c98037c22232b5fc45ef41fafe084089..58b027728e128aa1e0a16a08dc89d7740b93f189 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Joseph Wenninger, Martin Platter
 
-   $Id: jni.c 1801 2004-12-21 20:19:19Z jowenn $
+   $Id: jni.c 1807 2004-12-22 10:47:13Z twisti $
 
 */
 
@@ -794,9 +794,11 @@ jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *b
 
        c = class_new(utf_new_char_classname((char *) name));
 
+#if defined(USE_THREADS)
        /* enter a monitor on the class */
 
        builtin_monitorenter((java_objectheader *) c);
+#endif
 
        /* measure time */
        if (getloadingtime)
@@ -826,9 +828,11 @@ jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *b
        if (getloadingtime)
                loadingtime_stop();
 
+#if defined(USE_THREADS)
        /* leave the monitor */
 
        builtin_monitorexit((java_objectheader *) c);
+#endif
 
        /* XXX link the class here? */
 /*     if (class_link(c)) */
@@ -2991,16 +2995,22 @@ jint UnregisterNatives (JNIEnv* env, jclass clazz)
 
 /******************************* monitor operations ********************************/
 
-jint MonitorEnter (JNIEnv* env, jobject obj)
+jint MonitorEnter(JNIEnv* env, jobject obj)
 {
+#if defined(USE_THREADS)
     builtin_monitorenter(obj);
+#endif
+
     return 0;
 }
 
 
-jint MonitorExit (JNIEnv* env, jobject obj)
+jint MonitorExit(JNIEnv* env, jobject obj)
 {
+#if defined(USE_THREADS)
     builtin_monitorexit(obj);
+#endif
+
     return 0;
 }
 
index 9e543016a3cf79ac17be7702cd0ae92c74cf41d9..624f48b9e10b3522a5079e903806406fe5a14241 100644 (file)
@@ -34,7 +34,7 @@
    calls instead of machine instructions, using the C calling
    convention.
 
-   $Id: builtin.c 1774 2004-12-20 20:16:57Z jowenn $
+   $Id: builtin.c 1807 2004-12-22 10:47:13Z twisti $
 
 */
 
@@ -782,16 +782,16 @@ java_objectheader *builtin_trace_exception(java_objectheader *xptr,
                        if (m->flags & ACC_NATIVE) {
                                printf(",NATIVE");
 #if POINTERSIZE == 8
-                               printf(")(0x%016lx) at position %p\n", (s8) m->entrypoint, pos);
+                               printf(")(0x%016lx) at position 0x%016lx\n", (ptrint) m->entrypoint, (ptrint) pos);
 #else
-                               printf(")(0x%08lx) at position %p\n", (s4) m->entrypoint, pos);
+                               printf(")(0x%08x) at position 0x%08x\n", (ptrint) m->entrypoint, (ptrint) pos);
 #endif
 
                        } else {
 #if POINTERSIZE == 8
-                               printf(")(0x%016lx) at position %p (", (s8) m->entrypoint, pos);
+                               printf(")(0x%016lx) at position 0x%016lx (", (ptrint) m->entrypoint, (ptrint) pos);
 #else
-                               printf(")(0x%08lx) at position %p (", (s4) m->entrypoint, pos);
+                               printf(")(0x%08x) at position 0x%08x (", (ptrint) m->entrypoint, (ptrint) pos);
 #endif
                                if (m->class->sourcefile == NULL) {
                                        printf("<NO CLASSFILE INFORMATION>");
@@ -1038,12 +1038,12 @@ void builtin_displaymethodstop(methodinfo *m, s8 l, double d, float f)
                         SYNCHRONIZATION FUNCTIONS
 *****************************************************************************/
 
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
 /*
  * Lock the mutex of an object.
  */
 void internal_lock_mutex_for_object(java_objectheader *object)
 {
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
        mutexHashEntry *entry;
        int hashValue;
 
@@ -1084,16 +1084,16 @@ void internal_lock_mutex_for_object(java_objectheader *object)
                entry->object = object;
        
        internal_lock_mutex(&entry->mutex);
-#endif
 }
+#endif
 
 
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
 /*
  * Unlocks the mutex of an object.
  */
 void internal_unlock_mutex_for_object (java_objectheader *object)
 {
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
        int hashValue;
        mutexHashEntry *entry;
 
@@ -1119,13 +1119,13 @@ void internal_unlock_mutex_for_object (java_objectheader *object)
                        firstFreeOverflowEntry = unlinked;
                }
        }
-#endif
 }
+#endif
 
 
+#if defined(USE_THREADS)
 void builtin_monitorenter(java_objectheader *o)
 {
-#if defined(USE_THREADS)
 #if !defined(NATIVE_THREADS)
        int hashValue;
 
@@ -1142,10 +1142,11 @@ void builtin_monitorenter(java_objectheader *o)
 #else
        monitorEnter((threadobject *) THREADOBJECT, o);
 #endif
+}
 #endif
 
-}
 
+#if defined(USE_THREADS)
 /*
  * Locks the class object - needed for static synchronized methods.
  * The use_class_as_object call is needed in order to circumvent a
@@ -1157,11 +1158,12 @@ void builtin_staticmonitorenter(classinfo *c)
        use_class_as_object(c);
        builtin_monitorenter(&c->header);
 }
+#endif
 
 
+#if defined(USE_THREADS)
 void *builtin_monitorexit(java_objectheader *o)
 {
-#if defined(USE_THREADS)
 #if !defined(NATIVE_THREADS)
        int hashValue;
 
@@ -1184,8 +1186,8 @@ void *builtin_monitorexit(java_objectheader *o)
        monitorExit((threadobject *) THREADOBJECT, o);
        return o;
 #endif
-#endif
 }
+#endif
 
 
 /*****************************************************************************
index ca1cf5bb43f6f11915508297f66d3b3f958df446..3fccd1111f86020979d174d77c51a3a08f09ce37 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Edwin Steiner
 
-   $Id: builtin.h 1793 2004-12-21 10:14:35Z twisti $
+   $Id: builtin.h 1807 2004-12-22 10:47:13Z twisti $
 
 */
 
@@ -244,6 +244,7 @@ void builtin_displaymethodstart(methodinfo *m);
 void builtin_displaymethodstop(methodinfo *m, s8 l, double d, float f);
 /* NOT AN OP */
 
+#if defined(USE_THREADS)
 void builtin_monitorenter(java_objectheader *o);
 /* NOT AN OP */
 void builtin_staticmonitorenter(classinfo *c);
@@ -254,6 +255,7 @@ void *builtin_monitorexit(java_objectheader *o);
 /* NOT AN OP */
 void *asm_builtin_monitorexit(java_objectheader *o);
 #define BUILTIN_monitorexit (functionptr) asm_builtin_monitorexit
+#endif
 
 s4 builtin_idiv(s4 a, s4 b);
 /* NOT AN OP */
index 7026f8c4f80353af6b59a9ab277a09d024bc7c2d..38679ad03580f74dd3c59e36c0026660ec5e8c87 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes: Edwin Steiner
 
-   $Id: jit.c 1801 2004-12-21 20:19:19Z jowenn $
+   $Id: jit.c 1807 2004-12-22 10:47:13Z twisti $
 
 */
 
@@ -1313,8 +1313,10 @@ builtin_descriptor builtin_desc[] = {
        {255,BUILTIN_newarray_short  ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_short"},
        {255,BUILTIN_newarray_int    ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_int"},
        {255,BUILTIN_newarray_long   ,ICMD_BUILTIN1,TYPE_INT   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_ADR   ,0,0,"newarray_long"},
+#if defined(USE_THREADS)
        {255,BUILTIN_monitorenter    ,ICMD_BUILTIN1,TYPE_ADR   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_VOID  ,0,0,"monitorenter"},
        {255,BUILTIN_monitorexit     ,ICMD_BUILTIN1,TYPE_ADR   ,TYPE_VOID  ,TYPE_VOID  ,TYPE_VOID  ,0,0,"monitorexit"},
+#endif
 #if !SUPPORT_DIVISION
        {255,BUILTIN_idiv            ,ICMD_BUILTIN2,TYPE_INT   ,TYPE_INT   ,TYPE_VOID  ,TYPE_INT   ,0,0,"idiv"},
        {255,BUILTIN_irem            ,ICMD_BUILTIN2,TYPE_INT   ,TYPE_INT   ,TYPE_VOID  ,TYPE_INT   ,0,0,"irem"},
@@ -1369,14 +1371,18 @@ functionptr jit_compile(methodinfo *m)
        if (opt_stat)
                count_jit_calls++;
 
+#if defined(USE_THREADS)
        /* enter a monitor on the method */
 
        builtin_monitorenter((java_objectheader *) m);
+#endif
 
        /* if method has been already compiled return immediately */
 
        if (m->entrypoint) {
+#if defined(USE_THREADS)
                builtin_monitorexit((java_objectheader *) m);
+#endif
 
                return m->entrypoint;
        }
@@ -1473,9 +1479,11 @@ functionptr jit_compile(methodinfo *m)
                useinlining = false;
        #endif
 
+#if defined(USE_THREADS)
        /* leave the monitor */
 
        builtin_monitorexit((java_objectheader *) m );
+#endif
 
        if (r) {
                if (compileverbose)
index c71aabc0bd18fc711bafb391673f651b421ace4d..0314ed861152ff8d1f82f4b1f0f9186aec788621 100644 (file)
@@ -32,7 +32,7 @@
             Edwin Steiner
             Christian Thalinger
 
-   $Id: loader.c 1801 2004-12-21 20:19:19Z jowenn $
+   $Id: loader.c 1807 2004-12-22 10:47:13Z twisti $
 
 */
 
@@ -2122,13 +2122,17 @@ classinfo *class_load(classinfo *c)
        classbuffer *cb;
        classinfo *r;
 
+#if defined(USE_THREADS)
        /* enter a monitor on the class */
 
        builtin_monitorenter((java_objectheader *) c);
+#endif
 
        /* maybe the class is already loaded */
        if (c->loaded) {
+#if defined(USE_THREADS)
                builtin_monitorexit((java_objectheader *) c);
+#endif
 
                return c;
        }
@@ -2153,7 +2157,9 @@ classinfo *class_load(classinfo *c)
                        new_exception_utfmessage(string_java_lang_NoClassDefFoundError,
                                                                         c->name);
 
+#if defined(USE_THREADS)
                builtin_monitorexit((java_objectheader *) c);
+#endif
 
                return NULL;
        }
@@ -2180,9 +2186,11 @@ classinfo *class_load(classinfo *c)
        if (getcompilingtime)
                compilingtime_start();
 
+#if defined(USE_THREADS)
        /* leave the monitor */
 
        builtin_monitorexit((java_objectheader *) c);
+#endif
 
        return r;
 }
@@ -2837,13 +2845,17 @@ classinfo *class_link(classinfo *c)
 {
        classinfo *r;
 
+#if defined(USE_THREADS)
        /* enter a monitor on the class */
 
        builtin_monitorenter((java_objectheader *) c);
+#endif
 
        /* maybe the class is already linked */
        if (c->linked) {
+#if defined(USE_THREADS)
                builtin_monitorexit((java_objectheader *) c);
+#endif
 
                return c;
        }
@@ -2871,9 +2883,11 @@ classinfo *class_link(classinfo *c)
        if (getcompilingtime)
                compilingtime_start();
 
+#if defined(USE_THREADS)
        /* leave the monitor */
 
        builtin_monitorexit((java_objectheader *) c);
+#endif
 
        return r;
 }
@@ -3719,9 +3733,11 @@ classinfo *class_init(classinfo *c)
        if (!makeinitializations)
                return c;
 
+#if defined(USE_THREADS)
        /* enter a monitor on the class */
 
        builtin_monitorenter((java_objectheader *) c);
+#endif
 
        /* maybe the class is already initalized or the current thread, which can
           pass the monitor, is currently initalizing this class */
@@ -3732,7 +3748,9 @@ classinfo *class_init(classinfo *c)
         */
 
        if (c->initialized || c->initializing) {
+#if defined(USE_THREADS)
                builtin_monitorexit((java_objectheader *) c);
+#endif
 
                return c;
        }
@@ -3751,9 +3769,11 @@ classinfo *class_init(classinfo *c)
        /* this initalizing run is done */
        c->initializing = false;
 
+#if defined(USE_THREADS)
        /* leave the monitor */
 
        builtin_monitorexit((java_objectheader *) c);
+#endif
 
        return r;
 }