ART: Stack locals
Add reporting of stack-locals roots. Use the new
precise root visiting to get dalvik register
information for compiled frames.
Bug: 31385354
Test: m test-art-host-run-test-913-heaps
Change-Id: Ieb86f67829e546692c30faa08eb44e8dcf2b2c6a
diff --git a/runtime/openjdkjvmti/ti_heap.cc b/runtime/openjdkjvmti/ti_heap.cc
index 894cec2..7b2521d 100644
--- a/runtime/openjdkjvmti/ti_heap.cc
+++ b/runtime/openjdkjvmti/ti_heap.cc
@@ -190,7 +190,12 @@
REQUIRES(!*tag_table_->GetAllowDisallowLock()) {
if (initial_object_.IsNull()) {
CollectAndReportRootsVisitor carrv(this, tag_table_, &worklist_, &visited_);
- art::Runtime::Current()->VisitRoots(&carrv);
+
+ // We need precise info (e.g., vregs).
+ constexpr art::VisitRootFlags kRootFlags = static_cast<art::VisitRootFlags>(
+ art::VisitRootFlags::kVisitRootFlagAllRoots | art::VisitRootFlags::kVisitRootFlagPrecise);
+ art::Runtime::Current()->VisitRoots(&carrv, kRootFlags);
+
art::Runtime::Current()->VisitImageRoots(&carrv);
stop_reports_ = carrv.IsStopReports();
@@ -322,7 +327,36 @@
}
case art::RootType::kRootJavaFrame:
+ {
+ uint32_t thread_id = info.GetThreadId();
+ ref_info->stack_local.thread_id = thread_id;
+
+ art::Thread* thread = FindThread(info);
+ if (thread != nullptr) {
+ art::mirror::Object* thread_obj = thread->GetPeer();
+ if (thread->IsStillStarting()) {
+ thread_obj = nullptr;
+ } else {
+ thread_obj = thread->GetPeer();
+ }
+ if (thread_obj != nullptr) {
+ ref_info->stack_local.thread_tag = tag_table_->GetTagOrZero(thread_obj);
+ }
+ }
+
+ auto& java_info = static_cast<const art::JavaFrameRootInfo&>(info);
+ ref_info->stack_local.slot = static_cast<jint>(java_info.GetVReg());
+ const art::StackVisitor* visitor = java_info.GetVisitor();
+ ref_info->stack_local.location =
+ static_cast<jlocation>(visitor->GetDexPc(false /* abort_on_failure */));
+ ref_info->stack_local.depth = static_cast<jint>(visitor->GetFrameDepth());
+ art::ArtMethod* method = visitor->GetMethod();
+ if (method != nullptr) {
+ ref_info->stack_local.method = art::jni::EncodeArtMethod(method);
+ }
+
return JVMTI_HEAP_REFERENCE_STACK_LOCAL;
+ }
case art::RootType::kRootNativeStack:
case art::RootType::kRootThreadBlock: