Path: blob/master/src/hotspot/share/gc/g1/g1AllocRegion.inline.hpp
40960 views
/*1* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_G1_G1ALLOCREGION_INLINE_HPP25#define SHARE_GC_G1_G1ALLOCREGION_INLINE_HPP2627#include "gc/g1/g1AllocRegion.hpp"2829#include "gc/g1/heapRegion.inline.hpp"3031#define assert_alloc_region(p, message) \32do { \33assert((p), "[%s] %s c: %u b: %s r: " PTR_FORMAT " u: " SIZE_FORMAT, \34_name, (message), _count, BOOL_TO_STR(_bot_updates), \35p2i(_alloc_region), _used_bytes_before); \36} while (0)373839inline void G1AllocRegion::reset_alloc_region() {40_alloc_region = _dummy_region;41}4243inline HeapWord* G1AllocRegion::allocate(HeapRegion* alloc_region,44size_t word_size) {45assert(alloc_region != NULL, "pre-condition");4647if (!_bot_updates) {48return alloc_region->allocate_no_bot_updates(word_size);49} else {50return alloc_region->allocate(word_size);51}52}5354inline HeapWord* G1AllocRegion::par_allocate(HeapRegion* alloc_region, size_t word_size) {55size_t temp;56return par_allocate(alloc_region, word_size, word_size, &temp);57}5859inline HeapWord* G1AllocRegion::par_allocate(HeapRegion* alloc_region,60size_t min_word_size,61size_t desired_word_size,62size_t* actual_word_size) {63assert(alloc_region != NULL, "pre-condition");64assert(!alloc_region->is_empty(), "pre-condition");6566if (!_bot_updates) {67return alloc_region->par_allocate_no_bot_updates(min_word_size, desired_word_size, actual_word_size);68} else {69return alloc_region->par_allocate(min_word_size, desired_word_size, actual_word_size);70}71}7273inline HeapWord* G1AllocRegion::attempt_allocation(size_t word_size) {74size_t temp;75return attempt_allocation(word_size, word_size, &temp);76}7778inline HeapWord* G1AllocRegion::attempt_allocation(size_t min_word_size,79size_t desired_word_size,80size_t* actual_word_size) {81HeapRegion* alloc_region = _alloc_region;82assert_alloc_region(alloc_region != NULL, "not initialized properly");8384HeapWord* result = par_allocate(alloc_region, min_word_size, desired_word_size, actual_word_size);85if (result != NULL) {86trace("alloc", min_word_size, desired_word_size, *actual_word_size, result);87return result;88}89trace("alloc failed", min_word_size, desired_word_size);90return NULL;91}9293inline HeapWord* G1AllocRegion::attempt_allocation_locked(size_t word_size) {94size_t temp;95return attempt_allocation_locked(word_size, word_size, &temp);96}9798inline HeapWord* G1AllocRegion::attempt_allocation_locked(size_t min_word_size,99size_t desired_word_size,100size_t* actual_word_size) {101// First we have to redo the allocation, assuming we're holding the102// appropriate lock, in case another thread changed the region while103// we were waiting to get the lock.104HeapWord* result = attempt_allocation(min_word_size, desired_word_size, actual_word_size);105if (result != NULL) {106return result;107}108109retire(true /* fill_up */);110result = new_alloc_region_and_allocate(desired_word_size, false /* force */);111if (result != NULL) {112*actual_word_size = desired_word_size;113trace("alloc locked (second attempt)", min_word_size, desired_word_size, *actual_word_size, result);114return result;115}116trace("alloc locked failed", min_word_size, desired_word_size);117return NULL;118}119120inline HeapWord* G1AllocRegion::attempt_allocation_force(size_t word_size) {121assert_alloc_region(_alloc_region != NULL, "not initialized properly");122123trace("forcing alloc", word_size, word_size);124HeapWord* result = new_alloc_region_and_allocate(word_size, true /* force */);125if (result != NULL) {126trace("alloc forced", word_size, word_size, word_size, result);127return result;128}129trace("alloc forced failed", word_size, word_size);130return NULL;131}132133inline HeapWord* MutatorAllocRegion::attempt_retained_allocation(size_t min_word_size,134size_t desired_word_size,135size_t* actual_word_size) {136if (_retained_alloc_region != NULL) {137HeapWord* result = par_allocate(_retained_alloc_region, min_word_size, desired_word_size, actual_word_size);138if (result != NULL) {139trace("alloc retained", min_word_size, desired_word_size, *actual_word_size, result);140return result;141}142}143return NULL;144}145146#endif // SHARE_GC_G1_G1ALLOCREGION_INLINE_HPP147148149