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