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 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 SetGCState(NOT_IN_GC); | 1726 SetGCState(NOT_IN_GC); |
1727 } | 1727 } |
1728 | 1728 |
1729 | 1729 |
1730 String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap, | 1730 String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap, |
1731 Object** p) { | 1731 Object** p) { |
1732 MapWord first_word = HeapObject::cast(*p)->map_word(); | 1732 MapWord first_word = HeapObject::cast(*p)->map_word(); |
1733 | 1733 |
1734 if (!first_word.IsForwardingAddress()) { | 1734 if (!first_word.IsForwardingAddress()) { |
1735 // Unreachable external string can be finalized. | 1735 // Unreachable external string can be finalized. |
1736 String* string = String::cast(*p); | 1736 heap->FinalizeExternalString(String::cast(*p)); |
1737 if (!string->IsExternalString()) { | |
1738 // Original external string has been internalized. | |
1739 DCHECK(string->IsThinString()); | |
1740 return NULL; | |
1741 } | |
1742 heap->FinalizeExternalString(string); | |
1743 return NULL; | 1737 return NULL; |
1744 } | 1738 } |
1745 | 1739 |
1746 // String is still reachable. | 1740 // String is still reachable. |
1747 String* string = String::cast(first_word.ToForwardingAddress()); | 1741 return String::cast(first_word.ToForwardingAddress()); |
1748 if (string->IsThinString()) string = ThinString::cast(string)->actual(); | |
1749 // Internalization can replace external strings with non-external strings. | |
1750 return string->IsExternalString() ? string : nullptr; | |
1751 } | 1742 } |
1752 | 1743 |
1753 | 1744 |
1754 void Heap::UpdateNewSpaceReferencesInExternalStringTable( | 1745 void Heap::UpdateNewSpaceReferencesInExternalStringTable( |
1755 ExternalStringTableUpdaterCallback updater_func) { | 1746 ExternalStringTableUpdaterCallback updater_func) { |
1756 if (external_string_table_.new_space_strings_.is_empty()) return; | 1747 if (external_string_table_.new_space_strings_.is_empty()) return; |
1757 | 1748 |
1758 Object** start = &external_string_table_.new_space_strings_[0]; | 1749 Object** start = &external_string_table_.new_space_strings_[0]; |
1759 Object** end = start + external_string_table_.new_space_strings_.length(); | 1750 Object** end = start + external_string_table_.new_space_strings_.length(); |
1760 Object** last = start; | 1751 Object** last = start; |
(...skipping 4637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6398 void Heap::UpdateTotalGCTime(double duration) { | 6389 void Heap::UpdateTotalGCTime(double duration) { |
6399 if (FLAG_trace_gc_verbose) { | 6390 if (FLAG_trace_gc_verbose) { |
6400 total_gc_time_ms_ += duration; | 6391 total_gc_time_ms_ += duration; |
6401 } | 6392 } |
6402 } | 6393 } |
6403 | 6394 |
6404 void Heap::ExternalStringTable::CleanUpNewSpaceStrings() { | 6395 void Heap::ExternalStringTable::CleanUpNewSpaceStrings() { |
6405 int last = 0; | 6396 int last = 0; |
6406 Isolate* isolate = heap_->isolate(); | 6397 Isolate* isolate = heap_->isolate(); |
6407 for (int i = 0; i < new_space_strings_.length(); ++i) { | 6398 for (int i = 0; i < new_space_strings_.length(); ++i) { |
6408 Object* o = new_space_strings_[i]; | 6399 if (new_space_strings_[i]->IsTheHole(isolate)) { |
6409 if (o->IsTheHole(isolate)) { | |
6410 continue; | 6400 continue; |
6411 } | 6401 } |
6412 if (o->IsThinString()) { | 6402 DCHECK(new_space_strings_[i]->IsExternalString()); |
6413 o = ThinString::cast(o)->actual(); | 6403 if (heap_->InNewSpace(new_space_strings_[i])) { |
6414 if (!o->IsExternalString()) continue; | 6404 new_space_strings_[last++] = new_space_strings_[i]; |
6415 } | |
6416 DCHECK(o->IsExternalString()); | |
6417 if (heap_->InNewSpace(o)) { | |
6418 new_space_strings_[last++] = o; | |
6419 } else { | 6405 } else { |
6420 old_space_strings_.Add(o); | 6406 old_space_strings_.Add(new_space_strings_[i]); |
6421 } | 6407 } |
6422 } | 6408 } |
6423 new_space_strings_.Rewind(last); | 6409 new_space_strings_.Rewind(last); |
6424 new_space_strings_.Trim(); | 6410 new_space_strings_.Trim(); |
6425 } | 6411 } |
6426 | 6412 |
6427 void Heap::ExternalStringTable::CleanUpAll() { | 6413 void Heap::ExternalStringTable::CleanUpAll() { |
6428 CleanUpNewSpaceStrings(); | 6414 CleanUpNewSpaceStrings(); |
6429 int last = 0; | 6415 int last = 0; |
6430 Isolate* isolate = heap_->isolate(); | 6416 Isolate* isolate = heap_->isolate(); |
6431 for (int i = 0; i < old_space_strings_.length(); ++i) { | 6417 for (int i = 0; i < old_space_strings_.length(); ++i) { |
6432 Object* o = old_space_strings_[i]; | 6418 if (old_space_strings_[i]->IsTheHole(isolate)) { |
6433 if (o->IsTheHole(isolate)) { | |
6434 continue; | 6419 continue; |
6435 } | 6420 } |
6436 if (o->IsThinString()) { | 6421 DCHECK(old_space_strings_[i]->IsExternalString()); |
6437 o = ThinString::cast(o)->actual(); | 6422 DCHECK(!heap_->InNewSpace(old_space_strings_[i])); |
6438 if (!o->IsExternalString()) continue; | 6423 old_space_strings_[last++] = old_space_strings_[i]; |
6439 } | |
6440 DCHECK(o->IsExternalString()); | |
6441 DCHECK(!heap_->InNewSpace(o)); | |
6442 old_space_strings_[last++] = o; | |
6443 } | 6424 } |
6444 old_space_strings_.Rewind(last); | 6425 old_space_strings_.Rewind(last); |
6445 old_space_strings_.Trim(); | 6426 old_space_strings_.Trim(); |
6446 #ifdef VERIFY_HEAP | 6427 #ifdef VERIFY_HEAP |
6447 if (FLAG_verify_heap) { | 6428 if (FLAG_verify_heap) { |
6448 Verify(); | 6429 Verify(); |
6449 } | 6430 } |
6450 #endif | 6431 #endif |
6451 } | 6432 } |
6452 | 6433 |
6453 void Heap::ExternalStringTable::TearDown() { | 6434 void Heap::ExternalStringTable::TearDown() { |
6454 for (int i = 0; i < new_space_strings_.length(); ++i) { | 6435 for (int i = 0; i < new_space_strings_.length(); ++i) { |
6455 Object* o = new_space_strings_[i]; | 6436 heap_->FinalizeExternalString(ExternalString::cast(new_space_strings_[i])); |
6456 if (o->IsThinString()) { | |
6457 o = ThinString::cast(o)->actual(); | |
6458 if (!o->IsExternalString()) continue; | |
6459 } | |
6460 heap_->FinalizeExternalString(ExternalString::cast(o)); | |
6461 } | 6437 } |
6462 new_space_strings_.Free(); | 6438 new_space_strings_.Free(); |
6463 for (int i = 0; i < old_space_strings_.length(); ++i) { | 6439 for (int i = 0; i < old_space_strings_.length(); ++i) { |
6464 Object* o = old_space_strings_[i]; | 6440 heap_->FinalizeExternalString(ExternalString::cast(old_space_strings_[i])); |
6465 if (o->IsThinString()) { | |
6466 o = ThinString::cast(o)->actual(); | |
6467 if (!o->IsExternalString()) continue; | |
6468 } | |
6469 heap_->FinalizeExternalString(ExternalString::cast(o)); | |
6470 } | 6441 } |
6471 old_space_strings_.Free(); | 6442 old_space_strings_.Free(); |
6472 } | 6443 } |
6473 | 6444 |
6474 | 6445 |
6475 void Heap::RememberUnmappedPage(Address page, bool compacted) { | 6446 void Heap::RememberUnmappedPage(Address page, bool compacted) { |
6476 uintptr_t p = reinterpret_cast<uintptr_t>(page); | 6447 uintptr_t p = reinterpret_cast<uintptr_t>(page); |
6477 // Tag the page pointer to make it findable in the dump file. | 6448 // Tag the page pointer to make it findable in the dump file. |
6478 if (compacted) { | 6449 if (compacted) { |
6479 p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. | 6450 p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6574 } | 6545 } |
6575 | 6546 |
6576 | 6547 |
6577 // static | 6548 // static |
6578 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6549 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6579 return StaticVisitorBase::GetVisitorId(map); | 6550 return StaticVisitorBase::GetVisitorId(map); |
6580 } | 6551 } |
6581 | 6552 |
6582 } // namespace internal | 6553 } // namespace internal |
6583 } // namespace v8 | 6554 } // namespace v8 |
OLD | NEW |