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 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 | 5 |
6 #ifndef V8_HANDLES_INL_H_ | 6 #ifndef V8_HANDLES_INL_H_ |
7 #define V8_HANDLES_INL_H_ | 7 #define V8_HANDLES_INL_H_ |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 template<typename T> | 23 template<typename T> |
24 Handle<T>::Handle(T* obj, Isolate* isolate) { | 24 Handle<T>::Handle(T* obj, Isolate* isolate) { |
25 location_ = HandleScope::CreateHandle(isolate, obj); | 25 location_ = HandleScope::CreateHandle(isolate, obj); |
26 } | 26 } |
27 | 27 |
28 | 28 |
29 template <typename T> | 29 template <typename T> |
30 inline bool Handle<T>::is_identical_to(const Handle<T> o) const { | 30 inline bool Handle<T>::is_identical_to(const Handle<T> o) const { |
31 // Dereferencing deferred handles to check object equality is safe. | 31 // Dereferencing deferred handles to check object equality is safe. |
32 SLOW_ASSERT( | 32 SLOW_DCHECK( |
33 (location_ == NULL || IsDereferenceAllowed(NO_DEFERRED_CHECK)) && | 33 (location_ == NULL || IsDereferenceAllowed(NO_DEFERRED_CHECK)) && |
34 (o.location_ == NULL || o.IsDereferenceAllowed(NO_DEFERRED_CHECK))); | 34 (o.location_ == NULL || o.IsDereferenceAllowed(NO_DEFERRED_CHECK))); |
35 if (location_ == o.location_) return true; | 35 if (location_ == o.location_) return true; |
36 if (location_ == NULL || o.location_ == NULL) return false; | 36 if (location_ == NULL || o.location_ == NULL) return false; |
37 return *location_ == *o.location_; | 37 return *location_ == *o.location_; |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 template <typename T> | 41 template <typename T> |
42 inline T* Handle<T>::operator*() const { | 42 inline T* Handle<T>::operator*() const { |
43 SLOW_ASSERT(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); | 43 SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
44 return *BitCast<T**>(location_); | 44 return *BitCast<T**>(location_); |
45 } | 45 } |
46 | 46 |
47 template <typename T> | 47 template <typename T> |
48 inline T** Handle<T>::location() const { | 48 inline T** Handle<T>::location() const { |
49 SLOW_ASSERT(location_ == NULL || | 49 SLOW_DCHECK(location_ == NULL || |
50 IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); | 50 IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
51 return location_; | 51 return location_; |
52 } | 52 } |
53 | 53 |
54 #ifdef DEBUG | 54 #ifdef DEBUG |
55 template <typename T> | 55 template <typename T> |
56 bool Handle<T>::IsDereferenceAllowed(DereferenceCheckMode mode) const { | 56 bool Handle<T>::IsDereferenceAllowed(DereferenceCheckMode mode) const { |
57 ASSERT(location_ != NULL); | 57 DCHECK(location_ != NULL); |
58 Object* object = *BitCast<T**>(location_); | 58 Object* object = *BitCast<T**>(location_); |
59 if (object->IsSmi()) return true; | 59 if (object->IsSmi()) return true; |
60 HeapObject* heap_object = HeapObject::cast(object); | 60 HeapObject* heap_object = HeapObject::cast(object); |
61 Heap* heap = heap_object->GetHeap(); | 61 Heap* heap = heap_object->GetHeap(); |
62 Object** handle = reinterpret_cast<Object**>(location_); | 62 Object** handle = reinterpret_cast<Object**>(location_); |
63 Object** roots_array_start = heap->roots_array_start(); | 63 Object** roots_array_start = heap->roots_array_start(); |
64 if (roots_array_start <= handle && | 64 if (roots_array_start <= handle && |
65 handle < roots_array_start + Heap::kStrongRootListLength && | 65 handle < roots_array_start + Heap::kStrongRootListLength && |
66 heap->RootCanBeTreatedAsConstant( | 66 heap->RootCanBeTreatedAsConstant( |
67 static_cast<Heap::RootListIndex>(handle - roots_array_start))) { | 67 static_cast<Heap::RootListIndex>(handle - roots_array_start))) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 | 117 |
118 template <typename T> | 118 template <typename T> |
119 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { | 119 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { |
120 HandleScopeData* current = isolate_->handle_scope_data(); | 120 HandleScopeData* current = isolate_->handle_scope_data(); |
121 | 121 |
122 T* value = *handle_value; | 122 T* value = *handle_value; |
123 // Throw away all handles in the current scope. | 123 // Throw away all handles in the current scope. |
124 CloseScope(isolate_, prev_next_, prev_limit_); | 124 CloseScope(isolate_, prev_next_, prev_limit_); |
125 // Allocate one handle in the parent scope. | 125 // Allocate one handle in the parent scope. |
126 ASSERT(current->level > 0); | 126 DCHECK(current->level > 0); |
127 Handle<T> result(CreateHandle<T>(isolate_, value)); | 127 Handle<T> result(CreateHandle<T>(isolate_, value)); |
128 // Reinitialize the current scope (so that it's ready | 128 // Reinitialize the current scope (so that it's ready |
129 // to be used or closed again). | 129 // to be used or closed again). |
130 prev_next_ = current->next; | 130 prev_next_ = current->next; |
131 prev_limit_ = current->limit; | 131 prev_limit_ = current->limit; |
132 current->level++; | 132 current->level++; |
133 return result; | 133 return result; |
134 } | 134 } |
135 | 135 |
136 | 136 |
137 template <typename T> | 137 template <typename T> |
138 T** HandleScope::CreateHandle(Isolate* isolate, T* value) { | 138 T** HandleScope::CreateHandle(Isolate* isolate, T* value) { |
139 ASSERT(AllowHandleAllocation::IsAllowed()); | 139 DCHECK(AllowHandleAllocation::IsAllowed()); |
140 HandleScopeData* current = isolate->handle_scope_data(); | 140 HandleScopeData* current = isolate->handle_scope_data(); |
141 | 141 |
142 internal::Object** cur = current->next; | 142 internal::Object** cur = current->next; |
143 if (cur == current->limit) cur = Extend(isolate); | 143 if (cur == current->limit) cur = Extend(isolate); |
144 // Update the current next field, set the value in the created | 144 // Update the current next field, set the value in the created |
145 // handle, and return the result. | 145 // handle, and return the result. |
146 ASSERT(cur < current->limit); | 146 DCHECK(cur < current->limit); |
147 current->next = cur + 1; | 147 current->next = cur + 1; |
148 | 148 |
149 T** result = reinterpret_cast<T**>(cur); | 149 T** result = reinterpret_cast<T**>(cur); |
150 *result = value; | 150 *result = value; |
151 return result; | 151 return result; |
152 } | 152 } |
153 | 153 |
154 | 154 |
155 #ifdef DEBUG | 155 #ifdef DEBUG |
156 inline SealHandleScope::SealHandleScope(Isolate* isolate) : isolate_(isolate) { | 156 inline SealHandleScope::SealHandleScope(Isolate* isolate) : isolate_(isolate) { |
157 // Make sure the current thread is allowed to create handles to begin with. | 157 // Make sure the current thread is allowed to create handles to begin with. |
158 CHECK(AllowHandleAllocation::IsAllowed()); | 158 CHECK(AllowHandleAllocation::IsAllowed()); |
159 HandleScopeData* current = isolate_->handle_scope_data(); | 159 HandleScopeData* current = isolate_->handle_scope_data(); |
160 // Shrink the current handle scope to make it impossible to do | 160 // Shrink the current handle scope to make it impossible to do |
161 // handle allocations without an explicit handle scope. | 161 // handle allocations without an explicit handle scope. |
162 limit_ = current->limit; | 162 limit_ = current->limit; |
163 current->limit = current->next; | 163 current->limit = current->next; |
164 level_ = current->level; | 164 level_ = current->level; |
165 current->level = 0; | 165 current->level = 0; |
166 } | 166 } |
167 | 167 |
168 | 168 |
169 inline SealHandleScope::~SealHandleScope() { | 169 inline SealHandleScope::~SealHandleScope() { |
170 // Restore state in current handle scope to re-enable handle | 170 // Restore state in current handle scope to re-enable handle |
171 // allocations. | 171 // allocations. |
172 HandleScopeData* current = isolate_->handle_scope_data(); | 172 HandleScopeData* current = isolate_->handle_scope_data(); |
173 ASSERT_EQ(0, current->level); | 173 DCHECK_EQ(0, current->level); |
174 current->level = level_; | 174 current->level = level_; |
175 ASSERT_EQ(current->next, current->limit); | 175 DCHECK_EQ(current->next, current->limit); |
176 current->limit = limit_; | 176 current->limit = limit_; |
177 } | 177 } |
178 | 178 |
179 #endif | 179 #endif |
180 | 180 |
181 } } // namespace v8::internal | 181 } } // namespace v8::internal |
182 | 182 |
183 #endif // V8_HANDLES_INL_H_ | 183 #endif // V8_HANDLES_INL_H_ |
OLD | NEW |