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

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

Issue 1474353002: Remove easy to remove calls to Isolate::Current() from api.cc (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: update Created 5 years 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
OLDNEW
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 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 for (int i = 0; i < kObjectsCount; i++) { 1532 for (int i = 0; i < kObjectsCount; i++) {
1533 objects_[i].Reset(isolate_, v8::Object::New(isolate_)); 1533 objects_[i].Reset(isolate_, v8::Object::New(isolate_));
1534 } 1534 }
1535 (*env)->Global()->Set(v8_str("root_object"), 1535 (*env)->Global()->Set(v8_str("root_object"),
1536 v8::Local<v8::Value>::New(isolate_, objects_[0])); 1536 v8::Local<v8::Value>::New(isolate_, objects_[0]));
1537 } 1537 }
1538 ~GraphWithImplicitRefs() { 1538 ~GraphWithImplicitRefs() {
1539 instance_ = NULL; 1539 instance_ = NULL;
1540 } 1540 }
1541 1541
1542 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) { 1542 static void gcPrologue(v8::Isolate* isolate, v8::GCType type,
1543 v8::GCCallbackFlags flags) {
1543 instance_->AddImplicitReferences(); 1544 instance_->AddImplicitReferences();
1544 } 1545 }
1545 1546
1546 private: 1547 private:
1547 void AddImplicitReferences() { 1548 void AddImplicitReferences() {
1548 // 0 -> 1 1549 // 0 -> 1
1549 isolate_->SetObjectGroupId(objects_[0], 1550 isolate_->SetObjectGroupId(objects_[0],
1550 v8::UniqueId(1)); 1551 v8::UniqueId(1));
1551 isolate_->SetReferenceFromGroup( 1552 isolate_->SetReferenceFromGroup(
1552 v8::UniqueId(1), objects_[1]); 1553 v8::UniqueId(1), objects_[1]);
(...skipping 11 matching lines...) Expand all
1564 1565
1565 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; 1566 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL;
1566 1567
1567 1568
1568 TEST(HeapSnapshotImplicitReferences) { 1569 TEST(HeapSnapshotImplicitReferences) {
1569 LocalContext env; 1570 LocalContext env;
1570 v8::HandleScope scope(env->GetIsolate()); 1571 v8::HandleScope scope(env->GetIsolate());
1571 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1572 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1572 1573
1573 GraphWithImplicitRefs graph(&env); 1574 GraphWithImplicitRefs graph(&env);
1574 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); 1575 env->GetIsolate()->AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
1575 1576
1576 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); 1577 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
1577 CHECK(ValidateSnapshot(snapshot)); 1578 CHECK(ValidateSnapshot(snapshot));
1578 1579
1579 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); 1580 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
1580 const v8::HeapGraphNode* obj0 = GetProperty( 1581 const v8::HeapGraphNode* obj0 = GetProperty(
1581 global_object, v8::HeapGraphEdge::kProperty, "root_object"); 1582 global_object, v8::HeapGraphEdge::kProperty, "root_object");
1582 CHECK(obj0); 1583 CHECK(obj0);
1583 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); 1584 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType());
1584 const v8::HeapGraphNode* obj1 = GetProperty( 1585 const v8::HeapGraphNode* obj1 = GetProperty(
1585 obj0, v8::HeapGraphEdge::kInternal, "native"); 1586 obj0, v8::HeapGraphEdge::kInternal, "native");
1586 CHECK(obj1); 1587 CHECK(obj1);
1587 int implicit_targets_count = 0; 1588 int implicit_targets_count = 0;
1588 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) { 1589 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) {
1589 const v8::HeapGraphEdge* prop = obj1->GetChild(i); 1590 const v8::HeapGraphEdge* prop = obj1->GetChild(i);
1590 v8::String::Utf8Value prop_name(prop->GetName()); 1591 v8::String::Utf8Value prop_name(prop->GetName());
1591 if (prop->GetType() == v8::HeapGraphEdge::kInternal && 1592 if (prop->GetType() == v8::HeapGraphEdge::kInternal &&
1592 strcmp("native", *prop_name) == 0) { 1593 strcmp("native", *prop_name) == 0) {
1593 ++implicit_targets_count; 1594 ++implicit_targets_count;
1594 } 1595 }
1595 } 1596 }
1596 CHECK_EQ(2, implicit_targets_count); 1597 CHECK_EQ(2, implicit_targets_count);
1597 v8::V8::RemoveGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); 1598 env->GetIsolate()->RemoveGCPrologueCallback(
1599 &GraphWithImplicitRefs::gcPrologue);
1598 } 1600 }
1599 1601
1600 1602
1601 TEST(DeleteAllHeapSnapshots) { 1603 TEST(DeleteAllHeapSnapshots) {
1602 LocalContext env; 1604 LocalContext env;
1603 v8::HandleScope scope(env->GetIsolate()); 1605 v8::HandleScope scope(env->GetIsolate());
1604 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1606 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1605 1607
1606 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1608 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1607 heap_profiler->DeleteAllHeapSnapshots(); 1609 heap_profiler->DeleteAllHeapSnapshots();
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 map.AddRange(ToAddress(0x180), 0x80, 6U); 2800 map.AddRange(ToAddress(0x180), 0x80, 6U);
2799 map.AddRange(ToAddress(0x180), 0x80, 7U); 2801 map.AddRange(ToAddress(0x180), 0x80, 7U);
2800 CHECK_EQ(7u, map.GetTraceNodeId(ToAddress(0x180))); 2802 CHECK_EQ(7u, map.GetTraceNodeId(ToAddress(0x180)));
2801 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x200))); 2803 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x200)));
2802 CHECK_EQ(3u, map.size()); 2804 CHECK_EQ(3u, map.size());
2803 2805
2804 map.Clear(); 2806 map.Clear();
2805 CHECK_EQ(0u, map.size()); 2807 CHECK_EQ(0u, map.size());
2806 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x400))); 2808 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x400)));
2807 } 2809 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698