OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_HEAP_H_ | 5 #ifndef VM_HEAP_H_ |
6 #define VM_HEAP_H_ | 6 #define VM_HEAP_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 kInvokeApiCallbacks | 38 kInvokeApiCallbacks |
39 }; | 39 }; |
40 | 40 |
41 // Default allocation sizes in MB for the old gen and code heaps. | 41 // Default allocation sizes in MB for the old gen and code heaps. |
42 static const intptr_t kHeapSizeInMB = 512; | 42 static const intptr_t kHeapSizeInMB = 512; |
43 static const intptr_t kCodeHeapSizeInMB = 12; | 43 static const intptr_t kCodeHeapSizeInMB = 12; |
44 | 44 |
45 ~Heap(); | 45 ~Heap(); |
46 | 46 |
47 uword Allocate(intptr_t size, Space space) { | 47 uword Allocate(intptr_t size, Space space) { |
| 48 ASSERT(!read_only_); |
48 switch (space) { | 49 switch (space) { |
49 case kNew: | 50 case kNew: |
50 // Do not attempt to allocate very large objects in new space. | 51 // Do not attempt to allocate very large objects in new space. |
51 if (!PageSpace::IsPageAllocatableSize(size)) { | 52 if (!PageSpace::IsPageAllocatableSize(size)) { |
52 return AllocateOld(size); | 53 return AllocateOld(size); |
53 } | 54 } |
54 return AllocateNew(size); | 55 return AllocateNew(size); |
55 case kOld: | 56 case kOld: |
56 return AllocateOld(size); | 57 return AllocateOld(size); |
57 case kCode: | 58 case kCode: |
58 return AllocateCode(code_space_, size); | 59 return AllocateCode(code_space_, size); |
59 default: | 60 default: |
60 UNREACHABLE(); | 61 UNREACHABLE(); |
61 } | 62 } |
62 return 0; | 63 return 0; |
63 } | 64 } |
64 | 65 |
65 uword TryAllocate(intptr_t size, Space space) { | 66 uword TryAllocate(intptr_t size, Space space) { |
| 67 ASSERT(!read_only_); |
66 switch (space) { | 68 switch (space) { |
67 case kNew: | 69 case kNew: |
68 return new_space_->TryAllocate(size); | 70 return new_space_->TryAllocate(size); |
69 case kOld: | 71 case kOld: |
70 return old_space_->TryAllocate(size); | 72 return old_space_->TryAllocate(size); |
71 case kCode: | 73 case kCode: |
72 return code_space_->TryAllocate(size); | 74 return code_space_->TryAllocate(size); |
73 default: | 75 default: |
74 UNREACHABLE(); | 76 UNREACHABLE(); |
75 } | 77 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 RawInstructions* FindObjectInStubCodeSpace(FindObjectVisitor* visitor); | 112 RawInstructions* FindObjectInStubCodeSpace(FindObjectVisitor* visitor); |
111 | 113 |
112 void CollectGarbage(Space space); | 114 void CollectGarbage(Space space); |
113 void CollectGarbage(Space space, ApiCallbacks api_callbacks); | 115 void CollectGarbage(Space space, ApiCallbacks api_callbacks); |
114 void CollectAllGarbage(); | 116 void CollectAllGarbage(); |
115 | 117 |
116 // Enables growth control on the page space heaps. This should be | 118 // Enables growth control on the page space heaps. This should be |
117 // called before any user code is executed. | 119 // called before any user code is executed. |
118 void EnableGrowthControl(); | 120 void EnableGrowthControl(); |
119 | 121 |
| 122 // Protect access to the heap. |
| 123 void WriteProtect(bool read_only); |
| 124 |
120 // Accessors for inlined allocation in generated code. | 125 // Accessors for inlined allocation in generated code. |
121 uword TopAddress(); | 126 uword TopAddress(); |
122 uword EndAddress(); | 127 uword EndAddress(); |
123 static intptr_t new_space_offset() { return OFFSET_OF(Heap, new_space_); } | 128 static intptr_t new_space_offset() { return OFFSET_OF(Heap, new_space_); } |
124 | 129 |
125 // Initialize the heap and register it with the isolate. | 130 // Initialize the heap and register it with the isolate. |
126 static void Init(Isolate* isolate); | 131 static void Init(Isolate* isolate); |
127 | 132 |
128 // Verify that all pointers in the heap point to the heap. | 133 // Verify that all pointers in the heap point to the heap. |
129 bool Verify() const; | 134 bool Verify() const; |
(...skipping 14 matching lines...) Expand all Loading... |
144 | 149 |
145 uword AllocateNew(intptr_t size); | 150 uword AllocateNew(intptr_t size); |
146 uword AllocateOld(intptr_t size); | 151 uword AllocateOld(intptr_t size); |
147 uword AllocateCode(PageSpace* space, intptr_t size); | 152 uword AllocateCode(PageSpace* space, intptr_t size); |
148 | 153 |
149 // The different spaces used for allocation. | 154 // The different spaces used for allocation. |
150 Scavenger* new_space_; | 155 Scavenger* new_space_; |
151 PageSpace* old_space_; | 156 PageSpace* old_space_; |
152 PageSpace* code_space_; | 157 PageSpace* code_space_; |
153 | 158 |
| 159 // This heap is in read-only mode: No allocation is allowed. |
| 160 bool read_only_; |
| 161 |
154 friend class GCTestHelper; | 162 friend class GCTestHelper; |
155 DISALLOW_COPY_AND_ASSIGN(Heap); | 163 DISALLOW_COPY_AND_ASSIGN(Heap); |
156 }; | 164 }; |
157 | 165 |
158 | 166 |
159 #if defined(DEBUG) | 167 #if defined(DEBUG) |
160 class NoGCScope : public StackResource { | 168 class NoGCScope : public StackResource { |
161 public: | 169 public: |
162 NoGCScope(); | 170 NoGCScope(); |
163 ~NoGCScope(); | 171 ~NoGCScope(); |
164 private: | 172 private: |
165 DISALLOW_COPY_AND_ASSIGN(NoGCScope); | 173 DISALLOW_COPY_AND_ASSIGN(NoGCScope); |
166 }; | 174 }; |
167 #else // defined(DEBUG) | 175 #else // defined(DEBUG) |
168 class NoGCScope : public ValueObject { | 176 class NoGCScope : public ValueObject { |
169 public: | 177 public: |
170 NoGCScope() {} | 178 NoGCScope() {} |
171 private: | 179 private: |
172 DISALLOW_COPY_AND_ASSIGN(NoGCScope); | 180 DISALLOW_COPY_AND_ASSIGN(NoGCScope); |
173 }; | 181 }; |
174 #endif // defined(DEBUG) | 182 #endif // defined(DEBUG) |
175 | 183 |
176 } // namespace dart | 184 } // namespace dart |
177 | 185 |
178 #endif // VM_HEAP_H_ | 186 #endif // VM_HEAP_H_ |
OLD | NEW |