| 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> |
| 11 | 11 |
| 12 #include "src/allocation.h" | 12 #include "src/allocation.h" |
| 13 #include "src/base/atomic-utils.h" | 13 #include "src/base/atomic-utils.h" |
| 14 #include "src/base/atomicops.h" | 14 #include "src/base/atomicops.h" |
| 15 #include "src/base/bits.h" | 15 #include "src/base/bits.h" |
| 16 #include "src/base/hashmap.h" | 16 #include "src/base/hashmap.h" |
| 17 #include "src/base/platform/mutex.h" | 17 #include "src/base/platform/mutex.h" |
| 18 #include "src/flags.h" | 18 #include "src/flags.h" |
| 19 #include "src/globals.h" | 19 #include "src/globals.h" |
| 20 #include "src/heap/heap.h" |
| 20 #include "src/heap/marking.h" | 21 #include "src/heap/marking.h" |
| 21 #include "src/list.h" | 22 #include "src/list.h" |
| 22 #include "src/objects.h" | 23 #include "src/objects.h" |
| 23 #include "src/utils.h" | 24 #include "src/utils.h" |
| 24 | 25 |
| 25 namespace v8 { | 26 namespace v8 { |
| 26 namespace internal { | 27 namespace internal { |
| 27 | 28 |
| 28 class AllocationInfo; | 29 class AllocationInfo; |
| 29 class AllocationObserver; | 30 class AllocationObserver; |
| (...skipping 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1861 | 1862 |
| 1862 PagedSpace* owner_; | 1863 PagedSpace* owner_; |
| 1863 base::AtomicNumber<intptr_t> wasted_bytes_; | 1864 base::AtomicNumber<intptr_t> wasted_bytes_; |
| 1864 FreeListCategory* categories_[kNumberOfCategories]; | 1865 FreeListCategory* categories_[kNumberOfCategories]; |
| 1865 | 1866 |
| 1866 friend class FreeListCategory; | 1867 friend class FreeListCategory; |
| 1867 | 1868 |
| 1868 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); | 1869 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); |
| 1869 }; | 1870 }; |
| 1870 | 1871 |
| 1871 | |
| 1872 class AllocationResult { | |
| 1873 public: | |
| 1874 // Implicit constructor from Object*. | |
| 1875 AllocationResult(Object* object) // NOLINT | |
| 1876 : object_(object) { | |
| 1877 // AllocationResults can't return Smis, which are used to represent | |
| 1878 // failure and the space to retry in. | |
| 1879 CHECK(!object->IsSmi()); | |
| 1880 } | |
| 1881 | |
| 1882 AllocationResult() : object_(Smi::FromInt(NEW_SPACE)) {} | |
| 1883 | |
| 1884 static inline AllocationResult Retry(AllocationSpace space = NEW_SPACE) { | |
| 1885 return AllocationResult(space); | |
| 1886 } | |
| 1887 | |
| 1888 inline bool IsRetry() { return object_->IsSmi(); } | |
| 1889 | |
| 1890 template <typename T> | |
| 1891 bool To(T** obj) { | |
| 1892 if (IsRetry()) return false; | |
| 1893 *obj = T::cast(object_); | |
| 1894 return true; | |
| 1895 } | |
| 1896 | |
| 1897 Object* ToObjectChecked() { | |
| 1898 CHECK(!IsRetry()); | |
| 1899 return object_; | |
| 1900 } | |
| 1901 | |
| 1902 inline AllocationSpace RetrySpace(); | |
| 1903 | |
| 1904 private: | |
| 1905 explicit AllocationResult(AllocationSpace space) | |
| 1906 : object_(Smi::FromInt(static_cast<int>(space))) {} | |
| 1907 | |
| 1908 Object* object_; | |
| 1909 }; | |
| 1910 | |
| 1911 | |
| 1912 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); | |
| 1913 | |
| 1914 | |
| 1915 // LocalAllocationBuffer represents a linear allocation area that is created | 1872 // LocalAllocationBuffer represents a linear allocation area that is created |
| 1916 // from a given {AllocationResult} and can be used to allocate memory without | 1873 // from a given {AllocationResult} and can be used to allocate memory without |
| 1917 // synchronization. | 1874 // synchronization. |
| 1918 // | 1875 // |
| 1919 // The buffer is properly closed upon destruction and reassignment. | 1876 // The buffer is properly closed upon destruction and reassignment. |
| 1920 // Example: | 1877 // Example: |
| 1921 // { | 1878 // { |
| 1922 // AllocationResult result = ...; | 1879 // AllocationResult result = ...; |
| 1923 // LocalAllocationBuffer a(heap, result, size); | 1880 // LocalAllocationBuffer a(heap, result, size); |
| 1924 // LocalAllocationBuffer b = a; | 1881 // LocalAllocationBuffer b = a; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2240 // Mutex guarding any concurrent access to the space. | 2197 // Mutex guarding any concurrent access to the space. |
| 2241 base::Mutex space_mutex_; | 2198 base::Mutex space_mutex_; |
| 2242 | 2199 |
| 2243 friend class IncrementalMarking; | 2200 friend class IncrementalMarking; |
| 2244 friend class MarkCompactCollector; | 2201 friend class MarkCompactCollector; |
| 2245 | 2202 |
| 2246 // Used in cctest. | 2203 // Used in cctest. |
| 2247 friend class HeapTester; | 2204 friend class HeapTester; |
| 2248 }; | 2205 }; |
| 2249 | 2206 |
| 2250 | |
| 2251 class NumberAndSizeInfo BASE_EMBEDDED { | |
| 2252 public: | |
| 2253 NumberAndSizeInfo() : number_(0), bytes_(0) {} | |
| 2254 | |
| 2255 int number() const { return number_; } | |
| 2256 void increment_number(int num) { number_ += num; } | |
| 2257 | |
| 2258 int bytes() const { return bytes_; } | |
| 2259 void increment_bytes(int size) { bytes_ += size; } | |
| 2260 | |
| 2261 void clear() { | |
| 2262 number_ = 0; | |
| 2263 bytes_ = 0; | |
| 2264 } | |
| 2265 | |
| 2266 private: | |
| 2267 int number_; | |
| 2268 int bytes_; | |
| 2269 }; | |
| 2270 | |
| 2271 | |
| 2272 // HistogramInfo class for recording a single "bar" of a histogram. This | |
| 2273 // class is used for collecting statistics to print to the log file. | |
| 2274 class HistogramInfo : public NumberAndSizeInfo { | |
| 2275 public: | |
| 2276 HistogramInfo() : NumberAndSizeInfo() {} | |
| 2277 | |
| 2278 const char* name() { return name_; } | |
| 2279 void set_name(const char* name) { name_ = name; } | |
| 2280 | |
| 2281 private: | |
| 2282 const char* name_; | |
| 2283 }; | |
| 2284 | |
| 2285 enum SemiSpaceId { kFromSpace = 0, kToSpace = 1 }; | 2207 enum SemiSpaceId { kFromSpace = 0, kToSpace = 1 }; |
| 2286 | 2208 |
| 2287 // ----------------------------------------------------------------------------- | 2209 // ----------------------------------------------------------------------------- |
| 2288 // SemiSpace in young generation | 2210 // SemiSpace in young generation |
| 2289 // | 2211 // |
| 2290 // A SemiSpace is a contiguous chunk of memory holding page-like memory chunks. | 2212 // A SemiSpace is a contiguous chunk of memory holding page-like memory chunks. |
| 2291 // The mark-compact collector uses the memory of the first page in the from | 2213 // The mark-compact collector uses the memory of the first page in the from |
| 2292 // space as a marking stack when tracing live objects. | 2214 // space as a marking stack when tracing live objects. |
| 2293 class SemiSpace : public Space { | 2215 class SemiSpace : public Space { |
| 2294 public: | 2216 public: |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3015 kFinishedState | 2937 kFinishedState |
| 3016 }; | 2938 }; |
| 3017 Heap* heap_; | 2939 Heap* heap_; |
| 3018 State state_; | 2940 State state_; |
| 3019 PageIterator old_iterator_; | 2941 PageIterator old_iterator_; |
| 3020 PageIterator code_iterator_; | 2942 PageIterator code_iterator_; |
| 3021 PageIterator map_iterator_; | 2943 PageIterator map_iterator_; |
| 3022 LargePageIterator lo_iterator_; | 2944 LargePageIterator lo_iterator_; |
| 3023 }; | 2945 }; |
| 3024 | 2946 |
| 3025 #ifdef DEBUG | |
| 3026 struct CommentStatistic { | |
| 3027 const char* comment; | |
| 3028 int size; | |
| 3029 int count; | |
| 3030 void Clear() { | |
| 3031 comment = NULL; | |
| 3032 size = 0; | |
| 3033 count = 0; | |
| 3034 } | |
| 3035 // Must be small, since an iteration is used for lookup. | |
| 3036 static const int kMaxComments = 64; | |
| 3037 }; | |
| 3038 #endif | |
| 3039 } // namespace internal | 2947 } // namespace internal |
| 3040 } // namespace v8 | 2948 } // namespace v8 |
| 3041 | 2949 |
| 3042 #endif // V8_HEAP_SPACES_H_ | 2950 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |