src/share/vm/gc_implementation/g1/g1EvacFailure.hpp

Mon, 07 Jul 2014 10:12:40 +0200

author
stefank
date
Mon, 07 Jul 2014 10:12:40 +0200
changeset 6992
2c6ef90f030a
parent 6198
55fb97c4c58d
child 7005
e0954897238a
permissions
-rw-r--r--

8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com

     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP
    26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP
    28 #include "gc_implementation/g1/concurrentMark.inline.hpp"
    29 #include "gc_implementation/g1/dirtyCardQueue.hpp"
    30 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
    31 #include "gc_implementation/g1/g1_globals.hpp"
    32 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
    33 #include "gc_implementation/g1/heapRegion.hpp"
    34 #include "gc_implementation/g1/heapRegionRemSet.hpp"
    35 #include "utilities/workgroup.hpp"
    37 // Closures and tasks associated with any self-forwarding pointers
    38 // installed as a result of an evacuation failure.
    40 class UpdateRSetDeferred : public OopsInHeapRegionClosure {
    41 private:
    42   G1CollectedHeap* _g1;
    43   DirtyCardQueue *_dcq;
    44   G1SATBCardTableModRefBS* _ct_bs;
    46 public:
    47   UpdateRSetDeferred(G1CollectedHeap* g1, DirtyCardQueue* dcq) :
    48     _g1(g1), _ct_bs(_g1->g1_barrier_set()), _dcq(dcq) {}
    50   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
    51   virtual void do_oop(      oop* p) { do_oop_work(p); }
    52   template <class T> void do_oop_work(T* p) {
    53     assert(_from->is_in_reserved(p), "paranoia");
    54     if (!_from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) &&
    55         !_from->is_survivor()) {
    56       size_t card_index = _ct_bs->index_for(p);
    57       if (_ct_bs->mark_card_deferred(card_index)) {
    58         _dcq->enqueue((jbyte*)_ct_bs->byte_for_index(card_index));
    59       }
    60     }
    61   }
    62 };
    64 class RemoveSelfForwardPtrObjClosure: public ObjectClosure {
    65 private:
    66   G1CollectedHeap* _g1;
    67   ConcurrentMark* _cm;
    68   HeapRegion* _hr;
    69   size_t _marked_bytes;
    70   OopsInHeapRegionClosure *_update_rset_cl;
    71   bool _during_initial_mark;
    72   bool _during_conc_mark;
    73   uint _worker_id;
    74   HeapWord* _end_of_last_gap;
    75   HeapWord* _last_gap_threshold;
    76   HeapWord* _last_obj_threshold;
    78 public:
    79   RemoveSelfForwardPtrObjClosure(G1CollectedHeap* g1, ConcurrentMark* cm,
    80                                  HeapRegion* hr,
    81                                  OopsInHeapRegionClosure* update_rset_cl,
    82                                  bool during_initial_mark,
    83                                  bool during_conc_mark,
    84                                  uint worker_id) :
    85     _g1(g1), _cm(cm), _hr(hr), _marked_bytes(0),
    86     _update_rset_cl(update_rset_cl),
    87     _during_initial_mark(during_initial_mark),
    88     _during_conc_mark(during_conc_mark),
    89     _worker_id(worker_id),
    90     _end_of_last_gap(hr->bottom()),
    91     _last_gap_threshold(hr->bottom()),
    92     _last_obj_threshold(hr->bottom()) { }
    94   size_t marked_bytes() { return _marked_bytes; }
    96   // <original comment>
    97   // The original idea here was to coalesce evacuated and dead objects.
    98   // However that caused complications with the block offset table (BOT).
    99   // In particular if there were two TLABs, one of them partially refined.
   100   // |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~|
   101   // The BOT entries of the unrefined part of TLAB_2 point to the start
   102   // of TLAB_2. If the last object of the TLAB_1 and the first object
   103   // of TLAB_2 are coalesced, then the cards of the unrefined part
   104   // would point into middle of the filler object.
   105   // The current approach is to not coalesce and leave the BOT contents intact.
   106   // </original comment>
   107   //
   108   // We now reset the BOT when we start the object iteration over the
   109   // region and refine its entries for every object we come across. So
   110   // the above comment is not really relevant and we should be able
   111   // to coalesce dead objects if we want to.
   112   void do_object(oop obj) {
   113     HeapWord* obj_addr = (HeapWord*) obj;
   114     assert(_hr->is_in(obj_addr), "sanity");
   115     size_t obj_size = obj->size();
   116     HeapWord* obj_end = obj_addr + obj_size;
   118     if (_end_of_last_gap != obj_addr) {
   119       // there was a gap before obj_addr
   120       _last_gap_threshold = _hr->cross_threshold(_end_of_last_gap, obj_addr);
   121     }
   123     if (obj->is_forwarded() && obj->forwardee() == obj) {
   124       // The object failed to move.
   126       // We consider all objects that we find self-forwarded to be
   127       // live. What we'll do is that we'll update the prev marking
   128       // info so that they are all under PTAMS and explicitly marked.
   129       if (!_cm->isPrevMarked(obj)) {
   130         _cm->markPrev(obj);
   131       }
   132       if (_during_initial_mark) {
   133         // For the next marking info we'll only mark the
   134         // self-forwarded objects explicitly if we are during
   135         // initial-mark (since, normally, we only mark objects pointed
   136         // to by roots if we succeed in copying them). By marking all
   137         // self-forwarded objects we ensure that we mark any that are
   138         // still pointed to be roots. During concurrent marking, and
   139         // after initial-mark, we don't need to mark any objects
   140         // explicitly and all objects in the CSet are considered
   141         // (implicitly) live. So, we won't mark them explicitly and
   142         // we'll leave them over NTAMS.
   143         _cm->grayRoot(obj, obj_size, _worker_id, _hr);
   144       }
   145       _marked_bytes += (obj_size * HeapWordSize);
   146       obj->set_mark(markOopDesc::prototype());
   148       // While we were processing RSet buffers during the collection,
   149       // we actually didn't scan any cards on the collection set,
   150       // since we didn't want to update remembered sets with entries
   151       // that point into the collection set, given that live objects
   152       // from the collection set are about to move and such entries
   153       // will be stale very soon.
   154       // This change also dealt with a reliability issue which
   155       // involved scanning a card in the collection set and coming
   156       // across an array that was being chunked and looking malformed.
   157       // The problem is that, if evacuation fails, we might have
   158       // remembered set entries missing given that we skipped cards on
   159       // the collection set. So, we'll recreate such entries now.
   160       obj->oop_iterate(_update_rset_cl);
   161     } else {
   163       // The object has been either evacuated or is dead. Fill it with a
   164       // dummy object.
   165       MemRegion mr(obj_addr, obj_size);
   166       CollectedHeap::fill_with_object(mr);
   168       // must nuke all dead objects which we skipped when iterating over the region
   169       _cm->clearRangePrevBitmap(MemRegion(_end_of_last_gap, obj_end));
   170     }
   171     _end_of_last_gap = obj_end;
   172     _last_obj_threshold = _hr->cross_threshold(obj_addr, obj_end);
   173   }
   174 };
   176 class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure {
   177   G1CollectedHeap* _g1h;
   178   ConcurrentMark* _cm;
   179   OopsInHeapRegionClosure *_update_rset_cl;
   180   uint _worker_id;
   182 public:
   183   RemoveSelfForwardPtrHRClosure(G1CollectedHeap* g1h,
   184                                 OopsInHeapRegionClosure* update_rset_cl,
   185                                 uint worker_id) :
   186     _g1h(g1h), _update_rset_cl(update_rset_cl),
   187     _worker_id(worker_id), _cm(_g1h->concurrent_mark()) { }
   189   bool doHeapRegion(HeapRegion *hr) {
   190     bool during_initial_mark = _g1h->g1_policy()->during_initial_mark_pause();
   191     bool during_conc_mark = _g1h->mark_in_progress();
   193     assert(!hr->isHumongous(), "sanity");
   194     assert(hr->in_collection_set(), "bad CS");
   196     if (hr->claimHeapRegion(HeapRegion::ParEvacFailureClaimValue)) {
   197       if (hr->evacuation_failed()) {
   198         RemoveSelfForwardPtrObjClosure rspc(_g1h, _cm, hr, _update_rset_cl,
   199                                             during_initial_mark,
   200                                             during_conc_mark,
   201                                             _worker_id);
   203         hr->note_self_forwarding_removal_start(during_initial_mark,
   204                                                during_conc_mark);
   206         // In the common case (i.e. when there is no evacuation
   207         // failure) we make sure that the following is done when
   208         // the region is freed so that it is "ready-to-go" when it's
   209         // re-allocated. However, when evacuation failure happens, a
   210         // region will remain in the heap and might ultimately be added
   211         // to a CSet in the future. So we have to be careful here and
   212         // make sure the region's RSet is ready for parallel iteration
   213         // whenever this might be required in the future.
   214         hr->rem_set()->reset_for_par_iteration();
   215         hr->reset_bot();
   216         _update_rset_cl->set_region(hr);
   217         hr->object_iterate(&rspc);
   219         hr->note_self_forwarding_removal_end(during_initial_mark,
   220                                              during_conc_mark,
   221                                              rspc.marked_bytes());
   222       }
   223     }
   224     return false;
   225   }
   226 };
   228 class G1ParRemoveSelfForwardPtrsTask: public AbstractGangTask {
   229 protected:
   230   G1CollectedHeap* _g1h;
   232 public:
   233   G1ParRemoveSelfForwardPtrsTask(G1CollectedHeap* g1h) :
   234     AbstractGangTask("G1 Remove Self-forwarding Pointers"),
   235     _g1h(g1h) { }
   237   void work(uint worker_id) {
   238     UpdateRSetImmediate immediate_update(_g1h->g1_rem_set());
   239     DirtyCardQueue dcq(&_g1h->dirty_card_queue_set());
   240     UpdateRSetDeferred deferred_update(_g1h, &dcq);
   242     OopsInHeapRegionClosure *update_rset_cl = &deferred_update;
   243     if (!G1DeferredRSUpdate) {
   244       update_rset_cl = &immediate_update;
   245     }
   247     RemoveSelfForwardPtrHRClosure rsfp_cl(_g1h, update_rset_cl, worker_id);
   249     HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id);
   250     _g1h->collection_set_iterate_from(hr, &rsfp_cl);
   251   }
   252 };
   254 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP

mercurial