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

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

Issue 1133773002: Keep track of array buffers in new space separately (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates 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 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 ProcessYoungWeakReferences(&weak_object_retainer); 1635 ProcessYoungWeakReferences(&weak_object_retainer);
1636 1636
1637 DCHECK(new_space_front == new_space_.top()); 1637 DCHECK(new_space_front == new_space_.top());
1638 1638
1639 // Set age mark. 1639 // Set age mark.
1640 new_space_.set_age_mark(new_space_.top()); 1640 new_space_.set_age_mark(new_space_.top());
1641 1641
1642 new_space_.LowerInlineAllocationLimit( 1642 new_space_.LowerInlineAllocationLimit(
1643 new_space_.inline_allocation_limit_step()); 1643 new_space_.inline_allocation_limit_step());
1644 1644
1645 FreeDeadArrayBuffers(true);
1646
1645 // Update how much has survived scavenge. 1647 // Update how much has survived scavenge.
1646 IncrementYoungSurvivorsCounter(static_cast<int>( 1648 IncrementYoungSurvivorsCounter(static_cast<int>(
1647 (PromotedSpaceSizeOfObjects() - survived_watermark) + new_space_.Size())); 1649 (PromotedSpaceSizeOfObjects() - survived_watermark) + new_space_.Size()));
1648 1650
1649 LOG(isolate_, ResourceEvent("scavenge", "end")); 1651 LOG(isolate_, ResourceEvent("scavenge", "end"));
1650 1652
1651 gc_state_ = NOT_IN_GC; 1653 gc_state_ = NOT_IN_GC;
1652 } 1654 }
1653 1655
1654 1656
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 } 1730 }
1729 1731
1730 1732
1731 void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) { 1733 void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) {
1732 Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer); 1734 Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer);
1733 // Update the head of the list of contexts. 1735 // Update the head of the list of contexts.
1734 set_native_contexts_list(head); 1736 set_native_contexts_list(head);
1735 } 1737 }
1736 1738
1737 1739
1738 void Heap::RegisterNewArrayBuffer(void* data, size_t length) { 1740 namespace {
1741
1742 void RegisterNewArrayBufferHelper(std::map<void*, size_t>& live_buffers,
1743 void* data, size_t length) {
1744 live_buffers[data] = length;
1745 }
1746
1747
1748 void UnregisterArrayBufferHelper(
1749 std::map<void*, size_t>& live_buffers,
1750 std::map<void*, size_t>& not_yet_discovered_buffers, void* data) {
1751 DCHECK(live_buffers.count(data) > 0);
1752 live_buffers.erase(data);
1753 not_yet_discovered_buffers.erase(data);
1754 }
1755
1756
1757 void RegisterLiveArrayBufferHelper(
1758 std::map<void*, size_t>& not_yet_discovered_buffers, void* data) {
1759 not_yet_discovered_buffers.erase(data);
1760 }
1761
1762
1763 size_t FreeDeadArrayBuffersHelper(
1764 Isolate* isolate, std::map<void*, size_t>& live_buffers,
1765 std::map<void*, size_t>& not_yet_discovered_buffers) {
1766 size_t freed_memory = 0;
1767 for (auto buffer = not_yet_discovered_buffers.begin();
1768 buffer != not_yet_discovered_buffers.end(); ++buffer) {
1769 isolate->array_buffer_allocator()->Free(buffer->first, buffer->second);
1770 freed_memory += buffer->second;
1771 live_buffers.erase(buffer->first);
1772 }
1773 not_yet_discovered_buffers = live_buffers;
1774 return freed_memory;
1775 }
1776
1777
1778 void TearDownArrayBuffersHelper(
1779 Isolate* isolate, std::map<void*, size_t>& live_buffers,
1780 std::map<void*, size_t>& not_yet_discovered_buffers) {
1781 for (auto buffer = live_buffers.begin(); buffer != live_buffers.end();
1782 ++buffer) {
1783 isolate->array_buffer_allocator()->Free(buffer->first, buffer->second);
1784 }
1785 live_buffers.clear();
1786 not_yet_discovered_buffers.clear();
1787 }
1788
1789 } // namespace
Hannes Payer (out of office) 2015/05/08 13:39:29 Why did you add a namespace?
jochen (gone - plz use gerrit) 2015/05/08 14:42:56 so the helpers above don't pollute the global name
Hannes Payer (out of office) 2015/05/12 06:33:28 I looked it up in the style guide. That's fine. Ho
1790
1791
1792 void Heap::RegisterNewArrayBuffer(bool in_new_space, void* data,
1793 size_t length) {
1739 if (!data) return; 1794 if (!data) return;
1740 live_array_buffers_[data] = length; 1795 RegisterNewArrayBufferHelper(
1796 in_new_space ? live_new_array_buffers_ : live_array_buffers_, data,
1797 length);
1741 reinterpret_cast<v8::Isolate*>(isolate_) 1798 reinterpret_cast<v8::Isolate*>(isolate_)
1742 ->AdjustAmountOfExternalAllocatedMemory(length); 1799 ->AdjustAmountOfExternalAllocatedMemory(length);
1743 } 1800 }
1744 1801
1745 1802
1746 void Heap::UnregisterArrayBuffer(void* data) { 1803 void Heap::UnregisterArrayBuffer(bool in_new_space, void* data) {
1747 if (!data) return; 1804 if (!data) return;
1748 DCHECK(live_array_buffers_.count(data) > 0); 1805 UnregisterArrayBufferHelper(
1749 live_array_buffers_.erase(data); 1806 in_new_space ? live_new_array_buffers_ : live_array_buffers_,
1750 not_yet_discovered_array_buffers_.erase(data); 1807 in_new_space ? not_yet_discovered_new_array_buffers_
1808 : not_yet_discovered_array_buffers_,
1809 data);
1751 } 1810 }
1752 1811
1753 1812
1754 void Heap::RegisterLiveArrayBuffer(void* data) { 1813 void Heap::RegisterLiveArrayBuffer(bool in_new_space, void* data) {
1755 not_yet_discovered_array_buffers_.erase(data); 1814 RegisterLiveArrayBufferHelper(in_new_space
1815 ? not_yet_discovered_new_array_buffers_
1816 : not_yet_discovered_array_buffers_,
1817 data);
1756 } 1818 }
1757 1819
1758 1820
1759 void Heap::FreeDeadArrayBuffers() { 1821 void Heap::FreeDeadArrayBuffers(bool in_new_space) {
1760 for (auto buffer = not_yet_discovered_array_buffers_.begin(); 1822 size_t freed_memory = FreeDeadArrayBuffersHelper(
1761 buffer != not_yet_discovered_array_buffers_.end(); ++buffer) { 1823 isolate_, in_new_space ? live_new_array_buffers_ : live_array_buffers_,
1762 isolate_->array_buffer_allocator()->Free(buffer->first, buffer->second); 1824 in_new_space ? not_yet_discovered_new_array_buffers_
1763 // Don't use the API method here since this could trigger another GC. 1825 : not_yet_discovered_array_buffers_);
1764 amount_of_external_allocated_memory_ -= buffer->second; 1826 if (freed_memory) {
1765 live_array_buffers_.erase(buffer->first); 1827 reinterpret_cast<v8::Isolate*>(isolate_)
1828 ->AdjustAmountOfExternalAllocatedMemory(
1829 -static_cast<int64_t>(freed_memory));
1766 } 1830 }
1767 not_yet_discovered_array_buffers_ = live_array_buffers_;
1768 } 1831 }
1769 1832
1770 1833
1771 void Heap::TearDownArrayBuffers() { 1834 void Heap::TearDownArrayBuffers() {
1772 for (auto buffer = live_array_buffers_.begin(); 1835 TearDownArrayBuffersHelper(isolate_, live_array_buffers_,
1773 buffer != live_array_buffers_.end(); ++buffer) { 1836 not_yet_discovered_array_buffers_);
1774 isolate_->array_buffer_allocator()->Free(buffer->first, buffer->second); 1837 TearDownArrayBuffersHelper(isolate_, live_new_array_buffers_,
1775 } 1838 not_yet_discovered_new_array_buffers_);
1776 live_array_buffers_.clear();
1777 not_yet_discovered_array_buffers_.clear();
1778 } 1839 }
1779 1840
1780 1841
1842 void Heap::PromoteArrayBuffer(JSArrayBuffer* buffer) {
1843 if (buffer->is_external()) return;
1844 void* data = buffer->backing_store();
1845 if (!data) return;
1846 DCHECK(live_new_array_buffers_.count(data) > 0);
1847 live_array_buffers_[data] = live_new_array_buffers_[data];
1848 live_new_array_buffers_.erase(data);
1849 not_yet_discovered_new_array_buffers_.erase(data);
1850 }
1851
1852
1781 void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) { 1853 void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) {
1782 Object* allocation_site_obj = 1854 Object* allocation_site_obj =
1783 VisitWeakList<AllocationSite>(this, allocation_sites_list(), retainer); 1855 VisitWeakList<AllocationSite>(this, allocation_sites_list(), retainer);
1784 set_allocation_sites_list(allocation_site_obj); 1856 set_allocation_sites_list(allocation_site_obj);
1785 } 1857 }
1786 1858
1787 1859
1788 void Heap::ResetAllAllocationSitesDependentCode(PretenureFlag flag) { 1860 void Heap::ResetAllAllocationSitesDependentCode(PretenureFlag flag) {
1789 DisallowHeapAllocation no_allocation_scope; 1861 DisallowHeapAllocation no_allocation_scope;
1790 Object* cur = allocation_sites_list(); 1862 Object* cur = allocation_sites_list();
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 *slot = target; 2238 *slot = target;
2167 2239
2168 if (object_contents == POINTER_OBJECT) { 2240 if (object_contents == POINTER_OBJECT) {
2169 if (map->instance_type() == JS_FUNCTION_TYPE) { 2241 if (map->instance_type() == JS_FUNCTION_TYPE) {
2170 heap->promotion_queue()->insert(target, 2242 heap->promotion_queue()->insert(target,
2171 JSFunction::kNonWeakFieldsEndOffset); 2243 JSFunction::kNonWeakFieldsEndOffset);
2172 } else { 2244 } else {
2173 heap->promotion_queue()->insert(target, object_size); 2245 heap->promotion_queue()->insert(target, object_size);
2174 } 2246 }
2175 } 2247 }
2248 if (map->instance_type() == JS_ARRAY_BUFFER_TYPE) {
2249 heap->PromoteArrayBuffer(JSArrayBuffer::cast(target));
2250 }
2176 heap->IncrementPromotedObjectsSize(object_size); 2251 heap->IncrementPromotedObjectsSize(object_size);
2177 return true; 2252 return true;
2178 } 2253 }
2179 return false; 2254 return false;
2180 } 2255 }
2181 2256
2182 2257
2183 template <ObjectContents object_contents, int alignment> 2258 template <ObjectContents object_contents, int alignment>
2184 static inline void EvacuateObject(Map* map, HeapObject** slot, 2259 static inline void EvacuateObject(Map* map, HeapObject** slot,
2185 HeapObject* object, int object_size) { 2260 HeapObject* object, int object_size) {
(...skipping 4310 matching lines...) Expand 10 before | Expand all | Expand 10 after
6496 } 6571 }
6497 delete list; 6572 delete list;
6498 } else { 6573 } else {
6499 prev = list; 6574 prev = list;
6500 } 6575 }
6501 list = next; 6576 list = next;
6502 } 6577 }
6503 } 6578 }
6504 } 6579 }
6505 } // namespace v8::internal 6580 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/mark-compact.cc » ('j') | src/heap/mark-compact.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698