OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/heap/heap.h" | 5 #include "src/heap/heap.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/ast/context-slot-cache.h" | 9 #include "src/ast/context-slot-cache.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 SetGCState(NOT_IN_GC); | 1731 SetGCState(NOT_IN_GC); |
1732 } | 1732 } |
1733 | 1733 |
1734 | 1734 |
1735 String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap, | 1735 String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap, |
1736 Object** p) { | 1736 Object** p) { |
1737 MapWord first_word = HeapObject::cast(*p)->map_word(); | 1737 MapWord first_word = HeapObject::cast(*p)->map_word(); |
1738 | 1738 |
1739 if (!first_word.IsForwardingAddress()) { | 1739 if (!first_word.IsForwardingAddress()) { |
1740 // Unreachable external string can be finalized. | 1740 // Unreachable external string can be finalized. |
1741 heap->FinalizeExternalString(String::cast(*p)); | 1741 String* string = String::cast(*p); |
| 1742 if (!string->IsExternalString()) { |
| 1743 // Original external string has been internalized. |
| 1744 DCHECK(string->IsThinString()); |
| 1745 return NULL; |
| 1746 } |
| 1747 heap->FinalizeExternalString(string); |
1742 return NULL; | 1748 return NULL; |
1743 } | 1749 } |
1744 | 1750 |
1745 // String is still reachable. | 1751 // String is still reachable. |
1746 return String::cast(first_word.ToForwardingAddress()); | 1752 String* string = String::cast(first_word.ToForwardingAddress()); |
| 1753 if (string->IsThinString()) string = ThinString::cast(string)->actual(); |
| 1754 // Internalization can replace external strings with non-external strings. |
| 1755 return string->IsExternalString() ? string : nullptr; |
1747 } | 1756 } |
1748 | 1757 |
1749 | 1758 |
1750 void Heap::UpdateNewSpaceReferencesInExternalStringTable( | 1759 void Heap::UpdateNewSpaceReferencesInExternalStringTable( |
1751 ExternalStringTableUpdaterCallback updater_func) { | 1760 ExternalStringTableUpdaterCallback updater_func) { |
1752 if (external_string_table_.new_space_strings_.is_empty()) return; | 1761 if (external_string_table_.new_space_strings_.is_empty()) return; |
1753 | 1762 |
1754 Object** start = &external_string_table_.new_space_strings_[0]; | 1763 Object** start = &external_string_table_.new_space_strings_[0]; |
1755 Object** end = start + external_string_table_.new_space_strings_.length(); | 1764 Object** end = start + external_string_table_.new_space_strings_.length(); |
1756 Object** last = start; | 1765 Object** last = start; |
(...skipping 4673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6430 void Heap::UpdateTotalGCTime(double duration) { | 6439 void Heap::UpdateTotalGCTime(double duration) { |
6431 if (FLAG_trace_gc_verbose) { | 6440 if (FLAG_trace_gc_verbose) { |
6432 total_gc_time_ms_ += duration; | 6441 total_gc_time_ms_ += duration; |
6433 } | 6442 } |
6434 } | 6443 } |
6435 | 6444 |
6436 void Heap::ExternalStringTable::CleanUpNewSpaceStrings() { | 6445 void Heap::ExternalStringTable::CleanUpNewSpaceStrings() { |
6437 int last = 0; | 6446 int last = 0; |
6438 Isolate* isolate = heap_->isolate(); | 6447 Isolate* isolate = heap_->isolate(); |
6439 for (int i = 0; i < new_space_strings_.length(); ++i) { | 6448 for (int i = 0; i < new_space_strings_.length(); ++i) { |
6440 if (new_space_strings_[i]->IsTheHole(isolate)) { | 6449 Object* o = new_space_strings_[i]; |
| 6450 if (o->IsTheHole(isolate)) { |
6441 continue; | 6451 continue; |
6442 } | 6452 } |
6443 DCHECK(new_space_strings_[i]->IsExternalString()); | 6453 if (o->IsThinString()) { |
6444 if (heap_->InNewSpace(new_space_strings_[i])) { | 6454 o = ThinString::cast(o)->actual(); |
6445 new_space_strings_[last++] = new_space_strings_[i]; | 6455 if (!o->IsExternalString()) continue; |
| 6456 } |
| 6457 DCHECK(o->IsExternalString()); |
| 6458 if (heap_->InNewSpace(o)) { |
| 6459 new_space_strings_[last++] = o; |
6446 } else { | 6460 } else { |
6447 old_space_strings_.Add(new_space_strings_[i]); | 6461 old_space_strings_.Add(o); |
6448 } | 6462 } |
6449 } | 6463 } |
6450 new_space_strings_.Rewind(last); | 6464 new_space_strings_.Rewind(last); |
6451 new_space_strings_.Trim(); | 6465 new_space_strings_.Trim(); |
6452 } | 6466 } |
6453 | 6467 |
6454 void Heap::ExternalStringTable::CleanUpAll() { | 6468 void Heap::ExternalStringTable::CleanUpAll() { |
6455 CleanUpNewSpaceStrings(); | 6469 CleanUpNewSpaceStrings(); |
6456 int last = 0; | 6470 int last = 0; |
6457 Isolate* isolate = heap_->isolate(); | 6471 Isolate* isolate = heap_->isolate(); |
6458 for (int i = 0; i < old_space_strings_.length(); ++i) { | 6472 for (int i = 0; i < old_space_strings_.length(); ++i) { |
6459 if (old_space_strings_[i]->IsTheHole(isolate)) { | 6473 Object* o = old_space_strings_[i]; |
| 6474 if (o->IsTheHole(isolate)) { |
6460 continue; | 6475 continue; |
6461 } | 6476 } |
6462 DCHECK(old_space_strings_[i]->IsExternalString()); | 6477 if (o->IsThinString()) { |
6463 DCHECK(!heap_->InNewSpace(old_space_strings_[i])); | 6478 o = ThinString::cast(o)->actual(); |
6464 old_space_strings_[last++] = old_space_strings_[i]; | 6479 if (!o->IsExternalString()) continue; |
| 6480 } |
| 6481 DCHECK(o->IsExternalString()); |
| 6482 DCHECK(!heap_->InNewSpace(o)); |
| 6483 old_space_strings_[last++] = o; |
6465 } | 6484 } |
6466 old_space_strings_.Rewind(last); | 6485 old_space_strings_.Rewind(last); |
6467 old_space_strings_.Trim(); | 6486 old_space_strings_.Trim(); |
6468 #ifdef VERIFY_HEAP | 6487 #ifdef VERIFY_HEAP |
6469 if (FLAG_verify_heap) { | 6488 if (FLAG_verify_heap) { |
6470 Verify(); | 6489 Verify(); |
6471 } | 6490 } |
6472 #endif | 6491 #endif |
6473 } | 6492 } |
6474 | 6493 |
6475 void Heap::ExternalStringTable::TearDown() { | 6494 void Heap::ExternalStringTable::TearDown() { |
6476 for (int i = 0; i < new_space_strings_.length(); ++i) { | 6495 for (int i = 0; i < new_space_strings_.length(); ++i) { |
6477 heap_->FinalizeExternalString(ExternalString::cast(new_space_strings_[i])); | 6496 Object* o = new_space_strings_[i]; |
| 6497 if (o->IsThinString()) { |
| 6498 o = ThinString::cast(o)->actual(); |
| 6499 if (!o->IsExternalString()) continue; |
| 6500 } |
| 6501 heap_->FinalizeExternalString(ExternalString::cast(o)); |
6478 } | 6502 } |
6479 new_space_strings_.Free(); | 6503 new_space_strings_.Free(); |
6480 for (int i = 0; i < old_space_strings_.length(); ++i) { | 6504 for (int i = 0; i < old_space_strings_.length(); ++i) { |
6481 heap_->FinalizeExternalString(ExternalString::cast(old_space_strings_[i])); | 6505 Object* o = old_space_strings_[i]; |
| 6506 if (o->IsThinString()) { |
| 6507 o = ThinString::cast(o)->actual(); |
| 6508 if (!o->IsExternalString()) continue; |
| 6509 } |
| 6510 heap_->FinalizeExternalString(ExternalString::cast(o)); |
6482 } | 6511 } |
6483 old_space_strings_.Free(); | 6512 old_space_strings_.Free(); |
6484 } | 6513 } |
6485 | 6514 |
6486 | 6515 |
6487 void Heap::RememberUnmappedPage(Address page, bool compacted) { | 6516 void Heap::RememberUnmappedPage(Address page, bool compacted) { |
6488 uintptr_t p = reinterpret_cast<uintptr_t>(page); | 6517 uintptr_t p = reinterpret_cast<uintptr_t>(page); |
6489 // Tag the page pointer to make it findable in the dump file. | 6518 // Tag the page pointer to make it findable in the dump file. |
6490 if (compacted) { | 6519 if (compacted) { |
6491 p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. | 6520 p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6586 } | 6615 } |
6587 | 6616 |
6588 | 6617 |
6589 // static | 6618 // static |
6590 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6619 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6591 return StaticVisitorBase::GetVisitorId(map); | 6620 return StaticVisitorBase::GetVisitorId(map); |
6592 } | 6621 } |
6593 | 6622 |
6594 } // namespace internal | 6623 } // namespace internal |
6595 } // namespace v8 | 6624 } // namespace v8 |
OLD | NEW |