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" | |
8 #include "src/base/logging.h" | 7 #include "src/base/logging.h" |
9 #include "src/identity-map.h" | |
10 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
11 | 9 |
12 namespace v8 { | 10 namespace v8 { |
13 namespace internal { | 11 namespace internal { |
14 | 12 |
15 #ifdef DEBUG | 13 #ifdef DEBUG |
16 bool HandleBase::IsDereferenceAllowed(DereferenceCheckMode mode) const { | 14 bool HandleBase::IsDereferenceAllowed(DereferenceCheckMode mode) const { |
17 DCHECK_NOT_NULL(location_); | 15 DCHECK_NOT_NULL(location_); |
18 Object* object = *location_; | 16 Object* object = *location_; |
19 if (object->IsSmi()) return true; | 17 if (object->IsSmi()) return true; |
(...skipping 30 matching lines...) Expand all Loading... |
50 | 48 |
51 | 49 |
52 Object** HandleScope::Extend(Isolate* isolate) { | 50 Object** HandleScope::Extend(Isolate* isolate) { |
53 HandleScopeData* current = isolate->handle_scope_data(); | 51 HandleScopeData* current = isolate->handle_scope_data(); |
54 | 52 |
55 Object** result = current->next; | 53 Object** result = current->next; |
56 | 54 |
57 DCHECK(result == current->limit); | 55 DCHECK(result == current->limit); |
58 // Make sure there's at least one scope on the stack and that the | 56 // Make sure there's at least one scope on the stack and that the |
59 // top of the scope stack isn't a barrier. | 57 // top of the scope stack isn't a barrier. |
60 if (!Utils::ApiCheck(current->level != current->sealed_level, | 58 if (!Utils::ApiCheck(current->level != 0, |
61 "v8::HandleScope::CreateHandle()", | 59 "v8::HandleScope::CreateHandle()", |
62 "Cannot create a handle without a HandleScope")) { | 60 "Cannot create a handle without a HandleScope")) { |
63 return NULL; | 61 return NULL; |
64 } | 62 } |
65 HandleScopeImplementer* impl = isolate->handle_scope_implementer(); | 63 HandleScopeImplementer* impl = isolate->handle_scope_implementer(); |
66 // If there's more room in the last block, we use that. This is used | 64 // If there's more room in the last block, we use that. This is used |
67 // for fast creation of scopes after scope barriers. | 65 // for fast creation of scopes after scope barriers. |
68 if (!impl->blocks()->is_empty()) { | 66 if (!impl->blocks()->is_empty()) { |
69 Object** limit = &impl->blocks()->last()[kHandleBlockSize]; | 67 Object** limit = &impl->blocks()->last()[kHandleBlockSize]; |
70 if (current->limit != limit) { | 68 if (current->limit != limit) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 Address HandleScope::current_next_address(Isolate* isolate) { | 110 Address HandleScope::current_next_address(Isolate* isolate) { |
113 return reinterpret_cast<Address>(&isolate->handle_scope_data()->next); | 111 return reinterpret_cast<Address>(&isolate->handle_scope_data()->next); |
114 } | 112 } |
115 | 113 |
116 | 114 |
117 Address HandleScope::current_limit_address(Isolate* isolate) { | 115 Address HandleScope::current_limit_address(Isolate* isolate) { |
118 return reinterpret_cast<Address>(&isolate->handle_scope_data()->limit); | 116 return reinterpret_cast<Address>(&isolate->handle_scope_data()->limit); |
119 } | 117 } |
120 | 118 |
121 | 119 |
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 | |
164 DeferredHandleScope::DeferredHandleScope(Isolate* isolate) | 120 DeferredHandleScope::DeferredHandleScope(Isolate* isolate) |
165 : impl_(isolate->handle_scope_implementer()) { | 121 : impl_(isolate->handle_scope_implementer()) { |
166 impl_->BeginDeferredScope(); | 122 impl_->BeginDeferredScope(); |
167 HandleScopeData* data = impl_->isolate()->handle_scope_data(); | 123 HandleScopeData* data = impl_->isolate()->handle_scope_data(); |
168 Object** new_next = impl_->GetSpareOrNewBlock(); | 124 Object** new_next = impl_->GetSpareOrNewBlock(); |
169 Object** new_limit = &new_next[kHandleBlockSize]; | 125 Object** new_limit = &new_next[kHandleBlockSize]; |
170 DCHECK(data->limit == &impl_->blocks()->last()[kHandleBlockSize]); | 126 DCHECK(data->limit == &impl_->blocks()->last()[kHandleBlockSize]); |
171 impl_->blocks()->Add(new_next); | 127 impl_->blocks()->Add(new_next); |
172 | 128 |
173 #ifdef DEBUG | 129 #ifdef DEBUG |
(...skipping 20 matching lines...) Expand all Loading... |
194 data->next = prev_next_; | 150 data->next = prev_next_; |
195 data->limit = prev_limit_; | 151 data->limit = prev_limit_; |
196 #ifdef DEBUG | 152 #ifdef DEBUG |
197 handles_detached_ = true; | 153 handles_detached_ = true; |
198 #endif | 154 #endif |
199 return deferred; | 155 return deferred; |
200 } | 156 } |
201 | 157 |
202 } // namespace internal | 158 } // namespace internal |
203 } // namespace v8 | 159 } // namespace v8 |
OLD | NEW |