| 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 FreeDeadArraybuffersAndResetTracker() { |
| 962 if (local_tracker_ != nullptr) { |
| 963 local_tracker_->FreeDeadAndReset(); |
| 964 if (local_tracker_->IsEmpty()) { |
| 965 delete local_tracker_; |
| 966 local_tracker_ = nullptr; |
| 967 } |
| 968 } |
| 969 } |
| 970 |
| 950 #ifdef DEBUG | 971 #ifdef DEBUG |
| 951 void Print(); | 972 void Print(); |
| 952 #endif // DEBUG | 973 #endif // DEBUG |
| 953 | 974 |
| 954 private: | 975 private: |
| 955 enum InitializationMode { kFreeMemory, kDoNotFreeMemory }; | 976 enum InitializationMode { kFreeMemory, kDoNotFreeMemory }; |
| 956 | 977 |
| 957 template <InitializationMode mode = kFreeMemory> | 978 template <InitializationMode mode = kFreeMemory> |
| 958 static inline Page* Initialize(Heap* heap, MemoryChunk* chunk, | 979 static inline Page* Initialize(Heap* heap, MemoryChunk* chunk, |
| 959 Executability executable, PagedSpace* owner); | 980 Executability executable, PagedSpace* owner); |
| (...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2852 return from_space_.Uncommit(); | 2873 return from_space_.Uncommit(); |
| 2853 } | 2874 } |
| 2854 | 2875 |
| 2855 bool IsFromSpaceCommitted() { return from_space_.is_committed(); } | 2876 bool IsFromSpaceCommitted() { return from_space_.is_committed(); } |
| 2856 | 2877 |
| 2857 SemiSpace* active_space() { return &to_space_; } | 2878 SemiSpace* active_space() { return &to_space_; } |
| 2858 | 2879 |
| 2859 void PauseAllocationObservers() override; | 2880 void PauseAllocationObservers() override; |
| 2860 void ResumeAllocationObservers() override; | 2881 void ResumeAllocationObservers() override; |
| 2861 | 2882 |
| 2883 SemiSpace* from_space() { return &from_space_; } |
| 2884 SemiSpace* to_space() { return &to_space_; } |
| 2885 |
| 2862 private: | 2886 private: |
| 2863 // Update allocation info to match the current to-space page. | 2887 // Update allocation info to match the current to-space page. |
| 2864 void UpdateAllocationInfo(); | 2888 void UpdateAllocationInfo(); |
| 2865 | 2889 |
| 2866 base::Mutex mutex_; | 2890 base::Mutex mutex_; |
| 2867 | 2891 |
| 2868 // The semispaces. | 2892 // The semispaces. |
| 2869 SemiSpace to_space_; | 2893 SemiSpace to_space_; |
| 2870 SemiSpace from_space_; | 2894 SemiSpace from_space_; |
| 2871 base::VirtualMemory reservation_; | 2895 base::VirtualMemory reservation_; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3142 count = 0; | 3166 count = 0; |
| 3143 } | 3167 } |
| 3144 // Must be small, since an iteration is used for lookup. | 3168 // Must be small, since an iteration is used for lookup. |
| 3145 static const int kMaxComments = 64; | 3169 static const int kMaxComments = 64; |
| 3146 }; | 3170 }; |
| 3147 #endif | 3171 #endif |
| 3148 } // namespace internal | 3172 } // namespace internal |
| 3149 } // namespace v8 | 3173 } // namespace v8 |
| 3150 | 3174 |
| 3151 #endif // V8_HEAP_SPACES_H_ | 3175 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |