* src/toolbox/hashtable.h (hashtable): Use mutex instead of java object
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Fri, 22 Aug 2008 09:16:17 +0000 (11:16 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Fri, 22 Aug 2008 09:16:17 +0000 (11:16 +0200)
for locking. Renamed member lock to mutex.
* src/toolbox/hashtable.c: Adapted to above change.
* src/native/jni.cpp: Likewise.
* src/native/native.c: Likewise.
* src/vm/loader.cpp: Likewise.
* src/vm/utf8.c: Likewise.
* src/vm/zip.c: Added include to prevent circular dependency with hashtable.

src/native/jni.cpp
src/native/native.c
src/toolbox/hashtable.c
src/toolbox/hashtable.h
src/vm/loader.cpp
src/vm/utf8.c
src/vm/zip.c

index aef5894dbf7a93f4d877bfe09997814f9bbe24b0..5969e99a1db4544cea5034284293a066b117f34a 100644 (file)
@@ -44,6 +44,7 @@
 #endif
 
 #include "threads/lock-common.h"
+#include "threads/mutex.hpp"
 #include "threads/thread.hpp"
 
 #include "toolbox/logging.h"
@@ -3253,7 +3254,7 @@ jobject jni_NewGlobalRef(JNIEnv* env, jobject obj)
 
        o = (java_handle_t *) obj;
 
-       LOCK_MONITOR_ENTER(hashtable_global_ref->header);
+       hashtable_global_ref->mutex->lock();
 
        LLNI_CRITICAL_START;
 
@@ -3308,7 +3309,7 @@ jobject jni_NewGlobalRef(JNIEnv* env, jobject obj)
                hashtable_global_ref->entries++;
        }
 
-       LOCK_MONITOR_EXIT(hashtable_global_ref->header);
+       hashtable_global_ref->mutex->unlock();
 
 #if defined(ENABLE_HANDLES)
        return gre;
@@ -3336,7 +3337,7 @@ void jni_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
 
        o = (java_handle_t *) globalRef;
 
-       LOCK_MONITOR_ENTER(hashtable_global_ref->header);
+       hashtable_global_ref->mutex->lock();
 
        LLNI_CRITICAL_START;
 
@@ -3379,7 +3380,7 @@ void jni_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
 
                        LLNI_CRITICAL_END;
 
-                       LOCK_MONITOR_EXIT(hashtable_global_ref->header);
+                       hashtable_global_ref->mutex->unlock();
 
                        return;
                }
@@ -3392,7 +3393,7 @@ void jni_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
 
        LLNI_CRITICAL_END;
 
-       LOCK_MONITOR_EXIT(hashtable_global_ref->header);
+       hashtable_global_ref->mutex->unlock();
 }
 
 
index ddf9c9b222e9fbad12a7b407afd465d0dd0f9948..7b56350e7d1d13dc812427300bb3d65dbc119dee 100644 (file)
@@ -39,7 +39,7 @@
 
 #include "native/vm/nativevm.h"
 
-#include "threads/lock-common.h"
+#include "threads/mutex.hpp"
 
 #include "toolbox/avl.h"
 #include "toolbox/hashtable.h"
@@ -731,7 +731,7 @@ void native_library_add(utf *filename, classloader_t *loader, void* handle)
        u4   key;                           /* hashkey                            */
        u4   slot;                          /* slot in hashtable                  */
 
-       LOCK_MONITOR_ENTER(hashtable_library->header);
+       Mutex_lock(hashtable_library->mutex);
 
        /* normally addresses are aligned to 4, 8 or 16 bytes */
 
@@ -774,7 +774,7 @@ void native_library_add(utf *filename, classloader_t *loader, void* handle)
 
        while (ne) {
                if (ne->name == filename) {
-                       LOCK_MONITOR_EXIT(hashtable_library->header);
+                       Mutex_unlock(hashtable_library->mutex);
 
                        return;
                }
@@ -794,7 +794,7 @@ void native_library_add(utf *filename, classloader_t *loader, void* handle)
        ne->hashlink = le->namelink;
        le->namelink = ne;
 
-       LOCK_MONITOR_EXIT(hashtable_library->header);
+       Mutex_unlock(hashtable_library->mutex);
 }
 #endif
 
index 8843324d7d278a423fd1ec1d3bb9dfa71f114405..dd49f3de543a65e191c909da805d04ab9c5764df 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "mm/memory.h"
 
-#include "threads/lock-common.h"
+#include "threads/mutex.hpp"
 
 #include "toolbox/hashtable.h"
 
@@ -39,7 +39,7 @@
 
    Initializes a hashtable structure and allocates memory. The
    parameter size specifies the initial size of the hashtable.
-       
+
 *******************************************************************************/
 
 void hashtable_create(hashtable *hash, u4 size)
@@ -47,13 +47,11 @@ void hashtable_create(hashtable *hash, u4 size)
        /* initialize locking pointer */
 
 #if defined(ENABLE_THREADS)
-       /* We need to seperately allocate a java_object_t here, as we
-          need to store the lock object in the new hashtable if it's
-          resized.  Otherwise we get an IllegalMonitorStateException. */
-
-       hash->header = NEW(java_object_t);
+       /* We need to seperately allocate a mutex here, as we need to
+          store the lock object in the new hashtable if it's resized.
+          Otherwise we get an IllegalMonitorStateException. */
 
-       LOCK_INIT_OBJECT_LOCK(hash->header);
+       hash->mutex   = Mutex_new();
 #endif
 
        /* set initial hash values */
@@ -87,9 +85,9 @@ hashtable *hashtable_resize(hashtable *hash, u4 size)
        /* We need to store the old lock object in the new hashtable.
           Otherwise we get an IllegalMonitorStateException. */
 
-       FREE(newhash->header, java_object_t);
+       Mutex_delete(newhash->mutex);
 
-       newhash->header  = hash->header;
+       newhash->mutex   = hash->mutex;
 #endif
 
        /* store the number of entries in the new hashtable */
index 51161b7832e64444ab72190a36bf8cabce0856d3..40d41efcb4537870607945e83f77182079c05888 100644 (file)
@@ -34,6 +34,8 @@ typedef struct hashtable hashtable;
 #include "config.h"
 #include "vm/types.h"
 
+#include "threads/mutex.hpp"
+
 #include "vm/global.h"
 #include "vm/utf8.h"
 
@@ -93,7 +95,7 @@ hashtable.ptr-->+-------------------+
 
 struct hashtable {            
 #if defined(ENABLE_THREADS)
-       java_object_t      *header;         /* required for locking               */
+       Mutex              *mutex;          /* required for locking               */
 #endif
        u4                  size;           /* current size of the hashtable      */
        u4                  entries;        /* number of entries in the table     */
index 28db3bfe5375599dd0c6e2de3c394b8845b75c64..2c4a5d1ad215443102d7ff5dbdad98b7d40a77ee 100644 (file)
@@ -36,6 +36,7 @@
 #include "native/llni.h"
 
 #include "threads/lock-common.h"
+#include "threads/mutex.hpp"
 
 #include "toolbox/hashtable.h"
 #include "toolbox/logging.h"
@@ -267,7 +268,7 @@ classloader_t *loader_hashtable_classloader_add(java_handle_t *cl)
        if (cl == NULL)
                return NULL;
 
-       LOCK_MONITOR_ENTER(hashtable_classloader->header);
+       hashtable_classloader->mutex->lock();
 
        LLNI_CRITICAL_START;
 
@@ -324,8 +325,7 @@ classloader_t *loader_hashtable_classloader_add(java_handle_t *cl)
                hashtable_classloader->entries++;
        }
 
-
-       LOCK_MONITOR_EXIT(hashtable_classloader->header);
+       hashtable_classloader->mutex->unlock();
 
 #if defined(ENABLE_HANDLES)
        return cle;
index 7616aa117f1823a25a1e3bd1495f3fb6bca97f90..1d7d7605fae6a4565acb47c69aabb3e3eb8c4479 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "mm/memory.h"
 
-#include "threads/lock-common.h"
+#include "threads/mutex.hpp"
 
 #include "toolbox/hashtable.h"
 
@@ -691,7 +691,7 @@ utf *utf_new(const char *text, u2 length)
        utf *u;                             /* hashtable element                  */
        u2 i;
 
-       LOCK_MONITOR_ENTER(hashtable_utf->header);
+       Mutex_lock(hashtable_utf->mutex);
 
 #if defined(ENABLE_STATISTICS)
        if (opt_stat)
@@ -719,7 +719,7 @@ utf *utf_new(const char *text, u2 length)
 
                        /* symbol found in hashtable */
 
-                       LOCK_MONITOR_EXIT(hashtable_utf->header);
+                       Mutex_unlock(hashtable_utf->mutex);
 
                        return u;
                }
@@ -792,7 +792,7 @@ utf *utf_new(const char *text, u2 length)
                hashtable_utf = newhash;
        }
 
-       LOCK_MONITOR_EXIT(hashtable_utf->header);
+       Mutex_unlock(hashtable_utf->mutex);
 
        return u;
 }
@@ -812,7 +812,7 @@ utf *utf_new_u2(u2 *unicode_pos, u4 unicode_length, bool isclassname)
        u4 left;                        /* unicode characters left                */
        u4 buflength;                   /* utf length in bytes of the u2 array    */
        utf *result;                    /* resulting utf-string                   */
-       int i;          
+       int i;
 
        /* determine utf length in bytes and allocate memory */
 
index da8f0782984af9bbecebc7ab94b476b99fcb5387..c23ccc22d4600b67fec50b4df30d098474782540 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "vm/types.h"
 
+#include "vm/descriptor.h" /* needed to prevent circular dependency */
 #include "toolbox/hashtable.h"
 
 #include "mm/memory.h"