g1CollectedHeap.inline.hpp revision 1472
342N/A/*
1472N/A * Copyright (c) 2001, 2009, 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
342N/A// Inline functions for G1CollectedHeap
342N/A
342N/Ainline HeapRegion*
342N/AG1CollectedHeap::heap_region_containing(const void* addr) const {
342N/A HeapRegion* hr = _hrs->addr_to_region(addr);
342N/A // hr can be null if addr in perm_gen
342N/A if (hr != NULL && hr->continuesHumongous()) {
342N/A hr = hr->humongous_start_region();
342N/A }
342N/A return hr;
342N/A}
342N/A
342N/Ainline HeapRegion*
342N/AG1CollectedHeap::heap_region_containing_raw(const void* addr) const {
526N/A assert(_g1_reserved.contains(addr), "invariant");
752N/A size_t index = pointer_delta(addr, _g1_reserved.start(), 1)
752N/A >> HeapRegion::LogOfHRGrainBytes;
752N/A
526N/A HeapRegion* res = _hrs->at(index);
526N/A assert(res == _hrs->addr_to_region(addr), "sanity");
342N/A return res;
342N/A}
342N/A
342N/Ainline bool G1CollectedHeap::obj_in_cs(oop obj) {
342N/A HeapRegion* r = _hrs->addr_to_region(obj);
342N/A return r != NULL && r->in_collection_set();
342N/A}
342N/A
342N/Ainline HeapWord* G1CollectedHeap::attempt_allocation(size_t word_size,
342N/A bool permit_collection_pause) {
342N/A HeapWord* res = NULL;
342N/A
342N/A assert( SafepointSynchronize::is_at_safepoint() ||
342N/A Heap_lock->owned_by_self(), "pre-condition of the call" );
342N/A
342N/A if (_cur_alloc_region != NULL) {
342N/A
342N/A // If this allocation causes a region to become non empty,
342N/A // then we need to update our free_regions count.
342N/A
342N/A if (_cur_alloc_region->is_empty()) {
342N/A res = _cur_alloc_region->allocate(word_size);
342N/A if (res != NULL)
342N/A _free_regions--;
342N/A } else {
342N/A res = _cur_alloc_region->allocate(word_size);
342N/A }
342N/A }
342N/A if (res != NULL) {
342N/A if (!SafepointSynchronize::is_at_safepoint()) {
342N/A assert( Heap_lock->owned_by_self(), "invariant" );
342N/A Heap_lock->unlock();
342N/A }
342N/A return res;
342N/A }
342N/A // attempt_allocation_slow will also unlock the heap lock when appropriate.
342N/A return attempt_allocation_slow(word_size, permit_collection_pause);
342N/A}
342N/A
342N/Ainline RefToScanQueue* G1CollectedHeap::task_queue(int i) {
342N/A return _task_queues->queue(i);
342N/A}
342N/A
342N/A
342N/Ainline bool G1CollectedHeap::isMarkedPrev(oop obj) const {
342N/A return _cm->prevMarkBitMap()->isMarked((HeapWord *)obj);
342N/A}
342N/A
342N/Ainline bool G1CollectedHeap::isMarkedNext(oop obj) const {
342N/A return _cm->nextMarkBitMap()->isMarked((HeapWord *)obj);
342N/A}