| 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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 bottom_up_.Print(); | 485 bottom_up_.Print(); |
| 486 } | 486 } |
| 487 | 487 |
| 488 | 488 |
| 489 CodeEntry* const CodeMap::kSharedFunctionCodeEntry = NULL; | 489 CodeEntry* const CodeMap::kSharedFunctionCodeEntry = NULL; |
| 490 const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL; | 490 const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL; |
| 491 const CodeMap::CodeTreeConfig::Value CodeMap::CodeTreeConfig::kNoValue = | 491 const CodeMap::CodeTreeConfig::Value CodeMap::CodeTreeConfig::kNoValue = |
| 492 CodeMap::CodeEntryInfo(NULL, 0); | 492 CodeMap::CodeEntryInfo(NULL, 0); |
| 493 | 493 |
| 494 | 494 |
| 495 void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) { |
| 496 DeleteAllCoveredCode(addr, addr + size); |
| 497 CodeTree::Locator locator; |
| 498 tree_.Insert(addr, &locator); |
| 499 locator.set_value(CodeEntryInfo(entry, size)); |
| 500 } |
| 501 |
| 502 |
| 503 void CodeMap::DeleteAllCoveredCode(Address start, Address end) { |
| 504 List<Address> to_delete; |
| 505 Address addr = end - 1; |
| 506 while (addr >= start) { |
| 507 CodeTree::Locator locator; |
| 508 if (!tree_.FindGreatestLessThan(addr, &locator)) break; |
| 509 Address start2 = locator.key(), end2 = start2 + locator.value().size; |
| 510 if (start2 < end && start < end2) to_delete.Add(start2); |
| 511 addr = start2 - 1; |
| 512 } |
| 513 for (int i = 0; i < to_delete.length(); ++i) tree_.Remove(to_delete[i]); |
| 514 } |
| 515 |
| 516 |
| 495 CodeEntry* CodeMap::FindEntry(Address addr) { | 517 CodeEntry* CodeMap::FindEntry(Address addr) { |
| 496 CodeTree::Locator locator; | 518 CodeTree::Locator locator; |
| 497 if (tree_.FindGreatestLessThan(addr, &locator)) { | 519 if (tree_.FindGreatestLessThan(addr, &locator)) { |
| 498 // locator.key() <= addr. Need to check that addr is within entry. | 520 // locator.key() <= addr. Need to check that addr is within entry. |
| 499 const CodeEntryInfo& entry = locator.value(); | 521 const CodeEntryInfo& entry = locator.value(); |
| 500 if (addr < (locator.key() + entry.size)) | 522 if (addr < (locator.key() + entry.size)) |
| 501 return entry.entry; | 523 return entry.entry; |
| 502 } | 524 } |
| 503 return NULL; | 525 return NULL; |
| 504 } | 526 } |
| 505 | 527 |
| 506 | 528 |
| 507 int CodeMap::GetSharedId(Address addr) { | 529 int CodeMap::GetSharedId(Address addr) { |
| 508 CodeTree::Locator locator; | 530 CodeTree::Locator locator; |
| 509 // For shared function entries, 'size' field is used to store their IDs. | 531 // For shared function entries, 'size' field is used to store their IDs. |
| 510 if (tree_.Find(addr, &locator)) { | 532 if (tree_.Find(addr, &locator)) { |
| 511 const CodeEntryInfo& entry = locator.value(); | 533 const CodeEntryInfo& entry = locator.value(); |
| 512 ASSERT(entry.entry == kSharedFunctionCodeEntry); | 534 ASSERT(entry.entry == kSharedFunctionCodeEntry); |
| 513 return entry.size; | 535 return entry.size; |
| 514 } else { | 536 } else { |
| 515 tree_.Insert(addr, &locator); | 537 tree_.Insert(addr, &locator); |
| 516 int id = next_shared_id_++; | 538 int id = next_shared_id_++; |
| 517 locator.set_value(CodeEntryInfo(kSharedFunctionCodeEntry, id)); | 539 locator.set_value(CodeEntryInfo(kSharedFunctionCodeEntry, id)); |
| 518 return id; | 540 return id; |
| 519 } | 541 } |
| 520 } | 542 } |
| 521 | 543 |
| 522 | 544 |
| 545 void CodeMap::MoveCode(Address from, Address to) { |
| 546 if (from == to) return; |
| 547 CodeTree::Locator locator; |
| 548 if (!tree_.Find(from, &locator)) return; |
| 549 CodeEntryInfo entry = locator.value(); |
| 550 tree_.Remove(from); |
| 551 AddCode(to, entry.entry, entry.size); |
| 552 } |
| 553 |
| 554 |
| 523 void CodeMap::CodeTreePrinter::Call( | 555 void CodeMap::CodeTreePrinter::Call( |
| 524 const Address& key, const CodeMap::CodeEntryInfo& value) { | 556 const Address& key, const CodeMap::CodeEntryInfo& value) { |
| 525 OS::Print("%p %5d %s\n", key, value.size, value.entry->name()); | 557 OS::Print("%p %5d %s\n", key, value.size, value.entry->name()); |
| 526 } | 558 } |
| 527 | 559 |
| 528 | 560 |
| 529 void CodeMap::Print() { | 561 void CodeMap::Print() { |
| 530 CodeTreePrinter printer; | 562 CodeTreePrinter printer; |
| 531 tree_.ForEach(&printer); | 563 tree_.ForEach(&printer); |
| 532 } | 564 } |
| (...skipping 2761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3294 | 3326 |
| 3295 | 3327 |
| 3296 void HeapSnapshotJSONSerializer::SortHashMap( | 3328 void HeapSnapshotJSONSerializer::SortHashMap( |
| 3297 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3329 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
| 3298 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3330 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
| 3299 sorted_entries->Add(p); | 3331 sorted_entries->Add(p); |
| 3300 sorted_entries->Sort(SortUsingEntryValue); | 3332 sorted_entries->Sort(SortUsingEntryValue); |
| 3301 } | 3333 } |
| 3302 | 3334 |
| 3303 } } // namespace v8::internal | 3335 } } // namespace v8::internal |
| OLD | NEW |