Implement the DDMS heap walking (for native and managed heaps).
This gets you the DDMS histograms of what's on your heaps.
Change-Id: I7133d044030b10a787277faf3a77e20c565e69c5
diff --git a/src/heap.cc b/src/heap.cc
index 6fd4ade..40bc673 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -54,17 +54,6 @@
bool Heap::verify_objects_ = false;
-class ScopedHeapLock {
- public:
- ScopedHeapLock() {
- Heap::Lock();
- }
-
- ~ScopedHeapLock() {
- Heap::Unlock();
- }
-};
-
void Heap::Init(bool is_verbose_heap, bool is_verbose_gc,
size_t initial_size, size_t maximum_size, size_t growth_size,
const std::vector<std::string>& image_file_names) {
@@ -183,13 +172,18 @@
bool Heap::IsHeapAddress(const Object* obj) {
// Note: we deliberately don't take the lock here, and mustn't test anything that would
// require taking the lock.
- if (!IsAligned<kObjectAlignment>(obj)) {
+ if (obj == NULL || !IsAligned<kObjectAlignment>(obj)) {
return false;
}
// TODO
return true;
}
+bool Heap::IsLiveObjectLocked(const Object* obj) {
+ lock_->AssertHeld();
+ return IsHeapAddress(obj) && live_bitmap_->Test(obj);
+}
+
#if VERIFY_OBJECT_ENABLED
void Heap::VerifyObject(const Object* obj) {
if (!verify_objects_) {
@@ -543,6 +537,13 @@
lock_->AssertHeld();
}
+void Heap::WalkHeap(void(*callback)(const void*, size_t, const void*, size_t, void*), void* arg) {
+ typedef std::vector<Space*>::iterator It; // C++0x auto.
+ for (It it = spaces_.begin(); it != spaces_.end(); ++it) {
+ (*it)->Walk(callback, arg);
+ }
+}
+
/* Terminology:
* 1. Footprint: Capacity we allocate from system.
* 2. Active space: a.k.a. alloc_space_.