Eliminate more unused variables and compiler warnings.

This change also introduces wrappers for condition variable operations
similar to what we have already for mutex operations.

Almost all the remaining warnings are now in the compiler or non-debug
uses of the CHECK_JIT macro.

Change-Id: I9f492f1582a06065e3a52287c7834adddfbefff9
diff --git a/vm/Debugger.c b/vm/Debugger.c
index 5bf3ec0..aa37d5d 100644
--- a/vm/Debugger.c
+++ b/vm/Debugger.c
@@ -137,17 +137,17 @@
 }
 void dvmDbgCondWait(pthread_cond_t* pCond, pthread_mutex_t* pMutex)
 {
-    int cc = pthread_cond_wait(pCond, pMutex);
+    int cc __attribute__ ((__unused__)) = pthread_cond_wait(pCond, pMutex);
     assert(cc == 0);
 }
 void dvmDbgCondSignal(pthread_cond_t* pCond)
 {
-    int cc = pthread_cond_signal(pCond);
+    int cc __attribute__ ((__unused__)) = pthread_cond_signal(pCond);
     assert(cc == 0);
 }
 void dvmDbgCondBroadcast(pthread_cond_t* pCond)
 {
-    int cc = pthread_cond_broadcast(pCond);
+    int cc __attribute__ ((__unused__)) = pthread_cond_broadcast(pCond);
     assert(cc == 0);
 }
 
@@ -183,6 +183,7 @@
  *
  * Lock the registry before calling here.
  */
+#ifndef NDEBUG
 static bool lookupId(ObjectId id)
 {
     void* found;
@@ -194,6 +195,7 @@
     assert(found == (void*)(u4) id);
     return true;
 }
+#endif
 
 /*
  * Register an object, if it hasn't already been.
@@ -271,6 +273,7 @@
  *
  * Note this actually takes both ObjectId and RefTypeId.
  */
+#ifndef NDEBUG
 static bool objectIsRegistered(ObjectId id, RegistryType type)
 {
     UNUSED_PARAMETER(type);
@@ -283,6 +286,7 @@
     dvmHashTableUnlock(gDvm.dbgRegistry);
     return result;
 }
+#endif
 
 /*
  * Convert to/from a RefTypeId.
diff --git a/vm/LinearAlloc.c b/vm/LinearAlloc.c
index bf89d50..3a79a8b 100644
--- a/vm/LinearAlloc.c
+++ b/vm/LinearAlloc.c
@@ -419,12 +419,11 @@
 #ifdef DISABLE_LINEAR_ALLOC
     return realloc(mem, newSize);
 #endif
-    LinearAllocHdr* pHdr = getHeader(classLoader);
-
     /* make sure we have the right region (and mem != NULL) */
     assert(mem != NULL);
-    assert(mem >= (void*) pHdr->mapAddr &&
-           mem < (void*) (pHdr->mapAddr + pHdr->curOffset));
+    assert(mem >= (void*) getHeader(classLoader)->mapAddr &&
+           mem < (void*) (getHeader(classLoader)->mapAddr +
+                          getHeader(classLoader)->curOffset));
 
     const u4* pLen = getBlockHeader(mem);
     LOGV("--- LinearRealloc(%d) old=%d\n", newSize, *pLen);
@@ -570,11 +569,10 @@
     if (mem == NULL)
         return;
 
-    LinearAllocHdr* pHdr = getHeader(classLoader);
-
     /* make sure we have the right region */
-    assert(mem >= (void*) pHdr->mapAddr &&
-           mem < (void*) (pHdr->mapAddr + pHdr->curOffset));
+    assert(mem >= (void*) getHeader(classLoader)->mapAddr &&
+           mem < (void*) (getHeader(classLoader)->mapAddr +
+                          getHeader(classLoader)->curOffset));
 
     if (ENFORCE_READ_ONLY)
         dvmLinearSetReadWrite(classLoader, mem);
diff --git a/vm/Profile.c b/vm/Profile.c
index bc5e05a..657dd5a 100644
--- a/vm/Profile.c
+++ b/vm/Profile.c
@@ -654,8 +654,7 @@
     state->traceFile = NULL;
 
     /* wake any threads that were waiting for profiling to complete */
-    int cc = pthread_cond_broadcast(&state->threadExitCond);
-    assert(cc == 0);
+    dvmBroadcastCond(&state->threadExitCond);
     dvmUnlockMutex(&state->startStopLock);
 }
 
diff --git a/vm/StdioConverter.c b/vm/StdioConverter.c
index efc1e89..520d984 100644
--- a/vm/StdioConverter.c
+++ b/vm/StdioConverter.c
@@ -109,9 +109,7 @@
     /* new thread owns pipeStorage */
 
     while (!gDvm.stdioConverterReady) {
-        int cc = pthread_cond_wait(&gDvm.stdioConverterCond,
-                    &gDvm.stdioConverterLock);
-        assert(cc == 0);
+        dvmWaitCond(&gDvm.stdioConverterCond, &gDvm.stdioConverterLock);
     }
     dvmUnlockMutex(&gDvm.stdioConverterLock);
 
diff --git a/vm/Sync.c b/vm/Sync.c
index 90df500..8f906ac 100644
--- a/vm/Sync.c
+++ b/vm/Sync.c
@@ -470,6 +470,7 @@
  *
  * Returns "true" on success.
  */
+#ifdef WITH_COPYING_GC
 static bool tryLockMonitor(Thread* self, Monitor* mon)
 {
     if (mon->owner == self) {
@@ -485,7 +486,7 @@
         }
     }
 }
-
+#endif
 
 /*
  * Unlock a monitor.
@@ -524,6 +525,7 @@
  * Checks the wait set for circular structure.  Returns 0 if the list
  * is not circular.  Otherwise, returns 1.  Used only by asserts.
  */
+#ifndef NDEBUG
 static int waitSetCheck(Monitor *mon)
 {
     Thread *fast, *slow;
@@ -541,6 +543,7 @@
         slow = slow->waitNext;
     }
 }
+#endif
 
 /*
  * Links a thread into a monitor's wait set.  The monitor lock must be
diff --git a/vm/Thread.c b/vm/Thread.c
index 8a3fa53..46b2137 100644
--- a/vm/Thread.c
+++ b/vm/Thread.c
@@ -2286,10 +2286,8 @@
         LOGI("threadid=%d: waiting for method trace to finish\n",
             self->threadId);
         while (traceState->traceEnabled) {
-            int cc;
-            cc = pthread_cond_wait(&traceState->threadExitCond,
-                    &traceState->startStopLock);
-            assert(cc == 0);
+            dvmWaitCond(&traceState->threadExitCond,
+                        &traceState->startStopLock);
         }
     }
     dvmUnlockMutex(&traceState->startStopLock);
@@ -2398,8 +2396,7 @@
         thread->threadId, thread->suspendCount);
 
     if (thread->suspendCount == 0) {
-        int cc = pthread_cond_broadcast(&gDvm.threadSuspendCountCond);
-        assert(cc == 0);
+        dvmBroadcastCond(&gDvm.threadSuspendCountCond);
     }
 
     unlockThreadSuspendCount();
@@ -2449,10 +2446,8 @@
     }
 
     while (self->suspendCount != 0) {
-        int cc;
-        cc = pthread_cond_wait(&gDvm.threadSuspendCountCond,
-                &gDvm.threadSuspendCountLock);
-        assert(cc == 0);
+        dvmWaitCond(&gDvm.threadSuspendCountCond,
+                    &gDvm.threadSuspendCountLock);
         if (self->suspendCount != 0) {
             /*
              * The condition was signaled but we're still suspended.  This
diff --git a/vm/Thread.h b/vm/Thread.h
index 4956009..f00b0df 100644
--- a/vm/Thread.h
+++ b/vm/Thread.h
@@ -379,8 +379,7 @@
  */
 INLINE void dvmLockMutex(pthread_mutex_t* pMutex)
 {
-    int cc __attribute__ ((__unused__));
-    cc = pthread_mutex_lock(pMutex);
+    int cc __attribute__ ((__unused__)) = pthread_mutex_lock(pMutex);
     assert(cc == 0);
 }
 
@@ -399,8 +398,7 @@
  */
 INLINE void dvmUnlockMutex(pthread_mutex_t* pMutex)
 {
-    int cc __attribute__ ((__unused__));
-    cc = pthread_mutex_unlock(pMutex);
+    int cc __attribute__ ((__unused__)) = pthread_mutex_unlock(pMutex);
     assert(cc == 0);
 }
 
@@ -409,8 +407,25 @@
  */
 INLINE void dvmDestroyMutex(pthread_mutex_t* pMutex)
 {
-    int cc __attribute__ ((__unused__));
-    cc  = pthread_mutex_destroy(pMutex);
+    int cc __attribute__ ((__unused__)) = pthread_mutex_destroy(pMutex);
+    assert(cc == 0);
+}
+
+INLINE void dvmBroadcastCond(pthread_cond_t* pCond)
+{
+    int cc __attribute__ ((__unused__)) = pthread_cond_broadcast(pCond);
+    assert(cc == 0);
+}
+
+INLINE void dvmSignalCond(pthread_cond_t* pCond)
+{
+    int cc __attribute__ ((__unused__)) = pthread_cond_signal(pCond);
+    assert(cc == 0);
+}
+
+INLINE void dvmWaitCond(pthread_cond_t* pCond, pthread_mutex_t* pMutex)
+{
+    int cc __attribute__ ((__unused__)) = pthread_cond_wait(pCond, pMutex);
     assert(cc == 0);
 }
 
diff --git a/vm/alloc/MarkSweep.c b/vm/alloc/MarkSweep.c
index ecd663c..fcea5ea 100644
--- a/vm/alloc/MarkSweep.c
+++ b/vm/alloc/MarkSweep.c
@@ -147,7 +147,7 @@
     assert(obj != NULL);
     assert(dvmIsValidObject(obj));
 
-    if (obj < ctx->immuneLimit) {
+    if (obj < (Object *)ctx->immuneLimit) {
         assert(isMarked(obj, ctx));
         return;
     }
diff --git a/vm/compiler/Compiler.c b/vm/compiler/Compiler.c
index 63f7512..0f60f20 100644
--- a/vm/compiler/Compiler.c
+++ b/vm/compiler/Compiler.c
@@ -40,8 +40,7 @@
     }
     gDvmJit.compilerQueueLength--;
     if (gDvmJit.compilerQueueLength == 0) {
-        int cc = pthread_cond_signal(&gDvmJit.compilerQueueEmpty);
-        assert(cc == 0);
+        dvmSignalCond(&gDvmJit.compilerQueueEmpty);
     }
 
     /* Remember the high water mark of the queue length */
diff --git a/vm/mterp/Mterp.c b/vm/mterp/Mterp.c
index 36f1e1c..51cef04 100644
--- a/vm/mterp/Mterp.c
+++ b/vm/mterp/Mterp.c
@@ -33,8 +33,6 @@
 
     extern char dvmAsmInstructionStart[];
     extern char dvmAsmInstructionEnd[];
-    extern char dvmAsmSisterStart[];
-    extern char dvmAsmSisterEnd[];
 
 #define ASM_DEF_VERIFY
 #include "mterp/common/asm-constants.h"
@@ -55,9 +53,6 @@
         LOGE("(did an instruction handler exceed %d bytes?)\n", width);
         dvmAbort();
     }
-    int sisterSize = dvmAsmSisterEnd - dvmAsmSisterStart;
-    LOGV("mterp: interp is %d bytes, sisters are %d bytes\n",
-        interpSize, sisterSize);
 
 #endif // ndef DVM_NO_ASM_INTERP
 
diff --git a/vm/mterp/armv5te/debug.c b/vm/mterp/armv5te/debug.c
index 9d7413c..9f893fe 100644
--- a/vm/mterp/armv5te/debug.c
+++ b/vm/mterp/armv5te/debug.c
@@ -18,15 +18,15 @@
     register uint32_t r9        asm("r9");
     register uint32_t r10       asm("r10");
 
-    extern char dvmAsmInstructionStart[];
+    //extern char dvmAsmInstructionStart[];
 
     printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3);
     printf("    : rPC=%08x rFP=%08x rGLUE=%08x rINST=%08x\n",
         rPC, rFP, rGLUE, rINST);
     printf("    : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10);
 
-    MterpGlue* glue = (MterpGlue*) rGLUE;
-    const Method* method = glue->method;
+    //MterpGlue* glue = (MterpGlue*) rGLUE;
+    //const Method* method = glue->method;
     printf("    + self is %p\n", dvmThreadSelf());
     //printf("    + currently in %s.%s %s\n",
     //    method->clazz->descriptor, method->name, method->shorty);
diff --git a/vm/mterp/out/InterpC-armv4t.c b/vm/mterp/out/InterpC-armv4t.c
index 53255a9..76c8664 100644
--- a/vm/mterp/out/InterpC-armv4t.c
+++ b/vm/mterp/out/InterpC-armv4t.c
@@ -1232,15 +1232,15 @@
     register uint32_t r9        asm("r9");
     register uint32_t r10       asm("r10");
 
-    extern char dvmAsmInstructionStart[];
+    //extern char dvmAsmInstructionStart[];
 
     printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3);
     printf("    : rPC=%08x rFP=%08x rGLUE=%08x rINST=%08x\n",
         rPC, rFP, rGLUE, rINST);
     printf("    : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10);
 
-    MterpGlue* glue = (MterpGlue*) rGLUE;
-    const Method* method = glue->method;
+    //MterpGlue* glue = (MterpGlue*) rGLUE;
+    //const Method* method = glue->method;
     printf("    + self is %p\n", dvmThreadSelf());
     //printf("    + currently in %s.%s %s\n",
     //    method->clazz->descriptor, method->name, method->shorty);
diff --git a/vm/mterp/out/InterpC-armv5te-vfp.c b/vm/mterp/out/InterpC-armv5te-vfp.c
index bf9ba3b..a991c2b 100644
--- a/vm/mterp/out/InterpC-armv5te-vfp.c
+++ b/vm/mterp/out/InterpC-armv5te-vfp.c
@@ -1232,15 +1232,15 @@
     register uint32_t r9        asm("r9");
     register uint32_t r10       asm("r10");
 
-    extern char dvmAsmInstructionStart[];
+    //extern char dvmAsmInstructionStart[];
 
     printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3);
     printf("    : rPC=%08x rFP=%08x rGLUE=%08x rINST=%08x\n",
         rPC, rFP, rGLUE, rINST);
     printf("    : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10);
 
-    MterpGlue* glue = (MterpGlue*) rGLUE;
-    const Method* method = glue->method;
+    //MterpGlue* glue = (MterpGlue*) rGLUE;
+    //const Method* method = glue->method;
     printf("    + self is %p\n", dvmThreadSelf());
     //printf("    + currently in %s.%s %s\n",
     //    method->clazz->descriptor, method->name, method->shorty);
diff --git a/vm/mterp/out/InterpC-armv5te.c b/vm/mterp/out/InterpC-armv5te.c
index 7f297a7..21ed408 100644
--- a/vm/mterp/out/InterpC-armv5te.c
+++ b/vm/mterp/out/InterpC-armv5te.c
@@ -1232,15 +1232,15 @@
     register uint32_t r9        asm("r9");
     register uint32_t r10       asm("r10");
 
-    extern char dvmAsmInstructionStart[];
+    //extern char dvmAsmInstructionStart[];
 
     printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3);
     printf("    : rPC=%08x rFP=%08x rGLUE=%08x rINST=%08x\n",
         rPC, rFP, rGLUE, rINST);
     printf("    : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10);
 
-    MterpGlue* glue = (MterpGlue*) rGLUE;
-    const Method* method = glue->method;
+    //MterpGlue* glue = (MterpGlue*) rGLUE;
+    //const Method* method = glue->method;
     printf("    + self is %p\n", dvmThreadSelf());
     //printf("    + currently in %s.%s %s\n",
     //    method->clazz->descriptor, method->name, method->shorty);
diff --git a/vm/mterp/out/InterpC-armv7-a-neon.c b/vm/mterp/out/InterpC-armv7-a-neon.c
index 98fccd9..a9de36f 100644
--- a/vm/mterp/out/InterpC-armv7-a-neon.c
+++ b/vm/mterp/out/InterpC-armv7-a-neon.c
@@ -1232,15 +1232,15 @@
     register uint32_t r9        asm("r9");
     register uint32_t r10       asm("r10");
 
-    extern char dvmAsmInstructionStart[];
+    //extern char dvmAsmInstructionStart[];
 
     printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3);
     printf("    : rPC=%08x rFP=%08x rGLUE=%08x rINST=%08x\n",
         rPC, rFP, rGLUE, rINST);
     printf("    : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10);
 
-    MterpGlue* glue = (MterpGlue*) rGLUE;
-    const Method* method = glue->method;
+    //MterpGlue* glue = (MterpGlue*) rGLUE;
+    //const Method* method = glue->method;
     printf("    + self is %p\n", dvmThreadSelf());
     //printf("    + currently in %s.%s %s\n",
     //    method->clazz->descriptor, method->name, method->shorty);
diff --git a/vm/mterp/out/InterpC-armv7-a.c b/vm/mterp/out/InterpC-armv7-a.c
index ab22ab6..3dfca56 100644
--- a/vm/mterp/out/InterpC-armv7-a.c
+++ b/vm/mterp/out/InterpC-armv7-a.c
@@ -1232,15 +1232,15 @@
     register uint32_t r9        asm("r9");
     register uint32_t r10       asm("r10");
 
-    extern char dvmAsmInstructionStart[];
+    //extern char dvmAsmInstructionStart[];
 
     printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3);
     printf("    : rPC=%08x rFP=%08x rGLUE=%08x rINST=%08x\n",
         rPC, rFP, rGLUE, rINST);
     printf("    : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10);
 
-    MterpGlue* glue = (MterpGlue*) rGLUE;
-    const Method* method = glue->method;
+    //MterpGlue* glue = (MterpGlue*) rGLUE;
+    //const Method* method = glue->method;
     printf("    + self is %p\n", dvmThreadSelf());
     //printf("    + currently in %s.%s %s\n",
     //    method->clazz->descriptor, method->name, method->shorty);
diff --git a/vm/test/AtomicSpeed.c b/vm/test/AtomicSpeed.c
index e2ffbef..b569668 100644
--- a/vm/test/AtomicSpeed.c
+++ b/vm/test/AtomicSpeed.c
@@ -47,16 +47,16 @@
         j += i; j += i; j += i; j += i; j += i;
 #else
         // succeed 10x (Dream: 155.9ns)
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
-        ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+        (void)ATOMIC_CMP_SWAP(valuePtr, 7, 7);
 
         // fail 10x (Dream: 158.5ns)
         /*