OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 495 } |
496 | 496 |
497 | 497 |
498 TEST(HeapSnapshotWeakCollection) { | 498 TEST(HeapSnapshotWeakCollection) { |
499 i::FLAG_harmony_collections = true; | 499 i::FLAG_harmony_collections = true; |
500 | 500 |
501 LocalContext env; | 501 LocalContext env; |
502 v8::HandleScope scope(env->GetIsolate()); | 502 v8::HandleScope scope(env->GetIsolate()); |
503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
504 | 504 |
505 CompileRun("k = {}; v = {};\n" | 505 CompileRun( |
506 "ws = new WeakSet(); ws.add(k); ws.add(v);\n" | 506 "k = {}; v = {}; s = 'str';\n" |
507 "wm = new WeakMap(); wm.set(k, v);\n"); | 507 "ws = new WeakSet(); ws.add(k); ws.add(v); ws[s] = s;\n" |
| 508 "wm = new WeakMap(); wm.set(k, v); wm[s] = s;\n"); |
508 const v8::HeapSnapshot* snapshot = | 509 const v8::HeapSnapshot* snapshot = |
509 heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections")); | 510 heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections")); |
510 CHECK(ValidateSnapshot(snapshot)); | 511 CHECK(ValidateSnapshot(snapshot)); |
511 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 512 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
512 const v8::HeapGraphNode* k = | 513 const v8::HeapGraphNode* k = |
513 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); | 514 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); |
514 CHECK_NE(NULL, k); | 515 CHECK_NE(NULL, k); |
515 const v8::HeapGraphNode* v = | 516 const v8::HeapGraphNode* v = |
516 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); | 517 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); |
517 CHECK_NE(NULL, v); | 518 CHECK_NE(NULL, v); |
| 519 const v8::HeapGraphNode* s = |
| 520 GetProperty(global, v8::HeapGraphEdge::kProperty, "s"); |
| 521 CHECK_NE(NULL, s); |
518 | 522 |
519 const v8::HeapGraphNode* ws = | 523 const v8::HeapGraphNode* ws = |
520 GetProperty(global, v8::HeapGraphEdge::kProperty, "ws"); | 524 GetProperty(global, v8::HeapGraphEdge::kProperty, "ws"); |
521 CHECK_NE(NULL, ws); | 525 CHECK_NE(NULL, ws); |
522 CHECK_EQ(v8::HeapGraphNode::kObject, ws->GetType()); | 526 CHECK_EQ(v8::HeapGraphNode::kObject, ws->GetType()); |
523 CHECK_EQ(v8_str("WeakSet"), ws->GetName()); | 527 CHECK_EQ(v8_str("WeakSet"), ws->GetName()); |
524 | 528 |
525 const v8::HeapGraphNode* ws_table = | 529 const v8::HeapGraphNode* ws_table = |
526 GetProperty(ws, v8::HeapGraphEdge::kInternal, "table"); | 530 GetProperty(ws, v8::HeapGraphEdge::kInternal, "table"); |
527 CHECK_EQ(v8::HeapGraphNode::kArray, ws_table->GetType()); | 531 CHECK_EQ(v8::HeapGraphNode::kArray, ws_table->GetType()); |
528 CHECK_GT(ws_table->GetChildrenCount(), 0); | 532 CHECK_GT(ws_table->GetChildrenCount(), 0); |
529 int weak_entries = 0; | 533 int weak_entries = 0; |
530 for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) { | 534 for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) { |
531 const v8::HeapGraphEdge* prop = ws_table->GetChild(i); | 535 const v8::HeapGraphEdge* prop = ws_table->GetChild(i); |
532 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; | 536 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; |
533 if (k->GetId() == prop->GetToNode()->GetId()) { | 537 if (k->GetId() == prop->GetToNode()->GetId()) { |
534 ++weak_entries; | 538 ++weak_entries; |
535 } | 539 } |
536 } | 540 } |
537 CHECK_EQ(1, weak_entries); | 541 CHECK_EQ(1, weak_entries); |
| 542 const v8::HeapGraphNode* ws_s = |
| 543 GetProperty(ws, v8::HeapGraphEdge::kProperty, "str"); |
| 544 CHECK_NE(NULL, ws_s); |
| 545 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(ws_s->GetId())); |
538 | 546 |
539 const v8::HeapGraphNode* wm = | 547 const v8::HeapGraphNode* wm = |
540 GetProperty(global, v8::HeapGraphEdge::kProperty, "wm"); | 548 GetProperty(global, v8::HeapGraphEdge::kProperty, "wm"); |
541 CHECK_NE(NULL, wm); | 549 CHECK_NE(NULL, wm); |
542 CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType()); | 550 CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType()); |
543 CHECK_EQ(v8_str("WeakMap"), wm->GetName()); | 551 CHECK_EQ(v8_str("WeakMap"), wm->GetName()); |
544 | 552 |
545 const v8::HeapGraphNode* wm_table = | 553 const v8::HeapGraphNode* wm_table = |
546 GetProperty(wm, v8::HeapGraphEdge::kInternal, "table"); | 554 GetProperty(wm, v8::HeapGraphEdge::kInternal, "table"); |
547 CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType()); | 555 CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType()); |
548 CHECK_GT(wm_table->GetChildrenCount(), 0); | 556 CHECK_GT(wm_table->GetChildrenCount(), 0); |
549 weak_entries = 0; | 557 weak_entries = 0; |
550 for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) { | 558 for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) { |
551 const v8::HeapGraphEdge* prop = wm_table->GetChild(i); | 559 const v8::HeapGraphEdge* prop = wm_table->GetChild(i); |
552 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; | 560 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; |
553 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); | 561 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); |
554 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { | 562 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { |
555 ++weak_entries; | 563 ++weak_entries; |
556 } | 564 } |
557 } | 565 } |
558 CHECK_EQ(2, weak_entries); | 566 CHECK_EQ(2, weak_entries); |
| 567 const v8::HeapGraphNode* wm_s = |
| 568 GetProperty(wm, v8::HeapGraphEdge::kProperty, "str"); |
| 569 CHECK_NE(NULL, wm_s); |
| 570 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(wm_s->GetId())); |
559 } | 571 } |
560 | 572 |
561 | 573 |
| 574 TEST(HeapSnapshotCollection) { |
| 575 i::FLAG_harmony_collections = true; |
| 576 |
| 577 LocalContext env; |
| 578 v8::HandleScope scope(env->GetIsolate()); |
| 579 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 580 |
| 581 CompileRun( |
| 582 "k = {}; v = {}; s = 'str';\n" |
| 583 "set = new Set(); set.add(k); set.add(v); set[s] = s;\n" |
| 584 "map = new Map(); map.set(k, v); map[s] = s;\n"); |
| 585 const v8::HeapSnapshot* snapshot = |
| 586 heap_profiler->TakeHeapSnapshot(v8_str("Collections")); |
| 587 CHECK(ValidateSnapshot(snapshot)); |
| 588 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 589 const v8::HeapGraphNode* k = |
| 590 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); |
| 591 CHECK_NE(NULL, k); |
| 592 const v8::HeapGraphNode* v = |
| 593 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); |
| 594 CHECK_NE(NULL, v); |
| 595 const v8::HeapGraphNode* s = |
| 596 GetProperty(global, v8::HeapGraphEdge::kProperty, "s"); |
| 597 CHECK_NE(NULL, s); |
| 598 |
| 599 const v8::HeapGraphNode* set = |
| 600 GetProperty(global, v8::HeapGraphEdge::kProperty, "set"); |
| 601 CHECK_NE(NULL, set); |
| 602 CHECK_EQ(v8::HeapGraphNode::kObject, set->GetType()); |
| 603 CHECK_EQ(v8_str("Set"), set->GetName()); |
| 604 |
| 605 const v8::HeapGraphNode* set_table = |
| 606 GetProperty(set, v8::HeapGraphEdge::kInternal, "table"); |
| 607 CHECK_EQ(v8::HeapGraphNode::kArray, set_table->GetType()); |
| 608 CHECK_GT(set_table->GetChildrenCount(), 0); |
| 609 int entries = 0; |
| 610 for (int i = 0, count = set_table->GetChildrenCount(); i < count; ++i) { |
| 611 const v8::HeapGraphEdge* prop = set_table->GetChild(i); |
| 612 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); |
| 613 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { |
| 614 ++entries; |
| 615 } |
| 616 } |
| 617 CHECK_EQ(2, entries); |
| 618 const v8::HeapGraphNode* set_s = |
| 619 GetProperty(set, v8::HeapGraphEdge::kProperty, "str"); |
| 620 CHECK_NE(NULL, set_s); |
| 621 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(set_s->GetId())); |
| 622 |
| 623 const v8::HeapGraphNode* map = |
| 624 GetProperty(global, v8::HeapGraphEdge::kProperty, "map"); |
| 625 CHECK_NE(NULL, map); |
| 626 CHECK_EQ(v8::HeapGraphNode::kObject, map->GetType()); |
| 627 CHECK_EQ(v8_str("Map"), map->GetName()); |
| 628 |
| 629 const v8::HeapGraphNode* map_table = |
| 630 GetProperty(map, v8::HeapGraphEdge::kInternal, "table"); |
| 631 CHECK_EQ(v8::HeapGraphNode::kArray, map_table->GetType()); |
| 632 CHECK_GT(map_table->GetChildrenCount(), 0); |
| 633 entries = 0; |
| 634 for (int i = 0, count = map_table->GetChildrenCount(); i < count; ++i) { |
| 635 const v8::HeapGraphEdge* prop = map_table->GetChild(i); |
| 636 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); |
| 637 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { |
| 638 ++entries; |
| 639 } |
| 640 } |
| 641 CHECK_EQ(2, entries); |
| 642 const v8::HeapGraphNode* map_s = |
| 643 GetProperty(map, v8::HeapGraphEdge::kProperty, "str"); |
| 644 CHECK_NE(NULL, map_s); |
| 645 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(map_s->GetId())); |
| 646 } |
| 647 |
| 648 |
562 TEST(HeapSnapshotInternalReferences) { | 649 TEST(HeapSnapshotInternalReferences) { |
563 v8::Isolate* isolate = CcTest::isolate(); | 650 v8::Isolate* isolate = CcTest::isolate(); |
564 v8::HandleScope scope(isolate); | 651 v8::HandleScope scope(isolate); |
565 v8::Local<v8::ObjectTemplate> global_template = | 652 v8::Local<v8::ObjectTemplate> global_template = |
566 v8::ObjectTemplate::New(isolate); | 653 v8::ObjectTemplate::New(isolate); |
567 global_template->SetInternalFieldCount(2); | 654 global_template->SetInternalFieldCount(2); |
568 LocalContext env(NULL, global_template); | 655 LocalContext env(NULL, global_template); |
569 v8::Handle<v8::Object> global_proxy = env->Global(); | 656 v8::Handle<v8::Object> global_proxy = env->Global(); |
570 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 657 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
571 CHECK_EQ(2, global->InternalFieldCount()); | 658 CHECK_EQ(2, global->InternalFieldCount()); |
(...skipping 2104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2676 map.AddRange(ToAddress(0x180), 0x80, 6U); | 2763 map.AddRange(ToAddress(0x180), 0x80, 6U); |
2677 map.AddRange(ToAddress(0x180), 0x80, 7U); | 2764 map.AddRange(ToAddress(0x180), 0x80, 7U); |
2678 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); | 2765 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); |
2679 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); | 2766 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); |
2680 CHECK_EQ(3, static_cast<int>(map.size())); | 2767 CHECK_EQ(3, static_cast<int>(map.size())); |
2681 | 2768 |
2682 map.Clear(); | 2769 map.Clear(); |
2683 CHECK_EQ(0, static_cast<int>(map.size())); | 2770 CHECK_EQ(0, static_cast<int>(map.size())); |
2684 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); | 2771 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); |
2685 } | 2772 } |
OLD | NEW |