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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 || !(*location_)->IsFailure()); | 56 ASSERT(location_ == NULL || !(*location_)->IsFailure()); |
57 if (location_ == other.location_) return true; | 57 if (location_ == other.location_) return true; |
58 if (location_ == NULL || other.location_ == NULL) return false; | 58 if (location_ == NULL || other.location_ == NULL) return false; |
59 // Dereferencing deferred handles to check object equality is safe. | 59 // Dereferencing deferred handles to check object equality is safe. |
60 SLOW_ASSERT(IsDereferenceAllowed(true) && other.IsDereferenceAllowed(true)); | 60 SLOW_ASSERT(IsDereferenceAllowed(NO_DEFERRED_CHECK) && |
| 61 other.IsDereferenceAllowed(NO_DEFERRED_CHECK)); |
61 return *location_ == *other.location_; | 62 return *location_ == *other.location_; |
62 } | 63 } |
63 | 64 |
64 | 65 |
65 template <typename T> | 66 template <typename T> |
66 inline T* Handle<T>::operator*() const { | 67 inline T* Handle<T>::operator*() const { |
67 ASSERT(location_ != NULL && !(*location_)->IsFailure()); | 68 ASSERT(location_ != NULL && !(*location_)->IsFailure()); |
68 SLOW_ASSERT(IsDereferenceAllowed(false)); | 69 SLOW_ASSERT(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
69 return *BitCast<T**>(location_); | 70 return *BitCast<T**>(location_); |
70 } | 71 } |
71 | 72 |
72 template <typename T> | 73 template <typename T> |
73 inline T** Handle<T>::location() const { | 74 inline T** Handle<T>::location() const { |
74 ASSERT(location_ == NULL || !(*location_)->IsFailure()); | 75 ASSERT(location_ == NULL || !(*location_)->IsFailure()); |
75 SLOW_ASSERT(location_ == NULL || IsDereferenceAllowed(false)); | 76 SLOW_ASSERT(location_ == NULL || |
| 77 IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK)); |
76 return location_; | 78 return location_; |
77 } | 79 } |
78 | 80 |
79 #ifdef DEBUG | 81 #ifdef DEBUG |
80 template <typename T> | 82 template <typename T> |
81 bool Handle<T>::IsDereferenceAllowed(bool explicitly_allow_deferred) const { | 83 bool Handle<T>::IsDereferenceAllowed(DereferenceCheckMode mode) const { |
82 ASSERT(location_ != NULL); | 84 ASSERT(location_ != NULL); |
83 Object* object = *BitCast<T**>(location_); | 85 Object* object = *BitCast<T**>(location_); |
84 if (object->IsSmi()) return true; | 86 if (object->IsSmi()) return true; |
85 HeapObject* heap_object = HeapObject::cast(object); | 87 HeapObject* heap_object = HeapObject::cast(object); |
86 Isolate* isolate = heap_object->GetIsolate(); | 88 Isolate* isolate = heap_object->GetIsolate(); |
87 Object** handle = reinterpret_cast<Object**>(location_); | 89 Object** handle = reinterpret_cast<Object**>(location_); |
88 Object** roots_array_start = isolate->heap()->roots_array_start(); | 90 Object** roots_array_start = isolate->heap()->roots_array_start(); |
89 if (roots_array_start <= handle && | 91 if (roots_array_start <= handle && |
90 handle < roots_array_start + Heap::kStrongRootListLength) { | 92 handle < roots_array_start + Heap::kStrongRootListLength) { |
91 return true; | 93 return true; |
92 } | 94 } |
93 if (!AllowHandleDereference::IsAllowed()) return false; | 95 if (!AllowHandleDereference::IsAllowed()) return false; |
94 if (!explicitly_allow_deferred && | 96 if (mode == INCLUDE_DEFERRED_CHECK && |
95 !AllowDeferredHandleDereference::IsAllowed()) { | 97 !AllowDeferredHandleDereference::IsAllowed()) { |
96 // Accessing maps and internalized strings is safe. | 98 // Accessing maps and internalized strings is safe. |
97 if (heap_object->IsMap()) return true; | 99 if (heap_object->IsMap()) return true; |
98 if (heap_object->IsInternalizedString()) return true; | 100 if (heap_object->IsInternalizedString()) return true; |
99 return !isolate->IsDeferredHandle(handle); | 101 return !isolate->IsDeferredHandle(handle); |
100 } | 102 } |
101 return true; | 103 return true; |
102 } | 104 } |
103 #endif | 105 #endif |
104 | 106 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 current->level = level_; | 203 current->level = level_; |
202 ASSERT_EQ(current->next, current->limit); | 204 ASSERT_EQ(current->next, current->limit); |
203 current->limit = limit_; | 205 current->limit = limit_; |
204 } | 206 } |
205 | 207 |
206 #endif | 208 #endif |
207 | 209 |
208 } } // namespace v8::internal | 210 } } // namespace v8::internal |
209 | 211 |
210 #endif // V8_HANDLES_INL_H_ | 212 #endif // V8_HANDLES_INL_H_ |
OLD | NEW |