Index: test/cctest/test-heap.cc |
=================================================================== |
--- test/cctest/test-heap.cc (revision 5846) |
+++ test/cctest/test-heap.cc (working copy) |
@@ -1095,3 +1095,32 @@ |
ctx[i]->Exit(); |
} |
} |
+ |
+ |
+TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { |
+ InitializeVM(); |
+ intptr_t size_of_objects_1 = Heap::SizeOfObjects(); |
+ HeapIterator iterator(HeapIterator::kPreciseFiltering); |
+ intptr_t size_of_objects_2 = 0; |
+ for (HeapObject* obj = iterator.next(); |
+ obj != NULL; |
+ obj = iterator.next()) { |
+ size_of_objects_2 += obj->Size(); |
+ } |
+ // Delta must be within 1% of the larger result. |
+ if (size_of_objects_1 > size_of_objects_2) { |
+ intptr_t delta = size_of_objects_1 - size_of_objects_2; |
+ PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " |
+ "Iterator: %" V8_PTR_PREFIX "d, " |
+ "delta: %" V8_PTR_PREFIX "d\n", |
+ size_of_objects_1, size_of_objects_2, delta); |
+ CHECK_GT(size_of_objects_1 / 100, delta); |
+ } else { |
+ intptr_t delta = size_of_objects_2 - size_of_objects_1; |
+ PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " |
+ "Iterator: %" V8_PTR_PREFIX "d, " |
+ "delta: %" V8_PTR_PREFIX "d\n", |
+ size_of_objects_1, size_of_objects_2, delta); |
+ CHECK_GT(size_of_objects_2 / 100, delta); |
+ } |
+} |