| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 | 2 |
| 3 #include <stdlib.h> | 3 #include <stdlib.h> |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "execution.h" | 7 #include "execution.h" |
| 8 #include "factory.h" | 8 #include "factory.h" |
| 9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
| 10 #include "global-handles.h" | 10 #include "global-handles.h" |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 DeleteArray(non_ascii); | 784 DeleteArray(non_ascii); |
| 785 DeleteArray(ascii); | 785 DeleteArray(ascii); |
| 786 } | 786 } |
| 787 } | 787 } |
| 788 | 788 |
| 789 | 789 |
| 790 static int ObjectsFoundInHeap(Handle<Object> objs[], int size) { | 790 static int ObjectsFoundInHeap(Handle<Object> objs[], int size) { |
| 791 // Count the number of objects found in the heap. | 791 // Count the number of objects found in the heap. |
| 792 int found_count = 0; | 792 int found_count = 0; |
| 793 HeapIterator iterator; | 793 HeapIterator iterator; |
| 794 for (HeapObject* obj = iterator.Next(); obj != NULL; obj = iterator.Next()) { | 794 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 795 for (int i = 0; i < size; i++) { | 795 for (int i = 0; i < size; i++) { |
| 796 if (*objs[i] == obj) { | 796 if (*objs[i] == obj) { |
| 797 found_count++; | 797 found_count++; |
| 798 } | 798 } |
| 799 } | 799 } |
| 800 } | 800 } |
| 801 return found_count; | 801 return found_count; |
| 802 } | 802 } |
| 803 | 803 |
| 804 | 804 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 ctx[0]->Exit(); | 1187 ctx[0]->Exit(); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 | 1190 |
| 1191 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { | 1191 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { |
| 1192 InitializeVM(); | 1192 InitializeVM(); |
| 1193 HEAP->EnsureHeapIsIterable(); | 1193 HEAP->EnsureHeapIsIterable(); |
| 1194 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); | 1194 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); |
| 1195 HeapIterator iterator; | 1195 HeapIterator iterator; |
| 1196 intptr_t size_of_objects_2 = 0; | 1196 intptr_t size_of_objects_2 = 0; |
| 1197 for (HeapObject* obj = iterator.Next(); | 1197 for (HeapObject* obj = iterator.next(); |
| 1198 obj != NULL; | 1198 obj != NULL; |
| 1199 obj = iterator.Next()) { | 1199 obj = iterator.next()) { |
| 1200 size_of_objects_2 += obj->Size(); | 1200 size_of_objects_2 += obj->Size(); |
| 1201 } | 1201 } |
| 1202 // Delta must be within 5% of the larger result. | 1202 // Delta must be within 5% of the larger result. |
| 1203 // TODO(gc): Tighten this up by distinguishing between byte | 1203 // TODO(gc): Tighten this up by distinguishing between byte |
| 1204 // arrays that are real and those that merely mark free space | 1204 // arrays that are real and those that merely mark free space |
| 1205 // on the heap. | 1205 // on the heap. |
| 1206 if (size_of_objects_1 > size_of_objects_2) { | 1206 if (size_of_objects_1 > size_of_objects_2) { |
| 1207 intptr_t delta = size_of_objects_1 - size_of_objects_2; | 1207 intptr_t delta = size_of_objects_1 - size_of_objects_2; |
| 1208 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " | 1208 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " |
| 1209 "Iterator: %" V8_PTR_PREFIX "d, " | 1209 "Iterator: %" V8_PTR_PREFIX "d, " |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1222 | 1222 |
| 1223 | 1223 |
| 1224 class HeapIteratorTestHelper { | 1224 class HeapIteratorTestHelper { |
| 1225 public: | 1225 public: |
| 1226 HeapIteratorTestHelper(Object* a, Object* b) | 1226 HeapIteratorTestHelper(Object* a, Object* b) |
| 1227 : a_(a), b_(b), a_found_(false), b_found_(false) {} | 1227 : a_(a), b_(b), a_found_(false), b_found_(false) {} |
| 1228 bool a_found() { return a_found_; } | 1228 bool a_found() { return a_found_; } |
| 1229 bool b_found() { return b_found_; } | 1229 bool b_found() { return b_found_; } |
| 1230 void IterateHeap() { | 1230 void IterateHeap() { |
| 1231 HeapIterator iterator; | 1231 HeapIterator iterator; |
| 1232 for (HeapObject* obj = iterator.Next(); | 1232 for (HeapObject* obj = iterator.next(); |
| 1233 obj != NULL; | 1233 obj != NULL; |
| 1234 obj = iterator.Next()) { | 1234 obj = iterator.next()) { |
| 1235 if (obj == a_) | 1235 if (obj == a_) |
| 1236 a_found_ = true; | 1236 a_found_ = true; |
| 1237 else if (obj == b_) | 1237 else if (obj == b_) |
| 1238 b_found_ = true; | 1238 b_found_ = true; |
| 1239 } | 1239 } |
| 1240 } | 1240 } |
| 1241 private: | 1241 private: |
| 1242 Object* a_; | 1242 Object* a_; |
| 1243 Object* b_; | 1243 Object* b_; |
| 1244 bool a_found_; | 1244 bool a_found_; |
| 1245 bool b_found_; | 1245 bool b_found_; |
| 1246 }; | 1246 }; |
| OLD | NEW |