* src/threads/native/lock.c (LOCK_LOG): Removed.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 14 Sep 2007 18:19:27 +0000 (20:19 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 14 Sep 2007 18:19:27 +0000 (20:19 +0200)
(DEBUGLOCKS): New macro.
(lock_record_new): Added DEBUGLOCKS.
(lock_record_free): Likewise.
(lock_hashtable_grow): Likewise.
(lock_hashtable_get): Likewise.
(lock_inflate): Likewise.
(lock_monitor_enter): Likewise.
(lock_monitor_exit): Likewise.
(lock_record_wait): Likewise.
(lock_record_notify): Likewise.

* src/vmcore/options.c (opt_DebugLocks): Added.
(options_xx): Likewise.
* src/vmcore/options.h (opt_DebugLocks): Added.

src/threads/native/lock.c
src/vmcore/options.c
src/vmcore/options.h

index 6c127f5f7e06bb47a4fd95bb2ed6d255a82f30d3..d6248c929097d6e98feb1e954e97285da02edb2a 100644 (file)
 #endif
 
 
-/******************************************************************************/
-/* DEBUGGING MACROS                                                           */
-/******************************************************************************/
-
-/* #define LOCK_VERBOSE */
-
-#if defined(LOCK_VERBOSE)
-#define LOCK_LOG(args)  do { printf args; fflush(stdout); } while (0)
+/* debug **********************************************************************/
+
+#if !defined(NDEBUG)
+# define DEBUGLOCKS(format) \
+    do { \
+        if (opt_DebugLocks) { \
+            log_println format; \
+        } \
+    } while (0)
 #else
-#define LOCK_LOG(args)
+# define DEBUGLOCKS(format)
 #endif
 
 
@@ -275,6 +276,8 @@ static lock_record_t *lock_record_new(void)
 
        pthread_mutex_init(&(lr->mutex), NULL);
 
+       DEBUGLOCKS(("[lock_record_new   : lr=%p]", (void *) lr));
+
        return lr;
 }
 
@@ -290,6 +293,8 @@ static lock_record_t *lock_record_new(void)
 
 static void lock_record_free(lock_record_t *lr)
 {
+       DEBUGLOCKS(("[lock_record_free  : lr=%p]", (void *) lr));
+
        /* Destroy the mutex. */
 
        pthread_mutex_destroy(&(lr->mutex));
@@ -361,7 +366,7 @@ static void lock_hashtable_grow(void)
        oldsize = lock_hashtable.size;
        newsize = oldsize*2 + 1; /* XXX should use prime numbers */
 
-       LOCK_LOG(("growing lock hashtable to size %d\n", newsize));
+       DEBUGLOCKS(("growing lock hashtable to size %d", newsize));
 
        oldtable = lock_hashtable.ptr;
        newtable = MNEW(lock_record_t *, newsize);
@@ -460,9 +465,6 @@ static lock_record_t *lock_hashtable_get(java_object_t *o)
        GC_REGISTER_FINALIZER(o, lock_record_finalizer, 0, 0, 0);
 #endif
 
-       LOCK_LOG(("thread %d allocated for %p new lr %p\n",
-                         t->index, (void*) o, (void*) lr));
-
        /* enter it in the hashtable */
 
        lr->hashlink             = lock_hashtable.ptr[slot];
@@ -697,8 +699,8 @@ static void lock_inflate(threadobject *t, java_object_t *o, lock_record_t *lr)
                lr->count = (lockword & THIN_LOCK_COUNT_MASK) >> THIN_LOCK_COUNT_SHIFT;
        }
 
-       LOCK_LOG(("thread %3d: inflating lock of object %p current lockword %lx, count %d\n",
-                       t->index, (void*) o, (long)o->monitorPtr, (int)lr->count));
+       DEBUGLOCKS(("[lock_inflate      : lr=%p, t=%p, o=%p, o->monitorPtr=%lx, count=%d]",
+                               lr, t, o, o->monitorPtr, lr->count));
 
        /* clear flat-lock-contention bit */
 
@@ -835,25 +837,22 @@ bool lock_monitor_enter(java_object_t *o)
 
                LOCK_SET_FLC_BIT(o);
 
-               LOCK_LOG(("thread %d set flc bit on %p lr %p\n",
-                                 t->index, (void*) o, (void*) lr));
+               DEBUGLOCKS(("thread %d set flc bit on %p lr %p",
+                                       t->index, (void*) o, (void*) lr));
 
                /* try to lock the object */
 
                if (COMPARE_AND_SWAP_SUCCEEDS(&(o->monitorPtr), THIN_UNLOCKED, thinlock)) {
                        /* we can inflate the lock ourselves */
 
-                       LOCK_LOG(("thread %d inflating lock of %p to lr %p\n",
-                                         t->index, (void*) o, (void*) lr));
+                       DEBUGLOCKS(("thread %d inflating lock of %p to lr %p",
+                                               t->index, (void*) o, (void*) lr));
 
                        lock_inflate(t, o, lr);
                }
                else {
-                       /* wait until another thread sees the flc bit and notifies
-                          us of unlocking */
-
-                       LOCK_LOG(("thread %d waiting for notification on %p lr %p\n",
-                                         t->index, (void*) o, (void*) lr));
+                       /* Wait until another thread sees the flc bit and notifies
+                          us of unlocking. */
 
                        (void) lock_record_wait(t, lr, 0, 0);
                }
@@ -916,15 +915,15 @@ bool lock_monitor_exit(java_object_t *o)
                if (LOCK_TEST_FLC_BIT(o)) {
                        lock_record_t *lr;
 
-                       LOCK_LOG(("thread %d saw flc bit on %p %s\n",
-                                       t->index, (void*) o, o->vftbl->class->name->text));
+                       DEBUGLOCKS(("thread %d saw flc bit on %p",
+                                               t->index, (void*) o));
 
                        /* there has been a contention on this thin lock */
 
                        lr = lock_hashtable_get(o);
 
-                       LOCK_LOG(("thread %d for %p got lr %p\n",
-                                       t->index, (void*) o, (void*) lr));
+                       DEBUGLOCKS(("thread %d for %p got lr %p",
+                                               t->index, (void*) o, (void*) lr));
 
                        lock_record_enter(t, lr);
 
@@ -1094,6 +1093,9 @@ static bool lock_record_wait(threadobject *thread, lock_record_t *lr, s8 millis,
        s4   lockcount;
        bool wasinterrupted;
 
+       DEBUGLOCKS(("[lock_record_wait  : lr=%p, t=%p, millis=%lld, nanos=%d]",
+                               lr, thread, millis, nanos));
+
        /* { the thread t owns the fat lock record lr on the object o } */
 
        /* register us as waiter for this object */
@@ -1225,6 +1227,9 @@ static void lock_record_notify(threadobject *t, lock_record_t *lr, bool one)
 
                pthread_mutex_lock(&(waitingthread->waitmutex));
 
+               DEBUGLOCKS(("[lock_record_notify: lr=%p, t=%p, waitingthread=%p, sleeping=%d, one=%d]",
+                                       lr, t, waitingthread, waitingthread->sleeping, one));
+
                /* Signal the thread if it's sleeping. */
 
                if (waitingthread->sleeping)
index 17a9085a338368d93896ea1819066d28f6029b33..396fd3bb655da47af85c64612f7ec30f1ea75e49 100644 (file)
@@ -174,6 +174,7 @@ const char *opt_filter_show_method = 0;
 /* NOTE: For better readability keep these alpha-sorted. */
 
 int      opt_DebugExceptions           = 0;
+int      opt_DebugLocks                = 0;
 int      opt_DebugPatcher              = 0;
 int      opt_DebugProperties           = 0;
 int32_t  opt_DebugStackFrameInfo       = 0;
@@ -208,6 +209,7 @@ enum {
 
 enum {
        OPT_DebugExceptions,
+       OPT_DebugLocks,
        OPT_DebugPatcher,
        OPT_DebugProperties,
        OPT_DebugStackFrameInfo,
@@ -232,6 +234,7 @@ enum {
 
 option_t options_XX[] = {
        { "DebugExceptions",           OPT_DebugExceptions,           OPT_TYPE_BOOLEAN, "debug exceptions" },
+       { "DebugLocks",                OPT_DebugLocks,                OPT_TYPE_BOOLEAN, "print debug information for locks" },
        { "DebugPatcher",              OPT_DebugPatcher,              OPT_TYPE_BOOLEAN, "debug JIT code patching" },
        { "DebugProperties",           OPT_DebugProperties,           OPT_TYPE_BOOLEAN, "print debug information for properties" },
        { "DebugStackFrameInfo",       OPT_DebugStackFrameInfo,       OPT_TYPE_BOOLEAN, "TODO" },
@@ -515,6 +518,10 @@ void options_xx(JavaVMInitArgs *vm_args)
                        opt_DebugExceptions = enable;
                        break;
 
+               case OPT_DebugLocks:
+                       opt_DebugLocks = enable;
+                       break;
+
                case OPT_DebugPatcher:
                        opt_DebugPatcher = enable;
                        break;
index ffacb9ae5654bd6cc789d85ada7e72557a6deb15..59ccbb6647cbe5e46d21f8b9231d29e888fc6b88 100644 (file)
@@ -189,6 +189,7 @@ extern const char *opt_filter_show_method;
 /* NOTE: For better readability keep these alpha-sorted. */
 
 extern int      opt_DebugExceptions;
+extern int      opt_DebugLocks;
 extern int      opt_DebugPatcher;
 extern int      opt_DebugProperties;
 extern int32_t  opt_DebugStackFrameInfo;