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 externally_unreachable_ = 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 externally_unreachable_ = 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 MarkExternallyUnreachable(GlobalHandles* global_handles) { | |
160 ASSERT(state_ != FREE); | |
161 if (global_handles->isolate()->heap()->InNewSpace(object_)) | |
Michael Starzinger
2012/11/05 10:47:27
Put curly brackets around the body of this if-stat
haraken
2012/11/05 12:42:07
Done.
| |
162 externally_unreachable_ = true; | |
163 } | |
164 bool is_externally_unreachable() const { return externally_unreachable_; } | |
165 bool clear_externally_unreachable() { externally_unreachable_ = false; } | |
166 | |
157 // In-new-space-list flag accessors. | 167 // In-new-space-list flag accessors. |
158 void set_in_new_space_list(bool v) { in_new_space_list_ = v; } | 168 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_; } | 169 bool is_in_new_space_list() const { return in_new_space_list_; } |
160 | 170 |
161 // Callback accessor. | 171 // Callback accessor. |
162 WeakReferenceCallback callback() { return callback_; } | 172 WeakReferenceCallback callback() { return callback_; } |
163 | 173 |
164 // Callback parameter accessors. | 174 // Callback parameter accessors. |
165 void set_parameter(void* parameter) { | 175 void set_parameter(void* parameter) { |
166 ASSERT(state_ != FREE); | 176 ASSERT(state_ != FREE); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 // Wrapper class ID. | 263 // Wrapper class ID. |
254 uint16_t class_id_; | 264 uint16_t class_id_; |
255 | 265 |
256 // Index in the containing handle block. | 266 // Index in the containing handle block. |
257 uint8_t index_; | 267 uint8_t index_; |
258 | 268 |
259 // Need one more bit for MSVC as it treats enums as signed. | 269 // Need one more bit for MSVC as it treats enums as signed. |
260 State state_ : 4; | 270 State state_ : 4; |
261 | 271 |
262 bool independent_ : 1; | 272 bool independent_ : 1; |
273 bool externally_unreachable_ : 1; | |
263 bool in_new_space_list_ : 1; | 274 bool in_new_space_list_ : 1; |
264 | 275 |
265 // Handle specific callback. | 276 // Handle specific callback. |
266 WeakReferenceCallback callback_; | 277 WeakReferenceCallback callback_; |
267 | 278 |
268 // Provided data for callback. In FREE state, this is used for | 279 // Provided data for callback. In FREE state, this is used for |
269 // the free list link. | 280 // the free list link. |
270 union { | 281 union { |
271 void* parameter; | 282 void* parameter; |
272 Node* next_free; | 283 Node* next_free; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 void GlobalHandles::ClearWeakness(Object** location) { | 452 void GlobalHandles::ClearWeakness(Object** location) { |
442 Node::FromLocation(location)->ClearWeakness(this); | 453 Node::FromLocation(location)->ClearWeakness(this); |
443 } | 454 } |
444 | 455 |
445 | 456 |
446 void GlobalHandles::MarkIndependent(Object** location) { | 457 void GlobalHandles::MarkIndependent(Object** location) { |
447 Node::FromLocation(location)->MarkIndependent(); | 458 Node::FromLocation(location)->MarkIndependent(); |
448 } | 459 } |
449 | 460 |
450 | 461 |
462 void GlobalHandles::MarkExternallyUnreachable(Object** location) { | |
463 Node::FromLocation(location)->MarkExternallyUnreachable(this); | |
464 } | |
465 | |
466 | |
451 bool GlobalHandles::IsIndependent(Object** location) { | 467 bool GlobalHandles::IsIndependent(Object** location) { |
452 return Node::FromLocation(location)->is_independent(); | 468 return Node::FromLocation(location)->is_independent(); |
453 } | 469 } |
454 | 470 |
455 | 471 |
456 bool GlobalHandles::IsNearDeath(Object** location) { | 472 bool GlobalHandles::IsNearDeath(Object** location) { |
457 return Node::FromLocation(location)->IsNearDeath(); | 473 return Node::FromLocation(location)->IsNearDeath(); |
458 } | 474 } |
459 | 475 |
460 | 476 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 it.node()->MarkPending(); | 510 it.node()->MarkPending(); |
495 } | 511 } |
496 } | 512 } |
497 } | 513 } |
498 | 514 |
499 | 515 |
500 void GlobalHandles::IterateNewSpaceStrongAndDependentRoots(ObjectVisitor* v) { | 516 void GlobalHandles::IterateNewSpaceStrongAndDependentRoots(ObjectVisitor* v) { |
501 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 517 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
502 Node* node = new_space_nodes_[i]; | 518 Node* node = new_space_nodes_[i]; |
503 if (node->IsStrongRetainer() || | 519 if (node->IsStrongRetainer() || |
504 (node->IsWeakRetainer() && !node->is_independent())) { | 520 (node->IsWeakRetainer() && !node->is_independent() && |
505 v->VisitPointer(node->location()); | 521 !node->is_externally_unreachable())) { |
522 v->VisitPointer(node->location()); | |
506 } | 523 } |
507 } | 524 } |
508 } | 525 } |
509 | 526 |
510 | 527 |
511 void GlobalHandles::IdentifyNewSpaceWeakIndependentHandles( | 528 void GlobalHandles::IdentifyNewSpaceWeakIndependentHandles( |
512 WeakSlotCallbackWithHeap f) { | 529 WeakSlotCallbackWithHeap f) { |
513 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 530 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
514 Node* node = new_space_nodes_[i]; | 531 Node* node = new_space_nodes_[i]; |
515 ASSERT(node->is_in_new_space_list()); | 532 ASSERT(node->is_in_new_space_list()); |
516 if (node->is_independent() && node->IsWeak() && | 533 if ((node->is_independent() || node->is_externally_unreachable()) && |
517 f(isolate_->heap(), node->location())) { | 534 node->IsWeak() && f(isolate_->heap(), node->location())) { |
518 node->MarkPending(); | 535 node->MarkPending(); |
519 } | 536 } |
520 } | 537 } |
521 } | 538 } |
522 | 539 |
523 | 540 |
524 void GlobalHandles::IterateNewSpaceWeakIndependentRoots(ObjectVisitor* v) { | 541 void GlobalHandles::IterateNewSpaceWeakIndependentRoots(ObjectVisitor* v) { |
525 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 542 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
526 Node* node = new_space_nodes_[i]; | 543 Node* node = new_space_nodes_[i]; |
527 ASSERT(node->is_in_new_space_list()); | 544 ASSERT(node->is_in_new_space_list()); |
528 if (node->is_independent() && node->IsWeakRetainer()) { | 545 if ((node->is_independent() || node->is_externally_unreachable()) && |
546 node->IsWeakRetainer()) { | |
529 v->VisitPointer(node->location()); | 547 v->VisitPointer(node->location()); |
530 } | 548 } |
531 } | 549 } |
532 } | 550 } |
533 | 551 |
534 | 552 |
535 bool GlobalHandles::PostGarbageCollectionProcessing( | 553 bool GlobalHandles::PostGarbageCollectionProcessing( |
536 GarbageCollector collector) { | 554 GarbageCollector collector) { |
537 // Process weak global handle callbacks. This must be done after the | 555 // Process weak global handle callbacks. This must be done after the |
538 // GC is completely done, because the callbacks may invoke arbitrary | 556 // GC is completely done, because the callbacks may invoke arbitrary |
539 // API functions. | 557 // API functions. |
540 ASSERT(isolate_->heap()->gc_state() == Heap::NOT_IN_GC); | 558 ASSERT(isolate_->heap()->gc_state() == Heap::NOT_IN_GC); |
541 const int initial_post_gc_processing_count = ++post_gc_processing_count_; | 559 const int initial_post_gc_processing_count = ++post_gc_processing_count_; |
542 bool next_gc_likely_to_collect_more = false; | 560 bool next_gc_likely_to_collect_more = false; |
543 if (collector == SCAVENGER) { | 561 if (collector == SCAVENGER) { |
544 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 562 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
545 Node* node = new_space_nodes_[i]; | 563 Node* node = new_space_nodes_[i]; |
546 ASSERT(node->is_in_new_space_list()); | 564 ASSERT(node->is_in_new_space_list()); |
547 // Skip dependent handles. Their weak callbacks might expect to be | 565 // Skip dependent handles. Their weak callbacks might expect to be |
548 // called between two global garbage collection callbacks which | 566 // called between two global garbage collection callbacks which |
549 // are not called for minor collections. | 567 // are not called for minor collections. |
550 if (!node->is_independent()) continue; | 568 if (!node->is_independent() && !node->is_externally_unreachable()) { |
569 continue; | |
570 } | |
571 node->clear_externally_unreachable(); | |
551 if (node->PostGarbageCollectionProcessing(isolate_, this)) { | 572 if (node->PostGarbageCollectionProcessing(isolate_, this)) { |
552 if (initial_post_gc_processing_count != post_gc_processing_count_) { | 573 if (initial_post_gc_processing_count != post_gc_processing_count_) { |
553 // Weak callback triggered another GC and another round of | 574 // Weak callback triggered another GC and another round of |
554 // PostGarbageCollection processing. The current node might | 575 // PostGarbageCollection processing. The current node might |
555 // have been deleted in that round, so we need to bail out (or | 576 // have been deleted in that round, so we need to bail out (or |
556 // restart the processing). | 577 // restart the processing). |
557 return next_gc_likely_to_collect_more; | 578 return next_gc_likely_to_collect_more; |
558 } | 579 } |
559 } | 580 } |
560 if (!node->IsRetainer()) { | 581 if (!node->IsRetainer()) { |
561 next_gc_likely_to_collect_more = true; | 582 next_gc_likely_to_collect_more = true; |
562 } | 583 } |
563 } | 584 } |
564 } else { | 585 } else { |
565 for (NodeIterator it(this); !it.done(); it.Advance()) { | 586 for (NodeIterator it(this); !it.done(); it.Advance()) { |
587 it.node()->clear_externally_unreachable(); | |
566 if (it.node()->PostGarbageCollectionProcessing(isolate_, this)) { | 588 if (it.node()->PostGarbageCollectionProcessing(isolate_, this)) { |
567 if (initial_post_gc_processing_count != post_gc_processing_count_) { | 589 if (initial_post_gc_processing_count != post_gc_processing_count_) { |
568 // See the comment above. | 590 // See the comment above. |
569 return next_gc_likely_to_collect_more; | 591 return next_gc_likely_to_collect_more; |
570 } | 592 } |
571 } | 593 } |
572 if (!it.node()->IsRetainer()) { | 594 if (!it.node()->IsRetainer()) { |
573 next_gc_likely_to_collect_more = true; | 595 next_gc_likely_to_collect_more = true; |
574 } | 596 } |
575 } | 597 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 implicit_ref_groups_.Clear(); | 745 implicit_ref_groups_.Clear(); |
724 } | 746 } |
725 | 747 |
726 | 748 |
727 void GlobalHandles::TearDown() { | 749 void GlobalHandles::TearDown() { |
728 // TODO(1428): invoke weak callbacks. | 750 // TODO(1428): invoke weak callbacks. |
729 } | 751 } |
730 | 752 |
731 | 753 |
732 } } // namespace v8::internal | 754 } } // namespace v8::internal |
OLD | NEW |