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