ysr@777: /* mikael@6198: * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. ysr@777: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ysr@777: * ysr@777: * This code is free software; you can redistribute it and/or modify it ysr@777: * under the terms of the GNU General Public License version 2 only, as ysr@777: * published by the Free Software Foundation. ysr@777: * ysr@777: * This code is distributed in the hope that it will be useful, but WITHOUT ysr@777: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ysr@777: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ysr@777: * version 2 for more details (a copy is included in the LICENSE file that ysr@777: * accompanied this code). ysr@777: * ysr@777: * You should have received a copy of the GNU General Public License version ysr@777: * 2 along with this work; if not, write to the Free Software Foundation, ysr@777: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ysr@777: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. ysr@777: * ysr@777: */ ysr@777: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP stefank@2314: stefank@2314: #include "gc_implementation/g1/concurrentMark.hpp" stefank@2314: #include "gc_implementation/g1/g1CollectedHeap.hpp" tonyp@2715: #include "gc_implementation/g1/g1AllocRegion.inline.hpp" tonyp@2315: #include "gc_implementation/g1/g1CollectorPolicy.hpp" tschatzl@6541: #include "gc_implementation/g1/g1RemSet.inline.hpp" mgerdin@5860: #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" brutisso@6385: #include "gc_implementation/g1/heapRegionSet.inline.hpp" tonyp@2469: #include "gc_implementation/g1/heapRegionSeq.inline.hpp" stefank@2314: #include "utilities/taskqueue.hpp" stefank@2314: ysr@777: // Inline functions for G1CollectedHeap ysr@777: tschatzl@6541: // Return the region with the given index. It assumes the index is valid. tschatzl@6541: inline HeapRegion* G1CollectedHeap::region_at(uint index) const { return _hrs.at(index); } tschatzl@6541: tonyp@2963: template ysr@777: inline HeapRegion* tonyp@2963: G1CollectedHeap::heap_region_containing(const T addr) const { tonyp@2963: HeapRegion* hr = _hrs.addr_to_region((HeapWord*) addr); ysr@777: // hr can be null if addr in perm_gen ysr@777: if (hr != NULL && hr->continuesHumongous()) { ysr@777: hr = hr->humongous_start_region(); ysr@777: } ysr@777: return hr; ysr@777: } ysr@777: tonyp@2963: template ysr@777: inline HeapRegion* tonyp@2963: G1CollectedHeap::heap_region_containing_raw(const T addr) const { tonyp@2963: assert(_g1_reserved.contains((const void*) addr), "invariant"); tonyp@2963: HeapRegion* res = _hrs.addr_to_region_unsafe((HeapWord*) addr); ysr@777: return res; ysr@777: } ysr@777: tschatzl@6541: inline void G1CollectedHeap::old_set_remove(HeapRegion* hr) { tschatzl@6541: _old_set.remove(hr); tschatzl@6541: } tschatzl@6541: ysr@777: inline bool G1CollectedHeap::obj_in_cs(oop obj) { tonyp@2963: HeapRegion* r = _hrs.addr_to_region((HeapWord*) obj); ysr@777: return r != NULL && r->in_collection_set(); ysr@777: } ysr@777: tonyp@2315: inline HeapWord* tonyp@2715: G1CollectedHeap::attempt_allocation(size_t word_size, mgerdin@4853: unsigned int* gc_count_before_ret, mgerdin@4853: int* gclocker_retry_count_ret) { tonyp@2715: assert_heap_not_locked_and_not_at_safepoint(); tonyp@2715: assert(!isHumongous(word_size), "attempt_allocation() should not " tonyp@2715: "be called for humongous allocation requests"); ysr@777: tonyp@2715: HeapWord* result = _mutator_alloc_region.attempt_allocation(word_size, tonyp@2715: false /* bot_updates */); tonyp@2715: if (result == NULL) { mgerdin@4853: result = attempt_allocation_slow(word_size, mgerdin@4853: gc_count_before_ret, mgerdin@4853: gclocker_retry_count_ret); tonyp@2715: } tonyp@2715: assert_heap_not_locked(); tonyp@2315: if (result != NULL) { tonyp@2315: dirty_young_block(result, word_size); tonyp@2315: } tonyp@2715: return result; tonyp@2454: } tonyp@2454: tonyp@3028: inline HeapWord* G1CollectedHeap::survivor_attempt_allocation(size_t tonyp@3028: word_size) { tonyp@3028: assert(!isHumongous(word_size), tonyp@3028: "we should not be seeing humongous-size allocations in this path"); tonyp@3028: tonyp@3028: HeapWord* result = _survivor_gc_alloc_region.attempt_allocation(word_size, tonyp@3028: false /* bot_updates */); tonyp@3028: if (result == NULL) { tonyp@3028: MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag); tonyp@3028: result = _survivor_gc_alloc_region.attempt_allocation_locked(word_size, tonyp@3028: false /* bot_updates */); tonyp@3028: } tonyp@3028: if (result != NULL) { tonyp@3028: dirty_young_block(result, word_size); tonyp@3028: } tonyp@3028: return result; tonyp@3028: } tonyp@3028: tonyp@3028: inline HeapWord* G1CollectedHeap::old_attempt_allocation(size_t word_size) { tonyp@3028: assert(!isHumongous(word_size), tonyp@3028: "we should not be seeing humongous-size allocations in this path"); tonyp@3028: tonyp@3028: HeapWord* result = _old_gc_alloc_region.attempt_allocation(word_size, tonyp@3028: true /* bot_updates */); tonyp@3028: if (result == NULL) { tonyp@3028: MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag); tonyp@3028: result = _old_gc_alloc_region.attempt_allocation_locked(word_size, tonyp@3028: true /* bot_updates */); tonyp@3028: } tonyp@3028: return result; tonyp@3028: } tonyp@3028: tonyp@2315: // It dirties the cards that cover the block so that so that the post tonyp@2315: // write barrier never queues anything when updating objects on this tonyp@2315: // block. It is assumed (and in fact we assert) that the block tonyp@2315: // belongs to a young region. tonyp@2315: inline void tonyp@2315: G1CollectedHeap::dirty_young_block(HeapWord* start, size_t word_size) { tonyp@2315: assert_heap_not_locked(); tonyp@2315: tonyp@2315: // Assign the containing region to containing_hr so that we don't tonyp@2315: // have to keep calling heap_region_containing_raw() in the tonyp@2315: // asserts below. tonyp@2315: DEBUG_ONLY(HeapRegion* containing_hr = heap_region_containing_raw(start);) tonyp@2315: assert(containing_hr != NULL && start != NULL && word_size > 0, tonyp@2315: "pre-condition"); tonyp@2315: assert(containing_hr->is_in(start), "it should contain start"); tonyp@2315: assert(containing_hr->is_young(), "it should be young"); tonyp@2315: assert(!containing_hr->isHumongous(), "it should not be humongous"); tonyp@2315: tonyp@2315: HeapWord* end = start + word_size; tonyp@2315: assert(containing_hr->is_in(end - 1), "it should also contain end - 1"); tonyp@2315: tonyp@2315: MemRegion mr(start, end); mgerdin@5860: g1_barrier_set()->g1_mark_as_young(mr); ysr@777: } ysr@777: jcoomes@2064: inline RefToScanQueue* G1CollectedHeap::task_queue(int i) const { ysr@777: return _task_queues->queue(i); ysr@777: } ysr@777: johnc@4016: inline bool G1CollectedHeap::isMarkedPrev(oop obj) const { ysr@777: return _cm->prevMarkBitMap()->isMarked((HeapWord *)obj); ysr@777: } ysr@777: ysr@777: inline bool G1CollectedHeap::isMarkedNext(oop obj) const { ysr@777: return _cm->nextMarkBitMap()->isMarked((HeapWord *)obj); ysr@777: } stefank@2314: tschatzl@6541: tschatzl@6541: // This is a fast test on whether a reference points into the tschatzl@6541: // collection set or not. Assume that the reference tschatzl@6541: // points into the heap. tschatzl@6541: inline bool G1CollectedHeap::in_cset_fast_test(oop obj) { tschatzl@6541: assert(_in_cset_fast_test != NULL, "sanity"); tschatzl@6541: assert(_g1_committed.contains((HeapWord*) obj), err_msg("Given reference outside of heap, is "PTR_FORMAT, (HeapWord*)obj)); tschatzl@6541: // no need to subtract the bottom of the heap from obj, tschatzl@6541: // _in_cset_fast_test is biased tschatzl@6541: uintx index = cast_from_oop(obj) >> HeapRegion::LogOfHRGrainBytes; tschatzl@6541: bool ret = _in_cset_fast_test[index]; tschatzl@6541: // let's make sure the result is consistent with what the slower tschatzl@6541: // test returns tschatzl@6541: assert( ret || !obj_in_cs(obj), "sanity"); tschatzl@6541: assert(!ret || obj_in_cs(obj), "sanity"); tschatzl@6541: return ret; tschatzl@6541: } tschatzl@6541: johnc@4016: #ifndef PRODUCT johnc@4016: // Support for G1EvacuationFailureALot johnc@4016: johnc@4016: inline bool johnc@4016: G1CollectedHeap::evacuation_failure_alot_for_gc_type(bool gcs_are_young, johnc@4016: bool during_initial_mark, johnc@4016: bool during_marking) { johnc@4016: bool res = false; johnc@4016: if (during_marking) { johnc@4016: res |= G1EvacuationFailureALotDuringConcMark; johnc@4016: } johnc@4016: if (during_initial_mark) { johnc@4016: res |= G1EvacuationFailureALotDuringInitialMark; johnc@4016: } johnc@4016: if (gcs_are_young) { johnc@4016: res |= G1EvacuationFailureALotDuringYoungGC; johnc@4016: } else { johnc@4016: // GCs are mixed johnc@4016: res |= G1EvacuationFailureALotDuringMixedGC; johnc@4016: } johnc@4016: return res; johnc@4016: } johnc@4016: johnc@4016: inline void johnc@4016: G1CollectedHeap::set_evacuation_failure_alot_for_current_gc() { johnc@4016: if (G1EvacuationFailureALot) { johnc@4016: // Note we can't assert that _evacuation_failure_alot_for_current_gc johnc@4016: // is clear here. It may have been set during a previous GC but that GC johnc@4016: // did not copy enough objects (i.e. G1EvacuationFailureALotCount) to johnc@4016: // trigger an evacuation failure and clear the flags and and counts. johnc@4016: johnc@4016: // Check if we have gone over the interval. johnc@4016: const size_t gc_num = total_collections(); johnc@4016: const size_t elapsed_gcs = gc_num - _evacuation_failure_alot_gc_number; johnc@4016: johnc@4016: _evacuation_failure_alot_for_current_gc = (elapsed_gcs >= G1EvacuationFailureALotInterval); johnc@4016: johnc@4016: // Now check if G1EvacuationFailureALot is enabled for the current GC type. johnc@4016: const bool gcs_are_young = g1_policy()->gcs_are_young(); johnc@4016: const bool during_im = g1_policy()->during_initial_mark_pause(); johnc@4016: const bool during_marking = mark_in_progress(); johnc@4016: johnc@4016: _evacuation_failure_alot_for_current_gc &= johnc@4016: evacuation_failure_alot_for_gc_type(gcs_are_young, johnc@4016: during_im, johnc@4016: during_marking); johnc@4016: } johnc@4016: } johnc@4016: johnc@4016: inline bool johnc@4016: G1CollectedHeap::evacuation_should_fail() { johnc@4016: if (!G1EvacuationFailureALot || !_evacuation_failure_alot_for_current_gc) { johnc@4016: return false; johnc@4016: } johnc@4016: // G1EvacuationFailureALot is in effect for current GC johnc@4016: // Access to _evacuation_failure_alot_count is not atomic; johnc@4016: // the value does not have to be exact. johnc@4016: if (++_evacuation_failure_alot_count < G1EvacuationFailureALotCount) { johnc@4016: return false; johnc@4016: } johnc@4016: _evacuation_failure_alot_count = 0; johnc@4016: return true; johnc@4016: } johnc@4016: johnc@4016: inline void G1CollectedHeap::reset_evacuation_should_fail() { johnc@4016: if (G1EvacuationFailureALot) { johnc@4016: _evacuation_failure_alot_gc_number = total_collections(); johnc@4016: _evacuation_failure_alot_count = 0; johnc@4016: _evacuation_failure_alot_for_current_gc = false; johnc@4016: } johnc@4016: } johnc@4016: #endif // #ifndef PRODUCT johnc@4016: tschatzl@6541: inline bool G1CollectedHeap::is_in_young(const oop obj) { tschatzl@6541: HeapRegion* hr = heap_region_containing(obj); tschatzl@6541: return hr != NULL && hr->is_young(); tschatzl@6541: } tschatzl@6541: tschatzl@6541: // We don't need barriers for initializing stores to objects tschatzl@6541: // in the young gen: for the SATB pre-barrier, there is no tschatzl@6541: // pre-value that needs to be remembered; for the remembered-set tschatzl@6541: // update logging post-barrier, we don't maintain remembered set tschatzl@6541: // information for young gen objects. tschatzl@6541: inline bool G1CollectedHeap::can_elide_initializing_store_barrier(oop new_obj) { tschatzl@6541: return is_in_young(new_obj); tschatzl@6541: } tschatzl@6541: tschatzl@6541: inline bool G1CollectedHeap::is_obj_dead(const oop obj) const { tschatzl@6541: const HeapRegion* hr = heap_region_containing(obj); tschatzl@6541: if (hr == NULL) { tschatzl@6541: if (obj == NULL) return false; tschatzl@6541: else return true; tschatzl@6541: } tschatzl@6541: else return is_obj_dead(obj, hr); tschatzl@6541: } tschatzl@6541: tschatzl@6541: inline bool G1CollectedHeap::is_obj_ill(const oop obj) const { tschatzl@6541: const HeapRegion* hr = heap_region_containing(obj); tschatzl@6541: if (hr == NULL) { tschatzl@6541: if (obj == NULL) return false; tschatzl@6541: else return true; tschatzl@6541: } tschatzl@6541: else return is_obj_ill(obj, hr); tschatzl@6541: } tschatzl@6541: tschatzl@6541: template inline void G1ParScanThreadState::immediate_rs_update(HeapRegion* from, T* p, int tid) { tschatzl@6541: if (!from->is_survivor()) { tschatzl@6541: _g1_rem->par_write_ref(from, p, tid); tschatzl@6541: } tschatzl@6541: } tschatzl@6541: tschatzl@6541: template void G1ParScanThreadState::update_rs(HeapRegion* from, T* p, int tid) { tschatzl@6541: if (G1DeferredRSUpdate) { tschatzl@6541: deferred_rs_update(from, p, tid); tschatzl@6541: } else { tschatzl@6541: immediate_rs_update(from, p, tid); tschatzl@6541: } tschatzl@6541: } tschatzl@6541: tschatzl@6541: tschatzl@6541: inline void G1ParScanThreadState::do_oop_partial_array(oop* p) { tschatzl@6541: assert(has_partial_array_mask(p), "invariant"); tschatzl@6541: oop from_obj = clear_partial_array_mask(p); tschatzl@6541: tschatzl@6541: assert(Universe::heap()->is_in_reserved(from_obj), "must be in heap."); tschatzl@6541: assert(from_obj->is_objArray(), "must be obj array"); tschatzl@6541: objArrayOop from_obj_array = objArrayOop(from_obj); tschatzl@6541: // The from-space object contains the real length. tschatzl@6541: int length = from_obj_array->length(); tschatzl@6541: tschatzl@6541: assert(from_obj->is_forwarded(), "must be forwarded"); tschatzl@6541: oop to_obj = from_obj->forwardee(); tschatzl@6541: assert(from_obj != to_obj, "should not be chunking self-forwarded objects"); tschatzl@6541: objArrayOop to_obj_array = objArrayOop(to_obj); tschatzl@6541: // We keep track of the next start index in the length field of the tschatzl@6541: // to-space object. tschatzl@6541: int next_index = to_obj_array->length(); tschatzl@6541: assert(0 <= next_index && next_index < length, tschatzl@6541: err_msg("invariant, next index: %d, length: %d", next_index, length)); tschatzl@6541: tschatzl@6541: int start = next_index; tschatzl@6541: int end = length; tschatzl@6541: int remainder = end - start; tschatzl@6541: // We'll try not to push a range that's smaller than ParGCArrayScanChunk. tschatzl@6541: if (remainder > 2 * ParGCArrayScanChunk) { tschatzl@6541: end = start + ParGCArrayScanChunk; tschatzl@6541: to_obj_array->set_length(end); tschatzl@6541: // Push the remainder before we process the range in case another tschatzl@6541: // worker has run out of things to do and can steal it. tschatzl@6541: oop* from_obj_p = set_partial_array_mask(from_obj); tschatzl@6541: push_on_queue(from_obj_p); tschatzl@6541: } else { tschatzl@6541: assert(length == end, "sanity"); tschatzl@6541: // We'll process the final range for this object. Restore the length tschatzl@6541: // so that the heap remains parsable in case of evacuation failure. tschatzl@6541: to_obj_array->set_length(end); tschatzl@6541: } tschatzl@6541: _scanner.set_region(_g1h->heap_region_containing_raw(to_obj)); tschatzl@6541: // Process indexes [start,end). It will also process the header tschatzl@6541: // along with the first chunk (i.e., the chunk with start == 0). tschatzl@6541: // Note that at this point the length field of to_obj_array is not tschatzl@6541: // correct given that we are using it to keep track of the next tschatzl@6541: // start index. oop_iterate_range() (thankfully!) ignores the length tschatzl@6541: // field and only relies on the start / end parameters. It does tschatzl@6541: // however return the size of the object which will be incorrect. So tschatzl@6541: // we have to ignore it even if we wanted to use it. tschatzl@6541: to_obj_array->oop_iterate_range(&_scanner, start, end); tschatzl@6541: } tschatzl@6541: tschatzl@6541: template inline void G1ParScanThreadState::deal_with_reference(T* ref_to_scan) { tschatzl@6541: if (!has_partial_array_mask(ref_to_scan)) { tschatzl@6541: // Note: we can use "raw" versions of "region_containing" because tschatzl@6541: // "obj_to_scan" is definitely in the heap, and is not in a tschatzl@6541: // humongous region. tschatzl@6541: HeapRegion* r = _g1h->heap_region_containing_raw(ref_to_scan); tschatzl@6541: do_oop_evac(ref_to_scan, r); tschatzl@6541: } else { tschatzl@6541: do_oop_partial_array((oop*)ref_to_scan); tschatzl@6541: } tschatzl@6541: } tschatzl@6541: tschatzl@6541: inline void G1ParScanThreadState::deal_with_reference(StarTask ref) { tschatzl@6541: assert(verify_task(ref), "sanity"); tschatzl@6541: if (ref.is_narrow()) { tschatzl@6541: deal_with_reference((narrowOop*)ref); tschatzl@6541: } else { tschatzl@6541: deal_with_reference((oop*)ref); tschatzl@6541: } tschatzl@6541: } tschatzl@6541: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP