OSDN Git Service

am 813a3a2d: Merge "If dalvik wants ASCII casing, it needs to ask for it."
[android-x86/dalvik.git] / vm / Sync.cpp
index 61c7b95..f42004c 100644 (file)
@@ -82,10 +82,10 @@ struct Monitor {
 
     /*
      * Who last acquired this monitor, when lock sampling is enabled.
-     * Even when enabled, ownerFileName may be NULL.
+     * Even when enabled, ownerMethod may be NULL.
      */
-    const char* ownerFileName;
-    u4          ownerLineNumber;
+    const Method* ownerMethod;
+    u4 ownerPc;
 };
 
 
@@ -98,11 +98,7 @@ Monitor* dvmCreateMonitor(Object* obj)
 
     mon = (Monitor*) calloc(1, sizeof(Monitor));
     if (mon == NULL) {
-        LOGE("Unable to allocate monitor");
-        dvmAbort();
-    }
-    if (((u4)mon & 7) != 0) {
-        LOGE("Misaligned monitor: %p", mon);
+        ALOGE("Unable to allocate monitor");
         dvmAbort();
     }
     mon->obj = obj;
@@ -276,6 +272,11 @@ static void logContentionEvent(Thread *self, u4 waitMs, u4 samplePercent,
     size_t len;
     int fd;
 
+    /* When a thread is being destroyed it is normal that the frame depth is zero */
+    if (self->interpSave.curFrame == NULL) {
+        return;
+    }
+
     saveArea = SAVEAREA_FROM_FP(self->interpSave.curFrame);
     meth = saveArea->method;
     cp = eventBuffer;
@@ -355,8 +356,9 @@ static void lockMonitor(Thread* self, Monitor* mon)
         if (waitThreshold) {
             waitStart = dvmGetRelativeTimeUsec();
         }
-        const char* currentOwnerFileName = mon->ownerFileName;
-        u4 currentOwnerLineNumber = mon->ownerLineNumber;
+
+        const Method* currentOwnerMethod = mon->ownerMethod;
+        u4 currentOwnerPc = mon->ownerPc;
 
         dvmLockMutex(&mon->lock);
         if (waitThreshold) {
@@ -371,6 +373,15 @@ static void lockMonitor(Thread* self, Monitor* mon)
                 samplePercent = 100 * waitMs / waitThreshold;
             }
             if (samplePercent != 0 && ((u4)rand() % 100 < samplePercent)) {
+                const char* currentOwnerFileName = "no_method";
+                u4 currentOwnerLineNumber = 0;
+                if (currentOwnerMethod != NULL) {
+                    currentOwnerFileName = dvmGetMethodSourceFile(currentOwnerMethod);
+                    if (currentOwnerFileName == NULL) {
+                        currentOwnerFileName = "no_method_file";
+                    }
+                    currentOwnerLineNumber = dvmLineNumFromPC(currentOwnerMethod, currentOwnerPc);
+                }
                 logContentionEvent(self, waitMs, samplePercent,
                                    currentOwnerFileName, currentOwnerLineNumber);
             }
@@ -382,25 +393,17 @@ static void lockMonitor(Thread* self, Monitor* mon)
     // When debugging, save the current monitor holder for future
     // acquisition failures to use in sampled logging.
     if (gDvm.lockProfThreshold > 0) {
-        const StackSaveArea *saveArea;
-        const Method *meth;
-        mon->ownerLineNumber = 0;
+        mon->ownerMethod = NULL;
+        mon->ownerPc = 0;
         if (self->interpSave.curFrame == NULL) {
-            mon->ownerFileName = "no_frame";
-        } else if ((saveArea =
-                   SAVEAREA_FROM_FP(self->interpSave.curFrame)) == NULL) {
-            mon->ownerFileName = "no_save_area";
-        } else if ((meth = saveArea->method) == NULL) {
-            mon->ownerFileName = "no_method";
-        } else {
-            u4 relativePc = saveArea->xtra.currentPc - saveArea->method->insns;
-            mon->ownerFileName = (char*) dvmGetMethodSourceFile(meth);
-            if (mon->ownerFileName == NULL) {
-                mon->ownerFileName = "no_method_file";
-            } else {
-                mon->ownerLineNumber = dvmLineNumFromPC(meth, relativePc);
-            }
+            return;
         }
+        const StackSaveArea* saveArea = SAVEAREA_FROM_FP(self->interpSave.curFrame);
+        if (saveArea == NULL) {
+            return;
+        }
+        mon->ownerMethod = saveArea->method;
+        mon->ownerPc = (saveArea->xtra.currentPc - saveArea->method->insns);
     }
 }
 
@@ -443,8 +446,8 @@ static bool unlockMonitor(Thread* self, Monitor* mon)
          */
         if (mon->lockCount == 0) {
             mon->owner = NULL;
-            mon->ownerFileName = "unlocked";
-            mon->ownerLineNumber = 0;
+            mon->ownerMethod = NULL;
+            mon->ownerPc = 0;
             dvmUnlockMutex(&mon->lock);
         } else {
             mon->lockCount--;
@@ -617,8 +620,6 @@ static void waitMonitor(Thread* self, Monitor* mon, s8 msec, s4 nsec,
     bool wasInterrupted = false;
     bool timed;
     int ret;
-    const char *savedFileName;
-    u4 savedLineNumber;
 
     assert(self != NULL);
     assert(mon != NULL);
@@ -662,10 +663,11 @@ static void waitMonitor(Thread* self, Monitor* mon, s8 msec, s4 nsec,
     int prevLockCount = mon->lockCount;
     mon->lockCount = 0;
     mon->owner = NULL;
-    savedFileName = mon->ownerFileName;
-    mon->ownerFileName = NULL;
-    savedLineNumber = mon->ownerLineNumber;
-    mon->ownerLineNumber = 0;
+
+    const Method* savedMethod = mon->ownerMethod;
+    u4 savedPc = mon->ownerPc;
+    mon->ownerMethod = NULL;
+    mon->ownerPc = 0;
 
     /*
      * Update thread status.  If the GC wakes up, it'll ignore us, knowing
@@ -736,8 +738,8 @@ done:
      */
     mon->owner = self;
     mon->lockCount = prevLockCount;
-    mon->ownerFileName = savedFileName;
-    mon->ownerLineNumber = savedLineNumber;
+    mon->ownerMethod = savedMethod;
+    mon->ownerPc = savedPc;
     waitSetRemove(mon, self);
 
     /* set self->status back to THREAD_RUNNING, and self-suspend if needed */
@@ -1364,7 +1366,7 @@ retry:
         dvmUnlockThreadList();
         goto retry;
     }
-    LOGE("object %p has an unknown hash state %#x", obj, hashState);
+    ALOGE("object %p has an unknown hash state %#x", obj, hashState);
     dvmDumpThread(dvmThreadSelf(), false);
     dvmAbort();
     return 0;  /* Quiet the compiler. */