ysr@777: /* tonyp@2454: * Copyright (c) 2001, 2011, 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@2315: #include "gc_implementation/g1/g1CollectorPolicy.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: ysr@777: inline HeapRegion* ysr@777: G1CollectedHeap::heap_region_containing(const void* addr) const { ysr@777: HeapRegion* hr = _hrs->addr_to_region(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: ysr@777: inline HeapRegion* ysr@777: G1CollectedHeap::heap_region_containing_raw(const void* addr) const { tonyp@961: assert(_g1_reserved.contains(addr), "invariant"); johnc@1187: size_t index = pointer_delta(addr, _g1_reserved.start(), 1) johnc@1187: >> HeapRegion::LogOfHRGrainBytes; johnc@1187: tonyp@961: HeapRegion* res = _hrs->at(index); tonyp@961: assert(res == _hrs->addr_to_region(addr), "sanity"); ysr@777: return res; ysr@777: } ysr@777: ysr@777: inline bool G1CollectedHeap::obj_in_cs(oop obj) { ysr@777: HeapRegion* r = _hrs->addr_to_region(obj); ysr@777: return r != NULL && r->in_collection_set(); ysr@777: } ysr@777: tonyp@2315: // See the comment in the .hpp file about the locking protocol and tonyp@2315: // assumptions of this method (and other related ones). tonyp@2315: inline HeapWord* tonyp@2315: G1CollectedHeap::allocate_from_cur_alloc_region(HeapRegion* cur_alloc_region, tonyp@2454: size_t word_size, tonyp@2454: bool with_heap_lock) { tonyp@2454: assert_not_at_safepoint(); tonyp@2454: assert(with_heap_lock == Heap_lock->owned_by_self(), tonyp@2454: "with_heap_lock and Heap_lock->owned_by_self() should be a tautology"); tonyp@2315: assert(cur_alloc_region != NULL, "pre-condition of the method"); tonyp@2315: assert(cur_alloc_region->is_young(), tonyp@2315: "we only support young current alloc regions"); tonyp@2315: assert(!isHumongous(word_size), "allocate_from_cur_alloc_region() " tonyp@2315: "should not be used for humongous allocations"); tonyp@2315: assert(!cur_alloc_region->isHumongous(), "Catch a regression of this bug."); ysr@777: tonyp@2315: assert(!cur_alloc_region->is_empty(), tonyp@2315: err_msg("region ["PTR_FORMAT","PTR_FORMAT"] should not be empty", tonyp@2315: cur_alloc_region->bottom(), cur_alloc_region->end())); tonyp@2454: HeapWord* result = cur_alloc_region->par_allocate_no_bot_updates(word_size); tonyp@2315: if (result != NULL) { tonyp@2315: assert(is_in(result), "result should be in the heap"); ysr@777: tonyp@2454: if (with_heap_lock) { tonyp@2454: Heap_lock->unlock(); tonyp@2454: } tonyp@2454: assert_heap_not_locked(); tonyp@2315: // Do the dirtying after we release the Heap_lock. tonyp@2315: dirty_young_block(result, word_size); tonyp@2315: return result; tonyp@2315: } ysr@777: tonyp@2454: if (with_heap_lock) { tonyp@2454: assert_heap_locked(); tonyp@2454: } else { tonyp@2454: assert_heap_not_locked(); tonyp@2454: } tonyp@2315: return NULL; tonyp@2315: } tonyp@2315: tonyp@2315: // See the comment in the .hpp file about the locking protocol and tonyp@2315: // assumptions of this method (and other related ones). tonyp@2315: inline HeapWord* tonyp@2315: G1CollectedHeap::attempt_allocation(size_t word_size) { tonyp@2454: assert_heap_not_locked_and_not_at_safepoint(); tonyp@2315: assert(!isHumongous(word_size), "attempt_allocation() should not be called " tonyp@2315: "for humongous allocation requests"); tonyp@2315: tonyp@2315: HeapRegion* cur_alloc_region = _cur_alloc_region; tonyp@2315: if (cur_alloc_region != NULL) { tonyp@2315: HeapWord* result = allocate_from_cur_alloc_region(cur_alloc_region, tonyp@2454: word_size, tonyp@2454: false /* with_heap_lock */); tonyp@2454: assert_heap_not_locked(); tonyp@2315: if (result != NULL) { tonyp@2315: return result; ysr@777: } ysr@777: } tonyp@2315: tonyp@2454: // Our attempt to allocate lock-free failed as the current tonyp@2454: // allocation region is either NULL or full. So, we'll now take the tonyp@2454: // Heap_lock and retry. tonyp@2454: Heap_lock->lock(); tonyp@2454: tonyp@2454: HeapWord* result = attempt_allocation_locked(word_size); tonyp@2315: if (result != NULL) { tonyp@2315: assert_heap_not_locked(); tonyp@2315: return result; tonyp@2315: } tonyp@2315: tonyp@2315: assert_heap_locked(); tonyp@2315: return NULL; tonyp@2315: } tonyp@2315: tonyp@2315: inline void tonyp@2315: G1CollectedHeap::retire_cur_alloc_region_common(HeapRegion* cur_alloc_region) { tonyp@2472: assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); tonyp@2315: assert(cur_alloc_region != NULL && cur_alloc_region == _cur_alloc_region, tonyp@2315: "pre-condition of the call"); tonyp@2315: assert(cur_alloc_region->is_young(), tonyp@2315: "we only support young current alloc regions"); tonyp@2315: tonyp@2315: // The region is guaranteed to be young tonyp@2315: g1_policy()->add_region_to_incremental_cset_lhs(cur_alloc_region); tonyp@2315: _summary_bytes_used += cur_alloc_region->used(); tonyp@2315: _cur_alloc_region = NULL; tonyp@2315: } tonyp@2315: tonyp@2454: inline HeapWord* tonyp@2454: G1CollectedHeap::attempt_allocation_locked(size_t word_size) { tonyp@2454: assert_heap_locked_and_not_at_safepoint(); tonyp@2454: assert(!isHumongous(word_size), "attempt_allocation_locked() " tonyp@2454: "should not be called for humongous allocation requests"); tonyp@2454: tonyp@2454: // First, reread the current alloc region and retry the allocation tonyp@2454: // in case somebody replaced it while we were waiting to get the tonyp@2454: // Heap_lock. tonyp@2454: HeapRegion* cur_alloc_region = _cur_alloc_region; tonyp@2454: if (cur_alloc_region != NULL) { tonyp@2454: HeapWord* result = allocate_from_cur_alloc_region( tonyp@2454: cur_alloc_region, word_size, tonyp@2454: true /* with_heap_lock */); tonyp@2454: if (result != NULL) { tonyp@2454: assert_heap_not_locked(); tonyp@2454: return result; tonyp@2454: } tonyp@2454: tonyp@2454: // We failed to allocate out of the current alloc region, so let's tonyp@2454: // retire it before getting a new one. tonyp@2454: retire_cur_alloc_region(cur_alloc_region); tonyp@2454: } tonyp@2454: tonyp@2454: assert_heap_locked(); tonyp@2454: // Try to get a new region and allocate out of it tonyp@2454: HeapWord* result = replace_cur_alloc_region_and_allocate(word_size, tonyp@2454: false, /* at_safepoint */ tonyp@2454: true, /* do_dirtying */ tonyp@2454: false /* can_expand */); tonyp@2454: if (result != NULL) { tonyp@2454: assert_heap_not_locked(); tonyp@2454: return result; tonyp@2454: } tonyp@2454: tonyp@2454: assert_heap_locked(); tonyp@2454: return NULL; tonyp@2454: } tonyp@2454: 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); tonyp@2315: ((CardTableModRefBS*)_g1h->barrier_set())->dirty(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: ysr@777: 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: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP