| 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/v8.h" | 5 #include "src/v8.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/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // easier if you can define it as part of the build environment. | 147 // easier if you can define it as part of the build environment. |
| 148 #if defined(V8_MAX_SEMISPACE_SIZE) | 148 #if defined(V8_MAX_SEMISPACE_SIZE) |
| 149 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; | 149 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; |
| 150 #endif | 150 #endif |
| 151 | 151 |
| 152 // Ensure old_generation_size_ is a multiple of kPageSize. | 152 // Ensure old_generation_size_ is a multiple of kPageSize. |
| 153 DCHECK(MB >= Page::kPageSize); | 153 DCHECK(MB >= Page::kPageSize); |
| 154 | 154 |
| 155 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); | 155 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); |
| 156 set_native_contexts_list(NULL); | 156 set_native_contexts_list(NULL); |
| 157 set_array_buffers_list(Smi::FromInt(0)); | |
| 158 set_last_array_buffer_in_list(Smi::FromInt(0)); | |
| 159 set_allocation_sites_list(Smi::FromInt(0)); | 157 set_allocation_sites_list(Smi::FromInt(0)); |
| 160 set_encountered_weak_collections(Smi::FromInt(0)); | 158 set_encountered_weak_collections(Smi::FromInt(0)); |
| 161 set_encountered_weak_cells(Smi::FromInt(0)); | 159 set_encountered_weak_cells(Smi::FromInt(0)); |
| 162 // Put a dummy entry in the remembered pages so we can find the list the | 160 // Put a dummy entry in the remembered pages so we can find the list the |
| 163 // minidump even if there are no real unmapped pages. | 161 // minidump even if there are no real unmapped pages. |
| 164 RememberUnmappedPage(NULL, false); | 162 RememberUnmappedPage(NULL, false); |
| 165 | 163 |
| 166 ClearObjectStats(true); | 164 ClearObjectStats(true); |
| 167 } | 165 } |
| 168 | 166 |
| (...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 Object** start = &external_string_table_.old_space_strings_[0]; | 1696 Object** start = &external_string_table_.old_space_strings_[0]; |
| 1699 Object** end = start + external_string_table_.old_space_strings_.length(); | 1697 Object** end = start + external_string_table_.old_space_strings_.length(); |
| 1700 for (Object** p = start; p < end; ++p) *p = updater_func(this, p); | 1698 for (Object** p = start; p < end; ++p) *p = updater_func(this, p); |
| 1701 } | 1699 } |
| 1702 | 1700 |
| 1703 UpdateNewSpaceReferencesInExternalStringTable(updater_func); | 1701 UpdateNewSpaceReferencesInExternalStringTable(updater_func); |
| 1704 } | 1702 } |
| 1705 | 1703 |
| 1706 | 1704 |
| 1707 void Heap::ProcessAllWeakReferences(WeakObjectRetainer* retainer) { | 1705 void Heap::ProcessAllWeakReferences(WeakObjectRetainer* retainer) { |
| 1708 ProcessArrayBuffers(retainer, false); | |
| 1709 ProcessNativeContexts(retainer); | 1706 ProcessNativeContexts(retainer); |
| 1710 ProcessAllocationSites(retainer); | 1707 ProcessAllocationSites(retainer); |
| 1711 } | 1708 } |
| 1712 | 1709 |
| 1713 | 1710 |
| 1714 void Heap::ProcessYoungWeakReferences(WeakObjectRetainer* retainer) { | 1711 void Heap::ProcessYoungWeakReferences(WeakObjectRetainer* retainer) { |
| 1715 ProcessArrayBuffers(retainer, true); | |
| 1716 ProcessNativeContexts(retainer); | 1712 ProcessNativeContexts(retainer); |
| 1717 } | 1713 } |
| 1718 | 1714 |
| 1719 | 1715 |
| 1720 void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) { | 1716 void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) { |
| 1721 Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer, | 1717 Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer); |
| 1722 false, NULL); | |
| 1723 // Update the head of the list of contexts. | 1718 // Update the head of the list of contexts. |
| 1724 set_native_contexts_list(head); | 1719 set_native_contexts_list(head); |
| 1725 } | 1720 } |
| 1726 | 1721 |
| 1727 | 1722 |
| 1728 void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer, | 1723 void Heap::RegisterNewArrayBuffer(void* data, size_t length) { |
| 1729 bool stop_after_young) { | 1724 live_array_buffers_[data] = length; |
| 1730 Object* last_array_buffer = undefined_value(); | 1725 reinterpret_cast<v8::Isolate*>(isolate_) |
| 1731 Object* array_buffer_obj = | 1726 ->AdjustAmountOfExternalAllocatedMemory(length); |
| 1732 VisitWeakList<JSArrayBuffer>(this, array_buffers_list(), retainer, | 1727 } |
| 1733 stop_after_young, &last_array_buffer); | |
| 1734 set_array_buffers_list(array_buffer_obj); | |
| 1735 set_last_array_buffer_in_list(last_array_buffer); | |
| 1736 | 1728 |
| 1737 // Verify invariant that young array buffers come before old array buffers | 1729 |
| 1738 // in array buffers list if there was no promotion failure. | 1730 void Heap::UnregisterArrayBuffer(void* data) { |
| 1739 Object* undefined = undefined_value(); | 1731 DCHECK(live_array_buffers_.count(data) > 0); |
| 1740 Object* next = array_buffers_list(); | 1732 live_array_buffers_.erase(data); |
| 1741 bool old_objects_recorded = false; | 1733 not_yet_discovered_array_buffers_.erase(data); |
| 1742 while (next != undefined) { | 1734 } |
| 1743 if (!old_objects_recorded) { | 1735 |
| 1744 old_objects_recorded = !InNewSpace(next); | 1736 |
| 1745 } | 1737 void Heap::RegisterLiveArrayBuffer(void* data) { |
| 1746 CHECK((InNewSpace(next) && !old_objects_recorded) || !InNewSpace(next)); | 1738 not_yet_discovered_array_buffers_.erase(data); |
| 1747 next = JSArrayBuffer::cast(next)->weak_next(); | 1739 } |
| 1740 |
| 1741 |
| 1742 void Heap::FreeDeadArrayBuffers() { |
| 1743 for (auto buffer = not_yet_discovered_array_buffers_.begin(); |
| 1744 buffer != not_yet_discovered_array_buffers_.end(); ++buffer) { |
| 1745 isolate_->array_buffer_allocator()->Free(buffer->first, buffer->second); |
| 1746 // Don't use the API method here since this could trigger another GC. |
| 1747 amount_of_external_allocated_memory_ -= buffer->second; |
| 1748 live_array_buffers_.erase(buffer->first); |
| 1748 } | 1749 } |
| 1750 not_yet_discovered_array_buffers_ = live_array_buffers_; |
| 1749 } | 1751 } |
| 1750 | 1752 |
| 1751 | 1753 |
| 1752 void Heap::TearDownArrayBuffers() { | 1754 void Heap::TearDownArrayBuffers() { |
| 1753 Object* undefined = undefined_value(); | 1755 for (auto buffer = live_array_buffers_.begin(); |
| 1754 for (Object* o = array_buffers_list(); o != undefined;) { | 1756 buffer != live_array_buffers_.end(); ++buffer) { |
| 1755 JSArrayBuffer* buffer = JSArrayBuffer::cast(o); | 1757 isolate_->array_buffer_allocator()->Free(buffer->first, buffer->second); |
| 1756 Runtime::FreeArrayBuffer(isolate(), buffer); | |
| 1757 o = buffer->weak_next(); | |
| 1758 } | 1758 } |
| 1759 set_array_buffers_list(undefined); | 1759 live_array_buffers_.clear(); |
| 1760 not_yet_discovered_array_buffers_.clear(); |
| 1760 } | 1761 } |
| 1761 | 1762 |
| 1762 | 1763 |
| 1763 void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) { | 1764 void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) { |
| 1764 Object* allocation_site_obj = VisitWeakList<AllocationSite>( | 1765 Object* allocation_site_obj = |
| 1765 this, allocation_sites_list(), retainer, false, NULL); | 1766 VisitWeakList<AllocationSite>(this, allocation_sites_list(), retainer); |
| 1766 set_allocation_sites_list(allocation_site_obj); | 1767 set_allocation_sites_list(allocation_site_obj); |
| 1767 } | 1768 } |
| 1768 | 1769 |
| 1769 | 1770 |
| 1770 void Heap::ResetAllAllocationSitesDependentCode(PretenureFlag flag) { | 1771 void Heap::ResetAllAllocationSitesDependentCode(PretenureFlag flag) { |
| 1771 DisallowHeapAllocation no_allocation_scope; | 1772 DisallowHeapAllocation no_allocation_scope; |
| 1772 Object* cur = allocation_sites_list(); | 1773 Object* cur = allocation_sites_list(); |
| 1773 bool marked = false; | 1774 bool marked = false; |
| 1774 while (cur->IsAllocationSite()) { | 1775 while (cur->IsAllocationSite()) { |
| 1775 AllocationSite* casted = AllocationSite::cast(cur); | 1776 AllocationSite* casted = AllocationSite::cast(cur); |
| (...skipping 3624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5400 bool Heap::CreateHeapObjects() { | 5401 bool Heap::CreateHeapObjects() { |
| 5401 // Create initial maps. | 5402 // Create initial maps. |
| 5402 if (!CreateInitialMaps()) return false; | 5403 if (!CreateInitialMaps()) return false; |
| 5403 CreateApiObjects(); | 5404 CreateApiObjects(); |
| 5404 | 5405 |
| 5405 // Create initial objects | 5406 // Create initial objects |
| 5406 CreateInitialObjects(); | 5407 CreateInitialObjects(); |
| 5407 CHECK_EQ(0u, gc_count_); | 5408 CHECK_EQ(0u, gc_count_); |
| 5408 | 5409 |
| 5409 set_native_contexts_list(undefined_value()); | 5410 set_native_contexts_list(undefined_value()); |
| 5410 set_array_buffers_list(undefined_value()); | |
| 5411 set_last_array_buffer_in_list(undefined_value()); | |
| 5412 set_allocation_sites_list(undefined_value()); | 5411 set_allocation_sites_list(undefined_value()); |
| 5413 return true; | 5412 return true; |
| 5414 } | 5413 } |
| 5415 | 5414 |
| 5416 | 5415 |
| 5417 void Heap::SetStackLimits() { | 5416 void Heap::SetStackLimits() { |
| 5418 DCHECK(isolate_ != NULL); | 5417 DCHECK(isolate_ != NULL); |
| 5419 DCHECK(isolate_ == isolate()); | 5418 DCHECK(isolate_ == isolate()); |
| 5420 // On 64 bit machines, pointers are generally out of range of Smis. We write | 5419 // On 64 bit machines, pointers are generally out of range of Smis. We write |
| 5421 // something that looks like an out of range Smi to the GC. | 5420 // something that looks like an out of range Smi to the GC. |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6414 static_cast<int>(object_sizes_last_time_[index])); | 6413 static_cast<int>(object_sizes_last_time_[index])); |
| 6415 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6414 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 6416 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6415 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 6417 | 6416 |
| 6418 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6417 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 6419 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6418 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 6420 ClearObjectStats(); | 6419 ClearObjectStats(); |
| 6421 } | 6420 } |
| 6422 } | 6421 } |
| 6423 } // namespace v8::internal | 6422 } // namespace v8::internal |
| OLD | NEW |