diff options
| -rw-r--r-- | runtime/debugger.cc | 8 | ||||
| -rw-r--r-- | runtime/gc/heap.cc | 22 | ||||
| -rw-r--r-- | runtime/gc/heap.h | 5 |
3 files changed, 21 insertions, 14 deletions
diff --git a/runtime/debugger.cc b/runtime/debugger.cc index 073750e4df..ada1a237d6 100644 --- a/runtime/debugger.cc +++ b/runtime/debugger.cc @@ -918,11 +918,11 @@ JDWP::JdwpError Dbg::GetInstances(JDWP::RefTypeId class_id, int32_t max_count, if (c == nullptr) { return error; } - std::vector<ObjPtr<mirror::Object>> raw_instances; - StackHandleScope<1> hs(Thread::Current()); - Runtime::Current()->GetHeap()->GetInstances(hs.NewHandle(c), max_count, raw_instances); + VariableSizedHandleScope hs(Thread::Current()); + std::vector<Handle<mirror::Object>> raw_instances; + Runtime::Current()->GetHeap()->GetInstances(hs, hs.NewHandle(c), max_count, raw_instances); for (size_t i = 0; i < raw_instances.size(); ++i) { - instances->push_back(gRegistry->Add(raw_instances[i])); + instances->push_back(gRegistry->Add(raw_instances[i].Get())); } return JDWP::ERR_NONE; } diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index ddb5be1c37..db90a2a616 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -1923,11 +1923,15 @@ void Heap::CountInstances(const std::vector<Handle<mirror::Class>>& classes, class InstanceCollector { public: - InstanceCollector(Handle<mirror::Class> c, + InstanceCollector(VariableSizedHandleScope& scope, + Handle<mirror::Class> c, int32_t max_count, - std::vector<ObjPtr<mirror::Object>>& instances) + std::vector<Handle<mirror::Object>>& instances) REQUIRES_SHARED(Locks::mutator_lock_) - : class_(c), max_count_(max_count), instances_(instances) {} + : scope_(scope), + class_(c), + max_count_(max_count), + instances_(instances) {} static void Callback(mirror::Object* obj, void* arg) REQUIRES_SHARED(Locks::mutator_lock_, Locks::heap_bitmap_lock_) { @@ -1936,22 +1940,24 @@ class InstanceCollector { if (obj->GetClass() == instance_collector->class_.Get()) { if (instance_collector->max_count_ == 0 || instance_collector->instances_.size() < instance_collector->max_count_) { - instance_collector->instances_.push_back(obj); + instance_collector->instances_.push_back(instance_collector->scope_.NewHandle(obj)); } } } private: + VariableSizedHandleScope& scope_; Handle<mirror::Class> const class_; const uint32_t max_count_; - std::vector<ObjPtr<mirror::Object>>& instances_; + std::vector<Handle<mirror::Object>>& instances_; DISALLOW_COPY_AND_ASSIGN(InstanceCollector); }; -void Heap::GetInstances(Handle<mirror::Class> c, +void Heap::GetInstances(VariableSizedHandleScope& scope, + Handle<mirror::Class> c, int32_t max_count, - std::vector<ObjPtr<mirror::Object>>& instances) { - InstanceCollector collector(c, max_count, instances); + std::vector<Handle<mirror::Object>>& instances) { + InstanceCollector collector(scope, c, max_count, instances); VisitObjects(&InstanceCollector::Callback, &collector); } diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h index 796b51dbc3..6d37140e81 100644 --- a/runtime/gc/heap.h +++ b/runtime/gc/heap.h @@ -342,9 +342,10 @@ class Heap { REQUIRES_SHARED(Locks::mutator_lock_); // Implements JDWP RT_Instances. - void GetInstances(Handle<mirror::Class> c, + void GetInstances(VariableSizedHandleScope& scope, + Handle<mirror::Class> c, int32_t max_count, - std::vector<ObjPtr<mirror::Object>>& instances) + std::vector<Handle<mirror::Object>>& instances) REQUIRES(!Locks::heap_bitmap_lock_, !*gc_complete_lock_) REQUIRES_SHARED(Locks::mutator_lock_); |