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 #include <memory> | 9 #include <memory> |
10 #include <unordered_set> | 10 #include <unordered_set> |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 } | 911 } |
912 | 912 |
913 virtual void ResumeAllocationObservers() { | 913 virtual void ResumeAllocationObservers() { |
914 allocation_observers_paused_ = false; | 914 allocation_observers_paused_ = false; |
915 } | 915 } |
916 | 916 |
917 void AllocationStep(Address soon_object, int size); | 917 void AllocationStep(Address soon_object, int size); |
918 | 918 |
919 // Return the total amount committed memory for this space, i.e., allocatable | 919 // Return the total amount committed memory for this space, i.e., allocatable |
920 // memory and page headers. | 920 // memory and page headers. |
921 virtual intptr_t CommittedMemory() { return committed_; } | 921 virtual size_t CommittedMemory() { return committed_; } |
922 | 922 |
923 virtual intptr_t MaximumCommittedMemory() { return max_committed_; } | 923 virtual size_t MaximumCommittedMemory() { return max_committed_; } |
924 | 924 |
925 // Returns allocated size. | 925 // Returns allocated size. |
926 virtual intptr_t Size() = 0; | 926 virtual intptr_t Size() = 0; |
927 | 927 |
928 // Returns size of objects. Can differ from the allocated size | 928 // Returns size of objects. Can differ from the allocated size |
929 // (e.g. see LargeObjectSpace). | 929 // (e.g. see LargeObjectSpace). |
930 virtual intptr_t SizeOfObjects() { return Size(); } | 930 virtual intptr_t SizeOfObjects() { return Size(); } |
931 | 931 |
932 // Approximate amount of physical memory committed for this space. | 932 // Approximate amount of physical memory committed for this space. |
933 virtual size_t CommittedPhysicalMemory() = 0; | 933 virtual size_t CommittedPhysicalMemory() = 0; |
934 | 934 |
935 // Return the available bytes without growing. | 935 // Return the available bytes without growing. |
936 virtual intptr_t Available() = 0; | 936 virtual intptr_t Available() = 0; |
937 | 937 |
938 virtual int RoundSizeDownToObjectAlignment(int size) { | 938 virtual int RoundSizeDownToObjectAlignment(int size) { |
939 if (id_ == CODE_SPACE) { | 939 if (id_ == CODE_SPACE) { |
940 return RoundDown(size, kCodeAlignment); | 940 return RoundDown(size, kCodeAlignment); |
941 } else { | 941 } else { |
942 return RoundDown(size, kPointerSize); | 942 return RoundDown(size, kPointerSize); |
943 } | 943 } |
944 } | 944 } |
945 | 945 |
946 virtual std::unique_ptr<ObjectIterator> GetObjectIterator() = 0; | 946 virtual std::unique_ptr<ObjectIterator> GetObjectIterator() = 0; |
947 | 947 |
948 void AccountCommitted(intptr_t bytes) { | 948 void AccountCommitted(size_t bytes) { |
949 DCHECK_GE(bytes, 0); | 949 DCHECK_GE(committed_ + bytes, committed_); |
950 committed_ += bytes; | 950 committed_ += bytes; |
951 if (committed_ > max_committed_) { | 951 if (committed_ > max_committed_) { |
952 max_committed_ = committed_; | 952 max_committed_ = committed_; |
953 } | 953 } |
954 } | 954 } |
955 | 955 |
956 void AccountUncommitted(intptr_t bytes) { | 956 void AccountUncommitted(size_t bytes) { |
957 DCHECK_GE(bytes, 0); | 957 DCHECK_GE(committed_, committed_ - bytes); |
958 committed_ -= bytes; | 958 committed_ -= bytes; |
959 DCHECK_GE(committed_, 0); | |
960 } | 959 } |
961 | 960 |
962 #ifdef DEBUG | 961 #ifdef DEBUG |
963 virtual void Print() = 0; | 962 virtual void Print() = 0; |
964 #endif | 963 #endif |
965 | 964 |
966 protected: | 965 protected: |
967 std::unique_ptr<List<AllocationObserver*>> allocation_observers_; | 966 std::unique_ptr<List<AllocationObserver*>> allocation_observers_; |
968 bool allocation_observers_paused_; | 967 bool allocation_observers_paused_; |
969 | 968 |
970 private: | 969 private: |
971 Heap* heap_; | 970 Heap* heap_; |
972 AllocationSpace id_; | 971 AllocationSpace id_; |
973 Executability executable_; | 972 Executability executable_; |
974 | 973 |
975 // Keeps track of committed memory in a space. | 974 // Keeps track of committed memory in a space. |
976 intptr_t committed_; | 975 size_t committed_; |
977 intptr_t max_committed_; | 976 size_t max_committed_; |
978 | 977 |
979 DISALLOW_COPY_AND_ASSIGN(Space); | 978 DISALLOW_COPY_AND_ASSIGN(Space); |
980 }; | 979 }; |
981 | 980 |
982 | 981 |
983 class MemoryChunkValidator { | 982 class MemoryChunkValidator { |
984 // Computed offsets should match the compiler generated ones. | 983 // Computed offsets should match the compiler generated ones. |
985 STATIC_ASSERT(MemoryChunk::kSizeOffset == offsetof(MemoryChunk, size_)); | 984 STATIC_ASSERT(MemoryChunk::kSizeOffset == offsetof(MemoryChunk, size_)); |
986 STATIC_ASSERT(MemoryChunk::kWriteBarrierCounterOffset == | 985 STATIC_ASSERT(MemoryChunk::kWriteBarrierCounterOffset == |
987 offsetof(MemoryChunk, write_barrier_counter_)); | 986 offsetof(MemoryChunk, write_barrier_counter_)); |
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2454 intptr_t Size() override { | 2453 intptr_t Size() override { |
2455 return to_space_.pages_used() * Page::kAllocatableMemory + | 2454 return to_space_.pages_used() * Page::kAllocatableMemory + |
2456 static_cast<int>(top() - to_space_.page_low()); | 2455 static_cast<int>(top() - to_space_.page_low()); |
2457 } | 2456 } |
2458 | 2457 |
2459 intptr_t SizeOfObjects() override { | 2458 intptr_t SizeOfObjects() override { |
2460 return Size() - | 2459 return Size() - |
2461 static_cast<intptr_t>(fragmentation_in_intermediate_generation_); | 2460 static_cast<intptr_t>(fragmentation_in_intermediate_generation_); |
2462 } | 2461 } |
2463 | 2462 |
2464 // The same, but returning an int. We have to have the one that returns | |
2465 // intptr_t because it is inherited, but if we know we are dealing with the | |
2466 // new space, which can't get as big as the other spaces then this is useful: | |
2467 int SizeAsInt() { return static_cast<int>(Size()); } | |
2468 | |
2469 // Return the allocatable capacity of a semispace. | 2463 // Return the allocatable capacity of a semispace. |
2470 intptr_t Capacity() { | 2464 intptr_t Capacity() { |
2471 SLOW_DCHECK(to_space_.current_capacity() == from_space_.current_capacity()); | 2465 SLOW_DCHECK(to_space_.current_capacity() == from_space_.current_capacity()); |
2472 return (to_space_.current_capacity() / Page::kPageSize) * | 2466 return (to_space_.current_capacity() / Page::kPageSize) * |
2473 Page::kAllocatableMemory; | 2467 Page::kAllocatableMemory; |
2474 } | 2468 } |
2475 | 2469 |
2476 // Return the current size of a semispace, allocatable and non-allocatable | 2470 // Return the current size of a semispace, allocatable and non-allocatable |
2477 // memory. | 2471 // memory. |
2478 intptr_t TotalCapacity() { | 2472 intptr_t TotalCapacity() { |
2479 DCHECK(to_space_.current_capacity() == from_space_.current_capacity()); | 2473 DCHECK(to_space_.current_capacity() == from_space_.current_capacity()); |
2480 return to_space_.current_capacity(); | 2474 return to_space_.current_capacity(); |
2481 } | 2475 } |
2482 | 2476 |
2483 // Committed memory for NewSpace is the committed memory of both semi-spaces | 2477 // Committed memory for NewSpace is the committed memory of both semi-spaces |
2484 // combined. | 2478 // combined. |
2485 intptr_t CommittedMemory() override { | 2479 size_t CommittedMemory() override { |
2486 return from_space_.CommittedMemory() + to_space_.CommittedMemory(); | 2480 return from_space_.CommittedMemory() + to_space_.CommittedMemory(); |
2487 } | 2481 } |
2488 | 2482 |
2489 intptr_t MaximumCommittedMemory() override { | 2483 size_t MaximumCommittedMemory() override { |
2490 return from_space_.MaximumCommittedMemory() + | 2484 return from_space_.MaximumCommittedMemory() + |
2491 to_space_.MaximumCommittedMemory(); | 2485 to_space_.MaximumCommittedMemory(); |
2492 } | 2486 } |
2493 | 2487 |
2494 // Approximate amount of physical memory committed for this space. | 2488 // Approximate amount of physical memory committed for this space. |
2495 size_t CommittedPhysicalMemory() override; | 2489 size_t CommittedPhysicalMemory() override; |
2496 | 2490 |
2497 // Return the available bytes without growing. | 2491 // Return the available bytes without growing. |
2498 intptr_t Available() override { return Capacity() - Size(); } | 2492 intptr_t Available() override { return Capacity() - Size(); } |
2499 | 2493 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2927 PageIterator old_iterator_; | 2921 PageIterator old_iterator_; |
2928 PageIterator code_iterator_; | 2922 PageIterator code_iterator_; |
2929 PageIterator map_iterator_; | 2923 PageIterator map_iterator_; |
2930 LargePageIterator lo_iterator_; | 2924 LargePageIterator lo_iterator_; |
2931 }; | 2925 }; |
2932 | 2926 |
2933 } // namespace internal | 2927 } // namespace internal |
2934 } // namespace v8 | 2928 } // namespace v8 |
2935 | 2929 |
2936 #endif // V8_HEAP_SPACES_H_ | 2930 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |