657 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
657 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
658 |
658 |
659 // If we're within a stop-world GC, then we might look at a card in a |
659 // If we're within a stop-world GC, then we might look at a card in a |
660 // GC alloc region that extends onto a GC LAB, which may not be |
660 // GC alloc region that extends onto a GC LAB, which may not be |
661 // parseable. Stop such at the "saved_mark" of the region. |
661 // parseable. Stop such at the "saved_mark" of the region. |
662 if (G1CollectedHeap::heap()->is_gc_active()) { |
662 if (g1h->is_gc_active()) { |
663 mr = mr.intersection(used_region_at_save_marks()); |
663 mr = mr.intersection(used_region_at_save_marks()); |
664 } else { |
664 } else { |
665 mr = mr.intersection(used_region()); |
665 mr = mr.intersection(used_region()); |
666 } |
666 } |
667 if (mr.is_empty()) return NULL; |
667 if (mr.is_empty()) return NULL; |
686 *card_ptr = CardTableModRefBS::clean_card_val(); |
686 *card_ptr = CardTableModRefBS::clean_card_val(); |
687 // We must complete this write before we do any of the reads below. |
687 // We must complete this write before we do any of the reads below. |
688 OrderAccess::storeload(); |
688 OrderAccess::storeload(); |
689 } |
689 } |
690 |
690 |
|
691 // Cache the boundaries of the memory region in some const locals |
|
692 HeapWord* const start = mr.start(); |
|
693 HeapWord* const end = mr.end(); |
|
694 |
691 // We used to use "block_start_careful" here. But we're actually happy |
695 // We used to use "block_start_careful" here. But we're actually happy |
692 // to update the BOT while we do this... |
696 // to update the BOT while we do this... |
693 HeapWord* cur = block_start(mr.start()); |
697 HeapWord* cur = block_start(start); |
694 assert(cur <= mr.start(), "Postcondition"); |
698 assert(cur <= start, "Postcondition"); |
695 |
699 |
696 while (cur <= mr.start()) { |
700 oop obj; |
697 if (oop(cur)->klass_or_null() == NULL) { |
701 |
|
702 HeapWord* next = cur; |
|
703 while (next <= start) { |
|
704 cur = next; |
|
705 obj = oop(cur); |
|
706 if (obj->klass_or_null() == NULL) { |
698 // Ran into an unparseable point. |
707 // Ran into an unparseable point. |
699 return cur; |
708 return cur; |
700 } |
709 } |
701 // Otherwise... |
710 // Otherwise... |
702 int sz = oop(cur)->size(); |
711 next = (cur + obj->size()); |
703 if (cur + sz > mr.start()) break; |
712 } |
704 // Otherwise, go on. |
713 |
705 cur = cur + sz; |
714 // If we finish the above loop...We have a parseable object that |
706 } |
715 // begins on or before the start of the memory region, and ends |
707 oop obj; |
716 // inside or spans the entire region. |
708 obj = oop(cur); |
717 |
709 // If we finish this loop... |
718 assert(obj == oop(cur), "sanity"); |
710 assert(cur <= mr.start() |
719 assert(cur <= start && |
711 && obj->klass_or_null() != NULL |
720 obj->klass_or_null() != NULL && |
712 && cur + obj->size() > mr.start(), |
721 (cur + obj->size()) > start, |
713 "Loop postcondition"); |
722 "Loop postcondition"); |
|
723 |
714 if (!g1h->is_obj_dead(obj)) { |
724 if (!g1h->is_obj_dead(obj)) { |
715 obj->oop_iterate(cl, mr); |
725 obj->oop_iterate(cl, mr); |
716 } |
726 } |
717 |
727 |
718 HeapWord* next; |
728 while (cur < end) { |
719 while (cur < mr.end()) { |
|
720 obj = oop(cur); |
729 obj = oop(cur); |
721 if (obj->klass_or_null() == NULL) { |
730 if (obj->klass_or_null() == NULL) { |
722 // Ran into an unparseable point. |
731 // Ran into an unparseable point. |
723 return cur; |
732 return cur; |
724 }; |
733 }; |
|
734 |
725 // Otherwise: |
735 // Otherwise: |
726 next = (cur + obj->size()); |
736 next = (cur + obj->size()); |
|
737 |
727 if (!g1h->is_obj_dead(obj)) { |
738 if (!g1h->is_obj_dead(obj)) { |
728 if (next < mr.end()) { |
739 if (next < end || !obj->is_objArray()) { |
|
740 // This object either does not span the MemRegion |
|
741 // boundary, or if it does it's not an array. |
|
742 // Apply closure to whole object. |
729 obj->oop_iterate(cl); |
743 obj->oop_iterate(cl); |
730 } else { |
744 } else { |
731 // this obj spans the boundary. If it's an array, stop at the |
745 // This obj is an array that spans the boundary. |
732 // boundary. |
746 // Stop at the boundary. |
733 if (obj->is_objArray()) { |
747 obj->oop_iterate(cl, mr); |
734 obj->oop_iterate(cl, mr); |
|
735 } else { |
|
736 obj->oop_iterate(cl); |
|
737 } |
|
738 } |
748 } |
739 } |
749 } |
740 cur = next; |
750 cur = next; |
741 } |
751 } |
742 return NULL; |
752 return NULL; |