Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 12033011: Add Isolate parameter to Persistent class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added explicit Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-lockers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 return node; 1038 return node;
1039 } 1039 }
1040 } 1040 }
1041 return NULL; 1041 return NULL;
1042 } 1042 }
1043 1043
1044 1044
1045 TEST(HeapSnapshotRetainedObjectInfo) { 1045 TEST(HeapSnapshotRetainedObjectInfo) {
1046 v8::HandleScope scope; 1046 v8::HandleScope scope;
1047 LocalContext env; 1047 LocalContext env;
1048 v8::Isolate* isolate = env->GetIsolate();
1048 1049
1049 v8::HeapProfiler::DefineWrapperClass( 1050 v8::HeapProfiler::DefineWrapperClass(
1050 1, TestRetainedObjectInfo::WrapperInfoCallback); 1051 1, TestRetainedObjectInfo::WrapperInfoCallback);
1051 v8::HeapProfiler::DefineWrapperClass( 1052 v8::HeapProfiler::DefineWrapperClass(
1052 2, TestRetainedObjectInfo::WrapperInfoCallback); 1053 2, TestRetainedObjectInfo::WrapperInfoCallback);
1053 v8::Persistent<v8::String> p_AAA = 1054 v8::Persistent<v8::String> p_AAA =
1054 v8::Persistent<v8::String>::New(v8_str("AAA")); 1055 v8::Persistent<v8::String>::New(isolate, v8_str("AAA"));
1055 p_AAA.SetWrapperClassId(1); 1056 p_AAA.SetWrapperClassId(isolate, 1);
1056 v8::Persistent<v8::String> p_BBB = 1057 v8::Persistent<v8::String> p_BBB =
1057 v8::Persistent<v8::String>::New(v8_str("BBB")); 1058 v8::Persistent<v8::String>::New(isolate, v8_str("BBB"));
1058 p_BBB.SetWrapperClassId(1); 1059 p_BBB.SetWrapperClassId(isolate, 1);
1059 v8::Persistent<v8::String> p_CCC = 1060 v8::Persistent<v8::String> p_CCC =
1060 v8::Persistent<v8::String>::New(v8_str("CCC")); 1061 v8::Persistent<v8::String>::New(isolate, v8_str("CCC"));
1061 p_CCC.SetWrapperClassId(2); 1062 p_CCC.SetWrapperClassId(isolate, 2);
1062 CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); 1063 CHECK_EQ(0, TestRetainedObjectInfo::instances.length());
1063 const v8::HeapSnapshot* snapshot = 1064 const v8::HeapSnapshot* snapshot =
1064 v8::HeapProfiler::TakeSnapshot(v8_str("retained")); 1065 v8::HeapProfiler::TakeSnapshot(v8_str("retained"));
1065 1066
1066 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); 1067 CHECK_EQ(3, TestRetainedObjectInfo::instances.length());
1067 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { 1068 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) {
1068 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); 1069 CHECK(TestRetainedObjectInfo::instances[i]->disposed());
1069 delete TestRetainedObjectInfo::instances[i]; 1070 delete TestRetainedObjectInfo::instances[i];
1070 } 1071 }
1071 1072
(...skipping 28 matching lines...) Expand all
1100 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native")); 1101 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native"));
1101 } 1102 }
1102 1103
1103 1104
1104 class GraphWithImplicitRefs { 1105 class GraphWithImplicitRefs {
1105 public: 1106 public:
1106 static const int kObjectsCount = 4; 1107 static const int kObjectsCount = 4;
1107 explicit GraphWithImplicitRefs(LocalContext* env) { 1108 explicit GraphWithImplicitRefs(LocalContext* env) {
1108 CHECK_EQ(NULL, instance_); 1109 CHECK_EQ(NULL, instance_);
1109 instance_ = this; 1110 instance_ = this;
1111 v8::Isolate* isolate = (*env)->GetIsolate();
1110 for (int i = 0; i < kObjectsCount; i++) { 1112 for (int i = 0; i < kObjectsCount; i++) {
1111 objects_[i] = v8::Persistent<v8::Object>::New(v8::Object::New()); 1113 objects_[i] = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
1112 } 1114 }
1113 (*env)->Global()->Set(v8_str("root_object"), objects_[0]); 1115 (*env)->Global()->Set(v8_str("root_object"), objects_[0]);
1114 } 1116 }
1115 ~GraphWithImplicitRefs() { 1117 ~GraphWithImplicitRefs() {
1116 instance_ = NULL; 1118 instance_ = NULL;
1117 } 1119 }
1118 1120
1119 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) { 1121 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) {
1120 instance_->AddImplicitReferences(); 1122 instance_->AddImplicitReferences();
1121 } 1123 }
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 const v8::HeapGraphNode* gc_roots = GetNode( 1473 const v8::HeapGraphNode* gc_roots = GetNode(
1472 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)"); 1474 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
1473 CHECK_NE(NULL, gc_roots); 1475 CHECK_NE(NULL, gc_roots);
1474 const v8::HeapGraphNode* global_handles = GetNode( 1476 const v8::HeapGraphNode* global_handles = GetNode(
1475 gc_roots, v8::HeapGraphNode::kObject, "(Global handles)"); 1477 gc_roots, v8::HeapGraphNode::kObject, "(Global handles)");
1476 CHECK_NE(NULL, global_handles); 1478 CHECK_NE(NULL, global_handles);
1477 return HasWeakEdge(global_handles); 1479 return HasWeakEdge(global_handles);
1478 } 1480 }
1479 1481
1480 1482
1481 static void PersistentHandleCallback(v8::Persistent<v8::Value> handle, void*) { 1483 static void PersistentHandleCallback(v8::Isolate* isolate,
1482 handle.Dispose(); 1484 v8::Persistent<v8::Value> handle,
1485 void*) {
1486 handle.Dispose(isolate);
1483 } 1487 }
1484 1488
1485 1489
1486 TEST(WeakGlobalHandle) { 1490 TEST(WeakGlobalHandle) {
1487 v8::HandleScope scope; 1491 v8::HandleScope scope;
1488 LocalContext env; 1492 LocalContext env;
1489 1493
1490 CHECK(!HasWeakGlobalHandle()); 1494 CHECK(!HasWeakGlobalHandle());
1491 1495
1492 v8::Persistent<v8::Object> handle = 1496 v8::Persistent<v8::Object> handle =
1493 v8::Persistent<v8::Object>::New(v8::Object::New()); 1497 v8::Persistent<v8::Object>::New(env->GetIsolate(), v8::Object::New());
1494 handle.MakeWeak(NULL, PersistentHandleCallback); 1498 handle.MakeWeak(env->GetIsolate(), NULL, PersistentHandleCallback);
1495 1499
1496 CHECK(HasWeakGlobalHandle()); 1500 CHECK(HasWeakGlobalHandle());
1497 } 1501 }
1498 1502
1499 1503
1500 TEST(WeakNativeContextRefs) { 1504 TEST(WeakNativeContextRefs) {
1501 v8::HandleScope scope; 1505 v8::HandleScope scope;
1502 LocalContext env; 1506 LocalContext env;
1503 1507
1504 const v8::HeapSnapshot* snapshot = 1508 const v8::HeapSnapshot* snapshot =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 } 1561 }
1558 } 1562 }
1559 CHECK_EQ(1, globals_count); 1563 CHECK_EQ(1, globals_count);
1560 } 1564 }
1561 #endif // ENABLE_DEBUGGER_SUPPORT 1565 #endif // ENABLE_DEBUGGER_SUPPORT
1562 1566
1563 1567
1564 TEST(PersistentHandleCount) { 1568 TEST(PersistentHandleCount) {
1565 v8::HandleScope scope; 1569 v8::HandleScope scope;
1566 LocalContext env; 1570 LocalContext env;
1571 v8::Isolate* isolate = env->GetIsolate();
1567 1572
1568 // V8 also uses global handles internally, so we can't test for an absolute 1573 // V8 also uses global handles internally, so we can't test for an absolute
1569 // number. 1574 // number.
1570 int global_handle_count = v8::HeapProfiler::GetPersistentHandleCount(); 1575 int global_handle_count = v8::HeapProfiler::GetPersistentHandleCount();
1571 1576
1572 // Create some persistent handles. 1577 // Create some persistent handles.
1573 v8::Persistent<v8::String> p_AAA = 1578 v8::Persistent<v8::String> p_AAA =
1574 v8::Persistent<v8::String>::New(v8_str("AAA")); 1579 v8::Persistent<v8::String>::New(isolate, v8_str("AAA"));
1575 CHECK_EQ(global_handle_count + 1, 1580 CHECK_EQ(global_handle_count + 1,
1576 v8::HeapProfiler::GetPersistentHandleCount()); 1581 v8::HeapProfiler::GetPersistentHandleCount());
1577 v8::Persistent<v8::String> p_BBB = 1582 v8::Persistent<v8::String> p_BBB =
1578 v8::Persistent<v8::String>::New(v8_str("BBB")); 1583 v8::Persistent<v8::String>::New(isolate, v8_str("BBB"));
1579 CHECK_EQ(global_handle_count + 2, 1584 CHECK_EQ(global_handle_count + 2,
1580 v8::HeapProfiler::GetPersistentHandleCount()); 1585 v8::HeapProfiler::GetPersistentHandleCount());
1581 v8::Persistent<v8::String> p_CCC = 1586 v8::Persistent<v8::String> p_CCC =
1582 v8::Persistent<v8::String>::New(v8_str("CCC")); 1587 v8::Persistent<v8::String>::New(isolate, v8_str("CCC"));
1583 CHECK_EQ(global_handle_count + 3, 1588 CHECK_EQ(global_handle_count + 3,
1584 v8::HeapProfiler::GetPersistentHandleCount()); 1589 v8::HeapProfiler::GetPersistentHandleCount());
1585 1590
1586 // Dipose the persistent handles in a different order. 1591 // Dipose the persistent handles in a different order.
1587 p_AAA.Dispose(); 1592 p_AAA.Dispose(env->GetIsolate());
1588 CHECK_EQ(global_handle_count + 2, 1593 CHECK_EQ(global_handle_count + 2,
1589 v8::HeapProfiler::GetPersistentHandleCount()); 1594 v8::HeapProfiler::GetPersistentHandleCount());
1590 p_CCC.Dispose(); 1595 p_CCC.Dispose(env->GetIsolate());
1591 CHECK_EQ(global_handle_count + 1, 1596 CHECK_EQ(global_handle_count + 1,
1592 v8::HeapProfiler::GetPersistentHandleCount()); 1597 v8::HeapProfiler::GetPersistentHandleCount());
1593 p_BBB.Dispose(); 1598 p_BBB.Dispose(env->GetIsolate());
1594 CHECK_EQ(global_handle_count, v8::HeapProfiler::GetPersistentHandleCount()); 1599 CHECK_EQ(global_handle_count, v8::HeapProfiler::GetPersistentHandleCount());
1595 } 1600 }
1596 1601
1597 1602
1598 TEST(AllStrongGcRootsHaveNames) { 1603 TEST(AllStrongGcRootsHaveNames) {
1599 v8::HandleScope scope; 1604 v8::HandleScope scope;
1600 LocalContext env; 1605 LocalContext env;
1601 1606
1602 CompileRun("foo = {};"); 1607 CompileRun("foo = {};");
1603 const v8::HeapSnapshot* snapshot = 1608 const v8::HeapSnapshot* snapshot =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 const v8::HeapGraphNode* map = 1655 const v8::HeapGraphNode* map =
1651 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); 1656 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map");
1652 CHECK_NE(NULL, map); 1657 CHECK_NE(NULL, map);
1653 const v8::HeapGraphNode* own_descriptors = GetProperty( 1658 const v8::HeapGraphNode* own_descriptors = GetProperty(
1654 map, v8::HeapGraphEdge::kInternal, "descriptors"); 1659 map, v8::HeapGraphEdge::kInternal, "descriptors");
1655 CHECK_NE(NULL, own_descriptors); 1660 CHECK_NE(NULL, own_descriptors);
1656 const v8::HeapGraphNode* own_transitions = GetProperty( 1661 const v8::HeapGraphNode* own_transitions = GetProperty(
1657 map, v8::HeapGraphEdge::kInternal, "transitions"); 1662 map, v8::HeapGraphEdge::kInternal, "transitions");
1658 CHECK_EQ(NULL, own_transitions); 1663 CHECK_EQ(NULL, own_transitions);
1659 } 1664 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-lockers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698