| 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 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 CHECK_EQ(1, ccc->GetChildrenCount()); | 1563 CHECK_EQ(1, ccc->GetChildrenCount()); |
| 1564 const v8::HeapGraphNode* n_CCC = GetNode( | 1564 const v8::HeapGraphNode* n_CCC = GetNode( |
| 1565 ccc, v8::HeapGraphNode::kString, "CCC"); | 1565 ccc, v8::HeapGraphNode::kString, "CCC"); |
| 1566 CHECK(n_CCC); | 1566 CHECK(n_CCC); |
| 1567 | 1567 |
| 1568 CHECK_EQ(aaa, GetProperty(n_AAA, v8::HeapGraphEdge::kInternal, "native")); | 1568 CHECK_EQ(aaa, GetProperty(n_AAA, v8::HeapGraphEdge::kInternal, "native")); |
| 1569 CHECK_EQ(aaa, GetProperty(n_BBB, v8::HeapGraphEdge::kInternal, "native")); | 1569 CHECK_EQ(aaa, GetProperty(n_BBB, v8::HeapGraphEdge::kInternal, "native")); |
| 1570 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native")); | 1570 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native")); |
| 1571 } | 1571 } |
| 1572 | 1572 |
| 1573 | |
| 1574 class GraphWithImplicitRefs { | |
| 1575 public: | |
| 1576 static const int kObjectsCount = 4; | |
| 1577 explicit GraphWithImplicitRefs(LocalContext* env) { | |
| 1578 CHECK(!instance_); | |
| 1579 instance_ = this; | |
| 1580 isolate_ = (*env)->GetIsolate(); | |
| 1581 for (int i = 0; i < kObjectsCount; i++) { | |
| 1582 objects_[i].Reset(isolate_, v8::Object::New(isolate_)); | |
| 1583 } | |
| 1584 (*env) | |
| 1585 ->Global() | |
| 1586 ->Set(isolate_->GetCurrentContext(), v8_str("root_object"), | |
| 1587 v8::Local<v8::Value>::New(isolate_, objects_[0])) | |
| 1588 .FromJust(); | |
| 1589 } | |
| 1590 ~GraphWithImplicitRefs() { | |
| 1591 instance_ = NULL; | |
| 1592 } | |
| 1593 | |
| 1594 static void gcPrologue(v8::Isolate* isolate, v8::GCType type, | |
| 1595 v8::GCCallbackFlags flags) { | |
| 1596 instance_->AddImplicitReferences(); | |
| 1597 } | |
| 1598 | |
| 1599 private: | |
| 1600 void AddImplicitReferences() { | |
| 1601 // 0 -> 1 | |
| 1602 isolate_->SetObjectGroupId(objects_[0], | |
| 1603 v8::UniqueId(1)); | |
| 1604 isolate_->SetReferenceFromGroup( | |
| 1605 v8::UniqueId(1), objects_[1]); | |
| 1606 // Adding two more references: 1 -> 2, 1 -> 3 | |
| 1607 isolate_->SetReference(objects_[1].As<v8::Object>(), | |
| 1608 objects_[2]); | |
| 1609 isolate_->SetReference(objects_[1].As<v8::Object>(), | |
| 1610 objects_[3]); | |
| 1611 } | |
| 1612 | |
| 1613 v8::Persistent<v8::Value> objects_[kObjectsCount]; | |
| 1614 static GraphWithImplicitRefs* instance_; | |
| 1615 v8::Isolate* isolate_; | |
| 1616 }; | |
| 1617 | |
| 1618 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; | |
| 1619 | |
| 1620 | |
| 1621 TEST(HeapSnapshotImplicitReferences) { | |
| 1622 LocalContext env; | |
| 1623 v8::HandleScope scope(env->GetIsolate()); | |
| 1624 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | |
| 1625 | |
| 1626 GraphWithImplicitRefs graph(&env); | |
| 1627 env->GetIsolate()->AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); | |
| 1628 | |
| 1629 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); | |
| 1630 CHECK(ValidateSnapshot(snapshot)); | |
| 1631 | |
| 1632 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); | |
| 1633 const v8::HeapGraphNode* obj0 = GetProperty( | |
| 1634 global_object, v8::HeapGraphEdge::kProperty, "root_object"); | |
| 1635 CHECK(obj0); | |
| 1636 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); | |
| 1637 const v8::HeapGraphNode* obj1 = GetProperty( | |
| 1638 obj0, v8::HeapGraphEdge::kInternal, "native"); | |
| 1639 CHECK(obj1); | |
| 1640 int implicit_targets_count = 0; | |
| 1641 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) { | |
| 1642 const v8::HeapGraphEdge* prop = obj1->GetChild(i); | |
| 1643 v8::String::Utf8Value prop_name(prop->GetName()); | |
| 1644 if (prop->GetType() == v8::HeapGraphEdge::kInternal && | |
| 1645 strcmp("native", *prop_name) == 0) { | |
| 1646 ++implicit_targets_count; | |
| 1647 } | |
| 1648 } | |
| 1649 CHECK_EQ(2, implicit_targets_count); | |
| 1650 env->GetIsolate()->RemoveGCPrologueCallback( | |
| 1651 &GraphWithImplicitRefs::gcPrologue); | |
| 1652 } | |
| 1653 | |
| 1654 | |
| 1655 TEST(DeleteAllHeapSnapshots) { | 1573 TEST(DeleteAllHeapSnapshots) { |
| 1656 LocalContext env; | 1574 LocalContext env; |
| 1657 v8::HandleScope scope(env->GetIsolate()); | 1575 v8::HandleScope scope(env->GetIsolate()); |
| 1658 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1576 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1659 | 1577 |
| 1660 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1578 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
| 1661 heap_profiler->DeleteAllHeapSnapshots(); | 1579 heap_profiler->DeleteAllHeapSnapshots(); |
| 1662 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1580 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
| 1663 CHECK(heap_profiler->TakeHeapSnapshot()); | 1581 CHECK(heap_profiler->TakeHeapSnapshot()); |
| 1664 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); | 1582 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); |
| (...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3102 " a[i] = i;\n" | 3020 " a[i] = i;\n" |
| 3103 " for (var i = 0; i < 3; ++i)\n" | 3021 " for (var i = 0; i < 3; ++i)\n" |
| 3104 " a.shift();\n" | 3022 " a.shift();\n" |
| 3105 "}\n"); | 3023 "}\n"); |
| 3106 | 3024 |
| 3107 CcTest::CollectGarbage(v8::internal::NEW_SPACE); | 3025 CcTest::CollectGarbage(v8::internal::NEW_SPACE); |
| 3108 // Should not crash. | 3026 // Should not crash. |
| 3109 | 3027 |
| 3110 heap_profiler->StopSamplingHeapProfiler(); | 3028 heap_profiler->StopSamplingHeapProfiler(); |
| 3111 } | 3029 } |
| OLD | NEW |