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 #include "vm/handles.h" | 5 #include "vm/handles.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 | 85 |
86 int VMHandles::ZoneHandleCount() { | 86 int VMHandles::ZoneHandleCount() { |
87 Isolate* isolate = Isolate::Current(); | 87 Isolate* isolate = Isolate::Current(); |
88 ASSERT(isolate->current_zone() != NULL); | 88 ASSERT(isolate->current_zone() != NULL); |
89 VMHandles* handles = isolate->current_zone()->handles(); | 89 VMHandles* handles = isolate->current_zone()->handles(); |
90 return handles->CountZoneHandles(); | 90 return handles->CountZoneHandles(); |
91 } | 91 } |
92 | 92 |
93 | 93 |
| 94 void HandleScope::Initialize() { |
| 95 ASSERT(thread()->no_handle_scope_depth() == 0); |
| 96 VMHandles* handles = thread()->zone()->handles(); |
| 97 ASSERT(handles != NULL); |
| 98 saved_handle_block_ = handles->scoped_blocks_; |
| 99 saved_handle_slot_ = handles->scoped_blocks_->next_handle_slot(); |
| 100 #if defined(DEBUG) |
| 101 link_ = thread()->top_handle_scope(); |
| 102 thread()->set_top_handle_scope(this); |
| 103 #endif |
| 104 } |
| 105 |
| 106 |
| 107 HandleScope::HandleScope(Thread* thread) : StackResource(thread) { |
| 108 Initialize(); |
| 109 } |
| 110 |
| 111 |
94 HandleScope::HandleScope(Isolate* isolate) : StackResource(isolate) { | 112 HandleScope::HandleScope(Isolate* isolate) : StackResource(isolate) { |
95 ASSERT(isolate->no_handle_scope_depth() == 0); | 113 Initialize(); |
96 VMHandles* handles = isolate->current_zone()->handles(); | |
97 ASSERT(handles != NULL); | |
98 saved_handle_block_ = handles->scoped_blocks_; | |
99 saved_handle_slot_ = handles->scoped_blocks_->next_handle_slot(); | |
100 #if defined(DEBUG) | |
101 link_ = isolate->top_handle_scope(); | |
102 isolate->set_top_handle_scope(this); | |
103 #endif | |
104 } | 114 } |
105 | 115 |
106 | 116 |
107 HandleScope::~HandleScope() { | 117 HandleScope::~HandleScope() { |
108 ASSERT(isolate()->current_zone() != NULL); | 118 ASSERT(thread()->zone() != NULL); |
109 VMHandles* handles = isolate()->current_zone()->handles(); | 119 VMHandles* handles = thread()->zone()->handles(); |
110 ASSERT(handles != NULL); | 120 ASSERT(handles != NULL); |
111 handles->scoped_blocks_ = saved_handle_block_; | 121 handles->scoped_blocks_ = saved_handle_block_; |
112 handles->scoped_blocks_->set_next_handle_slot(saved_handle_slot_); | 122 handles->scoped_blocks_->set_next_handle_slot(saved_handle_slot_); |
113 #if defined(DEBUG) | 123 #if defined(DEBUG) |
114 handles->VerifyScopedHandleState(); | 124 handles->VerifyScopedHandleState(); |
115 handles->ZapFreeScopedHandles(); | 125 handles->ZapFreeScopedHandles(); |
116 ASSERT(isolate()->top_handle_scope() == this); | 126 ASSERT(thread()->top_handle_scope() == this); |
117 isolate()->set_top_handle_scope(link_); | 127 thread()->set_top_handle_scope(link_); |
118 #endif | 128 #endif |
119 } | 129 } |
120 | 130 |
121 | 131 |
122 #if defined(DEBUG) | 132 #if defined(DEBUG) |
123 NoHandleScope::NoHandleScope(Isolate* isolate) : StackResource(isolate) { | 133 NoHandleScope::NoHandleScope(Isolate* isolate) : StackResource(isolate) { |
124 isolate->IncrementNoHandleScopeDepth(); | 134 thread()->IncrementNoHandleScopeDepth(); |
125 } | 135 } |
126 | 136 |
127 | 137 |
128 NoHandleScope::NoHandleScope() : StackResource(Isolate::Current()) { | 138 NoHandleScope::NoHandleScope() : StackResource(Thread::Current()) { |
129 isolate()->IncrementNoHandleScopeDepth(); | 139 thread()->IncrementNoHandleScopeDepth(); |
130 } | 140 } |
131 | 141 |
132 | 142 |
133 NoHandleScope::~NoHandleScope() { | 143 NoHandleScope::~NoHandleScope() { |
134 isolate()->DecrementNoHandleScopeDepth(); | 144 thread()->DecrementNoHandleScopeDepth(); |
135 } | 145 } |
136 #endif // defined(DEBUG) | 146 #endif // defined(DEBUG) |
137 | 147 |
138 } // namespace dart | 148 } // namespace dart |
OLD | NEW |