diff options
| -rw-r--r-- | runtime/class_linker.cc | 17 | ||||
| -rw-r--r-- | runtime/native/java_lang_Class.cc | 5 | ||||
| -rw-r--r-- | runtime/thread.cc | 2 |
3 files changed, 14 insertions, 10 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 2d0b147a94..6c5679ec63 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -1658,23 +1658,24 @@ mirror::Class* ClassLinker::DefineClass(const char* descriptor, // size when the class becomes resolved. klass.Assign(AllocClass(self, SizeOfClassWithoutEmbeddedTables(dex_file, dex_class_def))); } - if (UNLIKELY(klass.Get() == NULL)) { + if (UNLIKELY(klass.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // Expect an OOME. - return NULL; + return nullptr; } klass->SetDexCache(FindDexCache(dex_file)); LoadClass(dex_file, dex_class_def, klass, class_loader.Get()); - // Check for a pending exception during load + ObjectLock<mirror::Class> lock(self, klass); if (self->IsExceptionPending()) { + // An exception occured during load, set status to erroneous while holding klass' lock in case + // notification is necessary. klass->SetStatus(mirror::Class::kStatusError, self); - return NULL; + return nullptr; } - ObjectLock<mirror::Class> lock(self, klass); klass->SetClinitThreadId(self->GetTid()); // Add the newly loaded class to the loaded classes table. mirror::Class* existing = InsertClass(descriptor, klass.Get(), Hash(descriptor)); - if (existing != NULL) { + if (existing != nullptr) { // We failed to insert because we raced with another thread. Calling EnsureResolved may cause // this thread to block. return EnsureResolved(self, descriptor, existing); @@ -1685,7 +1686,7 @@ mirror::Class* ClassLinker::DefineClass(const char* descriptor, if (!LoadSuperAndInterfaces(klass, dex_file)) { // Loading failed. klass->SetStatus(mirror::Class::kStatusError, self); - return NULL; + return nullptr; } CHECK(klass->IsLoaded()); // Link the class (if necessary) @@ -1697,7 +1698,7 @@ mirror::Class* ClassLinker::DefineClass(const char* descriptor, if (!LinkClass(self, descriptor, klass, interfaces, &new_class)) { // Linking failed. klass->SetStatus(mirror::Class::kStatusError, self); - return NULL; + return nullptr; } CHECK(new_class != nullptr) << descriptor; CHECK(new_class->IsResolved()) << descriptor; diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index e577c2c960..124bdf5475 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -71,7 +71,10 @@ static jclass Class_classForName(JNIEnv* env, jclass, jstring javaName, jboolean jthrowable cnfe = reinterpret_cast<jthrowable>(env->NewObject(WellKnownClasses::java_lang_ClassNotFoundException, WellKnownClasses::java_lang_ClassNotFoundException_init, javaName, cause.get())); - env->Throw(cnfe); + if (cnfe != nullptr) { + // Make sure allocation didn't fail with an OOME. + env->Throw(cnfe); + } return nullptr; } if (initialize) { diff --git a/runtime/thread.cc b/runtime/thread.cc index f888029af1..ba5f9d49d0 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -1138,7 +1138,7 @@ void Thread::AssertNoPendingExceptionForNewException(const char* msg) const { if (UNLIKELY(IsExceptionPending())) { ScopedObjectAccess soa(Thread::Current()); mirror::Throwable* exception = GetException(nullptr); - LOG(FATAL) << "Throwing new exception " << msg << " with unexpected pending exception: " + LOG(FATAL) << "Throwing new exception '" << msg << "' with unexpected pending exception: " << exception->Dump(); } } |