concurrentMark.inline.hpp revision 3067
2596N/A/*
3067N/A * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2596N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2596N/A *
2596N/A * This code is free software; you can redistribute it and/or modify it
2596N/A * under the terms of the GNU General Public License version 2 only, as
2596N/A * published by the Free Software Foundation.
2596N/A *
2596N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2596N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2596N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2596N/A * version 2 for more details (a copy is included in the LICENSE file that
2596N/A * accompanied this code).
2596N/A *
2596N/A * You should have received a copy of the GNU General Public License version
2596N/A * 2 along with this work; if not, write to the Free Software Foundation,
2596N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2596N/A *
2596N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2596N/A * or visit www.oracle.com if you need additional information or have any
2596N/A * questions.
2596N/A *
2596N/A */
2596N/A
2596N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_INLINE_HPP
2596N/A#define SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_INLINE_HPP
2596N/A
2596N/A#include "gc_implementation/g1/concurrentMark.hpp"
2596N/A#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
2596N/A
2596N/Ainline void CMTask::push(oop obj) {
2596N/A HeapWord* objAddr = (HeapWord*) obj;
2596N/A assert(_g1h->is_in_g1_reserved(objAddr), "invariant");
2596N/A assert(!_g1h->is_on_master_free_list(
2596N/A _g1h->heap_region_containing((HeapWord*) objAddr)), "invariant");
2596N/A assert(!_g1h->is_obj_ill(obj), "invariant");
2596N/A assert(_nextMarkBitMap->isMarked(objAddr), "invariant");
2596N/A
2596N/A if (_cm->verbose_high()) {
2596N/A gclog_or_tty->print_cr("[%d] pushing "PTR_FORMAT, _task_id, (void*) obj);
2596N/A }
2596N/A
2596N/A if (!_task_queue->push(obj)) {
2596N/A // The local task queue looks full. We need to push some entries
2596N/A // to the global stack.
2596N/A
2596N/A if (_cm->verbose_medium()) {
2596N/A gclog_or_tty->print_cr("[%d] task queue overflow, "
2596N/A "moving entries to the global stack",
2596N/A _task_id);
2596N/A }
2596N/A move_entries_to_global_stack();
2596N/A
2596N/A // this should succeed since, even if we overflow the global
2596N/A // stack, we should have definitely removed some entries from the
2596N/A // local queue. So, there must be space on it.
2596N/A bool success = _task_queue->push(obj);
2596N/A assert(success, "invariant");
2596N/A }
2596N/A
2596N/A statsOnly( int tmp_size = _task_queue->size();
2601N/A if (tmp_size > _local_max_size) {
2596N/A _local_max_size = tmp_size;
2601N/A }
2596N/A ++_local_pushes );
2596N/A}
2596N/A
2596N/A// This determines whether the method below will check both the local
2596N/A// and global fingers when determining whether to push on the stack a
2596N/A// gray object (value 1) or whether it will only check the global one
2596N/A// (value 0). The tradeoffs are that the former will be a bit more
2596N/A// accurate and possibly push less on the stack, but it might also be
2596N/A// a little bit slower.
2596N/A
2596N/A#define _CHECK_BOTH_FINGERS_ 1
2596N/A
2596N/Ainline void CMTask::deal_with_reference(oop obj) {
2596N/A if (_cm->verbose_high()) {
2596N/A gclog_or_tty->print_cr("[%d] we're dealing with reference = "PTR_FORMAT,
2596N/A _task_id, (void*) obj);
2596N/A }
2596N/A
2596N/A ++_refs_reached;
2596N/A
2596N/A HeapWord* objAddr = (HeapWord*) obj;
2596N/A assert(obj->is_oop_or_null(true /* ignore mark word */), "Error");
2596N/A if (_g1h->is_in_g1_reserved(objAddr)) {
2596N/A assert(obj != NULL, "null check is implicit");
2596N/A if (!_nextMarkBitMap->isMarked(objAddr)) {
2596N/A // Only get the containing region if the object is not marked on the
2596N/A // bitmap (otherwise, it's a waste of time since we won't do
2596N/A // anything with it).
2596N/A HeapRegion* hr = _g1h->heap_region_containing_raw(obj);
2596N/A if (!hr->obj_allocated_since_next_marking(obj)) {
2596N/A if (_cm->verbose_high()) {
2596N/A gclog_or_tty->print_cr("[%d] "PTR_FORMAT" is not considered marked",
2596N/A _task_id, (void*) obj);
2596N/A }
2596N/A
2596N/A // we need to mark it first
2596N/A if (_nextMarkBitMap->parMark(objAddr)) {
2596N/A // No OrderAccess:store_load() is needed. It is implicit in the
2596N/A // CAS done in parMark(objAddr) above
2596N/A HeapWord* global_finger = _cm->finger();
2596N/A
2596N/A#if _CHECK_BOTH_FINGERS_
2596N/A // we will check both the local and global fingers
2596N/A
2596N/A if (_finger != NULL && objAddr < _finger) {
2596N/A if (_cm->verbose_high()) {
2596N/A gclog_or_tty->print_cr("[%d] below the local finger ("PTR_FORMAT"), "
2596N/A "pushing it", _task_id, _finger);
2596N/A }
2596N/A push(obj);
2596N/A } else if (_curr_region != NULL && objAddr < _region_limit) {
2596N/A // do nothing
2596N/A } else if (objAddr < global_finger) {
2596N/A // Notice that the global finger might be moving forward
2596N/A // concurrently. This is not a problem. In the worst case, we
2596N/A // mark the object while it is above the global finger and, by
2596N/A // the time we read the global finger, it has moved forward
2596N/A // passed this object. In this case, the object will probably
2596N/A // be visited when a task is scanning the region and will also
2596N/A // be pushed on the stack. So, some duplicate work, but no
2596N/A // correctness problems.
2596N/A
2596N/A if (_cm->verbose_high()) {
2596N/A gclog_or_tty->print_cr("[%d] below the global finger "
2596N/A "("PTR_FORMAT"), pushing it",
2596N/A _task_id, global_finger);
2596N/A }
2596N/A push(obj);
2596N/A } else {
2596N/A // do nothing
2596N/A }
2596N/A#else // _CHECK_BOTH_FINGERS_
2596N/A // we will only check the global finger
2596N/A
2596N/A if (objAddr < global_finger) {
2596N/A // see long comment above
2596N/A
2596N/A if (_cm->verbose_high()) {
2596N/A gclog_or_tty->print_cr("[%d] below the global finger "
2596N/A "("PTR_FORMAT"), pushing it",
2596N/A _task_id, global_finger);
2596N/A }
2596N/A push(obj);
2596N/A }
2596N/A#endif // _CHECK_BOTH_FINGERS_
2596N/A }
2596N/A }
2596N/A }
2596N/A }
2596N/A}
2596N/A
3067N/Ainline void ConcurrentMark::markPrev(oop p) {
3067N/A assert(!_prevMarkBitMap->isMarked((HeapWord*) p), "sanity");
3067N/A // Note we are overriding the read-only view of the prev map here, via
3067N/A // the cast.
3067N/A ((CMBitMap*)_prevMarkBitMap)->mark((HeapWord*) p);
3067N/A}
3067N/A
3067N/Ainline void ConcurrentMark::markNext(oop p) {
3067N/A assert(!_nextMarkBitMap->isMarked((HeapWord*) p), "sanity");
3067N/A _nextMarkBitMap->mark((HeapWord*) p);
3067N/A}
3067N/A
3067N/Ainline void ConcurrentMark::grayRoot(oop obj, size_t word_size) {
3067N/A HeapWord* addr = (HeapWord*) obj;
3067N/A
3067N/A // Currently we don't do anything with word_size but we will use it
3067N/A // in the very near future in the liveness calculation piggy-backing
3067N/A // changes.
3067N/A
3067N/A#ifdef ASSERT
3067N/A HeapRegion* hr = _g1h->heap_region_containing(addr);
3067N/A assert(hr != NULL, "sanity");
3067N/A assert(!hr->is_survivor(), "should not allocate survivors during IM");
3067N/A assert(addr < hr->next_top_at_mark_start(),
3067N/A err_msg("addr: "PTR_FORMAT" hr: "HR_FORMAT" NTAMS: "PTR_FORMAT,
3067N/A addr, HR_FORMAT_PARAMS(hr), hr->next_top_at_mark_start()));
3067N/A // We cannot assert that word_size == obj->size() given that obj
3067N/A // might not be in a consistent state (another thread might be in
3067N/A // the process of copying it). So the best thing we can do is to
3067N/A // assert that word_size is under an upper bound which is its
3067N/A // containing region's capacity.
3067N/A assert(word_size * HeapWordSize <= hr->capacity(),
3067N/A err_msg("size: "SIZE_FORMAT" capacity: "SIZE_FORMAT" "HR_FORMAT,
3067N/A word_size * HeapWordSize, hr->capacity(),
3067N/A HR_FORMAT_PARAMS(hr)));
3067N/A#endif // ASSERT
3067N/A
3067N/A if (!_nextMarkBitMap->isMarked(addr)) {
3067N/A _nextMarkBitMap->parMark(addr);
3067N/A }
3067N/A}
3067N/A
2596N/A#endif // SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_INLINE_HPP