| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 v8::ImplementationUtilities::HandleScopeData* current = | 115 v8::ImplementationUtilities::HandleScopeData* current = |
| 116 isolate->handle_scope_data(); | 116 isolate->handle_scope_data(); |
| 117 isolate_ = isolate; | 117 isolate_ = isolate; |
| 118 prev_next_ = current->next; | 118 prev_next_ = current->next; |
| 119 prev_limit_ = current->limit; | 119 prev_limit_ = current->limit; |
| 120 current->level++; | 120 current->level++; |
| 121 } | 121 } |
| 122 | 122 |
| 123 | 123 |
| 124 HandleScope::~HandleScope() { | 124 HandleScope::~HandleScope() { |
| 125 CloseScope(); | 125 CloseScope(isolate_, prev_next_, prev_limit_); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void HandleScope::CloseScope() { | 128 |
| 129 void HandleScope::CloseScope(Isolate* isolate, |
| 130 Object** prev_next, |
| 131 Object** prev_limit) { |
| 129 v8::ImplementationUtilities::HandleScopeData* current = | 132 v8::ImplementationUtilities::HandleScopeData* current = |
| 130 isolate_->handle_scope_data(); | 133 isolate->handle_scope_data(); |
| 131 current->next = prev_next_; | 134 |
| 135 current->next = prev_next; |
| 132 current->level--; | 136 current->level--; |
| 133 if (current->limit != prev_limit_) { | 137 if (current->limit != prev_limit) { |
| 134 current->limit = prev_limit_; | 138 current->limit = prev_limit; |
| 135 DeleteExtensions(isolate_); | 139 DeleteExtensions(isolate); |
| 136 } | 140 } |
| 141 |
| 137 #ifdef ENABLE_EXTRA_CHECKS | 142 #ifdef ENABLE_EXTRA_CHECKS |
| 138 ZapRange(prev_next_, prev_limit_); | 143 ZapRange(prev_next, prev_limit); |
| 139 #endif | 144 #endif |
| 140 } | 145 } |
| 141 | 146 |
| 142 | 147 |
| 143 template <typename T> | 148 template <typename T> |
| 144 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { | 149 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { |
| 150 v8::ImplementationUtilities::HandleScopeData* current = |
| 151 isolate_->handle_scope_data(); |
| 152 |
| 145 T* value = *handle_value; | 153 T* value = *handle_value; |
| 146 // Throw away all handles in the current scope. | 154 // Throw away all handles in the current scope. |
| 147 CloseScope(); | 155 CloseScope(isolate_, prev_next_, prev_limit_); |
| 148 v8::ImplementationUtilities::HandleScopeData* current = | |
| 149 isolate_->handle_scope_data(); | |
| 150 // Allocate one handle in the parent scope. | 156 // Allocate one handle in the parent scope. |
| 151 ASSERT(current->level > 0); | 157 ASSERT(current->level > 0); |
| 152 Handle<T> result(CreateHandle<T>(isolate_, value)); | 158 Handle<T> result(CreateHandle<T>(isolate_, value)); |
| 153 // Reinitialize the current scope (so that it's ready | 159 // Reinitialize the current scope (so that it's ready |
| 154 // to be used or closed again). | 160 // to be used or closed again). |
| 155 prev_next_ = current->next; | 161 prev_next_ = current->next; |
| 156 prev_limit_ = current->limit; | 162 prev_limit_ = current->limit; |
| 157 current->level++; | 163 current->level++; |
| 158 return result; | 164 return result; |
| 159 } | 165 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 | 179 |
| 174 T** result = reinterpret_cast<T**>(cur); | 180 T** result = reinterpret_cast<T**>(cur); |
| 175 *result = value; | 181 *result = value; |
| 176 return result; | 182 return result; |
| 177 } | 183 } |
| 178 | 184 |
| 179 | 185 |
| 180 #ifdef DEBUG | 186 #ifdef DEBUG |
| 181 inline NoHandleAllocation::NoHandleAllocation(Isolate* isolate) | 187 inline NoHandleAllocation::NoHandleAllocation(Isolate* isolate) |
| 182 : isolate_(isolate) { | 188 : isolate_(isolate) { |
| 183 v8::ImplementationUtilities::HandleScopeData* current = | |
| 184 isolate_->handle_scope_data(); | |
| 185 | |
| 186 active_ = !isolate->optimizing_compiler_thread()->IsOptimizerThread(); | 189 active_ = !isolate->optimizing_compiler_thread()->IsOptimizerThread(); |
| 187 if (active_) { | 190 if (active_) { |
| 188 // Shrink the current handle scope to make it impossible to do | 191 // Shrink the current handle scope to make it impossible to do |
| 189 // handle allocations without an explicit handle scope. | 192 // handle allocations without an explicit handle scope. |
| 193 v8::ImplementationUtilities::HandleScopeData* current = |
| 194 isolate_->handle_scope_data(); |
| 195 limit_ = current->limit; |
| 190 current->limit = current->next; | 196 current->limit = current->next; |
| 191 | |
| 192 level_ = current->level; | 197 level_ = current->level; |
| 193 current->level = 0; | 198 current->level = 0; |
| 194 } | 199 } |
| 195 } | 200 } |
| 196 | 201 |
| 197 | 202 |
| 198 inline NoHandleAllocation::~NoHandleAllocation() { | 203 inline NoHandleAllocation::~NoHandleAllocation() { |
| 199 if (active_) { | 204 if (active_) { |
| 200 // Restore state in current handle scope to re-enable handle | 205 // Restore state in current handle scope to re-enable handle |
| 201 // allocations. | 206 // allocations. |
| 202 v8::ImplementationUtilities::HandleScopeData* data = | 207 v8::ImplementationUtilities::HandleScopeData* current = |
| 203 isolate_->handle_scope_data(); | 208 isolate_->handle_scope_data(); |
| 204 ASSERT_EQ(0, data->level); | 209 ASSERT_EQ(0, current->level); |
| 205 data->level = level_; | 210 current->level = level_; |
| 211 ASSERT_EQ(current->next, current->limit); |
| 212 current->limit = limit_; |
| 206 } | 213 } |
| 207 } | 214 } |
| 208 | 215 |
| 209 | 216 |
| 210 HandleDereferenceGuard::HandleDereferenceGuard(Isolate* isolate, State state) | 217 HandleDereferenceGuard::HandleDereferenceGuard(Isolate* isolate, State state) |
| 211 : isolate_(isolate) { | 218 : isolate_(isolate) { |
| 212 old_state_ = isolate_->HandleDereferenceGuardState(); | 219 old_state_ = isolate_->HandleDereferenceGuardState(); |
| 213 isolate_->SetHandleDereferenceGuardState(state); | 220 isolate_->SetHandleDereferenceGuardState(state); |
| 214 } | 221 } |
| 215 | 222 |
| 216 | 223 |
| 217 HandleDereferenceGuard::~HandleDereferenceGuard() { | 224 HandleDereferenceGuard::~HandleDereferenceGuard() { |
| 218 isolate_->SetHandleDereferenceGuardState(old_state_); | 225 isolate_->SetHandleDereferenceGuardState(old_state_); |
| 219 } | 226 } |
| 220 | 227 |
| 221 #endif | 228 #endif |
| 222 | 229 |
| 223 } } // namespace v8::internal | 230 } } // namespace v8::internal |
| 224 | 231 |
| 225 #endif // V8_HANDLES_INL_H_ | 232 #endif // V8_HANDLES_INL_H_ |
| OLD | NEW |