diff options
| author | 2012-04-09 13:55:55 -0700 | |
|---|---|---|
| committer | 2012-04-09 13:55:55 -0700 | |
| commit | 34e069606d6f1698cd3c33b39e72b79ae27e1c7b (patch) | |
| tree | 0feb7e9bde6cfe01c0df3ef2d8de3210570f7ce2 | |
| parent | e62934d85fbc2d935afdad57eeade39ecbd7440a (diff) | |
Remove the useless "suspend count already zero" message for new threads.
We can actually detect the expected case of this warning ourselves, and
not emit it. Then we can upgrade the WARNING to a FATAL.
I also tripped over the fact that the operator<< for Thread::State was out
of date, so I've moved the Thread enums up to namespace scope so the script
can automatically generate correct operator<< implementations for us. (All
the high-numbered thread states have been off by one for a couple of weeks.)
Change-Id: I5de573d33d641e5a3cba87b370e9620c8c66e633
40 files changed, 182 insertions, 202 deletions
diff --git a/build/Android.common.mk b/build/Android.common.mk index f70a1ca26a..b272649da9 100644 --- a/build/Android.common.mk +++ b/build/Android.common.mk @@ -273,7 +273,8 @@ LIBART_ENUM_OPERATOR_OUT_HEADER_FILES := \ src/invoke_type.h \ src/jdwp/jdwp.h \ src/jdwp/jdwp_constants.h \ - src/mutex.h + src/mutex.h \ + src/thread.h LIBARTTEST_COMMON_SRC_FILES := \ test/StackWalk/stack_walk_jni.cc \ diff --git a/src/check_jni.cc b/src/check_jni.cc index 1b28dd54df..9ae3d47ae4 100644 --- a/src/check_jni.cc +++ b/src/check_jni.cc @@ -54,7 +54,7 @@ void JniAbort(const char* jni_function_name) { if (vm->check_jni_abort_hook != NULL) { vm->check_jni_abort_hook(vm->check_jni_abort_hook_data, os.str()); } else { - self->SetState(Thread::kNative); // Ensure that we get a native stack trace for this thread. + self->SetState(kNative); // Ensure that we get a native stack trace for this thread. LOG(FATAL) << os.str(); } } diff --git a/src/class_linker.cc b/src/class_linker.cc index 095c94996e..ae1390869b 100644 --- a/src/class_linker.cc +++ b/src/class_linker.cc @@ -1187,7 +1187,7 @@ Class* ClassLinker::FindClass(const char* descriptor, const ClassLoader* class_l } else { std::string class_name_string(DescriptorToDot(descriptor)); - ScopedThreadStateChange tsc(self, Thread::kNative); + ScopedThreadStateChange tsc(self, kNative); JNIEnv* env = self->GetJniEnv(); ScopedLocalRef<jclass> c(env, AddLocalReference<jclass>(env, GetClassRoot(kJavaLangClassLoader))); CHECK(c.get() != NULL); @@ -2644,7 +2644,7 @@ bool ClassLinker::EnsureInitialized(Class* c, bool can_run_clinit, bool can_init } Thread* self = Thread::Current(); - ScopedThreadStateChange tsc(self, Thread::kRunnable); + ScopedThreadStateChange tsc(self, kRunnable); bool success = InitializeClass(c, can_run_clinit, can_init_fields); if (!success) { CHECK(self->IsExceptionPending() || !can_run_clinit) << PrettyClass(c); diff --git a/src/compiler.cc b/src/compiler.cc index bac39efe04..3980bacac2 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -943,10 +943,10 @@ class WorkerThread { if (worker->spawn_) { runtime->AttachCurrentThread("Compiler Worker", true, NULL); } - Thread::Current()->SetState(Thread::kRunnable); + Thread::Current()->SetState(kRunnable); worker->Run(); if (worker->spawn_) { - Thread::Current()->SetState(Thread::kNative); + Thread::Current()->SetState(kNative); runtime->DetachCurrentThread(); } return NULL; @@ -988,7 +988,7 @@ void ForAll(Context* context, size_t begin, size_t end, Callback callback, size_ threads[0]->Go(); // Switch to kVmWait while we're blocked waiting for the other threads to finish. - ScopedThreadStateChange tsc(self, Thread::kVmWait); + ScopedThreadStateChange tsc(self, kVmWait); STLDeleteElements(&threads); } diff --git a/src/compiler_llvm/jni_compiler.cc b/src/compiler_llvm/jni_compiler.cc index 071c0bd4e7..e0a570463a 100644 --- a/src/compiler_llvm/jni_compiler.cc +++ b/src/compiler_llvm/jni_compiler.cc @@ -142,7 +142,7 @@ CompiledMethod* JniCompiler::Compile() { // Set thread state to kNative StoreToObjectOffset(thread_object_addr, Thread::StateOffset().Int32Value(), - irb_.getInt32(Thread::kNative)); + irb_.getInt32(kNative)); // Get callee code_addr llvm::Value* code_addr_ = @@ -262,7 +262,7 @@ CompiledMethod* JniCompiler::Compile() { // Set thread state to kRunnable StoreToObjectOffset(thread_object_addr, Thread::StateOffset().Int32Value(), - irb_.getInt32(Thread::kRunnable)); + irb_.getInt32(kRunnable)); if (return_shorty == 'L') { // If the return value is reference, it may point to SIRT, we should decode it. diff --git a/src/dalvik_system_DexFile.cc b/src/dalvik_system_DexFile.cc index 3ada9f441e..96a1ac1636 100644 --- a/src/dalvik_system_DexFile.cc +++ b/src/dalvik_system_DexFile.cc @@ -126,7 +126,7 @@ static void DexFile_closeDexFile(JNIEnv* env, jclass, jint cookie) { static jclass DexFile_defineClassNative(JNIEnv* env, jclass, jstring javaName, jobject javaLoader, jint cookie) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); const DexFile* dex_file = toDexFile(env, cookie); if (dex_file == NULL) { return NULL; diff --git a/src/dalvik_system_VMRuntime.cc b/src/dalvik_system_VMRuntime.cc index 030caedc75..140fafffbd 100644 --- a/src/dalvik_system_VMRuntime.cc +++ b/src/dalvik_system_VMRuntime.cc @@ -47,7 +47,7 @@ static void VMRuntime_disableJitCompilation(JNIEnv*, jobject) { } static jobject VMRuntime_newNonMovableArray(JNIEnv* env, jobject, jclass javaElementClass, jint length) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); #ifdef MOVING_GARBAGE_COLLECTOR // TODO: right now, we don't have a copying collector, so there's no need // to do anything special here, but we ought to pass the non-movability @@ -81,7 +81,7 @@ static jlong VMRuntime_addressOf(JNIEnv* env, jobject, jobject javaArray) { if (javaArray == NULL) { // Most likely allocation failed return 0; } - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Array* array = Decode<Array*>(env, javaArray); if (!array->IsArrayInstance()) { Thread::Current()->ThrowNewException("Ljava/lang/IllegalArgumentException;", "not an array"); diff --git a/src/debugger.cc b/src/debugger.cc index 70f9c8e6a9..fbcd420286 100644 --- a/src/debugger.cc +++ b/src/debugger.cc @@ -418,7 +418,7 @@ void Dbg::StartJdwp() { // If a debugger has already attached, send the "welcome" message. // This may cause us to suspend all threads. if (gJdwpState->IsActive()) { - //ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + //ScopedThreadStateChange tsc(Thread::Current(), kRunnable); if (!gJdwpState->PostVMStart()) { LOG(WARNING) << "Failed to post 'start' message to debugger"; } @@ -532,15 +532,15 @@ int64_t Dbg::LastDebuggerActivity() { } int Dbg::ThreadRunning() { - return static_cast<int>(Thread::Current()->SetState(Thread::kRunnable)); + return static_cast<int>(Thread::Current()->SetState(kRunnable)); } int Dbg::ThreadWaiting() { - return static_cast<int>(Thread::Current()->SetState(Thread::kVmWait)); + return static_cast<int>(Thread::Current()->SetState(kVmWait)); } int Dbg::ThreadContinuing(int new_state) { - return static_cast<int>(Thread::Current()->SetState(static_cast<Thread::State>(new_state))); + return static_cast<int>(Thread::Current()->SetState(static_cast<ThreadState>(new_state))); } void Dbg::UndoDebuggerSuspensions() { @@ -1388,15 +1388,15 @@ bool Dbg::GetThreadStatus(JDWP::ObjectId threadId, JDWP::JdwpThreadStatus* pThre // TODO: if we're in Thread.sleep(long), we should return TS_SLEEPING, // even if it's implemented using Object.wait(long). switch (thread->GetState()) { - case Thread::kTerminated: *pThreadStatus = JDWP::TS_ZOMBIE; break; - case Thread::kRunnable: *pThreadStatus = JDWP::TS_RUNNING; break; - case Thread::kTimedWaiting: *pThreadStatus = JDWP::TS_WAIT; break; - case Thread::kBlocked: *pThreadStatus = JDWP::TS_MONITOR; break; - case Thread::kWaiting: *pThreadStatus = JDWP::TS_WAIT; break; - case Thread::kStarting: *pThreadStatus = JDWP::TS_ZOMBIE; break; - case Thread::kNative: *pThreadStatus = JDWP::TS_RUNNING; break; - case Thread::kVmWait: *pThreadStatus = JDWP::TS_WAIT; break; - case Thread::kSuspended: *pThreadStatus = JDWP::TS_RUNNING; break; + case kTerminated: *pThreadStatus = JDWP::TS_ZOMBIE; break; + case kRunnable: *pThreadStatus = JDWP::TS_RUNNING; break; + case kTimedWaiting: *pThreadStatus = JDWP::TS_WAIT; break; + case kBlocked: *pThreadStatus = JDWP::TS_MONITOR; break; + case kWaiting: *pThreadStatus = JDWP::TS_WAIT; break; + case kStarting: *pThreadStatus = JDWP::TS_ZOMBIE; break; + case kNative: *pThreadStatus = JDWP::TS_RUNNING; break; + case kVmWait: *pThreadStatus = JDWP::TS_WAIT; break; + case kSuspended: *pThreadStatus = JDWP::TS_RUNNING; break; // Don't add a 'default' here so the compiler can spot incompatible enum changes. } @@ -1524,7 +1524,7 @@ JDWP::ObjectId Dbg::GetThreadSelfId() { } void Dbg::SuspendVM() { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); // TODO: do we really want to change back? should the JDWP thread be Runnable usually? + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); // TODO: do we really want to change back? should the JDWP thread be Runnable usually? Runtime::Current()->GetThreadList()->SuspendAll(true); } @@ -2173,7 +2173,7 @@ JDWP::JdwpError Dbg::InvokeMethod(JDWP::ObjectId threadId, JDWP::ObjectId object * run out of memory. It's also a good idea to change it before locking * the invokeReq mutex, although that should never be held for long. */ - ScopedThreadStateChange tsc(Thread::Current(), Thread::kVmWait); + ScopedThreadStateChange tsc(Thread::Current(), kVmWait); VLOG(jdwp) << " Transferring control to event thread"; { @@ -2232,7 +2232,7 @@ void Dbg::ExecuteMethod(DebugInvokeReq* pReq) { SirtRef<Throwable> old_exception(self->GetException()); self->ClearException(); - ScopedThreadStateChange tsc(self, Thread::kRunnable); + ScopedThreadStateChange tsc(self, kRunnable); // Translate the method through the vtable, unless the debugger wants to suppress it. Method* m = pReq->method_; @@ -2401,7 +2401,7 @@ void Dbg::DdmBroadcast(bool connect) { VLOG(jdwp) << "Broadcasting DDM " << (connect ? "connect" : "disconnect") << "..."; Thread* self = Thread::Current(); - if (self->GetState() != Thread::kRunnable) { + if (self->GetState() != kRunnable) { LOG(ERROR) << "DDM broadcast in thread state " << self->GetState(); /* try anyway? */ } diff --git a/src/heap.cc b/src/heap.cc index 8a7ab3dd3d..76a620e949 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -427,7 +427,7 @@ Object* Heap::AllocateLocked(AllocSpace* space, size_t alloc_size) { // Since allocation can cause a GC which will need to SuspendAll, // make sure all allocators are in the kRunnable state. - CHECK_EQ(Thread::Current()->GetState(), Thread::kRunnable); + CHECK_EQ(Thread::Current()->GetState(), kRunnable); // Fail impossible allocations if (alloc_size > space->Capacity()) { @@ -687,13 +687,13 @@ pid_t Heap::GetLockOwner() { } void Heap::Lock() { - // Grab the lock, but put ourselves into Thread::kVmWait if it looks + // Grab the lock, but put ourselves into kVmWait if it looks // like we're going to have to wait on the mutex. This prevents // deadlock if another thread is calling CollectGarbageInternal, // since they will have the heap lock and be waiting for mutators to // suspend. if (!lock_->TryLock()) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kVmWait); + ScopedThreadStateChange tsc(Thread::Current(), kVmWait); lock_->Lock(); } } @@ -786,7 +786,7 @@ Object* Heap::DequeuePendingReference(Object** list) { } void Heap::AddFinalizerReference(Thread* self, Object* object) { - ScopedThreadStateChange tsc(self, Thread::kRunnable); + ScopedThreadStateChange tsc(self, kRunnable); static Method* FinalizerReference_add = java_lang_ref_FinalizerReference_->FindDirectMethod("add", "(Ljava/lang/Object;)V"); DCHECK(FinalizerReference_add != NULL); @@ -803,7 +803,7 @@ void Heap::EnqueueClearedReferences(Object** cleared) { DCHECK(ReferenceQueue_add != NULL); Thread* self = Thread::Current(); - ScopedThreadStateChange tsc(self, Thread::kRunnable); + ScopedThreadStateChange tsc(self, kRunnable); JValue args[1]; args[0].l = *cleared; ReferenceQueue_add->Invoke(self, NULL, args, NULL); diff --git a/src/hprof/hprof.cc b/src/hprof/hprof.cc index ce3050e9eb..b118b5cfd5 100644 --- a/src/hprof/hprof.cc +++ b/src/hprof/hprof.cc @@ -759,7 +759,7 @@ void HprofBitmapCallback(Object *obj, void *arg) { int DumpHeap(const char* fileName, int fd, bool directToDdms) { CHECK(fileName != NULL); ScopedHeapLock heap_lock; - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); ThreadList* thread_list = Runtime::Current()->GetThreadList(); thread_list->SuspendAll(); diff --git a/src/java_lang_Class.cc b/src/java_lang_Class.cc index 17b584a340..c1d6eb0230 100644 --- a/src/java_lang_Class.cc +++ b/src/java_lang_Class.cc @@ -39,7 +39,7 @@ static Class* DecodeClass(JNIEnv* env, jobject java_class) { // "name" is in "binary name" format, e.g. "dalvik.system.Debug$1". static jclass Class_classForName(JNIEnv* env, jclass, jstring javaName, jboolean initialize, jobject javaLoader) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); ScopedUtfChars name(env, javaName); if (name.c_str() == NULL) { return NULL; @@ -133,7 +133,7 @@ static bool IsVisibleField(Field* f, bool public_only) { } static jobjectArray Class_getDeclaredFields(JNIEnv* env, jclass javaClass, jboolean publicOnly) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Class* c = DecodeClass(env, javaClass); if (c == NULL) { return NULL; @@ -187,7 +187,7 @@ static bool IsVisibleMethod(Method* m, bool public_only) { } static jobjectArray Class_getDeclaredMethods(JNIEnv* env, jclass javaClass, jboolean publicOnly) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Class* c = DecodeClass(env, javaClass); if (c == NULL) { return NULL; @@ -308,7 +308,7 @@ static jobject Class_getDeclaredConstructorOrMethod(JNIEnv* env, jclass javaClas } static jobject Class_getDeclaredFieldNative(JNIEnv* env, jclass java_class, jobject jname) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Class* c = DecodeClass(env, java_class); if (c == NULL) { return NULL; @@ -344,19 +344,19 @@ static jobject Class_getDeclaredFieldNative(JNIEnv* env, jclass java_class, jobj } static jstring Class_getNameNative(JNIEnv* env, jobject javaThis) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Class* c = DecodeClass(env, javaThis); return AddLocalReference<jstring>(env, c->ComputeName()); } static jobjectArray Class_getProxyInterfaces(JNIEnv* env, jobject javaThis) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); SynthesizedProxyClass* c = down_cast<SynthesizedProxyClass*>(DecodeClass(env, javaThis)); return AddLocalReference<jobjectArray>(env, c->GetInterfaces()->Clone()); } static jboolean Class_isAssignableFrom(JNIEnv* env, jobject javaLhs, jclass javaRhs) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Class* lhs = DecodeClass(env, javaLhs); Class* rhs = Decode<Class*>(env, javaRhs); // Can be null. if (rhs == NULL) { @@ -396,7 +396,7 @@ static bool CheckMemberAccess(const Class* access_from, Class* access_to, uint32 } static jobject Class_newInstanceImpl(JNIEnv* env, jobject javaThis) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Class* c = DecodeClass(env, javaThis); if (c->IsPrimitive() || c->IsInterface() || c->IsArrayClass() || c->IsAbstract()) { Thread::Current()->ThrowNewExceptionF("Ljava/lang/InstantiationException;", diff --git a/src/java_lang_Object.cc b/src/java_lang_Object.cc index f95d1a1518..7c79fc1aed 100644 --- a/src/java_lang_Object.cc +++ b/src/java_lang_Object.cc @@ -22,7 +22,7 @@ namespace art { static jobject Object_internalClone(JNIEnv* env, jobject javaThis) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Object* o = Decode<Object*>(env, javaThis); return AddLocalReference<jobject>(env, o->Clone()); } diff --git a/src/java_lang_Runtime.cc b/src/java_lang_Runtime.cc index 44703b70c3..1b5520b8de 100644 --- a/src/java_lang_Runtime.cc +++ b/src/java_lang_Runtime.cc @@ -28,7 +28,7 @@ namespace art { static void Runtime_gc(JNIEnv*, jclass) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Runtime::Current()->GetHeap()->CollectGarbage(false); } diff --git a/src/java_lang_String.cc b/src/java_lang_String.cc index 17dbbe9447..49bf234e00 100644 --- a/src/java_lang_String.cc +++ b/src/java_lang_String.cc @@ -37,7 +37,7 @@ uint32_t MemCmp16(const uint16_t* s0, const uint16_t* s1, size_t count) { namespace art { static jint String_compareTo(JNIEnv* env, jobject javaThis, jobject javaRhs) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); String* lhs = Decode<String*>(env, javaThis); String* rhs = Decode<String*>(env, javaRhs); diff --git a/src/java_lang_System.cc b/src/java_lang_System.cc index fa8257b8c1..741b319718 100644 --- a/src/java_lang_System.cc +++ b/src/java_lang_System.cc @@ -109,7 +109,7 @@ static void ThrowArrayStoreException_NotAnArray(const char* identifier, Object* } static void System_arraycopy(JNIEnv* env, jclass, jobject javaSrc, jint srcPos, jobject javaDst, jint dstPos, jint length) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Thread* self = Thread::Current(); // Null pointer checks. diff --git a/src/java_lang_Thread.cc b/src/java_lang_Thread.cc index 6ce2609214..197c1b98e3 100644 --- a/src/java_lang_Thread.cc +++ b/src/java_lang_Thread.cc @@ -54,22 +54,22 @@ static jint Thread_nativeGetStatus(JNIEnv* env, jobject javaThread, jboolean has const jint kJavaTimedWaiting = 4; const jint kJavaTerminated = 5; - Thread::State internal_thread_state = (hasBeenStarted ? Thread::kTerminated : Thread::kStarting); + ThreadState internal_thread_state = (hasBeenStarted ? kTerminated : kStarting); ScopedThreadListLock thread_list_lock; Thread* thread = Thread::FromManagedThread(env, javaThread); if (thread != NULL) { internal_thread_state = thread->GetState(); } switch (internal_thread_state) { - case Thread::kTerminated: return kJavaTerminated; - case Thread::kRunnable: return kJavaRunnable; - case Thread::kTimedWaiting: return kJavaTimedWaiting; - case Thread::kBlocked: return kJavaBlocked; - case Thread::kWaiting: return kJavaWaiting; - case Thread::kStarting: return kJavaNew; - case Thread::kNative: return kJavaRunnable; - case Thread::kVmWait: return kJavaWaiting; - case Thread::kSuspended: return kJavaRunnable; + case kTerminated: return kJavaTerminated; + case kRunnable: return kJavaRunnable; + case kTimedWaiting: return kJavaTimedWaiting; + case kBlocked: return kJavaBlocked; + case kWaiting: return kJavaWaiting; + case kStarting: return kJavaNew; + case kNative: return kJavaRunnable; + case kVmWait: return kJavaWaiting; + case kSuspended: return kJavaRunnable; // Don't add a 'default' here so the compiler can spot incompatible enum changes. } return -1; // Unreachable. @@ -78,7 +78,7 @@ static jint Thread_nativeGetStatus(JNIEnv* env, jobject javaThread, jboolean has static jboolean Thread_nativeHoldsLock(JNIEnv* env, jobject javaThread, jobject javaObject) { Object* object = Decode<Object*>(env, javaObject); if (object == NULL) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Thread::Current()->ThrowNewException("Ljava/lang/NullPointerException;", "object == null"); return JNI_FALSE; } diff --git a/src/java_lang_reflect_Array.cc b/src/java_lang_reflect_Array.cc index 4a5f797685..1c86aacf8b 100644 --- a/src/java_lang_reflect_Array.cc +++ b/src/java_lang_reflect_Array.cc @@ -70,7 +70,7 @@ static Array* CreateMultiArray(Class* array_class, int current_dimension, IntArr // subtract pieces off. Besides, we want to start with the outermost // piece and work our way in. static jobject Array_createMultiArray(JNIEnv* env, jclass, jclass javaElementClass, jobject javaDimArray) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); DCHECK(javaElementClass != NULL); Class* element_class = Decode<Class*>(env, javaElementClass); DCHECK(element_class->IsClass()); @@ -118,7 +118,7 @@ static jobject Array_createMultiArray(JNIEnv* env, jclass, jclass javaElementCla } static jobject Array_createObjectArray(JNIEnv* env, jclass, jclass javaElementClass, jint length) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); DCHECK(javaElementClass != NULL); Class* element_class = Decode<Class*>(env, javaElementClass); if (length < 0) { diff --git a/src/java_lang_reflect_Constructor.cc b/src/java_lang_reflect_Constructor.cc index 9a498f423d..5d0434d4c7 100644 --- a/src/java_lang_reflect_Constructor.cc +++ b/src/java_lang_reflect_Constructor.cc @@ -32,7 +32,7 @@ namespace art { * with an interface, array, or primitive class. */ static jobject Constructor_newInstance(JNIEnv* env, jobject javaMethod, jobjectArray javaArgs) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Method* m = Decode<Object*>(env, javaMethod)->AsMethod(); Class* c = m->GetDeclaringClass(); if (c->IsAbstract()) { diff --git a/src/java_lang_reflect_Field.cc b/src/java_lang_reflect_Field.cc index a7785e7744..a8bde0363c 100644 --- a/src/java_lang_reflect_Field.cc +++ b/src/java_lang_reflect_Field.cc @@ -25,7 +25,7 @@ namespace art { static bool GetFieldValue(Object* o, Field* f, JValue& value, bool allow_references) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(f->GetDeclaringClass(), true, true)) { return false; } @@ -206,7 +206,7 @@ static void SetFieldValue(Object* o, Field* f, const JValue& new_value, bool all } static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Field* f = DecodeField(env->FromReflectedField(javaField)); // Unbox the value, if necessary. @@ -227,7 +227,7 @@ static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject j static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor, const JValue& new_value) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Field* f = DecodeField(env->FromReflectedField(javaField)); Object* o = NULL; if (!CheckReceiver(env, javaObj, f, o)) { diff --git a/src/java_lang_reflect_Method.cc b/src/java_lang_reflect_Method.cc index d9006dc21e..a5a705bab7 100644 --- a/src/java_lang_reflect_Method.cc +++ b/src/java_lang_reflect_Method.cc @@ -44,7 +44,7 @@ static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) { CHECK_NE(throws_index, -1); ObjectArray<Class>* declared_exceptions = proxy_class->GetThrows()->Get(throws_index); // Change thread state for allocation - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); return AddLocalReference<jobject>(env, declared_exceptions->Clone()); } diff --git a/src/java_lang_reflect_Proxy.cc b/src/java_lang_reflect_Proxy.cc index 7bc3e44e2c..bac20b05da 100644 --- a/src/java_lang_reflect_Proxy.cc +++ b/src/java_lang_reflect_Proxy.cc @@ -24,7 +24,7 @@ namespace art { static jclass Proxy_generateProxy(JNIEnv* env, jclass, jstring javaName, jobjectArray javaInterfaces, jobject javaLoader, jobjectArray javaMethods, jobjectArray javaThrows) { // Allocates Class so transition thread state to runnable - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); String* name = Decode<String*>(env, javaName); ObjectArray<Class>* interfaces = Decode<ObjectArray<Class>*>(env, javaInterfaces); ClassLoader* loader = Decode<ClassLoader*>(env, javaLoader); diff --git a/src/jdwp/jdwp_main.cc b/src/jdwp/jdwp_main.cc index ec85aa8baa..138b60a9b2 100644 --- a/src/jdwp/jdwp_main.cc +++ b/src/jdwp/jdwp_main.cc @@ -170,7 +170,7 @@ JdwpState* JdwpState::Create(const JdwpOptions* options) { */ if (options->suspend) { { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kVmWait); + ScopedThreadStateChange tsc(Thread::Current(), kVmWait); state->attach_cond_.Wait(state->attach_lock_); state->attach_lock_.Unlock(); @@ -327,7 +327,7 @@ void JdwpState::Run() { bool first = true; while (!Dbg::IsDisposed()) { // sanity check -- shouldn't happen? - if (Thread::Current()->GetState() != Thread::kVmWait) { + if (Thread::Current()->GetState() != kVmWait) { LOG(ERROR) << "JDWP thread no longer in VMWAIT (now " << Thread::Current()->GetState() << "); resetting"; Dbg::ThreadWaiting(); } diff --git a/src/jni_compiler_test.cc b/src/jni_compiler_test.cc index 175773657e..f8b7013957 100644 --- a/src/jni_compiler_test.cc +++ b/src/jni_compiler_test.cc @@ -106,7 +106,7 @@ int gJava_MyClassNatives_foo_calls = 0; void Java_MyClassNatives_foo(JNIEnv* env, jobject thisObj) { // 2 = SirtRef<ClassLoader> + thisObj EXPECT_EQ(2U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(thisObj != NULL); EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); @@ -155,7 +155,7 @@ int gJava_MyClassNatives_fooI_calls = 0; jint Java_MyClassNatives_fooI(JNIEnv* env, jobject thisObj, jint x) { // 2 = SirtRef<ClassLoader> + thisObj EXPECT_EQ(2U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(thisObj != NULL); EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); @@ -181,7 +181,7 @@ int gJava_MyClassNatives_fooII_calls = 0; jint Java_MyClassNatives_fooII(JNIEnv* env, jobject thisObj, jint x, jint y) { // 2 = SirtRef<ClassLoader> + thisObj EXPECT_EQ(2U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(thisObj != NULL); EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); @@ -208,7 +208,7 @@ int gJava_MyClassNatives_fooJJ_calls = 0; jlong Java_MyClassNatives_fooJJ(JNIEnv* env, jobject thisObj, jlong x, jlong y) { // 2 = SirtRef<ClassLoader> + thisObj EXPECT_EQ(2U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(thisObj != NULL); EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); @@ -236,7 +236,7 @@ int gJava_MyClassNatives_fooDD_calls = 0; jdouble Java_MyClassNatives_fooDD(JNIEnv* env, jobject thisObj, jdouble x, jdouble y) { // 2 = SirtRef<ClassLoader> + thisObj EXPECT_EQ(2U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(thisObj != NULL); EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); @@ -266,7 +266,7 @@ jobject Java_MyClassNatives_fooIOO(JNIEnv* env, jobject thisObj, jint x, jobject jobject z) { // 4 = SirtRef<ClassLoader> + this + y + z EXPECT_EQ(4U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(thisObj != NULL); EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); @@ -317,7 +317,7 @@ int gJava_MyClassNatives_fooSII_calls = 0; jint Java_MyClassNatives_fooSII(JNIEnv* env, jclass klass, jint x, jint y) { // 2 = SirtRef<ClassLoader> + klass EXPECT_EQ(2U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(klass != NULL); EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); @@ -340,7 +340,7 @@ int gJava_MyClassNatives_fooSDD_calls = 0; jdouble Java_MyClassNatives_fooSDD(JNIEnv* env, jclass klass, jdouble x, jdouble y) { // 2 = SirtRef<ClassLoader> + klass EXPECT_EQ(2U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(klass != NULL); EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); @@ -369,7 +369,7 @@ jobject Java_MyClassNatives_fooSIOO(JNIEnv* env, jclass klass, jint x, jobject y jobject z) { // 4 = SirtRef<ClassLoader> + klass + y + z EXPECT_EQ(4U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(klass != NULL); EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); @@ -422,7 +422,7 @@ jobject Java_MyClassNatives_fooSSIOO(JNIEnv* env, jclass klass, jint x, jobject jobject z) { // 4 = SirtRef<ClassLoader> + klass + y + z EXPECT_EQ(4U, Thread::Current()->NumStackReferences()); - EXPECT_EQ(Thread::kNative, Thread::Current()->GetState()); + EXPECT_EQ(kNative, Thread::Current()->GetState()); EXPECT_EQ(Thread::Current()->GetJniEnv(), env); EXPECT_TRUE(klass != NULL); EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); diff --git a/src/jni_internal.cc b/src/jni_internal.cc index 6ac36bdada..26f069c64b 100644 --- a/src/jni_internal.cc +++ b/src/jni_internal.cc @@ -586,7 +586,7 @@ class SharedLibrary { while (jni_on_load_result_ == kPending) { VLOG(jni) << "[" << *self << " waiting for \"" << path_ << "\" " << "JNI_OnLoad...]"; - ScopedThreadStateChange tsc(self, Thread::kVmWait); + ScopedThreadStateChange tsc(self, kVmWait); jni_on_load_cond_.Wait(jni_on_load_lock_); } @@ -2847,7 +2847,7 @@ bool JavaVMExt::LoadNativeLibrary(const std::string& path, ClassLoader* class_lo Thread* self = Thread::Current(); void* handle = NULL; { - ScopedThreadStateChange tsc(self, Thread::kVmWait); + ScopedThreadStateChange tsc(self, kVmWait); handle = dlopen(path.empty() ? NULL : path.c_str(), RTLD_LAZY); } @@ -2890,7 +2890,7 @@ bool JavaVMExt::LoadNativeLibrary(const std::string& path, ClassLoader* class_lo int version = 0; { - ScopedThreadStateChange tsc(self, Thread::kNative); + ScopedThreadStateChange tsc(self, kNative); VLOG(jni) << "[Calling JNI_OnLoad in \"" << path << "\"]"; version = (*jni_on_load)(this, NULL); } diff --git a/src/monitor.cc b/src/monitor.cc index dcb3c0440a..a42770e196 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -190,7 +190,7 @@ void Monitor::Lock(Thread* self) { const Method* current_locking_method = NULL; uintptr_t current_locking_pc = 0; { - ScopedThreadStateChange tsc(self, Thread::kBlocked); + ScopedThreadStateChange tsc(self, kBlocked); if (wait_threshold != 0) { waitStart = NanoTime() / 1000; } @@ -441,9 +441,9 @@ void Monitor::Wait(Thread* self, int64_t ms, int32_t ns, bool interruptShouldThr * our suspend mode before we transition out. */ if (timed) { - self->SetState(Thread::kTimedWaiting); + self->SetState(kTimedWaiting); } else { - self->SetState(Thread::kWaiting); + self->SetState(kWaiting); } self->wait_mutex_->Lock(); @@ -503,8 +503,8 @@ done: locking_pc_ = savedPc; RemoveFromWaitSet(self); - /* set self->status back to Thread::kRunnable, and self-suspend if needed */ - self->SetState(Thread::kRunnable); + /* set self->status back to kRunnable, and self-suspend if needed */ + self->SetState(kRunnable); if (wasInterrupted) { /* @@ -632,7 +632,7 @@ retry: threadId, thinp, PrettyTypeOf(obj).c_str(), LW_LOCK_OWNER(thin)); // The lock is owned by another thread. Notify the runtime that we are about to wait. self->monitor_enter_object_ = obj; - Thread::State oldStatus = self->SetState(Thread::kBlocked); + ThreadState oldStatus = self->SetState(kBlocked); // Spin until the thin lock is released or inflated. sleepDelayNs = 0; for (;;) { @@ -696,7 +696,7 @@ bool Monitor::MonitorExit(Thread* self, Object* obj) { volatile int32_t* thinp = obj->GetRawLockWordAddress(); DCHECK(self != NULL); - //DCHECK_EQ(self->GetState(), Thread::kRunnable); + //DCHECK_EQ(self->GetState(), kRunnable); DCHECK(obj != NULL); /* @@ -823,18 +823,18 @@ uint32_t Monitor::GetThinLockId(uint32_t raw_lock_word) { } void Monitor::DescribeWait(std::ostream& os, const Thread* thread) { - Thread::State state = thread->GetState(); + ThreadState state = thread->GetState(); Object* object = NULL; uint32_t lock_owner = ThreadList::kInvalidId; - if (state == Thread::kWaiting || state == Thread::kTimedWaiting) { + if (state == kWaiting || state == kTimedWaiting) { os << " - waiting on "; Monitor* monitor = thread->wait_monitor_; if (monitor != NULL) { object = monitor->obj_; } lock_owner = Thread::LockOwnerFromThreadLock(object); - } else if (state == Thread::kBlocked) { + } else if (state == kBlocked) { os << " - waiting to lock "; object = thread->monitor_enter_object_; if (object != NULL) { diff --git a/src/oat/jni/jni_compiler.cc b/src/oat/jni/jni_compiler.cc index 4a186aa92c..c1ae664ea4 100644 --- a/src/oat/jni/jni_compiler.cc +++ b/src/oat/jni/jni_compiler.cc @@ -34,7 +34,7 @@ namespace art { -static void ChangeThreadState(Assembler* jni_asm, Thread::State new_state, +static void ChangeThreadState(Assembler* jni_asm, ThreadState new_state, ManagedRegister scratch, ManagedRegister return_reg, FrameOffset return_save_location, size_t return_size) { @@ -42,19 +42,19 @@ static void ChangeThreadState(Assembler* jni_asm, Thread::State new_state, * This code mirrors that of Thread::SetState where detail is given on why * barriers occur when they do. */ - if (new_state == Thread::kRunnable) { + if (new_state == kRunnable) { /* - * Change our status to Thread::kRunnable. The transition requires + * Change our status to kRunnable. The transition requires * that we check for pending suspension, because the runtime considers * us to be "asleep" in all other states, and another thread could * be performing a GC now. */ - __ StoreImmediateToThread(Thread::StateOffset(), Thread::kRunnable, scratch); + __ StoreImmediateToThread(Thread::StateOffset(), kRunnable, scratch); __ MemoryBarrier(scratch); __ SuspendPoll(scratch, return_reg, return_save_location, return_size); } else { /* - * Not changing to Thread::kRunnable. No additional work required. + * Not changing to kRunnable. No additional work required. */ __ MemoryBarrier(scratch); __ StoreImmediateToThread(Thread::StateOffset(), new_state, scratch); @@ -264,7 +264,7 @@ CompiledMethod* ArtJniCompileMethodInternal(Compiler& compiler, __ StoreStackPointerToThread(Thread::TopOfManagedStackOffset()); __ StoreImmediateToThread(Thread::TopOfManagedStackPcOffset(), 0, mr_conv->InterproceduralScratchRegister()); - ChangeThreadState(jni_asm.get(), Thread::kNative, + ChangeThreadState(jni_asm.get(), kNative, mr_conv->InterproceduralScratchRegister(), ManagedRegister::NoRegister(), FrameOffset(0), 0); @@ -483,7 +483,7 @@ CompiledMethod* ArtJniCompileMethodInternal(Compiler& compiler, FrameOffset return_save_location = jni_conv->ReturnValueSaveLocation(); CHECK(return_save_location.Uint32Value() < frame_size || jni_conv->SizeOfReturnValue() == 0); - ChangeThreadState(jni_asm.get(), Thread::kRunnable, + ChangeThreadState(jni_asm.get(), kRunnable, jni_conv->InterproceduralScratchRegister(), jni_conv->ReturnRegister(), return_save_location, jni_conv->SizeOfReturnValue()); diff --git a/src/object.cc b/src/object.cc index f2bddc37c7..74195f8789 100644 --- a/src/object.cc +++ b/src/object.cc @@ -559,7 +559,7 @@ uint32_t Method::FindCatchBlock(Class* exception_type, uint32_t dex_pc) const { void Method::Invoke(Thread* self, Object* receiver, JValue* args, JValue* result) const { // Push a transition back into managed code onto the linked list in thread. - CHECK_EQ(Thread::kRunnable, self->GetState()); + CHECK_EQ(kRunnable, self->GetState()); #if !defined(ART_USE_LLVM_COMPILER) NativeToManagedRecord record; diff --git a/src/reflection.cc b/src/reflection.cc index 008c1cd514..f7c275c9c2 100644 --- a/src/reflection.cc +++ b/src/reflection.cc @@ -48,7 +48,7 @@ void InitBoxingMethods() { jobject InvokeMethod(JNIEnv* env, jobject javaMethod, jobject javaReceiver, jobject javaArgs) { Thread* self = Thread::Current(); - ScopedThreadStateChange tsc(self, Thread::kRunnable); + ScopedThreadStateChange tsc(self, kRunnable); jmethodID mid = env->FromReflectedMethod(javaMethod); Method* m = reinterpret_cast<Method*>(mid); @@ -269,7 +269,7 @@ void BoxPrimitive(Primitive::Type src_class, JValue& value) { } Thread* self = Thread::Current(); - ScopedThreadStateChange tsc(self, Thread::kRunnable); + ScopedThreadStateChange tsc(self, kRunnable); JValue args[1] = { value }; m->Invoke(self, NULL, args, &value); } diff --git a/src/runtime.cc b/src/runtime.cc index 1d0ab8fb9f..12f7c8b9c5 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -175,7 +175,7 @@ void Runtime::Abort(const char* file, int line) { void Runtime::CallExitHook(jint status) { if (exit_ != NULL) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kNative); + ScopedThreadStateChange tsc(Thread::Current(), kNative); exit_(status); LOG(WARNING) << "Exit hook returned instead of exiting!"; } @@ -499,7 +499,7 @@ void CreateSystemClassLoader() { Thread* self = Thread::Current(); // Must be in the kNative state for calling native methods. - CHECK_EQ(self->GetState(), Thread::kNative); + CHECK_EQ(self->GetState(), kNative); JNIEnv* env = self->GetJniEnv(); ScopedLocalRef<jclass> ClassLoader_class(env, env->FindClass("java/lang/ClassLoader")); @@ -533,7 +533,7 @@ void Runtime::Start() { class_linker_->RelocateExecutable(); // Restore main thread state to kNative as expected by native code - Thread::Current()->SetState(Thread::kNative); + Thread::Current()->SetState(kNative); started_ = true; @@ -578,7 +578,7 @@ void Runtime::StartDaemonThreads() { Thread* self = Thread::Current(); // Must be in the kNative state for calling native methods. - CHECK_EQ(self->GetState(), Thread::kNative); + CHECK_EQ(self->GetState(), kNative); JNIEnv* env = self->GetJniEnv(); ScopedLocalRef<jclass> c(env, env->FindClass("java/lang/Daemons")); @@ -649,7 +649,7 @@ bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) { Thread::Attach("main", false, NULL); // Set us to runnable so tools using a runtime can allocate and GC by default - Thread::Current()->SetState(Thread::kRunnable); + Thread::Current()->SetState(kRunnable); // Now we're attached, we can take the heap lock and validate the heap. GetHeap()->EnableObjectValidation(); @@ -682,7 +682,7 @@ void Runtime::InitNativeMethods() { JNIEnv* env = self->GetJniEnv(); // Must be in the kNative state for calling native methods (JNI_OnLoad code). - CHECK_EQ(self->GetState(), Thread::kNative); + CHECK_EQ(self->GetState(), kNative); // First set up JniConstants, which is used by both the runtime's built-in native // methods and libcore. diff --git a/src/scoped_jni_thread_state.h b/src/scoped_jni_thread_state.h index 1065a966d9..fdf65814c5 100644 --- a/src/scoped_jni_thread_state.h +++ b/src/scoped_jni_thread_state.h @@ -28,7 +28,7 @@ class ScopedJniThreadState { explicit ScopedJniThreadState(JNIEnv* env) : env_(reinterpret_cast<JNIEnvExt*>(env)) { self_ = ThreadForEnv(env); - old_thread_state_ = self_->SetState(Thread::kRunnable); + old_thread_state_ = self_->SetState(kRunnable); self_->VerifyStack(); } @@ -64,7 +64,7 @@ class ScopedJniThreadState { JNIEnvExt* env_; Thread* self_; - Thread::State old_thread_state_; + ThreadState old_thread_state_; DISALLOW_COPY_AND_ASSIGN(ScopedJniThreadState); }; diff --git a/src/scoped_thread_list_lock.cc b/src/scoped_thread_list_lock.cc index b999c3b243..269c97ed3b 100644 --- a/src/scoped_thread_list_lock.cc +++ b/src/scoped_thread_list_lock.cc @@ -32,7 +32,7 @@ ScopedThreadListLock::ScopedThreadListLock() { // Self may be null during shutdown, but in that case there's no point going to kVmWait. thread_list->thread_list_lock_.Lock(); } else { - Thread::State old_thread_state = self->SetState(Thread::kVmWait); + ThreadState old_thread_state = self->SetState(kVmWait); thread_list->thread_list_lock_.Lock(); // If we have the lock, by definition there's no GC in progress (though we // might be taking the lock in order to start one). We avoid the suspend diff --git a/src/signal_catcher.cc b/src/signal_catcher.cc index aad6a08b59..be213729cd 100644 --- a/src/signal_catcher.cc +++ b/src/signal_catcher.cc @@ -77,7 +77,7 @@ void SignalCatcher::Output(const std::string& s) { return; } - ScopedThreadStateChange tsc(Thread::Current(), Thread::kVmWait); + ScopedThreadStateChange tsc(Thread::Current(), kVmWait); int fd = open(stack_trace_file_.c_str(), O_APPEND | O_CREAT | O_WRONLY, 0666); if (fd == -1) { PLOG(ERROR) << "Unable to open stack trace file '" << stack_trace_file_ << "'"; @@ -136,7 +136,7 @@ void SignalCatcher::HandleSigUsr1() { } int SignalCatcher::WaitForSignal(sigset_t& mask) { - ScopedThreadStateChange tsc(thread_, Thread::kVmWait); + ScopedThreadStateChange tsc(thread_, kVmWait); // Signals for sigwait() must be blocked but not ignored. We // block signals like SIGQUIT for all threads, so the condition @@ -168,7 +168,7 @@ void* SignalCatcher::Run(void* arg) { Runtime* runtime = Runtime::Current(); runtime->AttachCurrentThread("Signal Catcher", true, Thread::GetSystemThreadGroup()); - Thread::Current()->SetState(Thread::kRunnable); + Thread::Current()->SetState(kRunnable); { MutexLock mu(signal_catcher->lock_); diff --git a/src/sun_misc_Unsafe.cc b/src/sun_misc_Unsafe.cc index d5d7444479..214771b2a3 100644 --- a/src/sun_misc_Unsafe.cc +++ b/src/sun_misc_Unsafe.cc @@ -30,7 +30,7 @@ static jlong Unsafe_objectFieldOffset0(JNIEnv* env, jclass, jobject javaField) { static jint Unsafe_arrayBaseOffset0(JNIEnv* env, jclass, jclass javaArrayClass) { // TODO: move to Java code - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Class* array_class = Decode<Class*>(env, javaArrayClass); return Array::DataOffset(array_class->GetComponentSize()).Int32Value(); } diff --git a/src/thread.cc b/src/thread.cc index 00b5188da8..b26928f0ef 100644 --- a/src/thread.cc +++ b/src/thread.cc @@ -113,7 +113,7 @@ void* Thread::CreateCallback(void* arg) { runtime->GetThreadList()->WaitForGo(); { - CHECK_EQ(self->GetState(), Thread::kRunnable); + CHECK_EQ(self->GetState(), kRunnable); SirtRef<String> thread_name(self->GetThreadName()); self->SetThreadName(thread_name->ToModifiedUtf8().c_str()); } @@ -179,7 +179,7 @@ void Thread::Create(Object* peer, size_t stack_size) { SetVmData(peer, native_thread); { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kVmWait); + ScopedThreadStateChange tsc(Thread::Current(), kVmWait); pthread_t new_pthread; pthread_attr_t attr; CHECK_PTHREAD_CALL(pthread_attr_init, (&attr), "new thread"); @@ -223,7 +223,7 @@ Thread* Thread::Attach(const char* thread_name, bool as_daemon, Object* thread_g Thread* self = new Thread; self->Init(); - self->SetState(Thread::kNative); + self->SetState(kNative); // If we're the main thread, ClassLinker won't be created until after we're attached, // so that thread needs a two-stage attach. Regular threads don't need this hack. @@ -534,21 +534,21 @@ struct StackDumpVisitor : public Thread::StackVisitor { void Thread::DumpStack(std::ostream& os) const { // If we're currently in native code, dump that stack before dumping the managed stack. - if (GetState() == Thread::kNative || GetState() == Thread::kVmWait) { + if (GetState() == kNative || GetState() == kVmWait) { DumpNativeStack(os); } StackDumpVisitor dumper(os, this); WalkStack(&dumper); } -void Thread::SetStateWithoutSuspendCheck(Thread::State new_state) { +void Thread::SetStateWithoutSuspendCheck(ThreadState new_state) { volatile void* raw = reinterpret_cast<volatile void*>(&state_); volatile int32_t* addr = reinterpret_cast<volatile int32_t*>(raw); android_atomic_release_store(new_state, addr); } -Thread::State Thread::SetState(Thread::State new_state) { - Thread::State old_state = state_; +ThreadState Thread::SetState(ThreadState new_state) { + ThreadState old_state = state_; if (old_state == new_state) { return old_state; } @@ -556,9 +556,9 @@ Thread::State Thread::SetState(Thread::State new_state) { volatile void* raw = reinterpret_cast<volatile void*>(&state_); volatile int32_t* addr = reinterpret_cast<volatile int32_t*>(raw); - if (new_state == Thread::kRunnable) { + if (new_state == kRunnable) { /* - * Change our status to Thread::kRunnable. The transition requires + * Change our status to kRunnable. The transition requires * that we check for pending suspension, because the runtime considers * us to be "asleep" in all other states, and another thread could * be performing a GC now. @@ -616,7 +616,7 @@ Thread::State Thread::SetState(Thread::State new_state) { } } else { /* - * Not changing to Thread::kRunnable. No additional work required. + * Not changing to kRunnable. No additional work required. * * We use a releasing store to ensure that, if we were runnable, * any updates we previously made to objects on the managed heap @@ -632,7 +632,7 @@ bool Thread::IsSuspended() { ANNOTATE_IGNORE_READS_BEGIN(); int suspend_count = suspend_count_; ANNOTATE_IGNORE_READS_END(); - return suspend_count != 0 && GetState() != Thread::kRunnable; + return suspend_count != 0 && GetState() != kRunnable; } static void ReportThreadSuspendTimeout(Thread* waiting_thread) { @@ -650,7 +650,7 @@ void Thread::WaitUntilSuspended() { useconds_t total_delay = 0; useconds_t delay = 0; - while (GetState() == Thread::kRunnable) { + while (GetState() == kRunnable) { if (total_delay >= kTimeoutUs) { ReportThreadSuspendTimeout(this); } @@ -715,7 +715,7 @@ void Thread::FinishStartup() { Thread* self = Thread::Current(); // Need to be kRunnable for FindClass - ScopedThreadStateChange tsc(self, Thread::kRunnable); + ScopedThreadStateChange tsc(self, kRunnable); // Now the ClassLinker is ready, we can find the various Class*, Field*, and Method*s we need. ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); @@ -787,7 +787,7 @@ Thread::Thread() top_sirt_(NULL), top_shadow_frame_(NULL), jni_env_(NULL), - state_(Thread::kNative), + state_(kNative), self_(NULL), runtime_(NULL), exception_(NULL), @@ -821,7 +821,7 @@ void Thread::Destroy() { Thread* self = this; // We may need to call user-supplied managed code. - SetState(Thread::kRunnable); + SetState(kRunnable); HandleUncaughtExceptions(); RemoveFromThreadGroup(); @@ -847,7 +847,7 @@ Thread::~Thread() { delete jni_env_; jni_env_ = NULL; - SetState(Thread::kTerminated); + SetState(kTerminated); delete wait_cond_; delete wait_mutex_; @@ -1737,28 +1737,6 @@ void Thread::VerifyStack() { } #endif -static const char* kStateNames[] = { - "Terminated", - "Runnable", - "TimedWaiting", - "Blocked", - "Waiting", - "Initializing", - "Starting", - "Native", - "VmWait", - "Suspended", -}; -std::ostream& operator<<(std::ostream& os, const Thread::State& state) { - int32_t int_state = static_cast<int32_t>(state); - if (state >= Thread::kTerminated && state <= Thread::kSuspended) { - os << kStateNames[int_state]; - } else { - os << "State[" << int_state << "]"; - } - return os; -} - std::ostream& operator<<(std::ostream& os, const Thread& thread) { thread.Dump(os, false); return os; diff --git a/src/thread.h b/src/thread.h index a6459c6f44..ad15c0f948 100644 --- a/src/thread.h +++ b/src/thread.h @@ -63,29 +63,28 @@ template<class T> class ObjectArray; template<class T> class PrimitiveArray; typedef PrimitiveArray<int32_t> IntArray; -class PACKED Thread { - public: - // Thread priorities. These must match the Thread.MIN_PRIORITY, - // Thread.NORM_PRIORITY, and Thread.MAX_PRIORITY constants. - enum Priority { - kMinPriority = 1, - kNormPriority = 5, - kMaxPriority = 10, - }; +// Thread priorities. These must match the Thread.MIN_PRIORITY, +// Thread.NORM_PRIORITY, and Thread.MAX_PRIORITY constants. +enum ThreadPriority { + kMinThreadPriority = 1, + kNormThreadPriority = 5, + kMaxThreadPriority = 10, +}; - // Thread states. - enum State { - kTerminated = 0, // Thread.TERMINATED JDWP TS_ZOMBIE - kRunnable = 1, // Thread.RUNNABLE JDWP TS_RUNNING - kTimedWaiting = 2, // Thread.TIMED_WAITING JDWP TS_WAIT - in Object.wait() with a timeout - kBlocked = 3, // Thread.BLOCKED JDWP TS_MONITOR - blocked on a monitor - kWaiting = 4, // Thread.WAITING JDWP TS_WAIT - in Object.wait() - kStarting = 5, // Thread.NEW - native thread started, not yet ready to run managed code - kNative = 6, // - running in a JNI native method - kVmWait = 7, // - waiting on an internal runtime resource - kSuspended = 8, // - suspended by GC or debugger - }; +enum ThreadState { + kTerminated = 0, // Thread.TERMINATED JDWP TS_ZOMBIE + kRunnable = 1, // Thread.RUNNABLE JDWP TS_RUNNING + kTimedWaiting = 2, // Thread.TIMED_WAITING JDWP TS_WAIT - in Object.wait() with a timeout + kBlocked = 3, // Thread.BLOCKED JDWP TS_MONITOR - blocked on a monitor + kWaiting = 4, // Thread.WAITING JDWP TS_WAIT - in Object.wait() + kStarting = 5, // Thread.NEW - native thread started, not yet ready to run managed code + kNative = 6, // - running in a JNI native method + kVmWait = 7, // - waiting on an internal runtime resource + kSuspended = 8, // - suspended by GC or debugger +}; +class PACKED Thread { + public: // Space to throw a StackOverflowError in. #if !defined(ART_USE_LLVM_COMPILER) static const size_t kStackOverflowReservedBytes = 4 * KB; @@ -126,12 +125,12 @@ class PACKED Thread { // When full == false, dumps a one-line summary of thread state (used for operator<<). void Dump(std::ostream& os, bool full = true) const; - State GetState() const { + ThreadState GetState() const { return state_; } - State SetState(State new_state); - void SetStateWithoutSuspendCheck(State new_state); + ThreadState SetState(ThreadState new_state); + void SetStateWithoutSuspendCheck(ThreadState new_state); bool IsDaemon(); bool IsSuspended(); @@ -572,7 +571,7 @@ class PACKED Thread { // Every thread may have an associated JNI environment JNIEnvExt* jni_env_; - volatile State state_; + volatile ThreadState state_; // Initialized to "this". On certain architectures (such as x86) reading // off of Thread::Current is easy but getting the address of Thread::Current @@ -627,11 +626,11 @@ class PACKED Thread { }; std::ostream& operator<<(std::ostream& os, const Thread& thread); -std::ostream& operator<<(std::ostream& os, const Thread::State& state); +std::ostream& operator<<(std::ostream& os, const ThreadState& state); class ScopedThreadStateChange { public: - ScopedThreadStateChange(Thread* thread, Thread::State new_state) : thread_(thread) { + ScopedThreadStateChange(Thread* thread, ThreadState new_state) : thread_(thread) { old_thread_state_ = thread_->SetState(new_state); } @@ -641,7 +640,7 @@ class ScopedThreadStateChange { private: Thread* thread_; - Thread::State old_thread_state_; + ThreadState old_thread_state_; DISALLOW_COPY_AND_ASSIGN(ScopedThreadStateChange); }; diff --git a/src/thread_android.cc b/src/thread_android.cc index 6f803335ad..d26f44644d 100644 --- a/src/thread_android.cc +++ b/src/thread_android.cc @@ -73,18 +73,18 @@ int Thread::GetNativePriority() { int native_priority = getpriority(PRIO_PROCESS, 0); if (native_priority == -1 && errno != 0) { PLOG(WARNING) << "getpriority failed"; - return Thread::kNormPriority; + return kNormThreadPriority; } - int managed_priority = Thread::kMinPriority; + int managed_priority = kMinThreadPriority; for (size_t i = 0; i < arraysize(kNiceValues); i++) { if (native_priority >= kNiceValues[i]) { break; } managed_priority++; } - if (managed_priority > Thread::kMaxPriority) { - managed_priority = Thread::kMaxPriority; + if (managed_priority > kMaxThreadPriority) { + managed_priority = kMaxThreadPriority; } return managed_priority; } diff --git a/src/thread_linux.cc b/src/thread_linux.cc index 50db13c222..314668d7a3 100644 --- a/src/thread_linux.cc +++ b/src/thread_linux.cc @@ -27,7 +27,7 @@ void Thread::SetNativePriority(int) { } int Thread::GetNativePriority() { - return Thread::kNormPriority; + return kNormThreadPriority; } } // namespace art diff --git a/src/thread_list.cc b/src/thread_list.cc index 2526fc2ba0..1a342da585 100644 --- a/src/thread_list.cc +++ b/src/thread_list.cc @@ -74,8 +74,10 @@ void ThreadList::ModifySuspendCount(Thread* thread, int delta, bool for_debugger DCHECK_GE(thread->suspend_count_, thread->debug_suspend_count_) << *thread; #endif if (delta == -1 && thread->suspend_count_ <= 0) { - // This can happen if you attach a thread during a GC. - LOG(WARNING) << *thread << " suspend count already zero"; + // This is expected if you attach a thread during a GC. + if (thread->GetState() != kStarting) { + LOG(FATAL) << *thread << " suspend count already zero"; + } return; } thread->suspend_count_ += delta; @@ -95,7 +97,7 @@ void ThreadList::FullSuspendCheck(Thread* thread) { VLOG(threads) << *thread << " self-suspending"; { - ScopedThreadStateChange tsc(thread, Thread::kSuspended); + ScopedThreadStateChange tsc(thread, kSuspended); while (thread->suspend_count_ != 0) { /* * Wait for wakeup signal, releasing lock. The act of releasing @@ -114,7 +116,7 @@ void ThreadList::SuspendAll(bool for_debugger) { VLOG(threads) << *self << " SuspendAll starting..." << (for_debugger ? " (debugger)" : ""); - CHECK_EQ(self->GetState(), Thread::kRunnable); + CHECK_EQ(self->GetState(), kRunnable); ScopedThreadListLock thread_list_lock; Thread* debug_thread = Dbg::GetDebugThread(); @@ -195,7 +197,7 @@ void ThreadList::SuspendSelfForDebugger() { // Suspend ourselves. CHECK_GT(self->suspend_count_, 0); - self->SetState(Thread::kSuspended); + self->SetState(kSuspended); VLOG(threads) << *self << " self-suspending (debugger)"; // Tell JDWP that we've completed suspension. The JDWP thread can't @@ -215,7 +217,7 @@ void ThreadList::SuspendSelfForDebugger() { } } CHECK_EQ(self->suspend_count_, 0); - self->SetState(Thread::kRunnable); + self->SetState(kRunnable); VLOG(threads) << *self << " self-reviving (debugger)"; } @@ -387,19 +389,19 @@ void ThreadList::SignalGo(Thread* child) { VLOG(threads) << *self << " waiting for child " << *child << " to be in thread list..."; // We wait for the child to tell us that it's in the thread list. - while (child->GetState() != Thread::kStarting) { + while (child->GetState() != kStarting) { thread_start_cond_.Wait(thread_list_lock_); } } // If we switch out of runnable and then back in, we know there's no pending suspend. - self->SetState(Thread::kVmWait); - self->SetState(Thread::kRunnable); + self->SetState(kVmWait); + self->SetState(kRunnable); // Tell the child that it's safe: it will see any future suspend request. ScopedThreadListLock thread_list_lock; VLOG(threads) << *self << " telling child " << *child << " it's safe to proceed..."; - child->SetState(Thread::kVmWait); + child->SetState(kVmWait); thread_start_cond_.Broadcast(); } @@ -412,13 +414,13 @@ void ThreadList::WaitForGo() { // Tell our parent that we're in the thread list. VLOG(threads) << *self << " telling parent that we're now in thread list..."; - self->SetState(Thread::kStarting); + self->SetState(kStarting); thread_start_cond_.Broadcast(); // Wait until our parent tells us there's no suspend still pending // from before we were on the thread list. VLOG(threads) << *self << " waiting for parent's go-ahead..."; - while (self->GetState() != Thread::kVmWait) { + while (self->GetState() != kVmWait) { thread_start_cond_.Wait(thread_list_lock_); } } @@ -432,7 +434,7 @@ void ThreadList::WaitForGo() { { ScopedHeapLock heap_lock; } - self->SetState(Thread::kRunnable); + self->SetState(kRunnable); } bool ThreadList::AllOtherThreadsAreDaemons() { @@ -475,7 +477,7 @@ void ThreadList::SuspendAllDaemonThreads() { bool all_suspended = true; for (It it = list_.begin(), end = list_.end(); it != end; ++it) { Thread* thread = *it; - if (thread != Thread::Current() && thread->GetState() == Thread::kRunnable) { + if (thread != Thread::Current() && thread->GetState() == kRunnable) { if (!have_complained) { LOG(WARNING) << "daemon thread not yet suspended: " << *thread; have_complained = true; diff --git a/src/trace.cc b/src/trace.cc index 3b4c3e5233..3278830948 100644 --- a/src/trace.cc +++ b/src/trace.cc @@ -200,7 +200,7 @@ void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int return; } - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Runtime::Current()->GetThreadList()->SuspendAll(false); // Open trace file if not going directly to ddms. @@ -240,7 +240,7 @@ void Trace::Stop() { return; } - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); Runtime::Current()->GetThreadList()->SuspendAll(false); Runtime::Current()->GetTracer()->FinishTracing(); diff --git a/test/ReferenceMap/stack_walk_refmap_jni.cc b/test/ReferenceMap/stack_walk_refmap_jni.cc index 3a16833384..0370ead955 100644 --- a/test/ReferenceMap/stack_walk_refmap_jni.cc +++ b/test/ReferenceMap/stack_walk_refmap_jni.cc @@ -63,7 +63,7 @@ struct ReferenceMap2Visitor : public Thread::StackVisitor { // Enable this to dump reference map to LOG(INFO) if (false) { - ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); + ScopedThreadStateChange tsc(Thread::Current(), kRunnable); art::verifier::DexVerifier::VerifyMethodAndDump(m); } const uint8_t* ref_bitmap = NULL; |