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

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

Issue 14908004: add weakcallback without persistent copying (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: missed some instances Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/global-handles.h ('k') | src/runtime.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 // 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 ASSERT(state() == FREE); 228 ASSERT(state() == FREE);
229 return parameter_or_next_free_.next_free; 229 return parameter_or_next_free_.next_free;
230 } 230 }
231 void set_next_free(Node* value) { 231 void set_next_free(Node* value) {
232 ASSERT(state() == FREE); 232 ASSERT(state() == FREE);
233 parameter_or_next_free_.next_free = value; 233 parameter_or_next_free_.next_free = value;
234 } 234 }
235 235
236 void MakeWeak(GlobalHandles* global_handles, 236 void MakeWeak(GlobalHandles* global_handles,
237 void* parameter, 237 void* parameter,
238 WeakReferenceCallback weak_reference_callback, 238 RevivableCallback weak_reference_callback,
239 NearDeathCallback near_death_callback) { 239 NearDeathCallback near_death_callback) {
240 ASSERT(state() != FREE); 240 ASSERT(state() != FREE);
241 set_state(WEAK); 241 set_state(WEAK);
242 set_parameter(parameter); 242 set_parameter(parameter);
243 if (weak_reference_callback != NULL) { 243 if (weak_reference_callback != NULL) {
244 flags_ = IsWeakCallback::update(flags_, true); 244 flags_ = IsWeakCallback::update(flags_, true);
245 near_death_callback_ = 245 near_death_callback_ =
246 reinterpret_cast<NearDeathCallback>(weak_reference_callback); 246 reinterpret_cast<NearDeathCallback>(weak_reference_callback);
247 } else { 247 } else {
248 flags_ = IsWeakCallback::update(flags_, false); 248 flags_ = IsWeakCallback::update(flags_, false);
(...skipping 11 matching lines...) Expand all
260 GlobalHandles* global_handles) { 260 GlobalHandles* global_handles) {
261 if (state() != Node::PENDING) return false; 261 if (state() != Node::PENDING) return false;
262 if (near_death_callback_ == NULL) { 262 if (near_death_callback_ == NULL) {
263 Release(global_handles); 263 Release(global_handles);
264 return false; 264 return false;
265 } 265 }
266 void* par = parameter(); 266 void* par = parameter();
267 set_state(NEAR_DEATH); 267 set_state(NEAR_DEATH);
268 set_parameter(NULL); 268 set_parameter(NULL);
269 269
270 v8::Persistent<v8::Object> object = ToApi<v8::Object>(handle()); 270 v8::Persistent<v8::Value> object = ToApi<v8::Value>(handle());
271 { 271 {
272 // Check that we are not passing a finalized external string to 272 // Check that we are not passing a finalized external string to
273 // the callback. 273 // the callback.
274 ASSERT(!object_->IsExternalAsciiString() || 274 ASSERT(!object_->IsExternalAsciiString() ||
275 ExternalAsciiString::cast(object_)->resource() != NULL); 275 ExternalAsciiString::cast(object_)->resource() != NULL);
276 ASSERT(!object_->IsExternalTwoByteString() || 276 ASSERT(!object_->IsExternalTwoByteString() ||
277 ExternalTwoByteString::cast(object_)->resource() != NULL); 277 ExternalTwoByteString::cast(object_)->resource() != NULL);
278 // Leaving V8. 278 // Leaving V8.
279 VMState<EXTERNAL> state(isolate); 279 VMState<EXTERNAL> state(isolate);
280 if (near_death_callback_ != NULL) { 280 if (near_death_callback_ != NULL) {
281 if (IsWeakCallback::decode(flags_)) { 281 if (IsWeakCallback::decode(flags_)) {
282 WeakReferenceCallback callback = 282 RevivableCallback callback =
283 reinterpret_cast<WeakReferenceCallback>(near_death_callback_); 283 reinterpret_cast<RevivableCallback>(near_death_callback_);
284 callback(object, par); 284 callback(reinterpret_cast<v8::Isolate*>(isolate),
285 &object,
286 par);
285 } else { 287 } else {
286 near_death_callback_(reinterpret_cast<v8::Isolate*>(isolate), 288 near_death_callback_(reinterpret_cast<v8::Isolate*>(isolate),
287 object, 289 object,
288 par); 290 par);
289 } 291 }
290 } 292 }
291 } 293 }
292 // Absence of explicit cleanup or revival of weak handle 294 // Absence of explicit cleanup or revival of weak handle
293 // in most of the cases would lead to memory leak. 295 // in most of the cases would lead to memory leak.
294 ASSERT(state() != NEAR_DEATH); 296 ASSERT(state() != NEAR_DEATH);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 void GlobalHandles::Destroy(Object** location) { 488 void GlobalHandles::Destroy(Object** location) {
487 isolate_->counters()->global_handles()->Decrement(); 489 isolate_->counters()->global_handles()->Decrement();
488 number_of_global_handles_--; 490 number_of_global_handles_--;
489 if (location == NULL) return; 491 if (location == NULL) return;
490 Node::FromLocation(location)->Release(this); 492 Node::FromLocation(location)->Release(this);
491 } 493 }
492 494
493 495
494 void GlobalHandles::MakeWeak(Object** location, 496 void GlobalHandles::MakeWeak(Object** location,
495 void* parameter, 497 void* parameter,
496 WeakReferenceCallback weak_reference_callback, 498 RevivableCallback weak_reference_callback,
497 NearDeathCallback near_death_callback) { 499 NearDeathCallback near_death_callback) {
498 ASSERT(near_death_callback != NULL); 500 ASSERT((weak_reference_callback == NULL) != (near_death_callback == NULL));
499 Node::FromLocation(location)->MakeWeak(this, 501 Node::FromLocation(location)->MakeWeak(this,
500 parameter, 502 parameter,
501 weak_reference_callback, 503 weak_reference_callback,
502 near_death_callback); 504 near_death_callback);
503 } 505 }
504 506
505 507
506 void GlobalHandles::ClearWeakness(Object** location) { 508 void GlobalHandles::ClearWeakness(Object** location) {
507 Node::FromLocation(location)->ClearWeakness(this); 509 Node::FromLocation(location)->ClearWeakness(this);
508 } 510 }
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 } 1012 }
1011 } 1013 }
1012 object_group_connections_.Clear(); 1014 object_group_connections_.Clear();
1013 object_group_connections_.Initialize(kObjectGroupConnectionsCapacity); 1015 object_group_connections_.Initialize(kObjectGroupConnectionsCapacity);
1014 retainer_infos_.Clear(); 1016 retainer_infos_.Clear();
1015 implicit_ref_connections_.Clear(); 1017 implicit_ref_connections_.Clear();
1016 } 1018 }
1017 1019
1018 1020
1019 } } // namespace v8::internal 1021 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/global-handles.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698