Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 Node() {} | 62 Node() {} |
| 63 | 63 |
| 64 #ifdef DEBUG | 64 #ifdef DEBUG |
| 65 ~Node() { | 65 ~Node() { |
| 66 // TODO(1428): if it's a weak handle we should have invoked its callback. | 66 // TODO(1428): if it's a weak handle we should have invoked its callback. |
| 67 // Zap the values for eager trapping. | 67 // Zap the values for eager trapping. |
| 68 object_ = NULL; | 68 object_ = NULL; |
| 69 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; | 69 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; |
| 70 index_ = 0; | 70 index_ = 0; |
| 71 independent_ = false; | 71 independent_ = false; |
| 72 partially_dependent_ = false; | |
| 72 in_new_space_list_ = false; | 73 in_new_space_list_ = false; |
| 73 parameter_or_next_free_.next_free = NULL; | 74 parameter_or_next_free_.next_free = NULL; |
| 74 callback_ = NULL; | 75 callback_ = NULL; |
| 75 } | 76 } |
| 76 #endif | 77 #endif |
| 77 | 78 |
| 78 void Initialize(int index, Node** first_free) { | 79 void Initialize(int index, Node** first_free) { |
| 79 index_ = static_cast<uint8_t>(index); | 80 index_ = static_cast<uint8_t>(index); |
| 80 ASSERT(static_cast<int>(index_) == index); | 81 ASSERT(static_cast<int>(index_) == index); |
| 81 state_ = FREE; | 82 state_ = FREE; |
| 82 in_new_space_list_ = false; | 83 in_new_space_list_ = false; |
| 83 parameter_or_next_free_.next_free = *first_free; | 84 parameter_or_next_free_.next_free = *first_free; |
| 84 *first_free = this; | 85 *first_free = this; |
| 85 } | 86 } |
| 86 | 87 |
| 87 void Acquire(Object* object, GlobalHandles* global_handles) { | 88 void Acquire(Object* object, GlobalHandles* global_handles) { |
| 88 ASSERT(state_ == FREE); | 89 ASSERT(state_ == FREE); |
| 89 object_ = object; | 90 object_ = object; |
| 90 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; | 91 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; |
| 91 independent_ = false; | 92 independent_ = false; |
| 93 partially_dependent_ = false; | |
| 92 state_ = NORMAL; | 94 state_ = NORMAL; |
| 93 parameter_or_next_free_.parameter = NULL; | 95 parameter_or_next_free_.parameter = NULL; |
| 94 callback_ = NULL; | 96 callback_ = NULL; |
| 95 IncreaseBlockUses(global_handles); | 97 IncreaseBlockUses(global_handles); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void Release(GlobalHandles* global_handles) { | 100 void Release(GlobalHandles* global_handles) { |
| 99 ASSERT(state_ != FREE); | 101 ASSERT(state_ != FREE); |
| 100 if (IsWeakRetainer()) { | 102 if (IsWeakRetainer()) { |
| 101 global_handles->number_of_weak_handles_--; | 103 global_handles->number_of_weak_handles_--; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 state_ = PENDING; | 149 state_ = PENDING; |
| 148 } | 150 } |
| 149 | 151 |
| 150 // Independent flag accessors. | 152 // Independent flag accessors. |
| 151 void MarkIndependent() { | 153 void MarkIndependent() { |
| 152 ASSERT(state_ != FREE); | 154 ASSERT(state_ != FREE); |
| 153 independent_ = true; | 155 independent_ = true; |
| 154 } | 156 } |
| 155 bool is_independent() const { return independent_; } | 157 bool is_independent() const { return independent_; } |
| 156 | 158 |
| 159 void MarkPartiallyDependent(GlobalHandles* global_handles) { | |
| 160 ASSERT(state_ != FREE); | |
| 161 if (global_handles->isolate()->heap()->InNewSpace(object_)) { | |
| 162 partially_dependent_ = true; | |
| 163 } | |
| 164 } | |
| 165 bool is_partially_dependent() const { return partially_dependent_; } | |
| 166 bool clear_partially_dependent() { partially_dependent_ = false; } | |
|
Michael Starzinger
2012/11/06 17:33:16
Had to change the return type of this method to vo
| |
| 167 | |
| 157 // In-new-space-list flag accessors. | 168 // In-new-space-list flag accessors. |
| 158 void set_in_new_space_list(bool v) { in_new_space_list_ = v; } | 169 void set_in_new_space_list(bool v) { in_new_space_list_ = v; } |
| 159 bool is_in_new_space_list() const { return in_new_space_list_; } | 170 bool is_in_new_space_list() const { return in_new_space_list_; } |
| 160 | 171 |
| 161 // Callback accessor. | 172 // Callback accessor. |
| 162 WeakReferenceCallback callback() { return callback_; } | 173 WeakReferenceCallback callback() { return callback_; } |
| 163 | 174 |
| 164 // Callback parameter accessors. | 175 // Callback parameter accessors. |
| 165 void set_parameter(void* parameter) { | 176 void set_parameter(void* parameter) { |
| 166 ASSERT(state_ != FREE); | 177 ASSERT(state_ != FREE); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 // Wrapper class ID. | 264 // Wrapper class ID. |
| 254 uint16_t class_id_; | 265 uint16_t class_id_; |
| 255 | 266 |
| 256 // Index in the containing handle block. | 267 // Index in the containing handle block. |
| 257 uint8_t index_; | 268 uint8_t index_; |
| 258 | 269 |
| 259 // Need one more bit for MSVC as it treats enums as signed. | 270 // Need one more bit for MSVC as it treats enums as signed. |
| 260 State state_ : 4; | 271 State state_ : 4; |
| 261 | 272 |
| 262 bool independent_ : 1; | 273 bool independent_ : 1; |
| 274 bool partially_dependent_ : 1; | |
| 263 bool in_new_space_list_ : 1; | 275 bool in_new_space_list_ : 1; |
| 264 | 276 |
| 265 // Handle specific callback. | 277 // Handle specific callback. |
| 266 WeakReferenceCallback callback_; | 278 WeakReferenceCallback callback_; |
| 267 | 279 |
| 268 // Provided data for callback. In FREE state, this is used for | 280 // Provided data for callback. In FREE state, this is used for |
| 269 // the free list link. | 281 // the free list link. |
| 270 union { | 282 union { |
| 271 void* parameter; | 283 void* parameter; |
| 272 Node* next_free; | 284 Node* next_free; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 void GlobalHandles::ClearWeakness(Object** location) { | 453 void GlobalHandles::ClearWeakness(Object** location) { |
| 442 Node::FromLocation(location)->ClearWeakness(this); | 454 Node::FromLocation(location)->ClearWeakness(this); |
| 443 } | 455 } |
| 444 | 456 |
| 445 | 457 |
| 446 void GlobalHandles::MarkIndependent(Object** location) { | 458 void GlobalHandles::MarkIndependent(Object** location) { |
| 447 Node::FromLocation(location)->MarkIndependent(); | 459 Node::FromLocation(location)->MarkIndependent(); |
| 448 } | 460 } |
| 449 | 461 |
| 450 | 462 |
| 463 void GlobalHandles::MarkPartiallyDependent(Object** location) { | |
| 464 Node::FromLocation(location)->MarkPartiallyDependent(this); | |
| 465 } | |
| 466 | |
| 467 | |
| 451 bool GlobalHandles::IsIndependent(Object** location) { | 468 bool GlobalHandles::IsIndependent(Object** location) { |
| 452 return Node::FromLocation(location)->is_independent(); | 469 return Node::FromLocation(location)->is_independent(); |
| 453 } | 470 } |
| 454 | 471 |
| 455 | 472 |
| 456 bool GlobalHandles::IsNearDeath(Object** location) { | 473 bool GlobalHandles::IsNearDeath(Object** location) { |
| 457 return Node::FromLocation(location)->IsNearDeath(); | 474 return Node::FromLocation(location)->IsNearDeath(); |
| 458 } | 475 } |
| 459 | 476 |
| 460 | 477 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 it.node()->MarkPending(); | 511 it.node()->MarkPending(); |
| 495 } | 512 } |
| 496 } | 513 } |
| 497 } | 514 } |
| 498 | 515 |
| 499 | 516 |
| 500 void GlobalHandles::IterateNewSpaceStrongAndDependentRoots(ObjectVisitor* v) { | 517 void GlobalHandles::IterateNewSpaceStrongAndDependentRoots(ObjectVisitor* v) { |
| 501 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 518 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
| 502 Node* node = new_space_nodes_[i]; | 519 Node* node = new_space_nodes_[i]; |
| 503 if (node->IsStrongRetainer() || | 520 if (node->IsStrongRetainer() || |
| 504 (node->IsWeakRetainer() && !node->is_independent())) { | 521 (node->IsWeakRetainer() && !node->is_independent() && |
| 505 v->VisitPointer(node->location()); | 522 !node->is_partially_dependent())) { |
| 523 v->VisitPointer(node->location()); | |
| 506 } | 524 } |
| 507 } | 525 } |
| 508 } | 526 } |
| 509 | 527 |
| 510 | 528 |
| 511 void GlobalHandles::IdentifyNewSpaceWeakIndependentHandles( | 529 void GlobalHandles::IdentifyNewSpaceWeakIndependentHandles( |
| 512 WeakSlotCallbackWithHeap f) { | 530 WeakSlotCallbackWithHeap f) { |
| 513 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 531 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
| 514 Node* node = new_space_nodes_[i]; | 532 Node* node = new_space_nodes_[i]; |
| 515 ASSERT(node->is_in_new_space_list()); | 533 ASSERT(node->is_in_new_space_list()); |
| 516 if (node->is_independent() && node->IsWeak() && | 534 if ((node->is_independent() || node->is_partially_dependent()) && |
| 517 f(isolate_->heap(), node->location())) { | 535 node->IsWeak() && f(isolate_->heap(), node->location())) { |
| 518 node->MarkPending(); | 536 node->MarkPending(); |
| 519 } | 537 } |
| 520 } | 538 } |
| 521 } | 539 } |
| 522 | 540 |
| 523 | 541 |
| 524 void GlobalHandles::IterateNewSpaceWeakIndependentRoots(ObjectVisitor* v) { | 542 void GlobalHandles::IterateNewSpaceWeakIndependentRoots(ObjectVisitor* v) { |
| 525 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 543 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
| 526 Node* node = new_space_nodes_[i]; | 544 Node* node = new_space_nodes_[i]; |
| 527 ASSERT(node->is_in_new_space_list()); | 545 ASSERT(node->is_in_new_space_list()); |
| 528 if (node->is_independent() && node->IsWeakRetainer()) { | 546 if ((node->is_independent() || node->is_partially_dependent()) && |
| 547 node->IsWeakRetainer()) { | |
| 529 v->VisitPointer(node->location()); | 548 v->VisitPointer(node->location()); |
| 530 } | 549 } |
| 531 } | 550 } |
| 532 } | 551 } |
| 533 | 552 |
| 534 | 553 |
| 535 bool GlobalHandles::PostGarbageCollectionProcessing( | 554 bool GlobalHandles::PostGarbageCollectionProcessing( |
| 536 GarbageCollector collector) { | 555 GarbageCollector collector) { |
| 537 // Process weak global handle callbacks. This must be done after the | 556 // Process weak global handle callbacks. This must be done after the |
| 538 // GC is completely done, because the callbacks may invoke arbitrary | 557 // GC is completely done, because the callbacks may invoke arbitrary |
| 539 // API functions. | 558 // API functions. |
| 540 ASSERT(isolate_->heap()->gc_state() == Heap::NOT_IN_GC); | 559 ASSERT(isolate_->heap()->gc_state() == Heap::NOT_IN_GC); |
| 541 const int initial_post_gc_processing_count = ++post_gc_processing_count_; | 560 const int initial_post_gc_processing_count = ++post_gc_processing_count_; |
| 542 bool next_gc_likely_to_collect_more = false; | 561 bool next_gc_likely_to_collect_more = false; |
| 543 if (collector == SCAVENGER) { | 562 if (collector == SCAVENGER) { |
| 544 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 563 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
| 545 Node* node = new_space_nodes_[i]; | 564 Node* node = new_space_nodes_[i]; |
| 546 ASSERT(node->is_in_new_space_list()); | 565 ASSERT(node->is_in_new_space_list()); |
| 547 // Skip dependent handles. Their weak callbacks might expect to be | 566 // Skip dependent handles. Their weak callbacks might expect to be |
| 548 // called between two global garbage collection callbacks which | 567 // called between two global garbage collection callbacks which |
| 549 // are not called for minor collections. | 568 // are not called for minor collections. |
| 550 if (!node->is_independent()) continue; | 569 if (!node->is_independent() && !node->is_partially_dependent()) { |
| 570 continue; | |
| 571 } | |
| 572 node->clear_partially_dependent(); | |
| 551 if (node->PostGarbageCollectionProcessing(isolate_, this)) { | 573 if (node->PostGarbageCollectionProcessing(isolate_, this)) { |
| 552 if (initial_post_gc_processing_count != post_gc_processing_count_) { | 574 if (initial_post_gc_processing_count != post_gc_processing_count_) { |
| 553 // Weak callback triggered another GC and another round of | 575 // Weak callback triggered another GC and another round of |
| 554 // PostGarbageCollection processing. The current node might | 576 // PostGarbageCollection processing. The current node might |
| 555 // have been deleted in that round, so we need to bail out (or | 577 // have been deleted in that round, so we need to bail out (or |
| 556 // restart the processing). | 578 // restart the processing). |
| 557 return next_gc_likely_to_collect_more; | 579 return next_gc_likely_to_collect_more; |
| 558 } | 580 } |
| 559 } | 581 } |
| 560 if (!node->IsRetainer()) { | 582 if (!node->IsRetainer()) { |
| 561 next_gc_likely_to_collect_more = true; | 583 next_gc_likely_to_collect_more = true; |
| 562 } | 584 } |
| 563 } | 585 } |
| 564 } else { | 586 } else { |
| 565 for (NodeIterator it(this); !it.done(); it.Advance()) { | 587 for (NodeIterator it(this); !it.done(); it.Advance()) { |
| 588 it.node()->clear_partially_dependent(); | |
| 566 if (it.node()->PostGarbageCollectionProcessing(isolate_, this)) { | 589 if (it.node()->PostGarbageCollectionProcessing(isolate_, this)) { |
| 567 if (initial_post_gc_processing_count != post_gc_processing_count_) { | 590 if (initial_post_gc_processing_count != post_gc_processing_count_) { |
| 568 // See the comment above. | 591 // See the comment above. |
| 569 return next_gc_likely_to_collect_more; | 592 return next_gc_likely_to_collect_more; |
| 570 } | 593 } |
| 571 } | 594 } |
| 572 if (!it.node()->IsRetainer()) { | 595 if (!it.node()->IsRetainer()) { |
| 573 next_gc_likely_to_collect_more = true; | 596 next_gc_likely_to_collect_more = true; |
| 574 } | 597 } |
| 575 } | 598 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 implicit_ref_groups_.Clear(); | 746 implicit_ref_groups_.Clear(); |
| 724 } | 747 } |
| 725 | 748 |
| 726 | 749 |
| 727 void GlobalHandles::TearDown() { | 750 void GlobalHandles::TearDown() { |
| 728 // TODO(1428): invoke weak callbacks. | 751 // TODO(1428): invoke weak callbacks. |
| 729 } | 752 } |
| 730 | 753 |
| 731 | 754 |
| 732 } } // namespace v8::internal | 755 } } // namespace v8::internal |
| OLD | NEW |