OSDN Git Service

Handlerize throw location in DumpJavaStack
authorIan Rogers <irogers@google.com>
Fri, 10 Oct 2014 22:57:19 +0000 (15:57 -0700)
committerBrian Carlstrom <bdc@google.com>
Sun, 12 Oct 2014 21:11:57 +0000 (14:11 -0700)
Handlerize this object and method during DumpJavaStack.
Bug: 17669899

(cherry picked from commit 79ffe35fa0784f26c2d25242ea1b3ce300a009cb)

Change-Id: Id090daaa2eef8cd445e52cbbe71b2e2ed7fef2fe

runtime/thread.cc

index d573a3f..fd37703 100644 (file)
@@ -950,12 +950,18 @@ void Thread::DumpJavaStack(std::ostream& os) const {
   // Dumping the Java stack involves the verifier for locks. The verifier operates under the
   // assumption that there is no exception pending on entry. Thus, stash any pending exception.
   // TODO: Find a way to avoid const_cast.
-  StackHandleScope<1> scope(const_cast<Thread*>(this));
+  StackHandleScope<3> scope(const_cast<Thread*>(this));
   Handle<mirror::Throwable> exc;
-  ThrowLocation exc_location;
+  Handle<mirror::Object> throw_location_this_object;
+  Handle<mirror::ArtMethod> throw_location_method;
+  uint32_t throw_location_dex_pc;
   bool have_exception = false;
   if (IsExceptionPending()) {
+    ThrowLocation exc_location;
     exc = scope.NewHandle(GetException(&exc_location));
+    throw_location_this_object = scope.NewHandle(exc_location.GetThis());
+    throw_location_method = scope.NewHandle(exc_location.GetMethod());
+    throw_location_dex_pc = exc_location.GetDexPc();
     const_cast<Thread*>(this)->ClearException();
     have_exception = true;
   }
@@ -966,6 +972,9 @@ void Thread::DumpJavaStack(std::ostream& os) const {
   dumper.WalkStack();
 
   if (have_exception) {
+    ThrowLocation exc_location(throw_location_this_object.Get(),
+                               throw_location_method.Get(),
+                               throw_location_dex_pc);
     const_cast<Thread*>(this)->SetException(exc_location, exc.Get());
   }
 }