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

Side by Side Diff: src/heap/spaces.h

Issue 1964023002: [heap] Fine-grained JSArrayBuffer tracking (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase again Created 4 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
« no previous file with comments | « src/heap/scavenger.cc ('k') | src/heap/spaces.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 #ifndef V8_HEAP_SPACES_H_ 5 #ifndef V8_HEAP_SPACES_H_
6 #define V8_HEAP_SPACES_H_ 6 #define V8_HEAP_SPACES_H_
7 7
8 #include <list> 8 #include <list>
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
11 #include "src/base/atomic-utils.h" 11 #include "src/base/atomic-utils.h"
12 #include "src/base/atomicops.h" 12 #include "src/base/atomicops.h"
13 #include "src/base/bits.h" 13 #include "src/base/bits.h"
14 #include "src/base/platform/mutex.h" 14 #include "src/base/platform/mutex.h"
15 #include "src/flags.h" 15 #include "src/flags.h"
16 #include "src/hashmap.h" 16 #include "src/hashmap.h"
17 #include "src/heap/array-buffer-tracker.h"
17 #include "src/list.h" 18 #include "src/list.h"
18 #include "src/objects.h" 19 #include "src/objects.h"
19 #include "src/utils.h" 20 #include "src/utils.h"
20 21
21 namespace v8 { 22 namespace v8 {
22 namespace internal { 23 namespace internal {
23 24
24 class AllocationInfo; 25 class AllocationInfo;
25 class AllocationObserver; 26 class AllocationObserver;
26 class CompactionSpace; 27 class CompactionSpace;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 static const size_t kMinHeaderSize = 517 static const size_t kMinHeaderSize =
517 kWriteBarrierCounterOffset + 518 kWriteBarrierCounterOffset +
518 kIntptrSize // intptr_t write_barrier_counter_ 519 kIntptrSize // intptr_t write_barrier_counter_
519 + kPointerSize // AtomicValue high_water_mark_ 520 + kPointerSize // AtomicValue high_water_mark_
520 + kPointerSize // base::Mutex* mutex_ 521 + kPointerSize // base::Mutex* mutex_
521 + kPointerSize // base::AtomicWord concurrent_sweeping_ 522 + kPointerSize // base::AtomicWord concurrent_sweeping_
522 + 2 * kPointerSize // AtomicNumber free-list statistics 523 + 2 * kPointerSize // AtomicNumber free-list statistics
523 + kPointerSize // AtomicValue next_chunk_ 524 + kPointerSize // AtomicValue next_chunk_
524 + kPointerSize // AtomicValue prev_chunk_ 525 + kPointerSize // AtomicValue prev_chunk_
525 // FreeListCategory categories_[kNumberOfCategories] 526 // FreeListCategory categories_[kNumberOfCategories]
526 + FreeListCategory::kSize * kNumberOfCategories; 527 + FreeListCategory::kSize * kNumberOfCategories +
528 kPointerSize; // LocalArrayBufferTracker tracker_
527 529
528 // We add some more space to the computed header size to amount for missing 530 // We add some more space to the computed header size to amount for missing
529 // alignment requirements in our computation. 531 // alignment requirements in our computation.
530 // Try to get kHeaderSize properly aligned on 32-bit and 64-bit machines. 532 // Try to get kHeaderSize properly aligned on 32-bit and 64-bit machines.
531 static const size_t kHeaderSize = kMinHeaderSize; 533 static const size_t kHeaderSize = kMinHeaderSize;
532 534
533 static const int kBodyOffset = 535 static const int kBodyOffset =
534 CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize); 536 CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize);
535 537
536 // The start offset of the object area in a page. Aligned to both maps and 538 // The start offset of the object area in a page. Aligned to both maps and
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 base::AtomicNumber<intptr_t> available_in_free_list_; 819 base::AtomicNumber<intptr_t> available_in_free_list_;
818 base::AtomicNumber<intptr_t> wasted_memory_; 820 base::AtomicNumber<intptr_t> wasted_memory_;
819 821
820 // next_chunk_ holds a pointer of type MemoryChunk 822 // next_chunk_ holds a pointer of type MemoryChunk
821 base::AtomicValue<MemoryChunk*> next_chunk_; 823 base::AtomicValue<MemoryChunk*> next_chunk_;
822 // prev_chunk_ holds a pointer of type MemoryChunk 824 // prev_chunk_ holds a pointer of type MemoryChunk
823 base::AtomicValue<MemoryChunk*> prev_chunk_; 825 base::AtomicValue<MemoryChunk*> prev_chunk_;
824 826
825 FreeListCategory categories_[kNumberOfCategories]; 827 FreeListCategory categories_[kNumberOfCategories];
826 828
829 LocalArrayBufferTracker* local_tracker_;
830
827 private: 831 private:
828 void InitializeReservedMemory() { reservation_.Reset(); } 832 void InitializeReservedMemory() { reservation_.Reset(); }
829 833
830 friend class MemoryAllocator; 834 friend class MemoryAllocator;
831 friend class MemoryChunkValidator; 835 friend class MemoryChunkValidator;
832 }; 836 };
833 837
834 // ----------------------------------------------------------------------------- 838 // -----------------------------------------------------------------------------
835 // A page is a memory chunk of a size 1MB. Large object pages may be larger. 839 // A page is a memory chunk of a size 1MB. Large object pages may be larger.
836 // 840 //
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 951
948 bool is_anchor() { return IsFlagSet(Page::ANCHOR); } 952 bool is_anchor() { return IsFlagSet(Page::ANCHOR); }
949 953
950 intptr_t wasted_memory() { return wasted_memory_.Value(); } 954 intptr_t wasted_memory() { return wasted_memory_.Value(); }
951 void add_wasted_memory(intptr_t waste) { wasted_memory_.Increment(waste); } 955 void add_wasted_memory(intptr_t waste) { wasted_memory_.Increment(waste); }
952 intptr_t available_in_free_list() { return available_in_free_list_.Value(); } 956 intptr_t available_in_free_list() { return available_in_free_list_.Value(); }
953 void add_available_in_free_list(intptr_t available) { 957 void add_available_in_free_list(intptr_t available) {
954 available_in_free_list_.Increment(available); 958 available_in_free_list_.Increment(available);
955 } 959 }
956 960
961 LocalArrayBufferTracker* local_tracker() {
962 if (local_tracker_ == nullptr) {
963 local_tracker_ = new LocalArrayBufferTracker(heap_);
964 }
965 return local_tracker_;
966 }
967
968 void FreeDeadArrayBuffers() {
969 if (local_tracker_ != nullptr) {
970 local_tracker_->FreeDead();
971 if (local_tracker_->IsEmpty()) {
972 delete local_tracker_;
973 local_tracker_ = nullptr;
974 }
975 }
976 }
977
978 template <LocalArrayBufferTracker::LivenessIndicator liveness_indicator>
979 void ScanAndFreeDeadArrayBuffers() {
980 if (local_tracker_ != nullptr) {
981 local_tracker_->ScanAndFreeDead<liveness_indicator>();
982 if (local_tracker_->IsEmpty()) {
983 delete local_tracker_;
984 local_tracker_ = nullptr;
985 }
986 }
987 }
988
989 void ResetTracker() {
990 if (local_tracker_ != nullptr) {
991 local_tracker_->Reset();
992 }
993 }
994
957 #ifdef DEBUG 995 #ifdef DEBUG
958 void Print(); 996 void Print();
959 #endif // DEBUG 997 #endif // DEBUG
960 998
961 private: 999 private:
962 enum InitializationMode { kFreeMemory, kDoNotFreeMemory }; 1000 enum InitializationMode { kFreeMemory, kDoNotFreeMemory };
963 1001
964 template <InitializationMode mode = kFreeMemory> 1002 template <InitializationMode mode = kFreeMemory>
965 static inline Page* Initialize(Heap* heap, MemoryChunk* chunk, 1003 static inline Page* Initialize(Heap* heap, MemoryChunk* chunk,
966 Executability executable, PagedSpace* owner); 1004 Executability executable, PagedSpace* owner);
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 // sweeper. 2326 // sweeper.
2289 virtual void RefillFreeList(); 2327 virtual void RefillFreeList();
2290 2328
2291 FreeList* free_list() { return &free_list_; } 2329 FreeList* free_list() { return &free_list_; }
2292 2330
2293 base::Mutex* mutex() { return &space_mutex_; } 2331 base::Mutex* mutex() { return &space_mutex_; }
2294 2332
2295 inline void UnlinkFreeListCategories(Page* page); 2333 inline void UnlinkFreeListCategories(Page* page);
2296 inline intptr_t RelinkFreeListCategories(Page* page); 2334 inline intptr_t RelinkFreeListCategories(Page* page);
2297 2335
2336 // Callback signature:
2337 // void Callback(Page*);
2338 template <typename Callback>
2339 void ForAllPages(Callback callback) {
2340 PageIterator it(this);
2341 while (it.has_next()) {
2342 callback(it.next());
2343 }
2344 }
2345
2298 protected: 2346 protected:
2299 // PagedSpaces that should be included in snapshots have different, i.e., 2347 // PagedSpaces that should be included in snapshots have different, i.e.,
2300 // smaller, initial pages. 2348 // smaller, initial pages.
2301 virtual bool snapshotable() { return true; } 2349 virtual bool snapshotable() { return true; }
2302 2350
2303 bool HasPages() { return anchor_.next_page() != &anchor_; } 2351 bool HasPages() { return anchor_.next_page() != &anchor_; }
2304 2352
2305 // Cleans up the space, frees all pages in this space except those belonging 2353 // Cleans up the space, frees all pages in this space except those belonging
2306 // to the initial chunk, uncommits addresses in the initial chunk. 2354 // to the initial chunk, uncommits addresses in the initial chunk.
2307 void TearDown(); 2355 void TearDown();
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
3149 count = 0; 3197 count = 0;
3150 } 3198 }
3151 // Must be small, since an iteration is used for lookup. 3199 // Must be small, since an iteration is used for lookup.
3152 static const int kMaxComments = 64; 3200 static const int kMaxComments = 64;
3153 }; 3201 };
3154 #endif 3202 #endif
3155 } // namespace internal 3203 } // namespace internal
3156 } // namespace v8 3204 } // namespace v8
3157 3205
3158 #endif // V8_HEAP_SPACES_H_ 3206 #endif // V8_HEAP_SPACES_H_
OLDNEW
« no previous file with comments | « src/heap/scavenger.cc ('k') | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698