OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #include "src/handles.h" | 5 #include "src/handles.h" |
6 | 6 |
| 7 #include "src/address-map.h" |
7 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
| 9 #include "src/identity-map.h" |
8 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
9 | 11 |
10 namespace v8 { | 12 namespace v8 { |
11 namespace internal { | 13 namespace internal { |
12 | 14 |
13 #ifdef DEBUG | 15 #ifdef DEBUG |
14 bool HandleBase::IsDereferenceAllowed(DereferenceCheckMode mode) const { | 16 bool HandleBase::IsDereferenceAllowed(DereferenceCheckMode mode) const { |
15 DCHECK_NOT_NULL(location_); | 17 DCHECK_NOT_NULL(location_); |
16 Object* object = *location_; | 18 Object* object = *location_; |
17 if (object->IsSmi()) return true; | 19 if (object->IsSmi()) return true; |
(...skipping 30 matching lines...) Expand all Loading... |
48 | 50 |
49 | 51 |
50 Object** HandleScope::Extend(Isolate* isolate) { | 52 Object** HandleScope::Extend(Isolate* isolate) { |
51 HandleScopeData* current = isolate->handle_scope_data(); | 53 HandleScopeData* current = isolate->handle_scope_data(); |
52 | 54 |
53 Object** result = current->next; | 55 Object** result = current->next; |
54 | 56 |
55 DCHECK(result == current->limit); | 57 DCHECK(result == current->limit); |
56 // Make sure there's at least one scope on the stack and that the | 58 // Make sure there's at least one scope on the stack and that the |
57 // top of the scope stack isn't a barrier. | 59 // top of the scope stack isn't a barrier. |
58 if (!Utils::ApiCheck(current->level != 0, | 60 if (!Utils::ApiCheck(current->level != current->sealed_level, |
59 "v8::HandleScope::CreateHandle()", | 61 "v8::HandleScope::CreateHandle()", |
60 "Cannot create a handle without a HandleScope")) { | 62 "Cannot create a handle without a HandleScope")) { |
61 return NULL; | 63 return NULL; |
62 } | 64 } |
63 HandleScopeImplementer* impl = isolate->handle_scope_implementer(); | 65 HandleScopeImplementer* impl = isolate->handle_scope_implementer(); |
64 // If there's more room in the last block, we use that. This is used | 66 // If there's more room in the last block, we use that. This is used |
65 // for fast creation of scopes after scope barriers. | 67 // for fast creation of scopes after scope barriers. |
66 if (!impl->blocks()->is_empty()) { | 68 if (!impl->blocks()->is_empty()) { |
67 Object** limit = &impl->blocks()->last()[kHandleBlockSize]; | 69 Object** limit = &impl->blocks()->last()[kHandleBlockSize]; |
68 if (current->limit != limit) { | 70 if (current->limit != limit) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 Address HandleScope::current_next_address(Isolate* isolate) { | 112 Address HandleScope::current_next_address(Isolate* isolate) { |
111 return reinterpret_cast<Address>(&isolate->handle_scope_data()->next); | 113 return reinterpret_cast<Address>(&isolate->handle_scope_data()->next); |
112 } | 114 } |
113 | 115 |
114 | 116 |
115 Address HandleScope::current_limit_address(Isolate* isolate) { | 117 Address HandleScope::current_limit_address(Isolate* isolate) { |
116 return reinterpret_cast<Address>(&isolate->handle_scope_data()->limit); | 118 return reinterpret_cast<Address>(&isolate->handle_scope_data()->limit); |
117 } | 119 } |
118 | 120 |
119 | 121 |
| 122 CanonicalHandleScope::CanonicalHandleScope(Isolate* isolate) |
| 123 : isolate_(isolate) { |
| 124 HandleScopeData* handle_scope_data = isolate_->handle_scope_data(); |
| 125 prev_canonical_scope_ = handle_scope_data->canonical_scope; |
| 126 handle_scope_data->canonical_scope = this; |
| 127 root_index_map_ = new RootIndexMap(isolate); |
| 128 identity_map_ = new IdentityMap<Object**>(isolate->heap(), &zone_); |
| 129 canonical_level_ = handle_scope_data->level; |
| 130 } |
| 131 |
| 132 |
| 133 CanonicalHandleScope::~CanonicalHandleScope() { |
| 134 delete root_index_map_; |
| 135 delete identity_map_; |
| 136 isolate_->handle_scope_data()->canonical_scope = prev_canonical_scope_; |
| 137 } |
| 138 |
| 139 |
| 140 Object** CanonicalHandleScope::Lookup(Object* object) { |
| 141 DCHECK_LE(canonical_level_, isolate_->handle_scope_data()->level); |
| 142 if (isolate_->handle_scope_data()->level != canonical_level_) { |
| 143 // We are in an inner handle scope. Do not canonicalize since we will leave |
| 144 // this handle scope while still being in the canonical scope. |
| 145 return HandleScope::CreateHandle(isolate_, object); |
| 146 } |
| 147 if (object->IsHeapObject()) { |
| 148 int index = root_index_map_->Lookup(HeapObject::cast(object)); |
| 149 if (index != RootIndexMap::kInvalidRootIndex) { |
| 150 return isolate_->heap() |
| 151 ->root_handle(static_cast<Heap::RootListIndex>(index)) |
| 152 .location(); |
| 153 } |
| 154 } |
| 155 Object*** entry = identity_map_->Get(object); |
| 156 if (*entry == nullptr) { |
| 157 // Allocate new handle location. |
| 158 *entry = HandleScope::CreateHandle(isolate_, object); |
| 159 } |
| 160 return reinterpret_cast<Object**>(*entry); |
| 161 } |
| 162 |
| 163 |
120 DeferredHandleScope::DeferredHandleScope(Isolate* isolate) | 164 DeferredHandleScope::DeferredHandleScope(Isolate* isolate) |
121 : impl_(isolate->handle_scope_implementer()) { | 165 : impl_(isolate->handle_scope_implementer()) { |
122 impl_->BeginDeferredScope(); | 166 impl_->BeginDeferredScope(); |
123 HandleScopeData* data = impl_->isolate()->handle_scope_data(); | 167 HandleScopeData* data = impl_->isolate()->handle_scope_data(); |
124 Object** new_next = impl_->GetSpareOrNewBlock(); | 168 Object** new_next = impl_->GetSpareOrNewBlock(); |
125 Object** new_limit = &new_next[kHandleBlockSize]; | 169 Object** new_limit = &new_next[kHandleBlockSize]; |
126 DCHECK(data->limit == &impl_->blocks()->last()[kHandleBlockSize]); | 170 DCHECK(data->limit == &impl_->blocks()->last()[kHandleBlockSize]); |
127 impl_->blocks()->Add(new_next); | 171 impl_->blocks()->Add(new_next); |
128 | 172 |
129 #ifdef DEBUG | 173 #ifdef DEBUG |
(...skipping 20 matching lines...) Expand all Loading... |
150 data->next = prev_next_; | 194 data->next = prev_next_; |
151 data->limit = prev_limit_; | 195 data->limit = prev_limit_; |
152 #ifdef DEBUG | 196 #ifdef DEBUG |
153 handles_detached_ = true; | 197 handles_detached_ = true; |
154 #endif | 198 #endif |
155 return deferred; | 199 return deferred; |
156 } | 200 } |
157 | 201 |
158 } // namespace internal | 202 } // namespace internal |
159 } // namespace v8 | 203 } // namespace v8 |
OLD | NEW |