From: Elliott Hughes Date: Tue, 26 Mar 2013 23:25:15 +0000 (-0700) Subject: pthread_create doesn't set errno. X-Git-Tag: android-x86-4.4-r1~28^2~9^2~61^2 X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fdalvik.git;a=commitdiff_plain;h=34a00d75391bf2eef4a5ae065d1b727f48317277 pthread_create doesn't set errno. Let's try to get slightly better logging and exception detail messages. Also fix the "set but not read" warnings for the other pthread functions in this file. Bug: 8470684 Change-Id: I7f9dbb4d39b4e3022cd5f1a8a45c6426e68c858b --- diff --git a/vm/Thread.cpp b/vm/Thread.cpp index dbdeec1b6..ded6f0f1f 100644 --- a/vm/Thread.cpp +++ b/vm/Thread.cpp @@ -1311,11 +1311,13 @@ bool dvmCreateInterpThread(Object* threadObj, int reqStackSize) * resource limits. VirtualMachineError is probably too severe, * so use OutOfMemoryError. */ - ALOGE("Thread creation failed (err=%s)", strerror(errno)); + ALOGE("pthread_create (stack size %d bytes) failed: %s", stackSize, strerror(cc)); dvmSetFieldObject(threadObj, gDvm.offJavaLangThread_vmThread, NULL); - dvmThrowOutOfMemoryError("thread creation failed"); + dvmThrowExceptionFmt(gDvm.exOutOfMemoryError, + "pthread_create (stack size %d bytes) failed: %s", + stackSize, strerror(cc)); goto fail; } @@ -1658,7 +1660,7 @@ bool dvmCreateInternalThread(pthread_t* pHandle, const char* name, int cc = pthread_create(pHandle, &threadAttr, internalThreadStart, pArgs); pthread_attr_destroy(&threadAttr); if (cc != 0) { - ALOGE("internal thread creation failed"); + ALOGE("internal thread creation failed: %s", strerror(cc)); free(pArgs->name); free(pArgs); return false; @@ -2145,13 +2147,14 @@ void dvmDetachCurrentThread() gDvm.nonDaemonThreadCount--; // guarded by thread list lock if (gDvm.nonDaemonThreadCount == 0) { - int cc; - ALOGV("threadid=%d: last non-daemon thread", self->threadId); //dvmDumpAllThreads(false); // cond var guarded by threadListLock, which we already hold - cc = pthread_cond_signal(&gDvm.vmExitCond); - assert(cc == 0); + int cc = pthread_cond_signal(&gDvm.vmExitCond); + if (cc != 0) { + ALOGE("pthread_cond_signal(&gDvm.vmExitCond) failed: %s", strerror(cc)); + dvmAbort(); + } } } @@ -2629,7 +2632,6 @@ void dvmResumeAllThreads(SuspendCause why) { Thread* self = dvmThreadSelf(); Thread* thread; - int cc; lockThreadSuspend("res-all", why); /* one suspend/resume at a time */ LOG_THREAD("threadid=%d: ResumeAll starting", self->threadId); @@ -2707,8 +2709,11 @@ void dvmResumeAllThreads(SuspendCause why) * which may choose to wake up. No need to wait for them. */ lockThreadSuspendCount(); - cc = pthread_cond_broadcast(&gDvm.threadSuspendCountCond); - assert(cc == 0); + int cc = pthread_cond_broadcast(&gDvm.threadSuspendCountCond); + if (cc != 0) { + ALOGE("pthread_cond_broadcast(&gDvm.threadSuspendCountCond) failed: %s", strerror(cc)); + dvmAbort(); + } unlockThreadSuspendCount(); LOG_THREAD("threadid=%d: ResumeAll complete", self->threadId); @@ -2722,7 +2727,6 @@ void dvmUndoDebuggerSuspensions() { Thread* self = dvmThreadSelf(); Thread* thread; - int cc; lockThreadSuspend("undo", SUSPEND_FOR_DEBUG); LOG_THREAD("threadid=%d: UndoDebuggerSusp starting", self->threadId); @@ -2756,8 +2760,11 @@ void dvmUndoDebuggerSuspensions() * which may choose to wake up. No need to wait for them. */ lockThreadSuspendCount(); - cc = pthread_cond_broadcast(&gDvm.threadSuspendCountCond); - assert(cc == 0); + int cc = pthread_cond_broadcast(&gDvm.threadSuspendCountCond); + if (cc != 0) { + ALOGE("pthread_cond_broadcast(&gDvm.threadSuspendCountCond) failed: %s", strerror(cc)); + dvmAbort(); + } unlockThreadSuspendCount(); unlockThreadSuspend();