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

Side by Side Diff: src/profile-generator.cc

Issue 6683022: [Isolates] Merge 7111:7152 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: Created 9 years, 9 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 | « src/profile-generator.h ('k') | src/v8globals.h » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 11 matching lines...) Expand all
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifdef ENABLE_LOGGING_AND_PROFILING 28 #ifdef ENABLE_LOGGING_AND_PROFILING
29 29
30 #include "v8.h" 30 #include "v8.h"
31 #include "global-handles.h" 31 #include "global-handles.h"
32 #include "heap-profiler.h"
32 #include "scopeinfo.h" 33 #include "scopeinfo.h"
33 #include "unicode.h" 34 #include "unicode.h"
34 #include "zone-inl.h" 35 #include "zone-inl.h"
35 36
36 #include "profile-generator-inl.h" 37 #include "profile-generator-inl.h"
37 38
38 namespace v8 { 39 namespace v8 {
39 namespace internal { 40 namespace internal {
40 41
41 42
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 90 }
90 } 91 }
91 } 92 }
92 93
93 94
94 StringsStorage::StringsStorage() 95 StringsStorage::StringsStorage()
95 : names_(StringsMatch) { 96 : names_(StringsMatch) {
96 } 97 }
97 98
98 99
99 static void DeleteIndexName(char** name_ptr) {
100 DeleteArray(*name_ptr);
101 }
102
103
104 StringsStorage::~StringsStorage() { 100 StringsStorage::~StringsStorage() {
105 for (HashMap::Entry* p = names_.Start(); 101 for (HashMap::Entry* p = names_.Start();
106 p != NULL; 102 p != NULL;
107 p = names_.Next(p)) { 103 p = names_.Next(p)) {
108 DeleteArray(reinterpret_cast<const char*>(p->value)); 104 DeleteArray(reinterpret_cast<const char*>(p->value));
109 } 105 }
110 index_names_.Iterate(DeleteIndexName); 106 }
107
108
109 const char* StringsStorage::GetCopy(const char* src) {
110 int len = static_cast<int>(strlen(src));
111 Vector<char> dst = Vector<char>::New(len + 1);
112 OS::StrNCpy(dst, src, len);
113 dst[len] = '\0';
114 uint32_t hash = HashSequentialString(dst.start(), len);
115 return AddOrDisposeString(dst.start(), hash);
116 }
117
118
119 const char* StringsStorage::GetFormatted(const char* format, ...) {
120 va_list args;
121 va_start(args, format);
122 const char* result = GetVFormatted(format, args);
123 va_end(args);
124 return result;
125 }
126
127
128 const char* StringsStorage::AddOrDisposeString(char* str, uint32_t hash) {
129 HashMap::Entry* cache_entry = names_.Lookup(str, hash, true);
130 if (cache_entry->value == NULL) {
131 // New entry added.
132 cache_entry->value = str;
133 } else {
134 DeleteArray(str);
135 }
136 return reinterpret_cast<const char*>(cache_entry->value);
137 }
138
139
140 const char* StringsStorage::GetVFormatted(const char* format, va_list args) {
141 Vector<char> str = Vector<char>::New(1024);
142 int len = OS::VSNPrintF(str, format, args);
143 if (len == -1) {
144 DeleteArray(str.start());
145 return format;
146 }
147 uint32_t hash = HashSequentialString(str.start(), len);
148 return AddOrDisposeString(str.start(), hash);
111 } 149 }
112 150
113 151
114 const char* StringsStorage::GetName(String* name) { 152 const char* StringsStorage::GetName(String* name) {
115 if (name->IsString()) { 153 if (name->IsString()) {
116 char* c_name = 154 return AddOrDisposeString(
117 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL).Detach(); 155 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL).Detach(),
118 HashMap::Entry* cache_entry = names_.Lookup(c_name, name->Hash(), true); 156 name->Hash());
119 if (cache_entry->value == NULL) {
120 // New entry added.
121 cache_entry->value = c_name;
122 } else {
123 DeleteArray(c_name);
124 }
125 return reinterpret_cast<const char*>(cache_entry->value);
126 } 157 }
127 return ""; 158 return "";
128 } 159 }
129 160
130 161
131 const char* StringsStorage::GetName(int index) { 162 const char* StringsStorage::GetName(int index) {
132 ASSERT(index >= 0); 163 return GetFormatted("%d", index);
133 if (index_names_.length() <= index) {
134 index_names_.AddBlock(
135 NULL, index - index_names_.length() + 1);
136 }
137 if (index_names_[index] == NULL) {
138 const int kMaximumNameLength = 32;
139 char* name = NewArray<char>(kMaximumNameLength);
140 OS::SNPrintF(Vector<char>(name, kMaximumNameLength), "%d", index);
141 index_names_[index] = name;
142 }
143 return index_names_[index];
144 } 164 }
145 165
146 166
147 const char* const CodeEntry::kEmptyNamePrefix = ""; 167 const char* const CodeEntry::kEmptyNamePrefix = "";
148 168
149 169
150 void CodeEntry::CopyData(const CodeEntry& source) { 170 void CodeEntry::CopyData(const CodeEntry& source) {
151 tag_ = source.tag_; 171 tag_ = source.tag_;
152 name_prefix_ = source.name_prefix_; 172 name_prefix_ = source.name_prefix_;
153 name_ = source.name_; 173 name_ = source.name_;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 480
461 481
462 void CpuProfile::Print() { 482 void CpuProfile::Print() {
463 OS::Print("[Top down]:\n"); 483 OS::Print("[Top down]:\n");
464 top_down_.Print(); 484 top_down_.Print();
465 OS::Print("[Bottom up]:\n"); 485 OS::Print("[Bottom up]:\n");
466 bottom_up_.Print(); 486 bottom_up_.Print();
467 } 487 }
468 488
469 489
470 CodeEntry* const CodeMap::kSfiCodeEntry = NULL; 490 CodeEntry* const CodeMap::kSharedFunctionCodeEntry = NULL;
471 const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL; 491 const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL;
472 const CodeMap::CodeTreeConfig::Value CodeMap::CodeTreeConfig::kNoValue = 492 const CodeMap::CodeTreeConfig::Value CodeMap::CodeTreeConfig::kNoValue =
473 CodeMap::CodeEntryInfo(NULL, 0); 493 CodeMap::CodeEntryInfo(NULL, 0);
474 494
475 495
476 CodeEntry* CodeMap::FindEntry(Address addr) { 496 CodeEntry* CodeMap::FindEntry(Address addr) {
477 CodeTree::Locator locator; 497 CodeTree::Locator locator;
478 if (tree_.FindGreatestLessThan(addr, &locator)) { 498 if (tree_.FindGreatestLessThan(addr, &locator)) {
479 // locator.key() <= addr. Need to check that addr is within entry. 499 // locator.key() <= addr. Need to check that addr is within entry.
480 const CodeEntryInfo& entry = locator.value(); 500 const CodeEntryInfo& entry = locator.value();
481 if (addr < (locator.key() + entry.size)) 501 if (addr < (locator.key() + entry.size))
482 return entry.entry; 502 return entry.entry;
483 } 503 }
484 return NULL; 504 return NULL;
485 } 505 }
486 506
487 507
488 int CodeMap::GetSFITag(Address addr) { 508 int CodeMap::GetSharedId(Address addr) {
489 CodeTree::Locator locator; 509 CodeTree::Locator locator;
490 // For SFI entries, 'size' field is used to store their IDs. 510 // For shared function entries, 'size' field is used to store their IDs.
491 if (tree_.Find(addr, &locator)) { 511 if (tree_.Find(addr, &locator)) {
492 const CodeEntryInfo& entry = locator.value(); 512 const CodeEntryInfo& entry = locator.value();
493 ASSERT(entry.entry == kSfiCodeEntry); 513 ASSERT(entry.entry == kSharedFunctionCodeEntry);
494 return entry.size; 514 return entry.size;
495 } else { 515 } else {
496 tree_.Insert(addr, &locator); 516 tree_.Insert(addr, &locator);
497 int tag = next_sfi_tag_++; 517 int id = next_shared_id_++;
498 locator.set_value(CodeEntryInfo(kSfiCodeEntry, tag)); 518 locator.set_value(CodeEntryInfo(kSharedFunctionCodeEntry, id));
499 return tag; 519 return id;
500 } 520 }
501 } 521 }
502 522
503 523
504 void CodeMap::CodeTreePrinter::Call( 524 void CodeMap::CodeTreePrinter::Call(
505 const Address& key, const CodeMap::CodeEntryInfo& value) { 525 const Address& key, const CodeMap::CodeEntryInfo& value) {
506 OS::Print("%p %5d %s\n", key, value.size, value.entry->name()); 526 OS::Print("%p %5d %s\n", key, value.size, value.entry->name());
507 } 527 }
508 528
509 529
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 const char* HeapEntry::TypeAsString() { 1026 const char* HeapEntry::TypeAsString() {
1007 switch (type()) { 1027 switch (type()) {
1008 case kHidden: return "/hidden/"; 1028 case kHidden: return "/hidden/";
1009 case kObject: return "/object/"; 1029 case kObject: return "/object/";
1010 case kClosure: return "/closure/"; 1030 case kClosure: return "/closure/";
1011 case kString: return "/string/"; 1031 case kString: return "/string/";
1012 case kCode: return "/code/"; 1032 case kCode: return "/code/";
1013 case kArray: return "/array/"; 1033 case kArray: return "/array/";
1014 case kRegExp: return "/regexp/"; 1034 case kRegExp: return "/regexp/";
1015 case kHeapNumber: return "/number/"; 1035 case kHeapNumber: return "/number/";
1036 case kNative: return "/native/";
1016 default: return "???"; 1037 default: return "???";
1017 } 1038 }
1018 } 1039 }
1019 1040
1020 1041
1021 int HeapEntry::EntriesSize(int entries_count, 1042 int HeapEntry::EntriesSize(int entries_count,
1022 int children_count, 1043 int children_count,
1023 int retainers_count) { 1044 int retainers_count) {
1024 return sizeof(HeapEntry) * entries_count // NOLINT 1045 return sizeof(HeapEntry) * entries_count // NOLINT
1025 + sizeof(HeapGraphEdge) * children_count // NOLINT 1046 + sizeof(HeapGraphEdge) * children_count // NOLINT
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection, 1223 HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection,
1203 HeapSnapshot::Type type, 1224 HeapSnapshot::Type type,
1204 const char* title, 1225 const char* title,
1205 unsigned uid) 1226 unsigned uid)
1206 : collection_(collection), 1227 : collection_(collection),
1207 type_(type), 1228 type_(type),
1208 title_(title), 1229 title_(title),
1209 uid_(uid), 1230 uid_(uid),
1210 root_entry_(NULL), 1231 root_entry_(NULL),
1211 gc_roots_entry_(NULL), 1232 gc_roots_entry_(NULL),
1233 natives_root_entry_(NULL),
1212 raw_entries_(NULL), 1234 raw_entries_(NULL),
1213 entries_sorted_(false), 1235 entries_sorted_(false),
1214 retaining_paths_(HeapEntry::Match) { 1236 retaining_paths_(HeapEntry::Match) {
1215 STATIC_ASSERT( 1237 STATIC_ASSERT(
1216 sizeof(HeapGraphEdge) == 1238 sizeof(HeapGraphEdge) ==
1217 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapGraphEdgeSize); // NOL INT 1239 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapGraphEdgeSize); // NOL INT
1218 STATIC_ASSERT( 1240 STATIC_ASSERT(
1219 sizeof(HeapEntry) == 1241 sizeof(HeapEntry) ==
1220 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapEntrySize); // NOLINT 1242 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapEntrySize); // NOLINT
1221 } 1243 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 ASSERT(gc_roots_entry_ == NULL); 1298 ASSERT(gc_roots_entry_ == NULL);
1277 return (gc_roots_entry_ = AddEntry(HeapEntry::kObject, 1299 return (gc_roots_entry_ = AddEntry(HeapEntry::kObject,
1278 "(GC roots)", 1300 "(GC roots)",
1279 HeapObjectsMap::kGcRootsObjectId, 1301 HeapObjectsMap::kGcRootsObjectId,
1280 0, 1302 0,
1281 children_count, 1303 children_count,
1282 retainers_count)); 1304 retainers_count));
1283 } 1305 }
1284 1306
1285 1307
1308 HeapEntry* HeapSnapshot::AddNativesRootEntry(int children_count,
1309 int retainers_count) {
1310 ASSERT(natives_root_entry_ == NULL);
1311 return (natives_root_entry_ = AddEntry(
1312 HeapEntry::kObject,
1313 "(Native objects)",
1314 HeapObjectsMap::kNativesRootObjectId,
1315 0,
1316 children_count,
1317 retainers_count));
1318 }
1319
1320
1286 HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type, 1321 HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type,
1287 const char* name, 1322 const char* name,
1288 uint64_t id, 1323 uint64_t id,
1289 int size, 1324 int size,
1290 int children_count, 1325 int children_count,
1291 int retainers_count) { 1326 int retainers_count) {
1292 HeapEntry* entry = GetNextEntryToInit(); 1327 HeapEntry* entry = GetNextEntryToInit();
1293 entry->Init(this, type, name, id, size, children_count, retainers_count); 1328 entry->Init(this, type, name, id, size, children_count, retainers_count);
1294 return entry; 1329 return entry;
1295 } 1330 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 } 1404 }
1370 return &entries_; 1405 return &entries_;
1371 } 1406 }
1372 1407
1373 1408
1374 void HeapSnapshot::Print(int max_depth) { 1409 void HeapSnapshot::Print(int max_depth) {
1375 root()->Print(max_depth, 0); 1410 root()->Print(max_depth, 0);
1376 } 1411 }
1377 1412
1378 1413
1379 const uint64_t HeapObjectsMap::kInternalRootObjectId = 0; 1414 // We split IDs on evens for embedder objects (see
1380 const uint64_t HeapObjectsMap::kGcRootsObjectId = 1; 1415 // HeapObjectsMap::GenerateId) and odds for native objects.
1416 const uint64_t HeapObjectsMap::kInternalRootObjectId = 1;
1417 const uint64_t HeapObjectsMap::kGcRootsObjectId = 3;
1418 const uint64_t HeapObjectsMap::kNativesRootObjectId = 5;
1381 // Increase kFirstAvailableObjectId if new 'special' objects appear. 1419 // Increase kFirstAvailableObjectId if new 'special' objects appear.
1382 const uint64_t HeapObjectsMap::kFirstAvailableObjectId = 2; 1420 const uint64_t HeapObjectsMap::kFirstAvailableObjectId = 7;
1383 1421
1384 HeapObjectsMap::HeapObjectsMap() 1422 HeapObjectsMap::HeapObjectsMap()
1385 : initial_fill_mode_(true), 1423 : initial_fill_mode_(true),
1386 next_id_(kFirstAvailableObjectId), 1424 next_id_(kFirstAvailableObjectId),
1387 entries_map_(AddressesMatch), 1425 entries_map_(AddressesMatch),
1388 entries_(new List<EntryInfo>()) { } 1426 entries_(new List<EntryInfo>()) { }
1389 1427
1390 1428
1391 HeapObjectsMap::~HeapObjectsMap() { 1429 HeapObjectsMap::~HeapObjectsMap() {
1392 delete entries_; 1430 delete entries_;
1393 } 1431 }
1394 1432
1395 1433
1396 void HeapObjectsMap::SnapshotGenerationFinished() { 1434 void HeapObjectsMap::SnapshotGenerationFinished() {
1397 initial_fill_mode_ = false; 1435 initial_fill_mode_ = false;
1398 RemoveDeadEntries(); 1436 RemoveDeadEntries();
1399 } 1437 }
1400 1438
1401 1439
1402 uint64_t HeapObjectsMap::FindObject(Address addr) { 1440 uint64_t HeapObjectsMap::FindObject(Address addr) {
1403 if (!initial_fill_mode_) { 1441 if (!initial_fill_mode_) {
1404 uint64_t existing = FindEntry(addr); 1442 uint64_t existing = FindEntry(addr);
1405 if (existing != 0) return existing; 1443 if (existing != 0) return existing;
1406 } 1444 }
1407 uint64_t id = next_id_++; 1445 uint64_t id = next_id_;
1446 next_id_ += 2;
1408 AddEntry(addr, id); 1447 AddEntry(addr, id);
1409 return id; 1448 return id;
1410 } 1449 }
1411 1450
1412 1451
1413 void HeapObjectsMap::MoveObject(Address from, Address to) { 1452 void HeapObjectsMap::MoveObject(Address from, Address to) {
1414 if (from == to) return; 1453 if (from == to) return;
1415 HashMap::Entry* entry = entries_map_.Lookup(from, AddressHash(from), false); 1454 HashMap::Entry* entry = entries_map_.Lookup(from, AddressHash(from), false);
1416 if (entry != NULL) { 1455 if (entry != NULL) {
1417 void* value = entry->value; 1456 void* value = entry->value;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 for (int i = 0; i < dead_entries.length(); ++i) { 1504 for (int i = 0; i < dead_entries.length(); ++i) {
1466 void* raw_entry = dead_entries[i]; 1505 void* raw_entry = dead_entries[i];
1467 entries_map_.Remove( 1506 entries_map_.Remove(
1468 raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry))); 1507 raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry)));
1469 } 1508 }
1470 delete entries_; 1509 delete entries_;
1471 entries_ = new_entries; 1510 entries_ = new_entries;
1472 } 1511 }
1473 1512
1474 1513
1514 uint64_t HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) {
1515 uint64_t id = static_cast<uint64_t>(info->GetHash());
1516 const char* label = info->GetLabel();
1517 id ^= HashSequentialString(label, static_cast<int>(strlen(label)));
1518 intptr_t element_count = info->GetElementCount();
1519 if (element_count != -1)
1520 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count));
1521 return id << 1;
1522 }
1523
1524
1475 HeapSnapshotsCollection::HeapSnapshotsCollection() 1525 HeapSnapshotsCollection::HeapSnapshotsCollection()
1476 : is_tracking_objects_(false), 1526 : is_tracking_objects_(false),
1477 snapshots_uids_(HeapSnapshotsMatch), 1527 snapshots_uids_(HeapSnapshotsMatch),
1478 token_enumerator_(new TokenEnumerator()) { 1528 token_enumerator_(new TokenEnumerator()) {
1479 } 1529 }
1480 1530
1481 1531
1482 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) { 1532 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) {
1483 delete *snapshot_ptr; 1533 delete *snapshot_ptr;
1484 } 1534 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 1598
1549 void HeapEntriesMap::AllocateEntries() { 1599 void HeapEntriesMap::AllocateEntries() {
1550 for (HashMap::Entry* p = entries_.Start(); 1600 for (HashMap::Entry* p = entries_.Start();
1551 p != NULL; 1601 p != NULL;
1552 p = entries_.Next(p)) { 1602 p = entries_.Next(p)) {
1553 EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(p->value); 1603 EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(p->value);
1554 entry_info->entry = entry_info->allocator->AllocateEntry( 1604 entry_info->entry = entry_info->allocator->AllocateEntry(
1555 p->key, 1605 p->key,
1556 entry_info->children_count, 1606 entry_info->children_count,
1557 entry_info->retainers_count); 1607 entry_info->retainers_count);
1608 ASSERT(entry_info->entry != NULL);
1609 ASSERT(entry_info->entry != kHeapEntryPlaceholder);
1558 entry_info->children_count = 0; 1610 entry_info->children_count = 0;
1559 entry_info->retainers_count = 0; 1611 entry_info->retainers_count = 0;
1560 } 1612 }
1561 } 1613 }
1562 1614
1563 1615
1564 HeapEntry* HeapEntriesMap::Map(HeapThing thing) { 1616 HeapEntry* HeapEntriesMap::Map(HeapThing thing) {
1565 HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), false); 1617 HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), false);
1566 if (cache_entry != NULL) { 1618 if (cache_entry != NULL) {
1567 EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(cache_entry->value); 1619 EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(cache_entry->value);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 HeapObject* object = HeapObject::cast(obj); 1679 HeapObject* object = HeapObject::cast(obj);
1628 HashMap::Entry* cache_entry = 1680 HashMap::Entry* cache_entry =
1629 entries_.Lookup(object, HeapEntriesMap::Hash(object), true); 1681 entries_.Lookup(object, HeapEntriesMap::Hash(object), true);
1630 if (cache_entry->value == NULL) { 1682 if (cache_entry->value == NULL) {
1631 cache_entry->value = HeapEntriesMap::kHeapEntryPlaceholder; 1683 cache_entry->value = HeapEntriesMap::kHeapEntryPlaceholder;
1632 } 1684 }
1633 } 1685 }
1634 1686
1635 1687
1636 HeapObject *const V8HeapExplorer::kInternalRootObject = 1688 HeapObject *const V8HeapExplorer::kInternalRootObject =
1637 reinterpret_cast<HeapObject*>(1); 1689 reinterpret_cast<HeapObject*>(
1690 static_cast<intptr_t>(HeapObjectsMap::kInternalRootObjectId));
1638 HeapObject *const V8HeapExplorer::kGcRootsObject = 1691 HeapObject *const V8HeapExplorer::kGcRootsObject =
1639 reinterpret_cast<HeapObject*>(2); 1692 reinterpret_cast<HeapObject*>(
1693 static_cast<intptr_t>(HeapObjectsMap::kGcRootsObjectId));
1640 1694
1641 1695
1642 V8HeapExplorer::V8HeapExplorer( 1696 V8HeapExplorer::V8HeapExplorer(
1643 HeapSnapshot* snapshot, 1697 HeapSnapshot* snapshot,
1644 SnapshottingProgressReportingInterface* progress) 1698 SnapshottingProgressReportingInterface* progress)
1645 : snapshot_(snapshot), 1699 : snapshot_(snapshot),
1646 collection_(snapshot_->collection()), 1700 collection_(snapshot_->collection()),
1647 progress_(progress), 1701 progress_(progress),
1648 filler_(NULL) { 1702 filler_(NULL) {
1649 } 1703 }
(...skipping 16 matching lines...) Expand all
1666 if (object == kInternalRootObject) { 1720 if (object == kInternalRootObject) {
1667 ASSERT(retainers_count == 0); 1721 ASSERT(retainers_count == 0);
1668 return snapshot_->AddRootEntry(children_count); 1722 return snapshot_->AddRootEntry(children_count);
1669 } else if (object == kGcRootsObject) { 1723 } else if (object == kGcRootsObject) {
1670 return snapshot_->AddGcRootsEntry(children_count, retainers_count); 1724 return snapshot_->AddGcRootsEntry(children_count, retainers_count);
1671 } else if (object->IsJSFunction()) { 1725 } else if (object->IsJSFunction()) {
1672 JSFunction* func = JSFunction::cast(object); 1726 JSFunction* func = JSFunction::cast(object);
1673 SharedFunctionInfo* shared = func->shared(); 1727 SharedFunctionInfo* shared = func->shared();
1674 return AddEntry(object, 1728 return AddEntry(object,
1675 HeapEntry::kClosure, 1729 HeapEntry::kClosure,
1676 collection_->GetName(String::cast(shared->name())), 1730 collection_->names()->GetName(String::cast(shared->name())),
1677 children_count, 1731 children_count,
1678 retainers_count); 1732 retainers_count);
1679 } else if (object->IsJSRegExp()) { 1733 } else if (object->IsJSRegExp()) {
1680 JSRegExp* re = JSRegExp::cast(object); 1734 JSRegExp* re = JSRegExp::cast(object);
1681 return AddEntry(object, 1735 return AddEntry(object,
1682 HeapEntry::kRegExp, 1736 HeapEntry::kRegExp,
1683 collection_->GetName(re->Pattern()), 1737 collection_->names()->GetName(re->Pattern()),
1684 children_count, 1738 children_count,
1685 retainers_count); 1739 retainers_count);
1686 } else if (object->IsJSObject()) { 1740 } else if (object->IsJSObject()) {
1687 return AddEntry(object, 1741 return AddEntry(object,
1688 HeapEntry::kObject, 1742 HeapEntry::kObject,
1689 collection_->GetName(GetConstructorNameForHeapProfile( 1743 collection_->names()->GetName(
1690 JSObject::cast(object))), 1744 GetConstructorNameForHeapProfile(
1745 JSObject::cast(object))),
1691 children_count, 1746 children_count,
1692 retainers_count); 1747 retainers_count);
1693 } else if (object->IsString()) { 1748 } else if (object->IsString()) {
1694 return AddEntry(object, 1749 return AddEntry(object,
1695 HeapEntry::kString, 1750 HeapEntry::kString,
1696 collection_->GetName(String::cast(object)), 1751 collection_->names()->GetName(String::cast(object)),
1697 children_count, 1752 children_count,
1698 retainers_count); 1753 retainers_count);
1699 } else if (object->IsCode()) { 1754 } else if (object->IsCode()) {
1700 return AddEntry(object, 1755 return AddEntry(object,
1701 HeapEntry::kCode, 1756 HeapEntry::kCode,
1702 "", 1757 "",
1703 children_count, 1758 children_count,
1704 retainers_count); 1759 retainers_count);
1705 } else if (object->IsSharedFunctionInfo()) { 1760 } else if (object->IsSharedFunctionInfo()) {
1706 SharedFunctionInfo* shared = SharedFunctionInfo::cast(object); 1761 SharedFunctionInfo* shared = SharedFunctionInfo::cast(object);
1707 return AddEntry(object, 1762 return AddEntry(object,
1708 HeapEntry::kCode, 1763 HeapEntry::kCode,
1709 collection_->GetName(String::cast(shared->name())), 1764 collection_->names()->GetName(String::cast(shared->name())),
1710 children_count, 1765 children_count,
1711 retainers_count); 1766 retainers_count);
1712 } else if (object->IsScript()) { 1767 } else if (object->IsScript()) {
1713 Script* script = Script::cast(object); 1768 Script* script = Script::cast(object);
1714 return AddEntry(object, 1769 return AddEntry(object,
1715 HeapEntry::kCode, 1770 HeapEntry::kCode,
1716 script->name()->IsString() ? 1771 script->name()->IsString() ?
1717 collection_->GetName(String::cast(script->name())) : "", 1772 collection_->names()->GetName(
1773 String::cast(script->name()))
1774 : "",
1718 children_count, 1775 children_count,
1719 retainers_count); 1776 retainers_count);
1720 } else if (object->IsFixedArray()) { 1777 } else if (object->IsFixedArray()) {
1721 return AddEntry(object, 1778 return AddEntry(object,
1722 HeapEntry::kArray, 1779 HeapEntry::kArray,
1723 "", 1780 "",
1724 children_count, 1781 children_count,
1725 retainers_count); 1782 retainers_count);
1726 } else if (object->IsHeapNumber()) { 1783 } else if (object->IsHeapNumber()) {
1727 return AddEntry(object, 1784 return AddEntry(object,
(...skipping 18 matching lines...) Expand all
1746 return snapshot_->AddEntry(type, 1803 return snapshot_->AddEntry(type,
1747 name, 1804 name,
1748 collection_->GetObjectId(object->address()), 1805 collection_->GetObjectId(object->address()),
1749 object->Size(), 1806 object->Size(),
1750 children_count, 1807 children_count,
1751 retainers_count); 1808 retainers_count);
1752 } 1809 }
1753 1810
1754 1811
1755 void V8HeapExplorer::AddRootEntries(SnapshotFillerInterface* filler) { 1812 void V8HeapExplorer::AddRootEntries(SnapshotFillerInterface* filler) {
1756 filler->AddEntry(kInternalRootObject); 1813 filler->AddEntry(kInternalRootObject, this);
1757 filler->AddEntry(kGcRootsObject); 1814 filler->AddEntry(kGcRootsObject, this);
1758 } 1815 }
1759 1816
1760 1817
1761 int V8HeapExplorer::EstimateObjectsCount() { 1818 int V8HeapExplorer::EstimateObjectsCount() {
1762 HeapIterator iterator(HeapIterator::kFilterUnreachable); 1819 HeapIterator iterator(HeapIterator::kFilterUnreachable);
1763 int objects_count = 0; 1820 int objects_count = 0;
1764 for (HeapObject* obj = iterator.next(); 1821 for (HeapObject* obj = iterator.next();
1765 obj != NULL; 1822 obj != NULL;
1766 obj = iterator.next(), ++objects_count) {} 1823 obj = iterator.next(), ++objects_count) {}
1767 return objects_count; 1824 return objects_count;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 int length = js_obj->GetInternalFieldCount(); 1994 int length = js_obj->GetInternalFieldCount();
1938 for (int i = 0; i < length; ++i) { 1995 for (int i = 0; i < length; ++i) {
1939 Object* o = js_obj->GetInternalField(i); 1996 Object* o = js_obj->GetInternalField(i);
1940 SetInternalReference(js_obj, entry, i, o); 1997 SetInternalReference(js_obj, entry, i, o);
1941 } 1998 }
1942 } 1999 }
1943 2000
1944 2001
1945 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) { 2002 HeapEntry* V8HeapExplorer::GetEntry(Object* obj) {
1946 if (!obj->IsHeapObject()) return NULL; 2003 if (!obj->IsHeapObject()) return NULL;
1947 return filler_->FindOrAddEntry(obj); 2004 return filler_->FindOrAddEntry(obj, this);
1948 } 2005 }
1949 2006
1950 2007
1951 class RootsReferencesExtractor : public ObjectVisitor { 2008 class RootsReferencesExtractor : public ObjectVisitor {
1952 public: 2009 public:
1953 explicit RootsReferencesExtractor(V8HeapExplorer* explorer) 2010 explicit RootsReferencesExtractor(V8HeapExplorer* explorer)
1954 : explorer_(explorer) { 2011 : explorer_(explorer) {
1955 } 2012 }
1956 void VisitPointers(Object** start, Object** end) { 2013 void VisitPointers(Object** start, Object** end) {
1957 for (Object** p = start; p < end; p++) explorer_->SetGcRootsReference(*p); 2014 for (Object** p = start; p < end; p++) explorer_->SetGcRootsReference(*p);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 2046
1990 void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj, 2047 void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj,
1991 HeapEntry* parent_entry, 2048 HeapEntry* parent_entry,
1992 String* reference_name, 2049 String* reference_name,
1993 Object* child_obj) { 2050 Object* child_obj) {
1994 HeapEntry* child_entry = GetEntry(child_obj); 2051 HeapEntry* child_entry = GetEntry(child_obj);
1995 if (child_entry != NULL) { 2052 if (child_entry != NULL) {
1996 filler_->SetNamedReference(HeapGraphEdge::kContextVariable, 2053 filler_->SetNamedReference(HeapGraphEdge::kContextVariable,
1997 parent_obj, 2054 parent_obj,
1998 parent_entry, 2055 parent_entry,
1999 collection_->GetName(reference_name), 2056 collection_->names()->GetName(reference_name),
2000 child_obj, 2057 child_obj,
2001 child_entry); 2058 child_entry);
2002 known_references_.Insert(child_obj); 2059 known_references_.Insert(child_obj);
2003 } 2060 }
2004 } 2061 }
2005 2062
2006 2063
2007 void V8HeapExplorer::SetElementReference(HeapObject* parent_obj, 2064 void V8HeapExplorer::SetElementReference(HeapObject* parent_obj,
2008 HeapEntry* parent_entry, 2065 HeapEntry* parent_entry,
2009 int index, 2066 int index,
(...skipping 30 matching lines...) Expand all
2040 2097
2041 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, 2098 void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
2042 HeapEntry* parent_entry, 2099 HeapEntry* parent_entry,
2043 int index, 2100 int index,
2044 Object* child_obj) { 2101 Object* child_obj) {
2045 HeapEntry* child_entry = GetEntry(child_obj); 2102 HeapEntry* child_entry = GetEntry(child_obj);
2046 if (child_entry != NULL) { 2103 if (child_entry != NULL) {
2047 filler_->SetNamedReference(HeapGraphEdge::kInternal, 2104 filler_->SetNamedReference(HeapGraphEdge::kInternal,
2048 parent_obj, 2105 parent_obj,
2049 parent_entry, 2106 parent_entry,
2050 collection_->GetName(index), 2107 collection_->names()->GetName(index),
2051 child_obj, 2108 child_obj,
2052 child_entry); 2109 child_entry);
2053 known_references_.Insert(child_obj); 2110 known_references_.Insert(child_obj);
2054 } 2111 }
2055 } 2112 }
2056 2113
2057 2114
2058 void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj, 2115 void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj,
2059 HeapEntry* parent_entry, 2116 HeapEntry* parent_entry,
2060 int index, 2117 int index,
(...skipping 14 matching lines...) Expand all
2075 HeapEntry* parent_entry, 2132 HeapEntry* parent_entry,
2076 String* reference_name, 2133 String* reference_name,
2077 Object* child_obj) { 2134 Object* child_obj) {
2078 HeapEntry* child_entry = GetEntry(child_obj); 2135 HeapEntry* child_entry = GetEntry(child_obj);
2079 if (child_entry != NULL) { 2136 if (child_entry != NULL) {
2080 HeapGraphEdge::Type type = reference_name->length() > 0 ? 2137 HeapGraphEdge::Type type = reference_name->length() > 0 ?
2081 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal; 2138 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal;
2082 filler_->SetNamedReference(type, 2139 filler_->SetNamedReference(type,
2083 parent_obj, 2140 parent_obj,
2084 parent_entry, 2141 parent_entry,
2085 collection_->GetName(reference_name), 2142 collection_->names()->GetName(reference_name),
2086 child_obj, 2143 child_obj,
2087 child_entry); 2144 child_entry);
2088 known_references_.Insert(child_obj); 2145 known_references_.Insert(child_obj);
2089 } 2146 }
2090 } 2147 }
2091 2148
2092 2149
2093 void V8HeapExplorer::SetPropertyShortcutReference( 2150 void V8HeapExplorer::SetPropertyShortcutReference(
2094 HeapObject* parent_obj, 2151 HeapObject* parent_obj,
2095 HeapEntry* parent_entry, 2152 HeapEntry* parent_entry,
2096 String* reference_name, 2153 String* reference_name,
2097 Object* child_obj) { 2154 Object* child_obj) {
2098 HeapEntry* child_entry = GetEntry(child_obj); 2155 HeapEntry* child_entry = GetEntry(child_obj);
2099 if (child_entry != NULL) { 2156 if (child_entry != NULL) {
2100 filler_->SetNamedReference(HeapGraphEdge::kShortcut, 2157 filler_->SetNamedReference(HeapGraphEdge::kShortcut,
2101 parent_obj, 2158 parent_obj,
2102 parent_entry, 2159 parent_entry,
2103 collection_->GetName(reference_name), 2160 collection_->names()->GetName(reference_name),
2104 child_obj, 2161 child_obj,
2105 child_entry); 2162 child_entry);
2106 } 2163 }
2107 } 2164 }
2108 2165
2109 2166
2110 void V8HeapExplorer::SetRootGcRootsReference() { 2167 void V8HeapExplorer::SetRootGcRootsReference() {
2111 filler_->SetIndexedAutoIndexReference( 2168 filler_->SetIndexedAutoIndexReference(
2112 HeapGraphEdge::kElement, 2169 HeapGraphEdge::kElement,
2113 kInternalRootObject, snapshot_->root(), 2170 kInternalRootObject, snapshot_->root(),
(...skipping 15 matching lines...) Expand all
2129 HeapEntry* child_entry = GetEntry(child_obj); 2186 HeapEntry* child_entry = GetEntry(child_obj);
2130 if (child_entry != NULL) { 2187 if (child_entry != NULL) {
2131 filler_->SetIndexedAutoIndexReference( 2188 filler_->SetIndexedAutoIndexReference(
2132 HeapGraphEdge::kElement, 2189 HeapGraphEdge::kElement,
2133 kGcRootsObject, snapshot_->gc_roots(), 2190 kGcRootsObject, snapshot_->gc_roots(),
2134 child_obj, child_entry); 2191 child_obj, child_entry);
2135 } 2192 }
2136 } 2193 }
2137 2194
2138 2195
2196 class GlobalHandlesExtractor : public ObjectVisitor {
2197 public:
2198 explicit GlobalHandlesExtractor(NativeObjectsExplorer* explorer)
2199 : explorer_(explorer) {}
2200 virtual ~GlobalHandlesExtractor() {}
2201 virtual void VisitPointers(Object** start, Object** end) {
2202 UNREACHABLE();
2203 }
2204 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {
2205 explorer_->VisitSubtreeWrapper(p, class_id);
2206 }
2207 private:
2208 NativeObjectsExplorer* explorer_;
2209 };
2210
2211 HeapThing const NativeObjectsExplorer::kNativesRootObject =
2212 reinterpret_cast<HeapThing>(
2213 static_cast<intptr_t>(HeapObjectsMap::kNativesRootObjectId));
2214
2215
2216 NativeObjectsExplorer::NativeObjectsExplorer(
2217 HeapSnapshot* snapshot, SnapshottingProgressReportingInterface* progress)
2218 : snapshot_(snapshot),
2219 collection_(snapshot_->collection()),
2220 progress_(progress),
2221 embedder_queried_(false),
2222 objects_by_info_(RetainedInfosMatch),
2223 filler_(NULL) {
2224 }
2225
2226
2227 NativeObjectsExplorer::~NativeObjectsExplorer() {
2228 for (HashMap::Entry* p = objects_by_info_.Start();
2229 p != NULL;
2230 p = objects_by_info_.Next(p)) {
2231 v8::RetainedObjectInfo* info =
2232 reinterpret_cast<v8::RetainedObjectInfo*>(p->key);
2233 info->Dispose();
2234 List<HeapObject*>* objects =
2235 reinterpret_cast<List<HeapObject*>* >(p->value);
2236 delete objects;
2237 }
2238 }
2239
2240
2241 HeapEntry* NativeObjectsExplorer::AllocateEntry(
2242 HeapThing ptr, int children_count, int retainers_count) {
2243 if (ptr == kNativesRootObject) {
2244 return snapshot_->AddNativesRootEntry(children_count, retainers_count);
2245 } else {
2246 v8::RetainedObjectInfo* info =
2247 reinterpret_cast<v8::RetainedObjectInfo*>(ptr);
2248 intptr_t elements = info->GetElementCount();
2249 intptr_t size = info->GetSizeInBytes();
2250 return snapshot_->AddEntry(
2251 HeapEntry::kNative,
2252 elements != -1 ?
2253 collection_->names()->GetFormatted(
2254 "%s / %" V8_PTR_PREFIX "d entries",
2255 info->GetLabel(),
2256 info->GetElementCount()) :
2257 collection_->names()->GetCopy(info->GetLabel()),
2258 HeapObjectsMap::GenerateId(info),
2259 size != -1 ? static_cast<int>(size) : 0,
2260 children_count,
2261 retainers_count);
2262 }
2263 }
2264
2265
2266 void NativeObjectsExplorer::AddRootEntries(SnapshotFillerInterface* filler) {
2267 if (EstimateObjectsCount() <= 0) return;
2268 filler->AddEntry(kNativesRootObject, this);
2269 }
2270
2271
2272 int NativeObjectsExplorer::EstimateObjectsCount() {
2273 FillRetainedObjects();
2274 return objects_by_info_.occupancy();
2275 }
2276
2277
2278 void NativeObjectsExplorer::FillRetainedObjects() {
2279 if (embedder_queried_) return;
2280 Isolate* isolate = Isolate::Current();
2281 // Record objects that are joined into ObjectGroups.
2282 isolate->heap()->CallGlobalGCPrologueCallback();
2283 List<ObjectGroup*>* groups = isolate->global_handles()->object_groups();
2284 for (int i = 0; i < groups->length(); ++i) {
2285 ObjectGroup* group = groups->at(i);
2286 if (group->info_ == NULL) continue;
2287 List<HeapObject*>* list = GetListMaybeDisposeInfo(group->info_);
2288 for (int j = 0; j < group->objects_.length(); ++j) {
2289 HeapObject* obj = HeapObject::cast(*group->objects_[j]);
2290 list->Add(obj);
2291 in_groups_.Insert(obj);
2292 }
2293 group->info_ = NULL; // Acquire info object ownership.
2294 }
2295 isolate->global_handles()->RemoveObjectGroups();
2296 isolate->heap()->CallGlobalGCEpilogueCallback();
2297 // Record objects that are not in ObjectGroups, but have class ID.
2298 GlobalHandlesExtractor extractor(this);
2299 isolate->global_handles()->IterateAllRootsWithClassIds(&extractor);
2300 embedder_queried_ = true;
2301 }
2302
2303
2304 List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo(
2305 v8::RetainedObjectInfo* info) {
2306 HashMap::Entry* entry =
2307 objects_by_info_.Lookup(info, InfoHash(info), true);
2308 if (entry->value != NULL) {
2309 info->Dispose();
2310 } else {
2311 entry->value = new List<HeapObject*>(4);
2312 }
2313 return reinterpret_cast<List<HeapObject*>* >(entry->value);
2314 }
2315
2316
2317 bool NativeObjectsExplorer::IterateAndExtractReferences(
2318 SnapshotFillerInterface* filler) {
2319 if (EstimateObjectsCount() <= 0) return true;
2320 filler_ = filler;
2321 FillRetainedObjects();
2322 for (HashMap::Entry* p = objects_by_info_.Start();
2323 p != NULL;
2324 p = objects_by_info_.Next(p)) {
2325 v8::RetainedObjectInfo* info =
2326 reinterpret_cast<v8::RetainedObjectInfo*>(p->key);
2327 SetNativeRootReference(info);
2328 List<HeapObject*>* objects =
2329 reinterpret_cast<List<HeapObject*>* >(p->value);
2330 for (int i = 0; i < objects->length(); ++i) {
2331 SetWrapperNativeReferences(objects->at(i), info);
2332 }
2333 }
2334 SetRootNativesRootReference();
2335 filler_ = NULL;
2336 return true;
2337 }
2338
2339
2340 void NativeObjectsExplorer::SetNativeRootReference(
2341 v8::RetainedObjectInfo* info) {
2342 HeapEntry* child_entry = filler_->FindOrAddEntry(info, this);
2343 ASSERT(child_entry != NULL);
2344 filler_->SetIndexedAutoIndexReference(
2345 HeapGraphEdge::kElement,
2346 kNativesRootObject, snapshot_->natives_root(),
2347 info, child_entry);
2348 }
2349
2350
2351 void NativeObjectsExplorer::SetWrapperNativeReferences(
2352 HeapObject* wrapper, v8::RetainedObjectInfo* info) {
2353 HeapEntry* wrapper_entry = filler_->FindEntry(wrapper);
2354 ASSERT(wrapper_entry != NULL);
2355 HeapEntry* info_entry = filler_->FindOrAddEntry(info, this);
2356 ASSERT(info_entry != NULL);
2357 filler_->SetNamedReference(HeapGraphEdge::kInternal,
2358 wrapper, wrapper_entry,
2359 "Native",
2360 info, info_entry);
2361 filler_->SetIndexedAutoIndexReference(HeapGraphEdge::kElement,
2362 info, info_entry,
2363 wrapper, wrapper_entry);
2364 }
2365
2366
2367 void NativeObjectsExplorer::SetRootNativesRootReference() {
2368 filler_->SetIndexedAutoIndexReference(
2369 HeapGraphEdge::kElement,
2370 V8HeapExplorer::kInternalRootObject, snapshot_->root(),
2371 kNativesRootObject, snapshot_->natives_root());
2372 }
2373
2374
2375 void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) {
2376 if (in_groups_.Contains(*p)) return;
2377 Isolate* isolate = Isolate::Current();
2378 v8::RetainedObjectInfo* info =
2379 isolate->heap_profiler()->ExecuteWrapperClassCallback(class_id, p);
2380 if (info == NULL) return;
2381 GetListMaybeDisposeInfo(info)->Add(HeapObject::cast(*p));
2382 }
2383
2384
2139 HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot, 2385 HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot,
2140 v8::ActivityControl* control) 2386 v8::ActivityControl* control)
2141 : snapshot_(snapshot), 2387 : snapshot_(snapshot),
2142 control_(control), 2388 control_(control),
2143 v8_heap_explorer_(snapshot_, this) { 2389 v8_heap_explorer_(snapshot_, this),
2390 dom_explorer_(snapshot_, this) {
2144 } 2391 }
2145 2392
2146 2393
2147 class SnapshotCounter : public SnapshotFillerInterface { 2394 class SnapshotCounter : public SnapshotFillerInterface {
2148 public: 2395 public:
2149 SnapshotCounter(HeapEntriesAllocator* allocator, HeapEntriesMap* entries) 2396 explicit SnapshotCounter(HeapEntriesMap* entries) : entries_(entries) { }
2150 : allocator_(allocator), entries_(entries) { } 2397 HeapEntry* AddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
2151 HeapEntry* AddEntry(HeapThing ptr) { 2398 entries_->Pair(ptr, allocator, HeapEntriesMap::kHeapEntryPlaceholder);
2152 entries_->Pair(ptr, allocator_, HeapEntriesMap::kHeapEntryPlaceholder);
2153 return HeapEntriesMap::kHeapEntryPlaceholder; 2399 return HeapEntriesMap::kHeapEntryPlaceholder;
2154 } 2400 }
2155 HeapEntry* FindOrAddEntry(HeapThing ptr) { 2401 HeapEntry* FindEntry(HeapThing ptr) {
2156 HeapEntry* entry = entries_->Map(ptr); 2402 return entries_->Map(ptr);
2157 return entry != NULL ? entry : AddEntry(ptr); 2403 }
2404 HeapEntry* FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
2405 HeapEntry* entry = FindEntry(ptr);
2406 return entry != NULL ? entry : AddEntry(ptr, allocator);
2158 } 2407 }
2159 void SetIndexedReference(HeapGraphEdge::Type, 2408 void SetIndexedReference(HeapGraphEdge::Type,
2160 HeapThing parent_ptr, 2409 HeapThing parent_ptr,
2161 HeapEntry*, 2410 HeapEntry*,
2162 int, 2411 int,
2163 HeapThing child_ptr, 2412 HeapThing child_ptr,
2164 HeapEntry*) { 2413 HeapEntry*) {
2165 entries_->CountReference(parent_ptr, child_ptr); 2414 entries_->CountReference(parent_ptr, child_ptr);
2166 } 2415 }
2167 void SetIndexedAutoIndexReference(HeapGraphEdge::Type, 2416 void SetIndexedAutoIndexReference(HeapGraphEdge::Type,
(...skipping 12 matching lines...) Expand all
2180 entries_->CountReference(parent_ptr, child_ptr); 2429 entries_->CountReference(parent_ptr, child_ptr);
2181 } 2430 }
2182 void SetNamedAutoIndexReference(HeapGraphEdge::Type, 2431 void SetNamedAutoIndexReference(HeapGraphEdge::Type,
2183 HeapThing parent_ptr, 2432 HeapThing parent_ptr,
2184 HeapEntry*, 2433 HeapEntry*,
2185 HeapThing child_ptr, 2434 HeapThing child_ptr,
2186 HeapEntry*) { 2435 HeapEntry*) {
2187 entries_->CountReference(parent_ptr, child_ptr); 2436 entries_->CountReference(parent_ptr, child_ptr);
2188 } 2437 }
2189 private: 2438 private:
2190 HeapEntriesAllocator* allocator_;
2191 HeapEntriesMap* entries_; 2439 HeapEntriesMap* entries_;
2192 }; 2440 };
2193 2441
2194 2442
2195 class SnapshotFiller : public SnapshotFillerInterface { 2443 class SnapshotFiller : public SnapshotFillerInterface {
2196 public: 2444 public:
2197 explicit SnapshotFiller(HeapSnapshot* snapshot, HeapEntriesMap* entries) 2445 explicit SnapshotFiller(HeapSnapshot* snapshot, HeapEntriesMap* entries)
2198 : snapshot_(snapshot), 2446 : snapshot_(snapshot),
2199 collection_(snapshot->collection()), 2447 collection_(snapshot->collection()),
2200 entries_(entries) { } 2448 entries_(entries) { }
2201 HeapEntry* AddEntry(HeapThing ptr) { 2449 HeapEntry* AddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
2202 UNREACHABLE(); 2450 UNREACHABLE();
2203 return NULL; 2451 return NULL;
2204 } 2452 }
2205 HeapEntry* FindOrAddEntry(HeapThing ptr) { 2453 HeapEntry* FindEntry(HeapThing ptr) {
2206 HeapEntry* entry = entries_->Map(ptr); 2454 return entries_->Map(ptr);
2207 return entry != NULL ? entry : AddEntry(ptr); 2455 }
2456 HeapEntry* FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
2457 HeapEntry* entry = FindEntry(ptr);
2458 return entry != NULL ? entry : AddEntry(ptr, allocator);
2208 } 2459 }
2209 void SetIndexedReference(HeapGraphEdge::Type type, 2460 void SetIndexedReference(HeapGraphEdge::Type type,
2210 HeapThing parent_ptr, 2461 HeapThing parent_ptr,
2211 HeapEntry* parent_entry, 2462 HeapEntry* parent_entry,
2212 int index, 2463 int index,
2213 HeapThing child_ptr, 2464 HeapThing child_ptr,
2214 HeapEntry* child_entry) { 2465 HeapEntry* child_entry) {
2215 int child_index, retainer_index; 2466 int child_index, retainer_index;
2216 entries_->CountReference( 2467 entries_->CountReference(
2217 parent_ptr, child_ptr, &child_index, &retainer_index); 2468 parent_ptr, child_ptr, &child_index, &retainer_index);
(...skipping 26 matching lines...) Expand all
2244 void SetNamedAutoIndexReference(HeapGraphEdge::Type type, 2495 void SetNamedAutoIndexReference(HeapGraphEdge::Type type,
2245 HeapThing parent_ptr, 2496 HeapThing parent_ptr,
2246 HeapEntry* parent_entry, 2497 HeapEntry* parent_entry,
2247 HeapThing child_ptr, 2498 HeapThing child_ptr,
2248 HeapEntry* child_entry) { 2499 HeapEntry* child_entry) {
2249 int child_index, retainer_index; 2500 int child_index, retainer_index;
2250 entries_->CountReference( 2501 entries_->CountReference(
2251 parent_ptr, child_ptr, &child_index, &retainer_index); 2502 parent_ptr, child_ptr, &child_index, &retainer_index);
2252 parent_entry->SetNamedReference(type, 2503 parent_entry->SetNamedReference(type,
2253 child_index, 2504 child_index,
2254 collection_->GetName(child_index + 1), 2505 collection_->names()->GetName(child_index + 1),
2255 child_entry, 2506 child_entry,
2256 retainer_index); 2507 retainer_index);
2257 } 2508 }
2258 private: 2509 private:
2259 HeapSnapshot* snapshot_; 2510 HeapSnapshot* snapshot_;
2260 HeapSnapshotsCollection* collection_; 2511 HeapSnapshotsCollection* collection_;
2261 HeapEntriesMap* entries_; 2512 HeapEntriesMap* entries_;
2262 }; 2513 };
2263 2514
2264 2515
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2300 return 2551 return
2301 control_->ReportProgressValue(progress_counter_, progress_total_) == 2552 control_->ReportProgressValue(progress_counter_, progress_total_) ==
2302 v8::ActivityControl::kContinue; 2553 v8::ActivityControl::kContinue;
2303 } 2554 }
2304 return true; 2555 return true;
2305 } 2556 }
2306 2557
2307 2558
2308 void HeapSnapshotGenerator::SetProgressTotal(int iterations_count) { 2559 void HeapSnapshotGenerator::SetProgressTotal(int iterations_count) {
2309 if (control_ == NULL) return; 2560 if (control_ == NULL) return;
2310 progress_total_ = v8_heap_explorer_.EstimateObjectsCount() * iterations_count; 2561 progress_total_ = (
2562 v8_heap_explorer_.EstimateObjectsCount() +
2563 dom_explorer_.EstimateObjectsCount()) * iterations_count;
2311 progress_counter_ = 0; 2564 progress_counter_ = 0;
2312 } 2565 }
2313 2566
2314 2567
2315 bool HeapSnapshotGenerator::CountEntriesAndReferences() { 2568 bool HeapSnapshotGenerator::CountEntriesAndReferences() {
2316 SnapshotCounter counter(&v8_heap_explorer_, &entries_); 2569 SnapshotCounter counter(&entries_);
2317 v8_heap_explorer_.AddRootEntries(&counter); 2570 v8_heap_explorer_.AddRootEntries(&counter);
2318 return v8_heap_explorer_.IterateAndExtractReferences(&counter); 2571 dom_explorer_.AddRootEntries(&counter);
2572 return
2573 v8_heap_explorer_.IterateAndExtractReferences(&counter) &&
2574 dom_explorer_.IterateAndExtractReferences(&counter);
2319 } 2575 }
2320 2576
2321 2577
2322 bool HeapSnapshotGenerator::FillReferences() { 2578 bool HeapSnapshotGenerator::FillReferences() {
2323 SnapshotFiller filler(snapshot_, &entries_); 2579 SnapshotFiller filler(snapshot_, &entries_);
2324 return v8_heap_explorer_.IterateAndExtractReferences(&filler); 2580 return
2581 v8_heap_explorer_.IterateAndExtractReferences(&filler) &&
2582 dom_explorer_.IterateAndExtractReferences(&filler);
2325 } 2583 }
2326 2584
2327 2585
2328 void HeapSnapshotGenerator::FillReversePostorderIndexes( 2586 void HeapSnapshotGenerator::FillReversePostorderIndexes(
2329 Vector<HeapEntry*>* entries) { 2587 Vector<HeapEntry*>* entries) {
2330 snapshot_->ClearPaint(); 2588 snapshot_->ClearPaint();
2331 int current_entry = 0; 2589 int current_entry = 0;
2332 List<HeapEntry*> nodes_to_visit; 2590 List<HeapEntry*> nodes_to_visit;
2333 nodes_to_visit.Add(snapshot_->root()); 2591 nodes_to_visit.Add(snapshot_->root());
2334 snapshot_->root()->paint_reachable(); 2592 snapshot_->root()->paint_reachable();
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
2732 "," JSON_S("children")) 2990 "," JSON_S("children"))
2733 "," JSON_S("types") ":" JSON_A( 2991 "," JSON_S("types") ":" JSON_A(
2734 JSON_A( 2992 JSON_A(
2735 JSON_S("hidden") 2993 JSON_S("hidden")
2736 "," JSON_S("array") 2994 "," JSON_S("array")
2737 "," JSON_S("string") 2995 "," JSON_S("string")
2738 "," JSON_S("object") 2996 "," JSON_S("object")
2739 "," JSON_S("code") 2997 "," JSON_S("code")
2740 "," JSON_S("closure") 2998 "," JSON_S("closure")
2741 "," JSON_S("regexp") 2999 "," JSON_S("regexp")
2742 "," JSON_S("number")) 3000 "," JSON_S("number")
3001 "," JSON_S("native"))
2743 "," JSON_S("string") 3002 "," JSON_S("string")
2744 "," JSON_S("number") 3003 "," JSON_S("number")
2745 "," JSON_S("number") 3004 "," JSON_S("number")
2746 "," JSON_S("number") 3005 "," JSON_S("number")
2747 "," JSON_S("number") 3006 "," JSON_S("number")
2748 "," JSON_S("number") 3007 "," JSON_S("number")
2749 "," JSON_O( 3008 "," JSON_O(
2750 JSON_S("fields") ":" JSON_A( 3009 JSON_S("fields") ":" JSON_A(
2751 JSON_S("type") 3010 JSON_S("type")
2752 "," JSON_S("name_or_index") 3011 "," JSON_S("name_or_index")
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2894 3153
2895 3154
2896 String* GetConstructorNameForHeapProfile(JSObject* object) { 3155 String* GetConstructorNameForHeapProfile(JSObject* object) {
2897 if (object->IsJSFunction()) return HEAP->closure_symbol(); 3156 if (object->IsJSFunction()) return HEAP->closure_symbol();
2898 return object->constructor_name(); 3157 return object->constructor_name();
2899 } 3158 }
2900 3159
2901 } } // namespace v8::internal 3160 } } // namespace v8::internal
2902 3161
2903 #endif // ENABLE_LOGGING_AND_PROFILING 3162 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/profile-generator.h ('k') | src/v8globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698