| 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 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // NOHANDLESCOPE(isolate); | 51 // NOHANDLESCOPE(isolate); |
| 52 // .... | 52 // .... |
| 53 // .... | 53 // .... |
| 54 // } | 54 // } |
| 55 | 55 |
| 56 | 56 |
| 57 // Forward declarations. | 57 // Forward declarations. |
| 58 class ObjectPointerVisitor; | 58 class ObjectPointerVisitor; |
| 59 | 59 |
| 60 | 60 |
| 61 class HandleVisitor { |
| 62 public: |
| 63 virtual void Visit(uword* addr) = 0; |
| 64 |
| 65 virtual ~HandleVisitor() { |
| 66 } |
| 67 }; |
| 68 |
| 69 |
| 61 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 70 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
| 62 class Handles { | 71 class Handles { |
| 63 public: | 72 public: |
| 64 Handles() | 73 Handles() |
| 65 : zone_blocks_(NULL), | 74 : zone_blocks_(NULL), |
| 66 first_scoped_block_(NULL), | 75 first_scoped_block_(NULL), |
| 67 scoped_blocks_(&first_scoped_block_) { | 76 scoped_blocks_(&first_scoped_block_) { |
| 68 } | 77 } |
| 69 ~Handles() { | 78 ~Handles() { |
| 70 DeleteAll(); | 79 DeleteAll(); |
| 71 } | 80 } |
| 72 | 81 |
| 73 // Visit all object pointers stored in the various handles. | 82 // Visit all object pointers stored in the various handles. |
| 74 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 83 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 75 | 84 |
| 85 // Visits all of the various handles. |
| 86 void Visit(HandleVisitor* visitor); |
| 87 |
| 76 // Allocates a handle in the current handle scope. This handle is valid only | 88 // Allocates a handle in the current handle scope. This handle is valid only |
| 77 // in the current handle scope and is destroyed when the current handle | 89 // in the current handle scope and is destroyed when the current handle |
| 78 // scope ends. | 90 // scope ends. |
| 79 static uword AllocateHandle(); | 91 static uword AllocateHandle(); |
| 80 | 92 |
| 81 // Allocates a handle in the current zone. This handle will be destroyed | 93 // Allocates a handle in the current zone. This handle will be destroyed |
| 82 // when the current zone is destroyed. | 94 // when the current zone is destroyed. |
| 83 static uword AllocateZoneHandle(); | 95 static uword AllocateZoneHandle(); |
| 84 | 96 |
| 85 // Returns true if specified handle is a zone handle. | 97 // Returns true if specified handle is a zone handle. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 uword AllocateHandle() { | 147 uword AllocateHandle() { |
| 136 ASSERT(!IsFull()); | 148 ASSERT(!IsFull()); |
| 137 uword handle_address = reinterpret_cast<uword>(data_ + next_handle_slot_); | 149 uword handle_address = reinterpret_cast<uword>(data_ + next_handle_slot_); |
| 138 next_handle_slot_ += kHandleSizeInWords; | 150 next_handle_slot_ += kHandleSizeInWords; |
| 139 return handle_address; | 151 return handle_address; |
| 140 } | 152 } |
| 141 | 153 |
| 142 // Visit all object pointers in the handle block. | 154 // Visit all object pointers in the handle block. |
| 143 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 155 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 144 | 156 |
| 157 // Visit all of the handles in the handle block. |
| 158 void Visit(HandleVisitor* visitor); |
| 159 |
| 145 #if defined(DEBUG) | 160 #if defined(DEBUG) |
| 146 // Zaps the free handle area to an uninitialized value. | 161 // Zaps the free handle area to an uninitialized value. |
| 147 void ZapFreeHandles(); | 162 void ZapFreeHandles(); |
| 148 #endif | 163 #endif |
| 149 | 164 |
| 150 // Returns number of active handles in the handle block. | 165 // Returns number of active handles in the handle block. |
| 151 int HandleCount() const; | 166 int HandleCount() const; |
| 152 | 167 |
| 153 // Accessors. | 168 // Accessors. |
| 154 intptr_t next_handle_slot() const { return next_handle_slot_; } | 169 intptr_t next_handle_slot() const { return next_handle_slot_; } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 }; | 315 }; |
| 301 #endif // defined(DEBUG) | 316 #endif // defined(DEBUG) |
| 302 | 317 |
| 303 // Macro to start a no handles scope in the code. | 318 // Macro to start a no handles scope in the code. |
| 304 #define NOHANDLESCOPE(isolate) \ | 319 #define NOHANDLESCOPE(isolate) \ |
| 305 dart::NoHandleScope no_vm_internal_handles_scope_(isolate); | 320 dart::NoHandleScope no_vm_internal_handles_scope_(isolate); |
| 306 | 321 |
| 307 } // namespace dart | 322 } // namespace dart |
| 308 | 323 |
| 309 #endif // VM_HANDLES_H_ | 324 #endif // VM_HANDLES_H_ |
| OLD | NEW |