| 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 VM_HANDLES_H_ | 5 #ifndef VM_HANDLES_H_ |
| 6 #define VM_HANDLES_H_ | 6 #define 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 | 11 |
| 11 namespace dart { | 12 namespace dart { |
| 12 | 13 |
| 13 // Handles are used in the Dart Virtual Machine to ensure that access | 14 // Handles are used in the Dart Virtual Machine to ensure that access |
| 14 // to dart objects in the virtual machine code is done in a | 15 // to dart objects in the virtual machine code is done in a |
| 15 // Garbage Collection safe manner. | 16 // Garbage Collection safe manner. |
| 16 // | 17 // |
| 17 // The class Handles is the basic type that implements creation of handles and | 18 // The class Handles is the basic type that implements creation of handles and |
| 18 // manages their life cycle (allocated either in the current zone or | 19 // manages their life cycle (allocated either in the current zone or |
| 19 // current handle scope). | 20 // current handle scope). |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // NOHANDLESCOPE(isolate); | 53 // NOHANDLESCOPE(isolate); |
| 53 // .... | 54 // .... |
| 54 // .... | 55 // .... |
| 55 // } | 56 // } |
| 56 | 57 |
| 57 | 58 |
| 58 // Forward declarations. | 59 // Forward declarations. |
| 59 class ObjectPointerVisitor; | 60 class ObjectPointerVisitor; |
| 60 | 61 |
| 61 DECLARE_FLAG(bool, verify_handles); | 62 DECLARE_FLAG(bool, verify_handles); |
| 63 DECLARE_DEBUG_FLAG(bool, trace_handles); |
| 62 | 64 |
| 63 class HandleVisitor { | 65 class HandleVisitor { |
| 64 public: | 66 public: |
| 65 virtual void VisitHandle(uword addr) = 0; | 67 virtual void VisitHandle(uword addr) = 0; |
| 66 | 68 |
| 67 virtual ~HandleVisitor() { | 69 virtual ~HandleVisitor() { |
| 68 } | 70 } |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 | 73 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 static const int kVMHandlesPerChunk = 64; | 249 static const int kVMHandlesPerChunk = 64; |
| 248 static const int kOffsetOfRawPtr = kWordSize; | 250 static const int kOffsetOfRawPtr = kWordSize; |
| 249 class VMHandles : public Handles<kVMHandleSizeInWords, | 251 class VMHandles : public Handles<kVMHandleSizeInWords, |
| 250 kVMHandlesPerChunk, | 252 kVMHandlesPerChunk, |
| 251 kOffsetOfRawPtr> { | 253 kOffsetOfRawPtr> { |
| 252 public: | 254 public: |
| 253 static const int kOffsetOfRawPtrInHandle = kOffsetOfRawPtr; | 255 static const int kOffsetOfRawPtrInHandle = kOffsetOfRawPtr; |
| 254 | 256 |
| 255 VMHandles() : Handles<kVMHandleSizeInWords, | 257 VMHandles() : Handles<kVMHandleSizeInWords, |
| 256 kVMHandlesPerChunk, | 258 kVMHandlesPerChunk, |
| 257 kOffsetOfRawPtr>() { } | 259 kOffsetOfRawPtr>() { |
| 260 #ifdef DEBUG |
| 261 if (FLAG_trace_handles) { |
| 262 OS::PrintErr("*** Starting a new VM handle block 0x%"Px"\n", |
| 263 reinterpret_cast<intptr_t>(this)); |
| 264 } |
| 265 #endif |
| 266 } |
| 258 ~VMHandles(); | 267 ~VMHandles(); |
| 259 | 268 |
| 260 // Visit all object pointers stored in the various handles. | 269 // Visit all object pointers stored in the various handles. |
| 261 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 270 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 262 | 271 |
| 263 // Allocates a handle in the current handle scope. This handle is valid only | 272 // Allocates a handle in the current handle scope. This handle is valid only |
| 264 // in the current handle scope and is destroyed when the current handle | 273 // in the current handle scope and is destroyed when the current handle |
| 265 // scope ends. | 274 // scope ends. |
| 266 static uword AllocateHandle(Isolate* isolate); | 275 static uword AllocateHandle(Isolate* isolate); |
| 267 | 276 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 }; | 349 }; |
| 341 #endif // defined(DEBUG) | 350 #endif // defined(DEBUG) |
| 342 | 351 |
| 343 // Macro to start a no handles scope in the code. | 352 // Macro to start a no handles scope in the code. |
| 344 #define NOHANDLESCOPE(isolate) \ | 353 #define NOHANDLESCOPE(isolate) \ |
| 345 dart::NoHandleScope no_vm_internal_handles_scope_(isolate); | 354 dart::NoHandleScope no_vm_internal_handles_scope_(isolate); |
| 346 | 355 |
| 347 } // namespace dart | 356 } // namespace dart |
| 348 | 357 |
| 349 #endif // VM_HANDLES_H_ | 358 #endif // VM_HANDLES_H_ |
| OLD | NEW |