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 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3033 count = 0; | 2990 count = 0; |
3034 } | 2991 } |
3035 // Must be small, since an iteration is used for lookup. | 2992 // Must be small, since an iteration is used for lookup. |
3036 static const int kMaxComments = 64; | 2993 static const int kMaxComments = 64; |
3037 }; | 2994 }; |
3038 #endif | 2995 #endif |
3039 } // namespace internal | 2996 } // namespace internal |
3040 } // namespace v8 | 2997 } // namespace v8 |
3041 | 2998 |
3042 #endif // V8_HEAP_SPACES_H_ | 2999 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |