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 // Tests for heap profiler | 3 // Tests for heap profiler |
4 | 4 |
5 #include <ctype.h> | 5 #include <ctype.h> |
6 | 6 |
7 #include "v8.h" | 7 #include "v8.h" |
8 | 8 |
9 #include "cctest.h" | 9 #include "cctest.h" |
10 #include "hashmap.h" | 10 #include "hashmap.h" |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 353 |
354 | 354 |
355 // Trying to introduce a check helper for uint32_t causes many | 355 // Trying to introduce a check helper for uint32_t causes many |
356 // overloading ambiguities, so it seems easier just to cast | 356 // overloading ambiguities, so it seems easier just to cast |
357 // them to a signed type. | 357 // them to a signed type. |
358 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \ | 358 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \ |
359 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b)) | 359 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b)) |
360 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \ | 360 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \ |
361 CHECK((a) != (b)) // NOLINT | 361 CHECK((a) != (b)) // NOLINT |
362 | 362 |
| 363 TEST(HeapSnapshotAddressReuse) { |
| 364 v8::HandleScope scope; |
| 365 LocalContext env; |
| 366 |
| 367 CompileRun( |
| 368 "function A() {}\n" |
| 369 "var a = [];\n" |
| 370 "for (var i = 0; i < 10000; ++i)\n" |
| 371 " a[i] = new A();\n"); |
| 372 const v8::HeapSnapshot* snapshot1 = |
| 373 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot1")); |
| 374 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); |
| 375 |
| 376 CompileRun( |
| 377 "for (var i = 0; i < 10000; ++i)\n" |
| 378 " a[i] = new A();\n"); |
| 379 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 380 |
| 381 const v8::HeapSnapshot* snapshot2 = |
| 382 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot2")); |
| 383 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
| 384 |
| 385 const v8::HeapGraphNode* array_node = |
| 386 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); |
| 387 CHECK_NE(NULL, array_node); |
| 388 int wrong_count = 0; |
| 389 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { |
| 390 const v8::HeapGraphEdge* prop = array_node->GetChild(i); |
| 391 if (prop->GetType() != v8::HeapGraphEdge::kElement) |
| 392 continue; |
| 393 v8::SnapshotObjectId id = prop->GetToNode()->GetId(); |
| 394 if (id < maxId1) |
| 395 ++wrong_count; |
| 396 } |
| 397 // FIXME: Object ids should be unique but it is not so at the moment. |
| 398 CHECK_NE(0, wrong_count); |
| 399 } |
| 400 |
| 401 |
363 TEST(HeapEntryIdsAndArrayShift) { | 402 TEST(HeapEntryIdsAndArrayShift) { |
364 v8::HandleScope scope; | 403 v8::HandleScope scope; |
365 LocalContext env; | 404 LocalContext env; |
366 | 405 |
367 CompileRun( | 406 CompileRun( |
368 "function AnObject() {\n" | 407 "function AnObject() {\n" |
369 " this.first = 'first';\n" | 408 " this.first = 'first';\n" |
370 " this.second = 'second';\n" | 409 " this.second = 'second';\n" |
371 "}\n" | 410 "}\n" |
372 "var a = new Array();\n" | 411 "var a = new Array();\n" |
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 const v8::HeapGraphNode* map = | 1694 const v8::HeapGraphNode* map = |
1656 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); | 1695 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); |
1657 CHECK_NE(NULL, map); | 1696 CHECK_NE(NULL, map); |
1658 const v8::HeapGraphNode* own_descriptors = GetProperty( | 1697 const v8::HeapGraphNode* own_descriptors = GetProperty( |
1659 map, v8::HeapGraphEdge::kInternal, "descriptors"); | 1698 map, v8::HeapGraphEdge::kInternal, "descriptors"); |
1660 CHECK_NE(NULL, own_descriptors); | 1699 CHECK_NE(NULL, own_descriptors); |
1661 const v8::HeapGraphNode* own_transitions = GetProperty( | 1700 const v8::HeapGraphNode* own_transitions = GetProperty( |
1662 map, v8::HeapGraphEdge::kInternal, "transitions"); | 1701 map, v8::HeapGraphEdge::kInternal, "transitions"); |
1663 CHECK_EQ(NULL, own_transitions); | 1702 CHECK_EQ(NULL, own_transitions); |
1664 } | 1703 } |
OLD | NEW |