OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 RUNTIME_VM_HANDLES_H_ | 5 #ifndef RUNTIME_VM_HANDLES_H_ |
6 #define RUNTIME_VM_HANDLES_H_ | 6 #define RUNTIME_VM_HANDLES_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/os.h" | 10 #include "vm/os.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // | 48 // |
49 // There are some critical regions of the Dart VM were we may need to manipulate | 49 // There are some critical regions of the Dart VM were we may need to manipulate |
50 // raw dart objects directly. We use NOHANDLESCOPE to assert that we do not | 50 // raw dart objects directly. We use NOHANDLESCOPE to assert that we do not |
51 // add code that will allocate new handles during this critical area. | 51 // add code that will allocate new handles during this critical area. |
52 // { | 52 // { |
53 // NOHANDLESCOPE(thread); | 53 // NOHANDLESCOPE(thread); |
54 // .... | 54 // .... |
55 // .... | 55 // .... |
56 // } | 56 // } |
57 | 57 |
58 | |
59 // Forward declarations. | 58 // Forward declarations. |
60 class ObjectPointerVisitor; | 59 class ObjectPointerVisitor; |
61 class Thread; | 60 class Thread; |
62 | 61 |
63 DECLARE_FLAG(bool, verify_handles); | 62 DECLARE_FLAG(bool, verify_handles); |
64 | 63 |
65 class HandleVisitor { | 64 class HandleVisitor { |
66 public: | 65 public: |
67 explicit HandleVisitor(Thread* thread) : thread_(thread) {} | 66 explicit HandleVisitor(Thread* thread) : thread_(thread) {} |
68 virtual ~HandleVisitor() {} | 67 virtual ~HandleVisitor() {} |
69 | 68 |
70 Thread* thread() const { return thread_; } | 69 Thread* thread() const { return thread_; } |
71 | 70 |
72 virtual void VisitHandle(uword addr) = 0; | 71 virtual void VisitHandle(uword addr) = 0; |
73 | 72 |
74 private: | 73 private: |
75 Thread* thread_; | 74 Thread* thread_; |
76 | 75 |
77 DISALLOW_IMPLICIT_CONSTRUCTORS(HandleVisitor); | 76 DISALLOW_IMPLICIT_CONSTRUCTORS(HandleVisitor); |
78 }; | 77 }; |
79 | 78 |
80 | |
81 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 79 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
82 class Handles { | 80 class Handles { |
83 public: | 81 public: |
84 Handles() | 82 Handles() |
85 : zone_blocks_(NULL), | 83 : zone_blocks_(NULL), |
86 first_scoped_block_(NULL), | 84 first_scoped_block_(NULL), |
87 scoped_blocks_(&first_scoped_block_) {} | 85 scoped_blocks_(&first_scoped_block_) {} |
88 ~Handles() { DeleteAll(); } | 86 ~Handles() { DeleteAll(); } |
89 | 87 |
90 // Visit all object pointers stored in the various handles. | 88 // Visit all object pointers stored in the various handles. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 HandlesBlock* scoped_blocks_; // List of scoped handles. | 230 HandlesBlock* scoped_blocks_; // List of scoped handles. |
233 | 231 |
234 friend class HandleScope; | 232 friend class HandleScope; |
235 friend class Dart; | 233 friend class Dart; |
236 friend class ObjectStore; | 234 friend class ObjectStore; |
237 friend class Thread; | 235 friend class Thread; |
238 DISALLOW_ALLOCATION(); | 236 DISALLOW_ALLOCATION(); |
239 DISALLOW_COPY_AND_ASSIGN(Handles); | 237 DISALLOW_COPY_AND_ASSIGN(Handles); |
240 }; | 238 }; |
241 | 239 |
242 | |
243 static const int kVMHandleSizeInWords = 2; | 240 static const int kVMHandleSizeInWords = 2; |
244 static const int kVMHandlesPerChunk = 64; | 241 static const int kVMHandlesPerChunk = 64; |
245 static const int kOffsetOfRawPtr = kWordSize; | 242 static const int kOffsetOfRawPtr = kWordSize; |
246 class VMHandles : public Handles<kVMHandleSizeInWords, | 243 class VMHandles : public Handles<kVMHandleSizeInWords, |
247 kVMHandlesPerChunk, | 244 kVMHandlesPerChunk, |
248 kOffsetOfRawPtr> { | 245 kOffsetOfRawPtr> { |
249 public: | 246 public: |
250 static const int kOffsetOfRawPtrInHandle = kOffsetOfRawPtr; | 247 static const int kOffsetOfRawPtrInHandle = kOffsetOfRawPtr; |
251 | 248 |
252 VMHandles() | 249 VMHandles() |
(...skipping 21 matching lines...) Expand all Loading... |
274 static bool IsZoneHandle(uword handle); | 271 static bool IsZoneHandle(uword handle); |
275 | 272 |
276 // Returns number of handles, these functions are used for testing purposes. | 273 // Returns number of handles, these functions are used for testing purposes. |
277 static int ScopedHandleCount(); | 274 static int ScopedHandleCount(); |
278 static int ZoneHandleCount(); | 275 static int ZoneHandleCount(); |
279 | 276 |
280 friend class ApiZone; | 277 friend class ApiZone; |
281 friend class ApiNativeScope; | 278 friend class ApiNativeScope; |
282 }; | 279 }; |
283 | 280 |
284 | |
285 // The class HandleScope is used to start a new handles scope in the code. | 281 // The class HandleScope is used to start a new handles scope in the code. |
286 // It is used as follows: | 282 // It is used as follows: |
287 // { | 283 // { |
288 // HANDLESCOPE(thread); | 284 // HANDLESCOPE(thread); |
289 // .... | 285 // .... |
290 // ..... | 286 // ..... |
291 // code that creates some scoped handles. | 287 // code that creates some scoped handles. |
292 // .... | 288 // .... |
293 // } | 289 // } |
294 class HandleScope : public StackResource { | 290 class HandleScope : public StackResource { |
295 public: | 291 public: |
296 explicit HandleScope(Thread* thread); | 292 explicit HandleScope(Thread* thread); |
297 ~HandleScope(); | 293 ~HandleScope(); |
298 | 294 |
299 private: | 295 private: |
300 void Initialize(); | 296 void Initialize(); |
301 | 297 |
302 VMHandles::HandlesBlock* saved_handle_block_; // Handle block at prev scope. | 298 VMHandles::HandlesBlock* saved_handle_block_; // Handle block at prev scope. |
303 uword saved_handle_slot_; // Next available handle slot at previous scope. | 299 uword saved_handle_slot_; // Next available handle slot at previous scope. |
304 #if defined(DEBUG) | 300 #if defined(DEBUG) |
305 HandleScope* link_; // Link to previous scope. | 301 HandleScope* link_; // Link to previous scope. |
306 #endif | 302 #endif |
307 DISALLOW_IMPLICIT_CONSTRUCTORS(HandleScope); | 303 DISALLOW_IMPLICIT_CONSTRUCTORS(HandleScope); |
308 }; | 304 }; |
309 | 305 |
310 // Macro to start a new Handle scope. | 306 // Macro to start a new Handle scope. |
311 #define HANDLESCOPE(thread) \ | 307 #define HANDLESCOPE(thread) \ |
312 dart::HandleScope vm_internal_handles_scope_(thread); | 308 dart::HandleScope vm_internal_handles_scope_(thread); |
313 | 309 |
314 | |
315 // The class NoHandleScope is used in critical regions of the virtual machine | 310 // The class NoHandleScope is used in critical regions of the virtual machine |
316 // code where raw dart object pointers are directly manipulated. | 311 // code where raw dart object pointers are directly manipulated. |
317 // This class asserts that we do not add code that will allocate new handles | 312 // This class asserts that we do not add code that will allocate new handles |
318 // during this critical area. | 313 // during this critical area. |
319 // It is used as follows: | 314 // It is used as follows: |
320 // { | 315 // { |
321 // NOHANDLESCOPE(thread); | 316 // NOHANDLESCOPE(thread); |
322 // .... | 317 // .... |
323 // ..... | 318 // ..... |
324 // critical code that manipulates dart objects directly. | 319 // critical code that manipulates dart objects directly. |
(...skipping 20 matching lines...) Expand all Loading... |
345 }; | 340 }; |
346 #endif // defined(DEBUG) | 341 #endif // defined(DEBUG) |
347 | 342 |
348 // Macro to start a no handles scope in the code. | 343 // Macro to start a no handles scope in the code. |
349 #define NOHANDLESCOPE(thread) \ | 344 #define NOHANDLESCOPE(thread) \ |
350 dart::NoHandleScope no_vm_internal_handles_scope_(thread); | 345 dart::NoHandleScope no_vm_internal_handles_scope_(thread); |
351 | 346 |
352 } // namespace dart | 347 } // namespace dart |
353 | 348 |
354 #endif // RUNTIME_VM_HANDLES_H_ | 349 #endif // RUNTIME_VM_HANDLES_H_ |
OLD | NEW |