| 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 // | 27 // |
| 28 | 28 |
| 29 #ifndef V8_HANDLES_INL_H_ | 29 #ifndef V8_HANDLES_INL_H_ |
| 30 #define V8_HANDLES_INL_H_ | 30 #define V8_HANDLES_INL_H_ |
| 31 | 31 |
| 32 #include "api.h" | 32 #include "api.h" |
| 33 #include "apiutils.h" | |
| 34 #include "handles.h" | 33 #include "handles.h" |
| 35 #include "heap.h" | 34 #include "heap.h" |
| 36 #include "isolate.h" | 35 #include "isolate.h" |
| 37 | 36 |
| 38 namespace v8 { | 37 namespace v8 { |
| 39 namespace internal { | 38 namespace internal { |
| 40 | 39 |
| 41 template<typename T> | 40 template<typename T> |
| 42 Handle<T>::Handle(T* obj) { | 41 Handle<T>::Handle(T* obj) { |
| 43 ASSERT(!obj->IsFailure()); | 42 ASSERT(!obj->IsFailure()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 if (heap_object->IsInternalizedString()) return true; | 102 if (heap_object->IsInternalizedString()) return true; |
| 104 return !heap->isolate()->IsDeferredHandle(handle); | 103 return !heap->isolate()->IsDeferredHandle(handle); |
| 105 } | 104 } |
| 106 return true; | 105 return true; |
| 107 } | 106 } |
| 108 #endif | 107 #endif |
| 109 | 108 |
| 110 | 109 |
| 111 | 110 |
| 112 HandleScope::HandleScope(Isolate* isolate) { | 111 HandleScope::HandleScope(Isolate* isolate) { |
| 113 v8::ImplementationUtilities::HandleScopeData* current = | 112 HandleScopeData* current = isolate->handle_scope_data(); |
| 114 isolate->handle_scope_data(); | |
| 115 isolate_ = isolate; | 113 isolate_ = isolate; |
| 116 prev_next_ = current->next; | 114 prev_next_ = current->next; |
| 117 prev_limit_ = current->limit; | 115 prev_limit_ = current->limit; |
| 118 current->level++; | 116 current->level++; |
| 119 } | 117 } |
| 120 | 118 |
| 121 | 119 |
| 122 HandleScope::~HandleScope() { | 120 HandleScope::~HandleScope() { |
| 123 CloseScope(isolate_, prev_next_, prev_limit_); | 121 CloseScope(isolate_, prev_next_, prev_limit_); |
| 124 } | 122 } |
| 125 | 123 |
| 126 | 124 |
| 127 void HandleScope::CloseScope(Isolate* isolate, | 125 void HandleScope::CloseScope(Isolate* isolate, |
| 128 Object** prev_next, | 126 Object** prev_next, |
| 129 Object** prev_limit) { | 127 Object** prev_limit) { |
| 130 v8::ImplementationUtilities::HandleScopeData* current = | 128 HandleScopeData* current = isolate->handle_scope_data(); |
| 131 isolate->handle_scope_data(); | |
| 132 | 129 |
| 133 std::swap(current->next, prev_next); | 130 std::swap(current->next, prev_next); |
| 134 current->level--; | 131 current->level--; |
| 135 if (current->limit != prev_limit) { | 132 if (current->limit != prev_limit) { |
| 136 current->limit = prev_limit; | 133 current->limit = prev_limit; |
| 137 DeleteExtensions(isolate); | 134 DeleteExtensions(isolate); |
| 138 #ifdef ENABLE_HANDLE_ZAPPING | 135 #ifdef ENABLE_HANDLE_ZAPPING |
| 139 ZapRange(current->next, prev_limit); | 136 ZapRange(current->next, prev_limit); |
| 140 } else { | 137 } else { |
| 141 ZapRange(current->next, prev_next); | 138 ZapRange(current->next, prev_next); |
| 142 #endif | 139 #endif |
| 143 } | 140 } |
| 144 } | 141 } |
| 145 | 142 |
| 146 | 143 |
| 147 template <typename T> | 144 template <typename T> |
| 148 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { | 145 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { |
| 149 v8::ImplementationUtilities::HandleScopeData* current = | 146 HandleScopeData* current = isolate_->handle_scope_data(); |
| 150 isolate_->handle_scope_data(); | |
| 151 | 147 |
| 152 T* value = *handle_value; | 148 T* value = *handle_value; |
| 153 // Throw away all handles in the current scope. | 149 // Throw away all handles in the current scope. |
| 154 CloseScope(isolate_, prev_next_, prev_limit_); | 150 CloseScope(isolate_, prev_next_, prev_limit_); |
| 155 // Allocate one handle in the parent scope. | 151 // Allocate one handle in the parent scope. |
| 156 ASSERT(current->level > 0); | 152 ASSERT(current->level > 0); |
| 157 Handle<T> result(CreateHandle<T>(isolate_, value)); | 153 Handle<T> result(CreateHandle<T>(isolate_, value)); |
| 158 // Reinitialize the current scope (so that it's ready | 154 // Reinitialize the current scope (so that it's ready |
| 159 // to be used or closed again). | 155 // to be used or closed again). |
| 160 prev_next_ = current->next; | 156 prev_next_ = current->next; |
| 161 prev_limit_ = current->limit; | 157 prev_limit_ = current->limit; |
| 162 current->level++; | 158 current->level++; |
| 163 return result; | 159 return result; |
| 164 } | 160 } |
| 165 | 161 |
| 166 | 162 |
| 167 template <typename T> | 163 template <typename T> |
| 168 T** HandleScope::CreateHandle(Isolate* isolate, T* value) { | 164 T** HandleScope::CreateHandle(Isolate* isolate, T* value) { |
| 169 ASSERT(AllowHandleAllocation::IsAllowed()); | 165 ASSERT(AllowHandleAllocation::IsAllowed()); |
| 170 v8::ImplementationUtilities::HandleScopeData* current = | 166 HandleScopeData* current = isolate->handle_scope_data(); |
| 171 isolate->handle_scope_data(); | |
| 172 | 167 |
| 173 internal::Object** cur = current->next; | 168 internal::Object** cur = current->next; |
| 174 if (cur == current->limit) cur = Extend(isolate); | 169 if (cur == current->limit) cur = Extend(isolate); |
| 175 // Update the current next field, set the value in the created | 170 // Update the current next field, set the value in the created |
| 176 // handle, and return the result. | 171 // handle, and return the result. |
| 177 ASSERT(cur < current->limit); | 172 ASSERT(cur < current->limit); |
| 178 current->next = cur + 1; | 173 current->next = cur + 1; |
| 179 | 174 |
| 180 T** result = reinterpret_cast<T**>(cur); | 175 T** result = reinterpret_cast<T**>(cur); |
| 181 *result = value; | 176 *result = value; |
| 182 return result; | 177 return result; |
| 183 } | 178 } |
| 184 | 179 |
| 185 | 180 |
| 186 #ifdef DEBUG | 181 #ifdef DEBUG |
| 187 inline SealHandleScope::SealHandleScope(Isolate* isolate) : isolate_(isolate) { | 182 inline SealHandleScope::SealHandleScope(Isolate* isolate) : isolate_(isolate) { |
| 188 // Make sure the current thread is allowed to create handles to begin with. | 183 // Make sure the current thread is allowed to create handles to begin with. |
| 189 CHECK(AllowHandleAllocation::IsAllowed()); | 184 CHECK(AllowHandleAllocation::IsAllowed()); |
| 190 v8::ImplementationUtilities::HandleScopeData* current = | 185 HandleScopeData* current = isolate_->handle_scope_data(); |
| 191 isolate_->handle_scope_data(); | |
| 192 // Shrink the current handle scope to make it impossible to do | 186 // Shrink the current handle scope to make it impossible to do |
| 193 // handle allocations without an explicit handle scope. | 187 // handle allocations without an explicit handle scope. |
| 194 limit_ = current->limit; | 188 limit_ = current->limit; |
| 195 current->limit = current->next; | 189 current->limit = current->next; |
| 196 level_ = current->level; | 190 level_ = current->level; |
| 197 current->level = 0; | 191 current->level = 0; |
| 198 } | 192 } |
| 199 | 193 |
| 200 | 194 |
| 201 inline SealHandleScope::~SealHandleScope() { | 195 inline SealHandleScope::~SealHandleScope() { |
| 202 // Restore state in current handle scope to re-enable handle | 196 // Restore state in current handle scope to re-enable handle |
| 203 // allocations. | 197 // allocations. |
| 204 v8::ImplementationUtilities::HandleScopeData* current = | 198 HandleScopeData* current = isolate_->handle_scope_data(); |
| 205 isolate_->handle_scope_data(); | |
| 206 ASSERT_EQ(0, current->level); | 199 ASSERT_EQ(0, current->level); |
| 207 current->level = level_; | 200 current->level = level_; |
| 208 ASSERT_EQ(current->next, current->limit); | 201 ASSERT_EQ(current->next, current->limit); |
| 209 current->limit = limit_; | 202 current->limit = limit_; |
| 210 } | 203 } |
| 211 | 204 |
| 212 #endif | 205 #endif |
| 213 | 206 |
| 214 } } // namespace v8::internal | 207 } } // namespace v8::internal |
| 215 | 208 |
| 216 #endif // V8_HANDLES_INL_H_ | 209 #endif // V8_HANDLES_INL_H_ |
| OLD | NEW |