hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
changeset 1384 163a4d4fa951
parent 1374 4c24294029a9
child 1385 1751733b089b
equal deleted inserted replaced
1383:3a216aa862b7 1384:163a4d4fa951
  2748 class RemoveSelfPointerClosure: public ObjectClosure {
  2748 class RemoveSelfPointerClosure: public ObjectClosure {
  2749 private:
  2749 private:
  2750   G1CollectedHeap* _g1;
  2750   G1CollectedHeap* _g1;
  2751   ConcurrentMark* _cm;
  2751   ConcurrentMark* _cm;
  2752   HeapRegion* _hr;
  2752   HeapRegion* _hr;
  2753   HeapWord* _last_self_forwarded_end;
       
  2754   size_t _prev_marked_bytes;
  2753   size_t _prev_marked_bytes;
  2755   size_t _next_marked_bytes;
  2754   size_t _next_marked_bytes;
  2756 public:
  2755 public:
  2757   RemoveSelfPointerClosure(G1CollectedHeap* g1, HeapRegion* hr) :
  2756   RemoveSelfPointerClosure(G1CollectedHeap* g1, HeapRegion* hr) :
  2758     _g1(g1), _cm(_g1->concurrent_mark()), _hr(hr),
  2757     _g1(g1), _cm(_g1->concurrent_mark()), _hr(hr),
  2759     _last_self_forwarded_end(_hr->bottom()),
       
  2760     _prev_marked_bytes(0), _next_marked_bytes(0)
  2758     _prev_marked_bytes(0), _next_marked_bytes(0)
  2761   {}
  2759   {}
  2762 
  2760 
  2763   size_t prev_marked_bytes() { return _prev_marked_bytes; }
  2761   size_t prev_marked_bytes() { return _prev_marked_bytes; }
  2764   size_t next_marked_bytes() { return _next_marked_bytes; }
  2762   size_t next_marked_bytes() { return _next_marked_bytes; }
  2765 
  2763 
  2766   void fill_remainder() {
  2764   // The original idea here was to coalesce evacuated and dead objects.
  2767     HeapWord* limit = _hr->top();
  2765   // However that caused complications with the block offset table (BOT).
  2768     MemRegion mr(_last_self_forwarded_end, limit);
  2766   // In particular if there were two TLABs, one of them partially refined.
  2769     if (!mr.is_empty()) {
  2767   // |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~|
       
  2768   // The BOT entries of the unrefined part of TLAB_2 point to the start
       
  2769   // of TLAB_2. If the last object of the TLAB_1 and the first object
       
  2770   // of TLAB_2 are coalesced, then the cards of the unrefined part
       
  2771   // would point into middle of the filler object.
       
  2772   //
       
  2773   // The current approach is to not coalesce and leave the BOT contents intact.
       
  2774   void do_object(oop obj) {
       
  2775     if (obj->is_forwarded() && obj->forwardee() == obj) {
       
  2776       // The object failed to move.
       
  2777       assert(!_g1->is_obj_dead(obj), "We should not be preserving dead objs.");
       
  2778       _cm->markPrev(obj);
       
  2779       assert(_cm->isPrevMarked(obj), "Should be marked!");
       
  2780       _prev_marked_bytes += (obj->size() * HeapWordSize);
       
  2781       if (_g1->mark_in_progress() && !_g1->is_obj_ill(obj)) {
       
  2782         _cm->markAndGrayObjectIfNecessary(obj);
       
  2783       }
       
  2784       obj->set_mark(markOopDesc::prototype());
       
  2785       // While we were processing RSet buffers during the
       
  2786       // collection, we actually didn't scan any cards on the
       
  2787       // collection set, since we didn't want to update remebered
       
  2788       // sets with entries that point into the collection set, given
       
  2789       // that live objects fromthe collection set are about to move
       
  2790       // and such entries will be stale very soon. This change also
       
  2791       // dealt with a reliability issue which involved scanning a
       
  2792       // card in the collection set and coming across an array that
       
  2793       // was being chunked and looking malformed. The problem is
       
  2794       // that, if evacuation fails, we might have remembered set
       
  2795       // entries missing given that we skipped cards on the
       
  2796       // collection set. So, we'll recreate such entries now.
       
  2797       RecreateRSetEntriesClosure cl(_g1, _hr);
       
  2798       obj->oop_iterate(&cl);
       
  2799       assert(_cm->isPrevMarked(obj), "Should be marked!");
       
  2800     } else {
       
  2801       // The object has been either evacuated or is dead. Fill it with a
       
  2802       // dummy object.
       
  2803       MemRegion mr((HeapWord*)obj, obj->size());
  2770       SharedHeap::fill_region_with_object(mr);
  2804       SharedHeap::fill_region_with_object(mr);
  2771       _cm->clearRangeBothMaps(mr);
  2805       _cm->clearRangeBothMaps(mr);
  2772       _hr->declare_filled_region_to_BOT(mr);
       
  2773     }
       
  2774   }
       
  2775 
       
  2776   void do_object(oop obj) {
       
  2777     if (obj->is_forwarded()) {
       
  2778       if (obj->forwardee() == obj) {
       
  2779         assert(!_g1->is_obj_dead(obj), "We should not be preserving dead objs.");
       
  2780         _cm->markPrev(obj);
       
  2781         assert(_cm->isPrevMarked(obj), "Should be marked!");
       
  2782         _prev_marked_bytes += (obj->size() * HeapWordSize);
       
  2783         if (_g1->mark_in_progress() && !_g1->is_obj_ill(obj)) {
       
  2784           _cm->markAndGrayObjectIfNecessary(obj);
       
  2785         }
       
  2786         HeapWord* obj_start = (HeapWord*)obj;
       
  2787         if (obj_start > _last_self_forwarded_end) {
       
  2788           MemRegion mr(_last_self_forwarded_end, obj_start);
       
  2789           SharedHeap::fill_region_with_object(mr);
       
  2790           assert(_cm->isPrevMarked(obj), "Should be marked!");
       
  2791           _cm->clearRangeBothMaps(mr);
       
  2792           assert(_cm->isPrevMarked(obj), "Should be marked!");
       
  2793           _hr->declare_filled_region_to_BOT(mr);
       
  2794         }
       
  2795         _last_self_forwarded_end = obj_start + obj->size();
       
  2796         obj->set_mark(markOopDesc::prototype());
       
  2797 
       
  2798         // While we were processing RSet buffers during the
       
  2799         // collection, we actually didn't scan any cards on the
       
  2800         // collection set, since we didn't want to update remebered
       
  2801         // sets with entries that point into the collection set, given
       
  2802         // that live objects fromthe collection set are about to move
       
  2803         // and such entries will be stale very soon. This change also
       
  2804         // dealt with a reliability issue which involved scanning a
       
  2805         // card in the collection set and coming across an array that
       
  2806         // was being chunked and looking malformed. The problem is
       
  2807         // that, if evacuation fails, we might have remembered set
       
  2808         // entries missing given that we skipped cards on the
       
  2809         // collection set. So, we'll recreate such entries now.
       
  2810         RecreateRSetEntriesClosure cl(_g1, _hr);
       
  2811         obj->oop_iterate(&cl);
       
  2812 
       
  2813         assert(_cm->isPrevMarked(obj), "Should be marked!");
       
  2814       }
       
  2815     }
  2806     }
  2816   }
  2807   }
  2817 };
  2808 };
  2818 
  2809 
  2819 void G1CollectedHeap::remove_self_forwarding_pointers() {
  2810 void G1CollectedHeap::remove_self_forwarding_pointers() {
  2824 
  2815 
  2825     if (cur->evacuation_failed()) {
  2816     if (cur->evacuation_failed()) {
  2826       RemoveSelfPointerClosure rspc(_g1h, cur);
  2817       RemoveSelfPointerClosure rspc(_g1h, cur);
  2827       assert(cur->in_collection_set(), "bad CS");
  2818       assert(cur->in_collection_set(), "bad CS");
  2828       cur->object_iterate(&rspc);
  2819       cur->object_iterate(&rspc);
  2829       rspc.fill_remainder();
       
  2830 
  2820 
  2831       // A number of manipulations to make the TAMS be the current top,
  2821       // A number of manipulations to make the TAMS be the current top,
  2832       // and the marked bytes be the ones observed in the iteration.
  2822       // and the marked bytes be the ones observed in the iteration.
  2833       if (_g1h->concurrent_mark()->at_least_one_mark_complete()) {
  2823       if (_g1h->concurrent_mark()->at_least_one_mark_complete()) {
  2834         // The comments below are the postconditions achieved by the
  2824         // The comments below are the postconditions achieved by the