Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: src/heap/heap.cc

Issue 1114563002: Remove the weak list of array buffers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 1286
1289 if (FLAG_allocation_site_pretenuring) { 1287 if (FLAG_allocation_site_pretenuring) {
1290 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc); 1288 EvaluateOldSpaceLocalPretenuring(size_of_objects_before_gc);
1291 } 1289 }
1292 } 1290 }
1293 1291
1294 1292
1295 void Heap::MarkCompactEpilogue() { 1293 void Heap::MarkCompactEpilogue() {
1296 gc_state_ = NOT_IN_GC; 1294 gc_state_ = NOT_IN_GC;
1297 1295
1296 ReapDeadArrayBuffers();
Hannes Payer (out of office) 2015/04/29 11:48:21 Please move this call to sweeping, since it frees
1297
1298 isolate_->counters()->objs_since_last_full()->Set(0); 1298 isolate_->counters()->objs_since_last_full()->Set(0);
1299 1299
1300 incremental_marking()->Epilogue(); 1300 incremental_marking()->Epilogue();
1301 1301
1302 PreprocessStackTraces(); 1302 PreprocessStackTraces();
1303 } 1303 }
1304 1304
1305 1305
1306 void Heap::MarkCompactPrologue() { 1306 void Heap::MarkCompactPrologue() {
1307 // At any old GC clear the keyed lookup cache to enable collection of unused 1307 // At any old GC clear the keyed lookup cache to enable collection of unused
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 Object** start = &external_string_table_.old_space_strings_[0]; 1698 Object** start = &external_string_table_.old_space_strings_[0];
1699 Object** end = start + external_string_table_.old_space_strings_.length(); 1699 Object** end = start + external_string_table_.old_space_strings_.length();
1700 for (Object** p = start; p < end; ++p) *p = updater_func(this, p); 1700 for (Object** p = start; p < end; ++p) *p = updater_func(this, p);
1701 } 1701 }
1702 1702
1703 UpdateNewSpaceReferencesInExternalStringTable(updater_func); 1703 UpdateNewSpaceReferencesInExternalStringTable(updater_func);
1704 } 1704 }
1705 1705
1706 1706
1707 void Heap::ProcessAllWeakReferences(WeakObjectRetainer* retainer) { 1707 void Heap::ProcessAllWeakReferences(WeakObjectRetainer* retainer) {
1708 ProcessArrayBuffers(retainer, false);
1709 ProcessNativeContexts(retainer); 1708 ProcessNativeContexts(retainer);
1710 ProcessAllocationSites(retainer); 1709 ProcessAllocationSites(retainer);
1711 } 1710 }
1712 1711
1713 1712
1714 void Heap::ProcessYoungWeakReferences(WeakObjectRetainer* retainer) { 1713 void Heap::ProcessYoungWeakReferences(WeakObjectRetainer* retainer) {
1715 ProcessArrayBuffers(retainer, true);
1716 ProcessNativeContexts(retainer); 1714 ProcessNativeContexts(retainer);
1717 } 1715 }
1718 1716
1719 1717
1720 void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) { 1718 void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) {
1721 Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer, 1719 Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer);
1722 false, NULL);
1723 // Update the head of the list of contexts. 1720 // Update the head of the list of contexts.
1724 set_native_contexts_list(head); 1721 set_native_contexts_list(head);
1725 } 1722 }
1726 1723
1727 1724
1728 void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer, 1725 void Heap::RegisterLiveArrayBuffer(void* data, size_t length) {
Hannes Payer (out of office) 2015/04/29 11:48:21 What about calling this method RegisterNewArrayBuf
1729 bool stop_after_young) { 1726 live_array_buffers_[data] = length;
1730 Object* last_array_buffer = undefined_value(); 1727 reinterpret_cast<v8::Isolate*>(isolate_)
1731 Object* array_buffer_obj = 1728 ->AdjustAmountOfExternalAllocatedMemory(length);
1732 VisitWeakList<JSArrayBuffer>(this, array_buffers_list(), retainer, 1729 }
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 1730
1737 // Verify invariant that young array buffers come before old array buffers 1731
1738 // in array buffers list if there was no promotion failure. 1732 void Heap::UnregisterArrayBuffer(void* data) {
1739 Object* undefined = undefined_value(); 1733 DCHECK(live_array_buffers_.count(data) > 0);
1740 Object* next = array_buffers_list(); 1734 live_array_buffers_.erase(data);
1741 bool old_objects_recorded = false; 1735 not_yet_discovered_array_buffers_.erase(data);
1742 while (next != undefined) { 1736 }
1743 if (!old_objects_recorded) { 1737
1744 old_objects_recorded = !InNewSpace(next); 1738
1745 } 1739 void Heap::AddDiscoveredArrayBuffer(void* data) {
Hannes Payer (out of office) 2015/04/29 11:48:21 And since this method is not adding an array buffe
1746 CHECK((InNewSpace(next) && !old_objects_recorded) || !InNewSpace(next)); 1740 not_yet_discovered_array_buffers_.erase(data);
1747 next = JSArrayBuffer::cast(next)->weak_next(); 1741 }
1742
1743
1744 void Heap::ReapDeadArrayBuffers() {
1745 for (auto buffer = not_yet_discovered_array_buffers_.begin();
1746 buffer != not_yet_discovered_array_buffers_.end(); ++buffer) {
1747 isolate_->array_buffer_allocator()->Free(buffer->first, buffer->second);
1748 // Don't use the API method here since this could trigger another GC.
1749 amount_of_external_allocated_memory_ -= buffer->second;
1750 live_array_buffers_.erase(buffer->first);
1748 } 1751 }
1752 not_yet_discovered_array_buffers_ = live_array_buffers_;
1749 } 1753 }
1750 1754
1751 1755
1752 void Heap::TearDownArrayBuffers() { 1756 void Heap::TearDownArrayBuffers() {
1753 Object* undefined = undefined_value(); 1757 for (auto buffer = live_array_buffers_.begin();
1754 for (Object* o = array_buffers_list(); o != undefined;) { 1758 buffer != live_array_buffers_.end(); ++buffer) {
1755 JSArrayBuffer* buffer = JSArrayBuffer::cast(o); 1759 isolate_->array_buffer_allocator()->Free(buffer->first, buffer->second);
1756 Runtime::FreeArrayBuffer(isolate(), buffer);
1757 o = buffer->weak_next();
1758 } 1760 }
1759 set_array_buffers_list(undefined); 1761 live_array_buffers_.clear();
1762 not_yet_discovered_array_buffers_.clear();
1760 } 1763 }
1761 1764
1762 1765
1763 void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) { 1766 void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) {
1764 Object* allocation_site_obj = VisitWeakList<AllocationSite>( 1767 Object* allocation_site_obj =
1765 this, allocation_sites_list(), retainer, false, NULL); 1768 VisitWeakList<AllocationSite>(this, allocation_sites_list(), retainer);
1766 set_allocation_sites_list(allocation_site_obj); 1769 set_allocation_sites_list(allocation_site_obj);
1767 } 1770 }
1768 1771
1769 1772
1770 void Heap::ResetAllAllocationSitesDependentCode(PretenureFlag flag) { 1773 void Heap::ResetAllAllocationSitesDependentCode(PretenureFlag flag) {
1771 DisallowHeapAllocation no_allocation_scope; 1774 DisallowHeapAllocation no_allocation_scope;
1772 Object* cur = allocation_sites_list(); 1775 Object* cur = allocation_sites_list();
1773 bool marked = false; 1776 bool marked = false;
1774 while (cur->IsAllocationSite()) { 1777 while (cur->IsAllocationSite()) {
1775 AllocationSite* casted = AllocationSite::cast(cur); 1778 AllocationSite* casted = AllocationSite::cast(cur);
(...skipping 3624 matching lines...) Expand 10 before | Expand all | Expand 10 after
5400 bool Heap::CreateHeapObjects() { 5403 bool Heap::CreateHeapObjects() {
5401 // Create initial maps. 5404 // Create initial maps.
5402 if (!CreateInitialMaps()) return false; 5405 if (!CreateInitialMaps()) return false;
5403 CreateApiObjects(); 5406 CreateApiObjects();
5404 5407
5405 // Create initial objects 5408 // Create initial objects
5406 CreateInitialObjects(); 5409 CreateInitialObjects();
5407 CHECK_EQ(0u, gc_count_); 5410 CHECK_EQ(0u, gc_count_);
5408 5411
5409 set_native_contexts_list(undefined_value()); 5412 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()); 5413 set_allocation_sites_list(undefined_value());
5413 return true; 5414 return true;
5414 } 5415 }
5415 5416
5416 5417
5417 void Heap::SetStackLimits() { 5418 void Heap::SetStackLimits() {
5418 DCHECK(isolate_ != NULL); 5419 DCHECK(isolate_ != NULL);
5419 DCHECK(isolate_ == isolate()); 5420 DCHECK(isolate_ == isolate());
5420 // On 64 bit machines, pointers are generally out of range of Smis. We write 5421 // 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. 5422 // something that looks like an out of range Smi to the GC.
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
6414 static_cast<int>(object_sizes_last_time_[index])); 6415 static_cast<int>(object_sizes_last_time_[index]));
6415 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6416 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6416 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6417 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6417 6418
6418 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6419 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6419 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6420 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6420 ClearObjectStats(); 6421 ClearObjectStats();
6421 } 6422 }
6422 } 6423 }
6423 } // namespace v8::internal 6424 } // namespace v8::internal
OLDNEW
« src/heap/heap.h ('K') | « src/heap/heap.h ('k') | src/heap/objects-visiting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698