diff options
| author | peshovec <jlesev@gmail.com> | 2012-03-08 14:30:49 +0200 |
|---|---|---|
| committer | Michael Bestas <mikeioannina@gmail.com> | 2013-03-12 04:19:09 +0200 |
| commit | 8826aa024a1c33766c8b20a952aeff89e6515cfe (patch) | |
| tree | 11c7a1386fd41aaff3a8126121199e46017f8e6a | |
| parent | 2b8f8a4697901a8232e08f9e34452da5144bd55e (diff) | |
| download | android_dalvik-8826aa024a1c33766c8b20a952aeff89e6515cfe.tar.gz android_dalvik-8826aa024a1c33766c8b20a952aeff89e6515cfe.tar.bz2 android_dalvik-8826aa024a1c33766c8b20a952aeff89e6515cfe.zip | |
Don't pay for filename/line number lookup unless you need to.gingerbread
picked from
https://github.com/android/platform_dalvik/commit/6cd72bd0161459e21d496b927967bd0ca6fe0f94
remove dependencies
Change-Id: I0040d6628feac782e286fa0307bc4df3ce140be0
| -rw-r--r-- | vm/Sync.c | 62 |
1 files changed, 31 insertions, 31 deletions
@@ -127,10 +127,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. */ - char* ownerFileName; - u4 ownerLineNumber; + const Method* ownerMethod; + u4 ownerPc; #ifdef WITH_DEADLOCK_PREDICTION /* @@ -472,8 +472,8 @@ 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) { @@ -488,6 +488,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); } @@ -499,24 +508,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->curFrame == NULL) { - mon->ownerFileName = "no_frame"; - } else if ((saveArea = SAVEAREA_FROM_FP(self->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->curFrame); + if (saveArea == NULL) { + return; } + mon->ownerMethod = saveArea->method; + mon->ownerPc = (saveArea->xtra.currentPc - saveArea->method->insns); } } @@ -559,8 +561,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--; @@ -734,8 +736,6 @@ static void waitMonitor(Thread* self, Monitor* mon, s8 msec, s4 nsec, bool wasInterrupted = false; bool timed; int ret; - char *savedFileName; - u4 savedLineNumber; assert(self != NULL); assert(mon != NULL); @@ -780,11 +780,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 * that we won't touch any references in this state, and we'll check @@ -854,8 +854,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 */ |
