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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 | 46 |
47 template<typename T> | 47 template<typename T> |
48 Handle<T>::Handle(T* obj, Isolate* isolate) { | 48 Handle<T>::Handle(T* obj, Isolate* isolate) { |
49 ASSERT(!obj->IsFailure()); | 49 ASSERT(!obj->IsFailure()); |
50 location_ = HandleScope::CreateHandle(isolate, obj); | 50 location_ = HandleScope::CreateHandle(isolate, obj); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 template <typename T> | 54 template <typename T> |
| 55 inline bool Handle<T>::is_identical_to(const Handle<T> other) const { |
| 56 ASSERT(location_ == NULL || |
| 57 reinterpret_cast<Address>(*location_) != kZapValue); |
| 58 #ifdef DEBUG |
| 59 if (FLAG_enable_slow_asserts) { |
| 60 Isolate* isolate = Isolate::Current(); |
| 61 CHECK(isolate->AllowHandleDereference() || |
| 62 Heap::RelocationLock::IsLocked(isolate->heap()) || |
| 63 !isolate->optimizing_compiler_thread()->IsOptimizerThread()); |
| 64 } |
| 65 #endif // DEBUG |
| 66 return *location_ == *other.location_; |
| 67 } |
| 68 |
| 69 |
| 70 template <typename T> |
55 inline T* Handle<T>::operator*() const { | 71 inline T* Handle<T>::operator*() const { |
56 ASSERT(location_ != NULL); | 72 ASSERT(location_ != NULL); |
57 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); | 73 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); |
58 SLOW_ASSERT(ISOLATE->allow_handle_deref()); | 74 SLOW_ASSERT(Isolate::Current()->AllowHandleDereference()); |
59 return *BitCast<T**>(location_); | 75 return *BitCast<T**>(location_); |
60 } | 76 } |
61 | 77 |
62 template <typename T> | 78 template <typename T> |
63 inline T** Handle<T>::location() const { | 79 inline T** Handle<T>::location() const { |
64 ASSERT(location_ == NULL || | 80 ASSERT(location_ == NULL || |
65 reinterpret_cast<Address>(*location_) != kZapValue); | 81 reinterpret_cast<Address>(*location_) != kZapValue); |
66 SLOW_ASSERT(ISOLATE->allow_handle_deref()); | 82 SLOW_ASSERT(Isolate::Current()->AllowHandleDereference()); |
67 return location_; | 83 return location_; |
68 } | 84 } |
69 | 85 |
70 | 86 |
71 HandleScope::HandleScope(Isolate* isolate) { | 87 HandleScope::HandleScope(Isolate* isolate) { |
72 v8::ImplementationUtilities::HandleScopeData* current = | 88 v8::ImplementationUtilities::HandleScopeData* current = |
73 isolate->handle_scope_data(); | 89 isolate->handle_scope_data(); |
74 isolate_ = isolate; | 90 isolate_ = isolate; |
75 prev_next_ = current->next; | 91 prev_next_ = current->next; |
76 prev_limit_ = current->limit; | 92 prev_limit_ = current->limit; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Restore state in current handle scope to re-enable handle | 173 // Restore state in current handle scope to re-enable handle |
158 // allocations. | 174 // allocations. |
159 v8::ImplementationUtilities::HandleScopeData* data = | 175 v8::ImplementationUtilities::HandleScopeData* data = |
160 isolate_->handle_scope_data(); | 176 isolate_->handle_scope_data(); |
161 ASSERT_EQ(0, data->level); | 177 ASSERT_EQ(0, data->level); |
162 data->level = level_; | 178 data->level = level_; |
163 } | 179 } |
164 } | 180 } |
165 | 181 |
166 | 182 |
167 NoHandleDereference::NoHandleDereference(Isolate* isolate) | 183 HandleDereferenceGuard::HandleDereferenceGuard(Isolate* isolate, State state) |
168 : isolate_(isolate) { | 184 : isolate_(isolate) { |
169 // The guard is set on a per-isolate basis, so it affects all threads. | 185 old_state_ = isolate_->AllowHandleDereference(); |
170 // That's why we can only use it when running without parallel recompilation. | 186 isolate_->SetAllowHandleDereference(state == ALLOW); |
171 if (FLAG_parallel_recompilation) return; | |
172 old_state_ = isolate->allow_handle_deref(); | |
173 isolate_->set_allow_handle_deref(false); | |
174 } | 187 } |
175 | 188 |
176 | 189 |
177 NoHandleDereference::~NoHandleDereference() { | 190 HandleDereferenceGuard::~HandleDereferenceGuard() { |
178 if (FLAG_parallel_recompilation) return; | 191 isolate_->SetAllowHandleDereference(old_state_); |
179 isolate_->set_allow_handle_deref(old_state_); | |
180 } | 192 } |
181 | 193 |
182 | |
183 AllowHandleDereference::AllowHandleDereference(Isolate* isolate) | |
184 : isolate_(isolate) { | |
185 // The guard is set on a per-isolate basis, so it affects all threads. | |
186 // That's why we can only use it when running without parallel recompilation. | |
187 if (FLAG_parallel_recompilation) return; | |
188 old_state_ = isolate->allow_handle_deref(); | |
189 isolate_->set_allow_handle_deref(true); | |
190 } | |
191 | |
192 | |
193 AllowHandleDereference::~AllowHandleDereference() { | |
194 if (FLAG_parallel_recompilation) return; | |
195 isolate_->set_allow_handle_deref(old_state_); | |
196 } | |
197 #endif | 194 #endif |
198 | 195 |
199 | |
200 } } // namespace v8::internal | 196 } } // namespace v8::internal |
201 | 197 |
202 #endif // V8_HANDLES_INL_H_ | 198 #endif // V8_HANDLES_INL_H_ |
OLD | NEW |