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 String* string = String::cast(*p); | 1741 heap->FinalizeExternalString(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); | |
1748 return NULL; | 1742 return NULL; |
1749 } | 1743 } |
1750 | 1744 |
1751 // String is still reachable. | 1745 // String is still reachable. |
1752 String* string = String::cast(first_word.ToForwardingAddress()); | 1746 return 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; | |
1756 } | 1747 } |
1757 | 1748 |
1758 | 1749 |
1759 void Heap::UpdateNewSpaceReferencesInExternalStringTable( | 1750 void Heap::UpdateNewSpaceReferencesInExternalStringTable( |
1760 ExternalStringTableUpdaterCallback updater_func) { | 1751 ExternalStringTableUpdaterCallback updater_func) { |
1761 if (external_string_table_.new_space_strings_.is_empty()) return; | 1752 if (external_string_table_.new_space_strings_.is_empty()) return; |
1762 | 1753 |
1763 Object** start = &external_string_table_.new_space_strings_[0]; | 1754 Object** start = &external_string_table_.new_space_strings_[0]; |
1764 Object** end = start + external_string_table_.new_space_strings_.length(); | 1755 Object** end = start + external_string_table_.new_space_strings_.length(); |
1765 Object** last = start; | 1756 Object** last = start; |
(...skipping 4649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6415 void Heap::UpdateTotalGCTime(double duration) { | 6406 void Heap::UpdateTotalGCTime(double duration) { |
6416 if (FLAG_trace_gc_verbose) { | 6407 if (FLAG_trace_gc_verbose) { |
6417 total_gc_time_ms_ += duration; | 6408 total_gc_time_ms_ += duration; |
6418 } | 6409 } |
6419 } | 6410 } |
6420 | 6411 |
6421 void Heap::ExternalStringTable::CleanUpNewSpaceStrings() { | 6412 void Heap::ExternalStringTable::CleanUpNewSpaceStrings() { |
6422 int last = 0; | 6413 int last = 0; |
6423 Isolate* isolate = heap_->isolate(); | 6414 Isolate* isolate = heap_->isolate(); |
6424 for (int i = 0; i < new_space_strings_.length(); ++i) { | 6415 for (int i = 0; i < new_space_strings_.length(); ++i) { |
6425 Object* o = new_space_strings_[i]; | 6416 if (new_space_strings_[i]->IsTheHole(isolate)) { |
6426 if (o->IsTheHole(isolate)) { | |
6427 continue; | 6417 continue; |
6428 } | 6418 } |
6429 if (o->IsThinString()) { | 6419 DCHECK(new_space_strings_[i]->IsExternalString()); |
6430 o = ThinString::cast(o)->actual(); | 6420 if (heap_->InNewSpace(new_space_strings_[i])) { |
6431 if (!o->IsExternalString()) continue; | 6421 new_space_strings_[last++] = new_space_strings_[i]; |
6432 } | |
6433 DCHECK(o->IsExternalString()); | |
6434 if (heap_->InNewSpace(o)) { | |
6435 new_space_strings_[last++] = o; | |
6436 } else { | 6422 } else { |
6437 old_space_strings_.Add(o); | 6423 old_space_strings_.Add(new_space_strings_[i]); |
6438 } | 6424 } |
6439 } | 6425 } |
6440 new_space_strings_.Rewind(last); | 6426 new_space_strings_.Rewind(last); |
6441 new_space_strings_.Trim(); | 6427 new_space_strings_.Trim(); |
6442 } | 6428 } |
6443 | 6429 |
6444 void Heap::ExternalStringTable::CleanUpAll() { | 6430 void Heap::ExternalStringTable::CleanUpAll() { |
6445 CleanUpNewSpaceStrings(); | 6431 CleanUpNewSpaceStrings(); |
6446 int last = 0; | 6432 int last = 0; |
6447 Isolate* isolate = heap_->isolate(); | 6433 Isolate* isolate = heap_->isolate(); |
6448 for (int i = 0; i < old_space_strings_.length(); ++i) { | 6434 for (int i = 0; i < old_space_strings_.length(); ++i) { |
6449 Object* o = old_space_strings_[i]; | 6435 if (old_space_strings_[i]->IsTheHole(isolate)) { |
6450 if (o->IsTheHole(isolate)) { | |
6451 continue; | 6436 continue; |
6452 } | 6437 } |
6453 if (o->IsThinString()) { | 6438 DCHECK(old_space_strings_[i]->IsExternalString()); |
6454 o = ThinString::cast(o)->actual(); | 6439 DCHECK(!heap_->InNewSpace(old_space_strings_[i])); |
6455 if (!o->IsExternalString()) continue; | 6440 old_space_strings_[last++] = old_space_strings_[i]; |
6456 } | |
6457 DCHECK(o->IsExternalString()); | |
6458 DCHECK(!heap_->InNewSpace(o)); | |
6459 old_space_strings_[last++] = o; | |
6460 } | 6441 } |
6461 old_space_strings_.Rewind(last); | 6442 old_space_strings_.Rewind(last); |
6462 old_space_strings_.Trim(); | 6443 old_space_strings_.Trim(); |
6463 #ifdef VERIFY_HEAP | 6444 #ifdef VERIFY_HEAP |
6464 if (FLAG_verify_heap) { | 6445 if (FLAG_verify_heap) { |
6465 Verify(); | 6446 Verify(); |
6466 } | 6447 } |
6467 #endif | 6448 #endif |
6468 } | 6449 } |
6469 | 6450 |
6470 void Heap::ExternalStringTable::TearDown() { | 6451 void Heap::ExternalStringTable::TearDown() { |
6471 for (int i = 0; i < new_space_strings_.length(); ++i) { | 6452 for (int i = 0; i < new_space_strings_.length(); ++i) { |
6472 Object* o = new_space_strings_[i]; | 6453 heap_->FinalizeExternalString(ExternalString::cast(new_space_strings_[i])); |
6473 if (o->IsThinString()) { | |
6474 o = ThinString::cast(o)->actual(); | |
6475 if (!o->IsExternalString()) continue; | |
6476 } | |
6477 heap_->FinalizeExternalString(ExternalString::cast(o)); | |
6478 } | 6454 } |
6479 new_space_strings_.Free(); | 6455 new_space_strings_.Free(); |
6480 for (int i = 0; i < old_space_strings_.length(); ++i) { | 6456 for (int i = 0; i < old_space_strings_.length(); ++i) { |
6481 Object* o = old_space_strings_[i]; | 6457 heap_->FinalizeExternalString(ExternalString::cast(old_space_strings_[i])); |
6482 if (o->IsThinString()) { | |
6483 o = ThinString::cast(o)->actual(); | |
6484 if (!o->IsExternalString()) continue; | |
6485 } | |
6486 heap_->FinalizeExternalString(ExternalString::cast(o)); | |
6487 } | 6458 } |
6488 old_space_strings_.Free(); | 6459 old_space_strings_.Free(); |
6489 } | 6460 } |
6490 | 6461 |
6491 | 6462 |
6492 void Heap::RememberUnmappedPage(Address page, bool compacted) { | 6463 void Heap::RememberUnmappedPage(Address page, bool compacted) { |
6493 uintptr_t p = reinterpret_cast<uintptr_t>(page); | 6464 uintptr_t p = reinterpret_cast<uintptr_t>(page); |
6494 // Tag the page pointer to make it findable in the dump file. | 6465 // Tag the page pointer to make it findable in the dump file. |
6495 if (compacted) { | 6466 if (compacted) { |
6496 p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. | 6467 p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6591 } | 6562 } |
6592 | 6563 |
6593 | 6564 |
6594 // static | 6565 // static |
6595 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6566 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6596 return StaticVisitorBase::GetVisitorId(map); | 6567 return StaticVisitorBase::GetVisitorId(map); |
6597 } | 6568 } |
6598 | 6569 |
6599 } // namespace internal | 6570 } // namespace internal |
6600 } // namespace v8 | 6571 } // namespace v8 |
OLD | NEW |