| OLD | NEW |
| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 set_independent(false); | 99 set_independent(false); |
| 100 set_partially_dependent(false); | 100 set_partially_dependent(false); |
| 101 set_state(NORMAL); | 101 set_state(NORMAL); |
| 102 parameter_or_next_free_.parameter = NULL; | 102 parameter_or_next_free_.parameter = NULL; |
| 103 callback_ = NULL; | 103 callback_ = NULL; |
| 104 IncreaseBlockUses(global_handles); | 104 IncreaseBlockUses(global_handles); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void Release(GlobalHandles* global_handles) { | 107 void Release(GlobalHandles* global_handles) { |
| 108 ASSERT(state() != FREE); | 108 ASSERT(state() != FREE); |
| 109 if (IsWeakRetainer()) { | |
| 110 global_handles->number_of_weak_handles_--; | |
| 111 if (object_->IsJSGlobalObject()) { | |
| 112 global_handles->number_of_global_object_weak_handles_--; | |
| 113 } | |
| 114 } | |
| 115 set_state(FREE); | 109 set_state(FREE); |
| 116 parameter_or_next_free_.next_free = global_handles->first_free_; | 110 parameter_or_next_free_.next_free = global_handles->first_free_; |
| 117 global_handles->first_free_ = this; | 111 global_handles->first_free_ = this; |
| 118 DecreaseBlockUses(global_handles); | 112 DecreaseBlockUses(global_handles); |
| 119 } | 113 } |
| 120 | 114 |
| 121 // Object slot accessors. | 115 // Object slot accessors. |
| 122 Object* object() const { return object_; } | 116 Object* object() const { return object_; } |
| 123 Object** location() { return &object_; } | 117 Object** location() { return &object_; } |
| 124 Handle<Object> handle() { return Handle<Object>(location()); } | 118 Handle<Object> handle() { return Handle<Object>(location()); } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 209 } |
| 216 void set_next_free(Node* value) { | 210 void set_next_free(Node* value) { |
| 217 ASSERT(state() == FREE); | 211 ASSERT(state() == FREE); |
| 218 parameter_or_next_free_.next_free = value; | 212 parameter_or_next_free_.next_free = value; |
| 219 } | 213 } |
| 220 | 214 |
| 221 void MakeWeak(GlobalHandles* global_handles, | 215 void MakeWeak(GlobalHandles* global_handles, |
| 222 void* parameter, | 216 void* parameter, |
| 223 WeakReferenceCallback callback) { | 217 WeakReferenceCallback callback) { |
| 224 ASSERT(state() != FREE); | 218 ASSERT(state() != FREE); |
| 225 if (!IsWeakRetainer()) { | |
| 226 global_handles->number_of_weak_handles_++; | |
| 227 if (object_->IsJSGlobalObject()) { | |
| 228 global_handles->number_of_global_object_weak_handles_++; | |
| 229 } | |
| 230 } | |
| 231 set_state(WEAK); | 219 set_state(WEAK); |
| 232 set_parameter(parameter); | 220 set_parameter(parameter); |
| 233 callback_ = callback; | 221 callback_ = callback; |
| 234 } | 222 } |
| 235 | 223 |
| 236 void ClearWeakness(GlobalHandles* global_handles) { | 224 void ClearWeakness(GlobalHandles* global_handles) { |
| 237 ASSERT(state() != FREE); | 225 ASSERT(state() != FREE); |
| 238 if (IsWeakRetainer()) { | |
| 239 global_handles->number_of_weak_handles_--; | |
| 240 if (object_->IsJSGlobalObject()) { | |
| 241 global_handles->number_of_global_object_weak_handles_--; | |
| 242 } | |
| 243 } | |
| 244 set_state(NORMAL); | 226 set_state(NORMAL); |
| 245 set_parameter(NULL); | 227 set_parameter(NULL); |
| 246 } | 228 } |
| 247 | 229 |
| 248 bool PostGarbageCollectionProcessing(Isolate* isolate, | 230 bool PostGarbageCollectionProcessing(Isolate* isolate, |
| 249 GlobalHandles* global_handles) { | 231 GlobalHandles* global_handles) { |
| 250 if (state() != Node::PENDING) return false; | 232 if (state() != Node::PENDING) return false; |
| 251 WeakReferenceCallback func = callback(); | 233 WeakReferenceCallback func = callback(); |
| 252 if (func == NULL) { | 234 if (func == NULL) { |
| 253 Release(global_handles); | 235 Release(global_handles); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 private: | 397 private: |
| 416 NodeBlock* block_; | 398 NodeBlock* block_; |
| 417 int index_; | 399 int index_; |
| 418 | 400 |
| 419 DISALLOW_COPY_AND_ASSIGN(NodeIterator); | 401 DISALLOW_COPY_AND_ASSIGN(NodeIterator); |
| 420 }; | 402 }; |
| 421 | 403 |
| 422 | 404 |
| 423 GlobalHandles::GlobalHandles(Isolate* isolate) | 405 GlobalHandles::GlobalHandles(Isolate* isolate) |
| 424 : isolate_(isolate), | 406 : isolate_(isolate), |
| 425 number_of_weak_handles_(0), | |
| 426 number_of_global_object_weak_handles_(0), | |
| 427 number_of_global_handles_(0), | 407 number_of_global_handles_(0), |
| 428 first_block_(NULL), | 408 first_block_(NULL), |
| 429 first_used_block_(NULL), | 409 first_used_block_(NULL), |
| 430 first_free_(NULL), | 410 first_free_(NULL), |
| 431 post_gc_processing_count_(0) {} | 411 post_gc_processing_count_(0) {} |
| 432 | 412 |
| 433 | 413 |
| 434 GlobalHandles::~GlobalHandles() { | 414 GlobalHandles::~GlobalHandles() { |
| 435 NodeBlock* block = first_block_; | 415 NodeBlock* block = first_block_; |
| 436 while (block != NULL) { | 416 while (block != NULL) { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 void GlobalHandles::IterateAllRootsWithClassIds(ObjectVisitor* v) { | 694 void GlobalHandles::IterateAllRootsWithClassIds(ObjectVisitor* v) { |
| 715 for (NodeIterator it(this); !it.done(); it.Advance()) { | 695 for (NodeIterator it(this); !it.done(); it.Advance()) { |
| 716 if (it.node()->IsRetainer() && it.node()->has_wrapper_class_id()) { | 696 if (it.node()->IsRetainer() && it.node()->has_wrapper_class_id()) { |
| 717 v->VisitEmbedderReference(it.node()->location(), | 697 v->VisitEmbedderReference(it.node()->location(), |
| 718 it.node()->wrapper_class_id()); | 698 it.node()->wrapper_class_id()); |
| 719 } | 699 } |
| 720 } | 700 } |
| 721 } | 701 } |
| 722 | 702 |
| 723 | 703 |
| 704 int GlobalHandles::NumberOfWeakHandles() { |
| 705 int count = 0; |
| 706 for (NodeIterator it(this); !it.done(); it.Advance()) { |
| 707 if (it.node()->IsWeakRetainer()) { |
| 708 count++; |
| 709 } |
| 710 } |
| 711 return count; |
| 712 } |
| 713 |
| 714 |
| 715 int GlobalHandles::NumberOfGlobalObjectWeakHandles() { |
| 716 int count = 0; |
| 717 for (NodeIterator it(this); !it.done(); it.Advance()) { |
| 718 if (it.node()->IsWeakRetainer() && |
| 719 it.node()->object()->IsJSGlobalObject()) { |
| 720 count++; |
| 721 } |
| 722 } |
| 723 return count; |
| 724 } |
| 725 |
| 726 |
| 724 void GlobalHandles::RecordStats(HeapStats* stats) { | 727 void GlobalHandles::RecordStats(HeapStats* stats) { |
| 725 *stats->global_handle_count = 0; | 728 *stats->global_handle_count = 0; |
| 726 *stats->weak_global_handle_count = 0; | 729 *stats->weak_global_handle_count = 0; |
| 727 *stats->pending_global_handle_count = 0; | 730 *stats->pending_global_handle_count = 0; |
| 728 *stats->near_death_global_handle_count = 0; | 731 *stats->near_death_global_handle_count = 0; |
| 729 *stats->free_global_handle_count = 0; | 732 *stats->free_global_handle_count = 0; |
| 730 for (NodeIterator it(this); !it.done(); it.Advance()) { | 733 for (NodeIterator it(this); !it.done(); it.Advance()) { |
| 731 *stats->global_handle_count += 1; | 734 *stats->global_handle_count += 1; |
| 732 if (it.node()->state() == Node::WEAK) { | 735 if (it.node()->state() == Node::WEAK) { |
| 733 *stats->weak_global_handle_count += 1; | 736 *stats->weak_global_handle_count += 1; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 implicit_ref_groups_.Clear(); | 829 implicit_ref_groups_.Clear(); |
| 827 } | 830 } |
| 828 | 831 |
| 829 | 832 |
| 830 void GlobalHandles::TearDown() { | 833 void GlobalHandles::TearDown() { |
| 831 // TODO(1428): invoke weak callbacks. | 834 // TODO(1428): invoke weak callbacks. |
| 832 } | 835 } |
| 833 | 836 |
| 834 | 837 |
| 835 } } // namespace v8::internal | 838 } } // namespace v8::internal |
| OLD | NEW |