Path: blob/master/src/hotspot/share/gc/g1/g1Allocator.inline.hpp
66644 views
/*1* Copyright (c) 2015, 2020, 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_G1ALLOCATOR_INLINE_HPP25#define SHARE_GC_G1_G1ALLOCATOR_INLINE_HPP2627#include "gc/g1/g1Allocator.hpp"2829#include "gc/g1/g1AllocRegion.inline.hpp"30#include "gc/shared/plab.inline.hpp"31#include "memory/universe.hpp"3233inline uint G1Allocator::current_node_index() const {34return _numa->index_of_current_thread();35}3637inline MutatorAllocRegion* G1Allocator::mutator_alloc_region(uint node_index) {38assert(node_index < _num_alloc_regions, "Invalid index: %u", node_index);39return &_mutator_alloc_regions[node_index];40}4142inline SurvivorGCAllocRegion* G1Allocator::survivor_gc_alloc_region(uint node_index) {43assert(node_index < _num_alloc_regions, "Invalid index: %u", node_index);44return &_survivor_gc_alloc_regions[node_index];45}4647inline OldGCAllocRegion* G1Allocator::old_gc_alloc_region() {48return &_old_gc_alloc_region;49}5051inline HeapWord* G1Allocator::attempt_allocation(size_t min_word_size,52size_t desired_word_size,53size_t* actual_word_size) {54uint node_index = current_node_index();5556HeapWord* result = mutator_alloc_region(node_index)->attempt_retained_allocation(min_word_size, desired_word_size, actual_word_size);57if (result != NULL) {58return result;59}6061return mutator_alloc_region(node_index)->attempt_allocation(min_word_size, desired_word_size, actual_word_size);62}6364inline HeapWord* G1Allocator::attempt_allocation_using_new_region(size_t word_size) {65uint node_index = current_node_index();66size_t temp;67HeapWord* result = mutator_alloc_region(node_index)->attempt_allocation_using_new_region(word_size, word_size, &temp);68assert(result != NULL || mutator_alloc_region(node_index)->get() == NULL,69"Must not have a mutator alloc region if there is no memory, but is " PTR_FORMAT,70p2i(mutator_alloc_region(node_index)->get()));71return result;72}7374inline HeapWord* G1Allocator::attempt_allocation_locked(size_t word_size) {75uint node_index = current_node_index();76HeapWord* result = mutator_alloc_region(node_index)->attempt_allocation_locked(word_size);7778assert(result != NULL || mutator_alloc_region(node_index)->get() == NULL,79"Must not have a mutator alloc region if there is no memory, but is " PTR_FORMAT, p2i(mutator_alloc_region(node_index)->get()));80return result;81}8283inline HeapWord* G1Allocator::attempt_allocation_force(size_t word_size) {84uint node_index = current_node_index();85return mutator_alloc_region(node_index)->attempt_allocation_force(word_size);86}8788inline PLAB* G1PLABAllocator::alloc_buffer(G1HeapRegionAttr dest, uint node_index) const {89assert(dest.is_valid(),90"Allocation buffer index out of bounds: %s", dest.get_type_str());91assert(_alloc_buffers[dest.type()] != NULL,92"Allocation buffer is NULL: %s", dest.get_type_str());93return alloc_buffer(dest.type(), node_index);94}9596inline PLAB* G1PLABAllocator::alloc_buffer(region_type_t dest, uint node_index) const {97assert(dest < G1HeapRegionAttr::Num,98"Allocation buffer index out of bounds: %u", dest);99100if (dest == G1HeapRegionAttr::Young) {101assert(node_index < alloc_buffers_length(dest),102"Allocation buffer index out of bounds: %u, %u", dest, node_index);103return _alloc_buffers[dest][node_index];104} else {105return _alloc_buffers[dest][0];106}107}108109inline uint G1PLABAllocator::alloc_buffers_length(region_type_t dest) const {110if (dest == G1HeapRegionAttr::Young) {111return _allocator->num_nodes();112} else {113return 1;114}115}116117inline HeapWord* G1PLABAllocator::plab_allocate(G1HeapRegionAttr dest,118size_t word_sz,119uint node_index) {120PLAB* buffer = alloc_buffer(dest, node_index);121return buffer->allocate(word_sz);122}123124inline HeapWord* G1PLABAllocator::allocate(G1HeapRegionAttr dest,125size_t word_sz,126bool* refill_failed,127uint node_index) {128HeapWord* const obj = plab_allocate(dest, word_sz, node_index);129if (obj != NULL) {130return obj;131}132return allocate_direct_or_new_plab(dest, word_sz, refill_failed, node_index);133}134135#endif // SHARE_GC_G1_G1ALLOCATOR_INLINE_HPP136137138