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