diff options
author | Mathieu Chartier <mathieuc@google.com> | 2014-07-14 10:16:05 -0700 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2014-07-14 10:58:09 -0700 |
commit | fd22d5bada15d95b5ea8ab5a4dda39077e1a54ee (patch) | |
tree | 3dc5aaa74f1272c357d339c3c61d7e1ed0aececf /runtime/mirror/class.cc | |
parent | e8b8086388159be5fecb23ae6185e70f3dfb5da6 (diff) | |
download | art-fd22d5bada15d95b5ea8ab5a4dda39077e1a54ee.zip art-fd22d5bada15d95b5ea8ab5a4dda39077e1a54ee.tar.gz art-fd22d5bada15d95b5ea8ab5a4dda39077e1a54ee.tar.bz2 |
Fix infinite loop when calling SetStatus after OOM.
There was a problem where we would call SetStatus when we had an OOM
error. This results in attempting to find the ExceptionInInitializer
class which if not loaded does more allocations resulting in an
infinite loop.
Also some cleanup addressing other comments.
Bug: 16082350
Change-Id: I5c1e638a03ddf700ab4e9cad9a3077d2b1b26c43
Diffstat (limited to 'runtime/mirror/class.cc')
-rw-r--r-- | runtime/mirror/class.cc | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index 371e984..be05fb8 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -88,18 +88,22 @@ void Class::SetStatus(Status new_status, Thread* self) { Handle<mirror::ArtMethod> old_throw_method(hs.NewHandle(old_throw_location.GetMethod())); uint32_t old_throw_dex_pc = old_throw_location.GetDexPc(); bool is_exception_reported = self->IsExceptionReportedToInstrumentation(); - // clear exception to call FindSystemClass - self->ClearException(); - ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - Class* eiie_class = class_linker->FindSystemClass(self, - "Ljava/lang/ExceptionInInitializerError;"); - CHECK(!self->IsExceptionPending()); - - // Only verification errors, not initialization problems, should set a verify error. - // This is to ensure that ThrowEarlierClassFailure will throw NoClassDefFoundError in that case. - Class* exception_class = old_exception->GetClass(); - if (!eiie_class->IsAssignableFrom(exception_class)) { - SetVerifyErrorClass(exception_class); + Class* eiie_class; + // Do't attempt to use FindClass if we have an OOM error since this can try to do more + // allocations and may cause infinite loops. + if (old_exception.Get() == nullptr || + old_exception->GetClass()->GetDescriptor() != "Ljava/lang/OutOfMemoryError;") { + // Clear exception to call FindSystemClass. + self->ClearException(); + eiie_class = Runtime::Current()->GetClassLinker()->FindSystemClass( + self, "Ljava/lang/ExceptionInInitializerError;"); + CHECK(!self->IsExceptionPending()); + // Only verification errors, not initialization problems, should set a verify error. + // This is to ensure that ThrowEarlierClassFailure will throw NoClassDefFoundError in that case. + Class* exception_class = old_exception->GetClass(); + if (!eiie_class->IsAssignableFrom(exception_class)) { + SetVerifyErrorClass(exception_class); + } } // Restore exception. |