OLD | NEW |
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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 static const size_t kMinHeaderSize = | 516 static const size_t kMinHeaderSize = |
516 kWriteBarrierCounterOffset + | 517 kWriteBarrierCounterOffset + |
517 kIntptrSize // intptr_t write_barrier_counter_ | 518 kIntptrSize // intptr_t write_barrier_counter_ |
518 + kPointerSize // AtomicValue high_water_mark_ | 519 + kPointerSize // AtomicValue high_water_mark_ |
519 + kPointerSize // base::Mutex* mutex_ | 520 + kPointerSize // base::Mutex* mutex_ |
520 + kPointerSize // base::AtomicWord concurrent_sweeping_ | 521 + kPointerSize // base::AtomicWord concurrent_sweeping_ |
521 + 2 * kPointerSize // AtomicNumber free-list statistics | 522 + 2 * kPointerSize // AtomicNumber free-list statistics |
522 + kPointerSize // AtomicValue next_chunk_ | 523 + kPointerSize // AtomicValue next_chunk_ |
523 + kPointerSize // AtomicValue prev_chunk_ | 524 + kPointerSize // AtomicValue prev_chunk_ |
524 // FreeListCategory categories_[kNumberOfCategories] | 525 // FreeListCategory categories_[kNumberOfCategories] |
525 + FreeListCategory::kSize * kNumberOfCategories; | 526 + FreeListCategory::kSize * kNumberOfCategories + |
| 527 kPointerSize; // LocalArrayBufferTracker tracker_ |
526 | 528 |
527 // We add some more space to the computed header size to amount for missing | 529 // We add some more space to the computed header size to amount for missing |
528 // alignment requirements in our computation. | 530 // alignment requirements in our computation. |
529 // Try to get kHeaderSize properly aligned on 32-bit and 64-bit machines. | 531 // Try to get kHeaderSize properly aligned on 32-bit and 64-bit machines. |
530 static const size_t kHeaderSize = kMinHeaderSize; | 532 static const size_t kHeaderSize = kMinHeaderSize; |
531 | 533 |
532 static const int kBodyOffset = | 534 static const int kBodyOffset = |
533 CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize); | 535 CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize); |
534 | 536 |
535 // The start offset of the object area in a page. Aligned to both maps and | 537 // The start offset of the object area in a page. Aligned to both maps and |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 base::AtomicNumber<intptr_t> available_in_free_list_; | 812 base::AtomicNumber<intptr_t> available_in_free_list_; |
811 base::AtomicNumber<intptr_t> wasted_memory_; | 813 base::AtomicNumber<intptr_t> wasted_memory_; |
812 | 814 |
813 // next_chunk_ holds a pointer of type MemoryChunk | 815 // next_chunk_ holds a pointer of type MemoryChunk |
814 base::AtomicValue<MemoryChunk*> next_chunk_; | 816 base::AtomicValue<MemoryChunk*> next_chunk_; |
815 // prev_chunk_ holds a pointer of type MemoryChunk | 817 // prev_chunk_ holds a pointer of type MemoryChunk |
816 base::AtomicValue<MemoryChunk*> prev_chunk_; | 818 base::AtomicValue<MemoryChunk*> prev_chunk_; |
817 | 819 |
818 FreeListCategory categories_[kNumberOfCategories]; | 820 FreeListCategory categories_[kNumberOfCategories]; |
819 | 821 |
| 822 LocalArrayBufferTracker* local_tracker_; |
| 823 |
820 private: | 824 private: |
821 void InitializeReservedMemory() { reservation_.Reset(); } | 825 void InitializeReservedMemory() { reservation_.Reset(); } |
822 | 826 |
823 friend class MemoryAllocator; | 827 friend class MemoryAllocator; |
824 friend class MemoryChunkValidator; | 828 friend class MemoryChunkValidator; |
825 }; | 829 }; |
826 | 830 |
827 // ----------------------------------------------------------------------------- | 831 // ----------------------------------------------------------------------------- |
828 // A page is a memory chunk of a size 1MB. Large object pages may be larger. | 832 // A page is a memory chunk of a size 1MB. Large object pages may be larger. |
829 // | 833 // |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 | 944 |
941 bool is_anchor() { return IsFlagSet(Page::ANCHOR); } | 945 bool is_anchor() { return IsFlagSet(Page::ANCHOR); } |
942 | 946 |
943 intptr_t wasted_memory() { return wasted_memory_.Value(); } | 947 intptr_t wasted_memory() { return wasted_memory_.Value(); } |
944 void add_wasted_memory(intptr_t waste) { wasted_memory_.Increment(waste); } | 948 void add_wasted_memory(intptr_t waste) { wasted_memory_.Increment(waste); } |
945 intptr_t available_in_free_list() { return available_in_free_list_.Value(); } | 949 intptr_t available_in_free_list() { return available_in_free_list_.Value(); } |
946 void add_available_in_free_list(intptr_t available) { | 950 void add_available_in_free_list(intptr_t available) { |
947 available_in_free_list_.Increment(available); | 951 available_in_free_list_.Increment(available); |
948 } | 952 } |
949 | 953 |
| 954 LocalArrayBufferTracker* local_tracker() { |
| 955 if (local_tracker_ == nullptr) { |
| 956 local_tracker_ = new LocalArrayBufferTracker(heap_); |
| 957 } |
| 958 return local_tracker_; |
| 959 } |
| 960 |
| 961 void FreeDeadArrayBuffers() { |
| 962 if (local_tracker_ != nullptr) { |
| 963 local_tracker_->FreeDead(); |
| 964 if (local_tracker_->IsEmpty()) { |
| 965 delete local_tracker_; |
| 966 local_tracker_ = nullptr; |
| 967 } |
| 968 } |
| 969 } |
| 970 |
| 971 template <LocalArrayBufferTracker::LivenessIndicator liveness_indicator> |
| 972 void ScanAndFreeDeadArrayBuffers() { |
| 973 if (local_tracker_ != nullptr) { |
| 974 local_tracker_->ScanAndFreeDead<liveness_indicator>(); |
| 975 if (local_tracker_->IsEmpty()) { |
| 976 delete local_tracker_; |
| 977 local_tracker_ = nullptr; |
| 978 } |
| 979 } |
| 980 } |
| 981 |
| 982 void ResetTracker() { |
| 983 if (local_tracker_ != nullptr) { |
| 984 local_tracker_->Reset(); |
| 985 } |
| 986 } |
| 987 |
950 #ifdef DEBUG | 988 #ifdef DEBUG |
951 void Print(); | 989 void Print(); |
952 #endif // DEBUG | 990 #endif // DEBUG |
953 | 991 |
954 private: | 992 private: |
955 enum InitializationMode { kFreeMemory, kDoNotFreeMemory }; | 993 enum InitializationMode { kFreeMemory, kDoNotFreeMemory }; |
956 | 994 |
957 template <InitializationMode mode = kFreeMemory> | 995 template <InitializationMode mode = kFreeMemory> |
958 static inline Page* Initialize(Heap* heap, MemoryChunk* chunk, | 996 static inline Page* Initialize(Heap* heap, MemoryChunk* chunk, |
959 Executability executable, PagedSpace* owner); | 997 Executability executable, PagedSpace* owner); |
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2281 // sweeper. | 2319 // sweeper. |
2282 virtual void RefillFreeList(); | 2320 virtual void RefillFreeList(); |
2283 | 2321 |
2284 FreeList* free_list() { return &free_list_; } | 2322 FreeList* free_list() { return &free_list_; } |
2285 | 2323 |
2286 base::Mutex* mutex() { return &space_mutex_; } | 2324 base::Mutex* mutex() { return &space_mutex_; } |
2287 | 2325 |
2288 inline void UnlinkFreeListCategories(Page* page); | 2326 inline void UnlinkFreeListCategories(Page* page); |
2289 inline intptr_t RelinkFreeListCategories(Page* page); | 2327 inline intptr_t RelinkFreeListCategories(Page* page); |
2290 | 2328 |
| 2329 // Callback signature: |
| 2330 // void Callback(Page*); |
| 2331 template <typename Callback> |
| 2332 void ForAllPages(Callback callback) { |
| 2333 PageIterator it(this); |
| 2334 while (it.has_next()) { |
| 2335 callback(it.next()); |
| 2336 } |
| 2337 } |
| 2338 |
2291 protected: | 2339 protected: |
2292 // PagedSpaces that should be included in snapshots have different, i.e., | 2340 // PagedSpaces that should be included in snapshots have different, i.e., |
2293 // smaller, initial pages. | 2341 // smaller, initial pages. |
2294 virtual bool snapshotable() { return true; } | 2342 virtual bool snapshotable() { return true; } |
2295 | 2343 |
2296 bool HasPages() { return anchor_.next_page() != &anchor_; } | 2344 bool HasPages() { return anchor_.next_page() != &anchor_; } |
2297 | 2345 |
2298 // Cleans up the space, frees all pages in this space except those belonging | 2346 // Cleans up the space, frees all pages in this space except those belonging |
2299 // to the initial chunk, uncommits addresses in the initial chunk. | 2347 // to the initial chunk, uncommits addresses in the initial chunk. |
2300 void TearDown(); | 2348 void TearDown(); |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3144 count = 0; | 3192 count = 0; |
3145 } | 3193 } |
3146 // Must be small, since an iteration is used for lookup. | 3194 // Must be small, since an iteration is used for lookup. |
3147 static const int kMaxComments = 64; | 3195 static const int kMaxComments = 64; |
3148 }; | 3196 }; |
3149 #endif | 3197 #endif |
3150 } // namespace internal | 3198 } // namespace internal |
3151 } // namespace v8 | 3199 } // namespace v8 |
3152 | 3200 |
3153 #endif // V8_HEAP_SPACES_H_ | 3201 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |