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 37 matching lines...) Loading... |
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 { | 55 inline bool Handle<T>::is_identical_to(const Handle<T> other) const { |
56 ASSERT(location_ == NULL || | 56 ASSERT(location_ == NULL || |
57 reinterpret_cast<Address>(*location_) != kZapValue); | 57 reinterpret_cast<Address>(*location_) != kZapValue); |
58 #ifdef DEBUG | 58 // Dereferencing deferred handles to check object equality is safe. |
59 if (FLAG_enable_slow_asserts) { | 59 SLOW_ASSERT(IsDereferenceAllowed(true) && other.IsDereferenceAllowed(true)); |
60 Isolate* isolate = Isolate::Current(); | |
61 CHECK(isolate->AllowHandleDereference() || | |
62 !isolate->optimizing_compiler_thread()->IsOptimizerThread()); | |
63 } | |
64 #endif // DEBUG | |
65 return *location_ == *other.location_; | 60 return *location_ == *other.location_; |
66 } | 61 } |
67 | 62 |
68 | 63 |
69 template <typename T> | 64 template <typename T> |
70 inline T* Handle<T>::operator*() const { | 65 inline T* Handle<T>::operator*() const { |
71 ASSERT(location_ != NULL); | 66 ASSERT(location_ != NULL); |
72 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); | 67 ASSERT(reinterpret_cast<Address>(*location_) != kHandleZapValue); |
73 SLOW_ASSERT(Isolate::Current()->AllowHandleDereference()); | 68 SLOW_ASSERT(IsDereferenceAllowed(false)); |
74 return *BitCast<T**>(location_); | 69 return *BitCast<T**>(location_); |
75 } | 70 } |
76 | 71 |
77 template <typename T> | 72 template <typename T> |
78 inline T** Handle<T>::location() const { | 73 inline T** Handle<T>::location() const { |
79 ASSERT(location_ == NULL || | 74 ASSERT(location_ == NULL || |
80 reinterpret_cast<Address>(*location_) != kZapValue); | 75 reinterpret_cast<Address>(*location_) != kZapValue); |
81 SLOW_ASSERT(Isolate::Current()->AllowHandleDereference()); | 76 SLOW_ASSERT(IsDereferenceAllowed(false)); |
82 return location_; | 77 return location_; |
83 } | 78 } |
84 | 79 |
| 80 #ifdef DEBUG |
| 81 template <typename T> |
| 82 bool Handle<T>::IsDereferenceAllowed(bool allow_deferred) const { |
| 83 if (location_ == NULL) return true; |
| 84 Object* object = *BitCast<T**>(location_); |
| 85 if (object->IsSmi()) return true; |
| 86 HeapObject* heap_object = HeapObject::cast(object); |
| 87 Isolate* isolate = heap_object->GetIsolate(); |
| 88 Object** handle = reinterpret_cast<Object**>(location_); |
| 89 Object** roots_array_start = isolate->heap()->roots_array_start(); |
| 90 if (roots_array_start <= handle && |
| 91 handle < roots_array_start + Heap::kStrongRootListLength) { |
| 92 return true; |
| 93 } |
| 94 switch (isolate->HandleDereferenceGuardState()) { |
| 95 case HandleDereferenceGuard::ALLOW: |
| 96 return true; |
| 97 case HandleDereferenceGuard::DISALLOW: |
| 98 return false; |
| 99 case HandleDereferenceGuard::DISALLOW_DEFERRED: |
| 100 // Accessing maps and internalized strings is safe. |
| 101 if (heap_object->IsMap()) return true; |
| 102 if (heap_object->IsInternalizedString()) return true; |
| 103 return allow_deferred || !isolate->IsDeferredHandle(handle); |
| 104 } |
| 105 return false; |
| 106 } |
| 107 #endif |
| 108 |
| 109 |
85 | 110 |
86 HandleScope::HandleScope(Isolate* isolate) { | 111 HandleScope::HandleScope(Isolate* isolate) { |
87 v8::ImplementationUtilities::HandleScopeData* current = | 112 v8::ImplementationUtilities::HandleScopeData* current = |
88 isolate->handle_scope_data(); | 113 isolate->handle_scope_data(); |
89 isolate_ = isolate; | 114 isolate_ = isolate; |
90 prev_next_ = current->next; | 115 prev_next_ = current->next; |
91 prev_limit_ = current->limit; | 116 prev_limit_ = current->limit; |
92 current->level++; | 117 current->level++; |
93 } | 118 } |
94 | 119 |
(...skipping 79 matching lines...) Loading... |
174 v8::ImplementationUtilities::HandleScopeData* data = | 199 v8::ImplementationUtilities::HandleScopeData* data = |
175 isolate_->handle_scope_data(); | 200 isolate_->handle_scope_data(); |
176 ASSERT_EQ(0, data->level); | 201 ASSERT_EQ(0, data->level); |
177 data->level = level_; | 202 data->level = level_; |
178 } | 203 } |
179 } | 204 } |
180 | 205 |
181 | 206 |
182 HandleDereferenceGuard::HandleDereferenceGuard(Isolate* isolate, State state) | 207 HandleDereferenceGuard::HandleDereferenceGuard(Isolate* isolate, State state) |
183 : isolate_(isolate) { | 208 : isolate_(isolate) { |
184 old_state_ = isolate_->AllowHandleDereference(); | 209 old_state_ = isolate_->HandleDereferenceGuardState(); |
185 isolate_->SetAllowHandleDereference(state == ALLOW); | 210 isolate_->SetHandleDereferenceGuardState(state); |
186 } | 211 } |
187 | 212 |
188 | 213 |
189 HandleDereferenceGuard::~HandleDereferenceGuard() { | 214 HandleDereferenceGuard::~HandleDereferenceGuard() { |
190 isolate_->SetAllowHandleDereference(old_state_); | 215 isolate_->SetHandleDereferenceGuardState(old_state_); |
191 } | 216 } |
192 | 217 |
193 #endif | 218 #endif |
194 | 219 |
195 } } // namespace v8::internal | 220 } } // namespace v8::internal |
196 | 221 |
197 #endif // V8_HANDLES_INL_H_ | 222 #endif // V8_HANDLES_INL_H_ |
OLD | NEW |