aoqi@0: /* aoqi@0: * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_INLINE_HPP aoqi@0: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_INLINE_HPP aoqi@0: aoqi@0: #include "gc_implementation/g1/concurrentMark.inline.hpp" aoqi@0: #include "gc_implementation/g1/g1CollectedHeap.hpp" aoqi@0: #include "gc_implementation/g1/g1OopClosures.hpp" tschatzl@6937: #include "gc_implementation/g1/g1ParScanThreadState.inline.hpp" aoqi@0: #include "gc_implementation/g1/g1RemSet.hpp" aoqi@0: #include "gc_implementation/g1/g1RemSet.inline.hpp" aoqi@0: #include "gc_implementation/g1/heapRegionRemSet.hpp" stefank@6992: #include "memory/iterator.inline.hpp" goetz@6912: #include "runtime/prefetch.inline.hpp" aoqi@0: aoqi@0: /* aoqi@0: * This really ought to be an inline function, but apparently the C++ aoqi@0: * compiler sometimes sees fit to ignore inline declarations. Sigh. aoqi@0: */ aoqi@0: aoqi@0: template aoqi@0: inline void FilterIntoCSClosure::do_oop_nv(T* p) { aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: if (!oopDesc::is_null(heap_oop) && tschatzl@7010: _g1->is_in_cset_or_humongous(oopDesc::decode_heap_oop_not_null(heap_oop))) { aoqi@0: _oc->do_oop(p); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void FilterOutOfRegionClosure::do_oop_nv(T* p) { aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: if (!oopDesc::is_null(heap_oop)) { aoqi@0: HeapWord* obj_hw = (HeapWord*)oopDesc::decode_heap_oop_not_null(heap_oop); aoqi@0: if (obj_hw < _r_bottom || obj_hw >= _r_end) { aoqi@0: _oc->do_oop(p); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // This closure is applied to the fields of the objects that have just been copied. aoqi@0: template aoqi@0: inline void G1ParScanClosure::do_oop_nv(T* p) { aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: aoqi@0: if (!oopDesc::is_null(heap_oop)) { aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); tschatzl@7010: G1CollectedHeap::in_cset_state_t state = _g1->in_cset_state(obj); tschatzl@7010: if (state == G1CollectedHeap::InCSet) { aoqi@0: // We're not going to even bother checking whether the object is aoqi@0: // already forwarded or not, as this usually causes an immediate aoqi@0: // stall. We'll try to prefetch the object (for write, given that aoqi@0: // we might need to install the forwarding reference) and we'll aoqi@0: // get back to it when pop it from the queue aoqi@0: Prefetch::write(obj->mark_addr(), 0); aoqi@0: Prefetch::read(obj->mark_addr(), (HeapWordSize*2)); aoqi@0: aoqi@0: // slightly paranoid test; I'm trying to catch potential aoqi@0: // problems before we go into push_on_queue to know where the aoqi@0: // problem is coming from aoqi@0: assert((obj == oopDesc::load_decode_heap_oop(p)) || aoqi@0: (obj->is_forwarded() && aoqi@0: obj->forwardee() == oopDesc::load_decode_heap_oop(p)), aoqi@0: "p should still be pointing to obj or to its forwardee"); aoqi@0: aoqi@0: _par_scan_state->push_on_queue(p); aoqi@0: } else { tschatzl@7010: if (state == G1CollectedHeap::IsHumongous) { tschatzl@7010: _g1->set_humongous_is_live(obj); tschatzl@7010: } aoqi@0: _par_scan_state->update_rs(_from, p, _worker_id); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void G1ParPushHeapRSClosure::do_oop_nv(T* p) { aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: aoqi@0: if (!oopDesc::is_null(heap_oop)) { aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); tschatzl@7010: if (_g1->is_in_cset_or_humongous(obj)) { aoqi@0: Prefetch::write(obj->mark_addr(), 0); aoqi@0: Prefetch::read(obj->mark_addr(), (HeapWordSize*2)); aoqi@0: aoqi@0: // Place on the references queue aoqi@0: _par_scan_state->push_on_queue(p); tschatzl@7010: } else { tschatzl@7010: assert(!_g1->obj_in_cs(obj), "checking"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void G1CMOopClosure::do_oop_nv(T* p) { aoqi@0: oop obj = oopDesc::load_decode_heap_oop(p); aoqi@0: if (_cm->verbose_high()) { aoqi@0: gclog_or_tty->print_cr("[%u] we're looking at location " aoqi@0: "*"PTR_FORMAT" = "PTR_FORMAT, aoqi@0: _task->worker_id(), p2i(p), p2i((void*) obj)); aoqi@0: } aoqi@0: _task->deal_with_reference(obj); aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void G1RootRegionScanClosure::do_oop_nv(T* p) { aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: if (!oopDesc::is_null(heap_oop)) { aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); aoqi@0: HeapRegion* hr = _g1h->heap_region_containing((HeapWord*) obj); brutisso@7049: _cm->grayRoot(obj, obj->size(), _worker_id, hr); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void G1Mux2Closure::do_oop_nv(T* p) { aoqi@0: // Apply first closure; then apply the second. aoqi@0: _c1->do_oop(p); aoqi@0: _c2->do_oop(p); aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void G1TriggerClosure::do_oop_nv(T* p) { aoqi@0: // Record that this closure was actually applied (triggered). aoqi@0: _triggered = true; aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void G1InvokeIfNotTriggeredClosure::do_oop_nv(T* p) { aoqi@0: if (!_trigger_cl->triggered()) { aoqi@0: _oop_cl->do_oop(p); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void G1UpdateRSOrPushRefOopClosure::do_oop_nv(T* p) { aoqi@0: oop obj = oopDesc::load_decode_heap_oop(p); brutisso@7049: if (obj == NULL) { brutisso@7049: return; brutisso@7049: } aoqi@0: #ifdef ASSERT aoqi@0: // can't do because of races aoqi@0: // assert(obj == NULL || obj->is_oop(), "expected an oop"); aoqi@0: aoqi@0: // Do the safe subset of is_oop aoqi@0: #ifdef CHECK_UNHANDLED_OOPS brutisso@7049: oopDesc* o = obj.obj(); aoqi@0: #else brutisso@7049: oopDesc* o = obj; aoqi@0: #endif // CHECK_UNHANDLED_OOPS brutisso@7049: assert((intptr_t)o % MinObjAlignmentInBytes == 0, "not oop aligned"); brutisso@7049: assert(Universe::heap()->is_in_reserved(obj), "must be in heap"); aoqi@0: #endif // ASSERT aoqi@0: aoqi@0: assert(_from != NULL, "from region must be non-NULL"); aoqi@0: assert(_from->is_in_reserved(p), "p is not in from"); aoqi@0: aoqi@0: HeapRegion* to = _g1->heap_region_containing(obj); brutisso@7049: if (_from == to) { brutisso@7049: // Normally this closure should only be called with cross-region references. brutisso@7049: // But since Java threads are manipulating the references concurrently and we brutisso@7049: // reload the values things may have changed. brutisso@7049: return; brutisso@7049: } brutisso@7049: // The _record_refs_into_cset flag is true during the RSet brutisso@7049: // updating part of an evacuation pause. It is false at all brutisso@7049: // other times: brutisso@7049: // * rebuilding the remembered sets after a full GC brutisso@7049: // * during concurrent refinement. brutisso@7049: // * updating the remembered sets of regions in the collection brutisso@7049: // set in the event of an evacuation failure (when deferred brutisso@7049: // updates are enabled). aoqi@0: brutisso@7049: if (_record_refs_into_cset && to->in_collection_set()) { brutisso@7049: // We are recording references that point into the collection brutisso@7049: // set and this particular reference does exactly that... brutisso@7049: // If the referenced object has already been forwarded brutisso@7049: // to itself, we are handling an evacuation failure and brutisso@7049: // we have already visited/tried to copy this object brutisso@7049: // there is no need to retry. brutisso@7049: if (!self_forwarded(obj)) { brutisso@7049: assert(_push_ref_cl != NULL, "should not be null"); brutisso@7049: // Push the reference in the refs queue of the G1ParScanThreadState brutisso@7049: // instance for this worker thread. brutisso@7049: _push_ref_cl->do_oop(p); brutisso@7049: } aoqi@0: brutisso@7049: // Deferred updates to the CSet are either discarded (in the normal case), brutisso@7049: // or processed (if an evacuation failure occurs) at the end brutisso@7049: // of the collection. brutisso@7049: // See G1RemSet::cleanup_after_oops_into_collection_set_do(). brutisso@7049: } else { aoqi@0: // We either don't care about pushing references that point into the aoqi@0: // collection set (i.e. we're not during an evacuation pause) _or_ aoqi@0: // the reference doesn't point into the collection set. Either way aoqi@0: // we add the reference directly to the RSet of the region containing aoqi@0: // the referenced object. aoqi@0: assert(to->rem_set() != NULL, "Need per-region 'into' remsets."); aoqi@0: to->rem_set()->add_reference(p, _worker_i); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_INLINE_HPP