Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/global-handles.cc

Issue 2741683004: [rename] Rename internal field to embedder field. (Closed)
Patch Set: [rename] Rename internal field to embedder field. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/global-handles.h ('k') | src/heap/heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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/global-handles.h" 5 #include "src/global-handles.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/cancelable-task.h" 8 #include "src/cancelable-task.h"
9 #include "src/objects-inl.h" 9 #include "src/objects-inl.h"
10 #include "src/v8.h" 10 #include "src/v8.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return state() == PENDING || state() == NEAR_DEATH; 155 return state() == PENDING || state() == NEAR_DEATH;
156 } 156 }
157 157
158 bool IsWeak() const { return state() == WEAK; } 158 bool IsWeak() const { return state() == WEAK; }
159 159
160 bool IsInUse() const { return state() != FREE; } 160 bool IsInUse() const { return state() != FREE; }
161 161
162 bool IsPendingPhantomCallback() const { 162 bool IsPendingPhantomCallback() const {
163 return state() == PENDING && 163 return state() == PENDING &&
164 (weakness_type() == PHANTOM_WEAK || 164 (weakness_type() == PHANTOM_WEAK ||
165 weakness_type() == PHANTOM_WEAK_2_INTERNAL_FIELDS); 165 weakness_type() == PHANTOM_WEAK_2_EMBEDDER_FIELDS);
166 } 166 }
167 167
168 bool IsPendingPhantomResetHandle() const { 168 bool IsPendingPhantomResetHandle() const {
169 return state() == PENDING && weakness_type() == PHANTOM_WEAK_RESET_HANDLE; 169 return state() == PENDING && weakness_type() == PHANTOM_WEAK_RESET_HANDLE;
170 } 170 }
171 171
172 bool IsRetainer() const { 172 bool IsRetainer() const {
173 return state() != FREE && 173 return state() != FREE &&
174 !(state() == NEAR_DEATH && weakness_type() != FINALIZER_WEAK); 174 !(state() == NEAR_DEATH && weakness_type() != FINALIZER_WEAK);
175 } 175 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 v8::WeakCallbackType type) { 217 v8::WeakCallbackType type) {
218 DCHECK(phantom_callback != nullptr); 218 DCHECK(phantom_callback != nullptr);
219 DCHECK(IsInUse()); 219 DCHECK(IsInUse());
220 CHECK_NE(object_, reinterpret_cast<Object*>(kGlobalHandleZapValue)); 220 CHECK_NE(object_, reinterpret_cast<Object*>(kGlobalHandleZapValue));
221 set_state(WEAK); 221 set_state(WEAK);
222 switch (type) { 222 switch (type) {
223 case v8::WeakCallbackType::kParameter: 223 case v8::WeakCallbackType::kParameter:
224 set_weakness_type(PHANTOM_WEAK); 224 set_weakness_type(PHANTOM_WEAK);
225 break; 225 break;
226 case v8::WeakCallbackType::kInternalFields: 226 case v8::WeakCallbackType::kInternalFields:
227 set_weakness_type(PHANTOM_WEAK_2_INTERNAL_FIELDS); 227 set_weakness_type(PHANTOM_WEAK_2_EMBEDDER_FIELDS);
228 break; 228 break;
229 case v8::WeakCallbackType::kFinalizer: 229 case v8::WeakCallbackType::kFinalizer:
230 set_weakness_type(FINALIZER_WEAK); 230 set_weakness_type(FINALIZER_WEAK);
231 break; 231 break;
232 } 232 }
233 set_parameter(parameter); 233 set_parameter(parameter);
234 weak_callback_ = phantom_callback; 234 weak_callback_ = phantom_callback;
235 } 235 }
236 236
237 void MakeWeak(Object*** location_addr) { 237 void MakeWeak(Object*** location_addr) {
(...skipping 10 matching lines...) Expand all
248 void* p = parameter(); 248 void* p = parameter();
249 set_state(NORMAL); 249 set_state(NORMAL);
250 set_parameter(NULL); 250 set_parameter(NULL);
251 return p; 251 return p;
252 } 252 }
253 253
254 void CollectPhantomCallbackData( 254 void CollectPhantomCallbackData(
255 Isolate* isolate, 255 Isolate* isolate,
256 List<PendingPhantomCallback>* pending_phantom_callbacks) { 256 List<PendingPhantomCallback>* pending_phantom_callbacks) {
257 DCHECK(weakness_type() == PHANTOM_WEAK || 257 DCHECK(weakness_type() == PHANTOM_WEAK ||
258 weakness_type() == PHANTOM_WEAK_2_INTERNAL_FIELDS); 258 weakness_type() == PHANTOM_WEAK_2_EMBEDDER_FIELDS);
259 DCHECK(state() == PENDING); 259 DCHECK(state() == PENDING);
260 DCHECK(weak_callback_ != nullptr); 260 DCHECK(weak_callback_ != nullptr);
261 261
262 void* internal_fields[v8::kInternalFieldsInWeakCallback] = {nullptr, 262 void* embedder_fields[v8::kEmbedderFieldsInWeakCallback] = {nullptr,
263 nullptr}; 263 nullptr};
264 if (weakness_type() != PHANTOM_WEAK && object()->IsJSObject()) { 264 if (weakness_type() != PHANTOM_WEAK && object()->IsJSObject()) {
265 auto jsobject = JSObject::cast(object()); 265 auto jsobject = JSObject::cast(object());
266 int field_count = jsobject->GetInternalFieldCount(); 266 int field_count = jsobject->GetEmbedderFieldCount();
267 for (int i = 0; i < v8::kInternalFieldsInWeakCallback; ++i) { 267 for (int i = 0; i < v8::kEmbedderFieldsInWeakCallback; ++i) {
268 if (field_count == i) break; 268 if (field_count == i) break;
269 auto field = jsobject->GetInternalField(i); 269 auto field = jsobject->GetEmbedderField(i);
270 if (field->IsSmi()) internal_fields[i] = field; 270 if (field->IsSmi()) embedder_fields[i] = field;
271 } 271 }
272 } 272 }
273 273
274 // Zap with something dangerous. 274 // Zap with something dangerous.
275 *location() = reinterpret_cast<Object*>(0x6057ca11); 275 *location() = reinterpret_cast<Object*>(0x6057ca11);
276 276
277 typedef v8::WeakCallbackInfo<void> Data; 277 typedef v8::WeakCallbackInfo<void> Data;
278 auto callback = reinterpret_cast<Data::Callback>(weak_callback_); 278 auto callback = reinterpret_cast<Data::Callback>(weak_callback_);
279 pending_phantom_callbacks->Add( 279 pending_phantom_callbacks->Add(
280 PendingPhantomCallback(this, callback, parameter(), internal_fields)); 280 PendingPhantomCallback(this, callback, parameter(), embedder_fields));
281 DCHECK(IsInUse()); 281 DCHECK(IsInUse());
282 set_state(NEAR_DEATH); 282 set_state(NEAR_DEATH);
283 } 283 }
284 284
285 void ResetPhantomHandle() { 285 void ResetPhantomHandle() {
286 DCHECK(weakness_type() == PHANTOM_WEAK_RESET_HANDLE); 286 DCHECK(weakness_type() == PHANTOM_WEAK_RESET_HANDLE);
287 DCHECK(state() == PENDING); 287 DCHECK(state() == PENDING);
288 DCHECK(weak_callback_ == nullptr); 288 DCHECK(weak_callback_ == nullptr);
289 Object*** handle = reinterpret_cast<Object***>(parameter()); 289 Object*** handle = reinterpret_cast<Object***>(parameter());
290 *handle = nullptr; 290 *handle = nullptr;
(...skipping 15 matching lines...) Expand all
306 ExternalOneByteString::cast(object_)->resource() != NULL); 306 ExternalOneByteString::cast(object_)->resource() != NULL);
307 DCHECK(!object_->IsExternalTwoByteString() || 307 DCHECK(!object_->IsExternalTwoByteString() ||
308 ExternalTwoByteString::cast(object_)->resource() != NULL); 308 ExternalTwoByteString::cast(object_)->resource() != NULL);
309 if (weakness_type() != FINALIZER_WEAK) { 309 if (weakness_type() != FINALIZER_WEAK) {
310 return false; 310 return false;
311 } 311 }
312 312
313 // Leaving V8. 313 // Leaving V8.
314 VMState<EXTERNAL> vmstate(isolate); 314 VMState<EXTERNAL> vmstate(isolate);
315 HandleScope handle_scope(isolate); 315 HandleScope handle_scope(isolate);
316 void* internal_fields[v8::kInternalFieldsInWeakCallback] = {nullptr, 316 void* embedder_fields[v8::kEmbedderFieldsInWeakCallback] = {nullptr,
317 nullptr}; 317 nullptr};
318 v8::WeakCallbackInfo<void> data(reinterpret_cast<v8::Isolate*>(isolate), 318 v8::WeakCallbackInfo<void> data(reinterpret_cast<v8::Isolate*>(isolate),
319 parameter(), internal_fields, nullptr); 319 parameter(), embedder_fields, nullptr);
320 weak_callback_(data); 320 weak_callback_(data);
321 321
322 // Absence of explicit cleanup or revival of weak handle 322 // Absence of explicit cleanup or revival of weak handle
323 // in most of the cases would lead to memory leak. 323 // in most of the cases would lead to memory leak.
324 CHECK(state() != NEAR_DEATH); 324 CHECK(state() != NEAR_DEATH);
325 return true; 325 return true;
326 } 326 }
327 327
328 inline GlobalHandles* GetGlobalHandles(); 328 inline GlobalHandles* GetGlobalHandles();
329 329
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 875
876 876
877 void GlobalHandles::PendingPhantomCallback::Invoke(Isolate* isolate) { 877 void GlobalHandles::PendingPhantomCallback::Invoke(Isolate* isolate) {
878 Data::Callback* callback_addr = nullptr; 878 Data::Callback* callback_addr = nullptr;
879 if (node_ != nullptr) { 879 if (node_ != nullptr) {
880 // Initialize for first pass callback. 880 // Initialize for first pass callback.
881 DCHECK(node_->state() == Node::NEAR_DEATH); 881 DCHECK(node_->state() == Node::NEAR_DEATH);
882 callback_addr = &callback_; 882 callback_addr = &callback_;
883 } 883 }
884 Data data(reinterpret_cast<v8::Isolate*>(isolate), parameter_, 884 Data data(reinterpret_cast<v8::Isolate*>(isolate), parameter_,
885 internal_fields_, callback_addr); 885 embedder_fields_, callback_addr);
886 Data::Callback callback = callback_; 886 Data::Callback callback = callback_;
887 callback_ = nullptr; 887 callback_ = nullptr;
888 callback(data); 888 callback(data);
889 if (node_ != nullptr) { 889 if (node_ != nullptr) {
890 // Transition to second pass state. 890 // Transition to second pass state.
891 DCHECK(node_->state() == Node::FREE); 891 DCHECK(node_->state() == Node::FREE);
892 node_ = nullptr; 892 node_ = nullptr;
893 } 893 }
894 } 894 }
895 895
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 blocks_[block][offset] = object; 1127 blocks_[block][offset] = object;
1128 if (isolate->heap()->InNewSpace(object)) { 1128 if (isolate->heap()->InNewSpace(object)) {
1129 new_space_indices_.Add(size_); 1129 new_space_indices_.Add(size_);
1130 } 1130 }
1131 *index = size_++; 1131 *index = size_++;
1132 } 1132 }
1133 1133
1134 1134
1135 } // namespace internal 1135 } // namespace internal
1136 } // namespace v8 1136 } // namespace v8
OLDNEW
« no previous file with comments | « src/global-handles.h ('k') | src/heap/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698