Path: blob/master/src/hotspot/share/gc/g1/g1Allocator.inline.hpp
40961 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();55HeapWord* result = mutator_alloc_region(node_index)->attempt_retained_allocation(min_word_size, desired_word_size, actual_word_size);56if (result != NULL) {57return result;58}59return mutator_alloc_region(node_index)->attempt_allocation(min_word_size, desired_word_size, actual_word_size);60}6162inline HeapWord* G1Allocator::attempt_allocation_locked(size_t word_size) {63uint node_index = current_node_index();64HeapWord* result = mutator_alloc_region(node_index)->attempt_allocation_locked(word_size);65assert(result != NULL || mutator_alloc_region(node_index)->get() == NULL,66"Must not have a mutator alloc region if there is no memory, but is " PTR_FORMAT, p2i(mutator_alloc_region(node_index)->get()));67return result;68}6970inline HeapWord* G1Allocator::attempt_allocation_force(size_t word_size) {71uint node_index = current_node_index();72return mutator_alloc_region(node_index)->attempt_allocation_force(word_size);73}7475inline PLAB* G1PLABAllocator::alloc_buffer(G1HeapRegionAttr dest, uint node_index) const {76assert(dest.is_valid(),77"Allocation buffer index out of bounds: %s", dest.get_type_str());78assert(_alloc_buffers[dest.type()] != NULL,79"Allocation buffer is NULL: %s", dest.get_type_str());80return alloc_buffer(dest.type(), node_index);81}8283inline PLAB* G1PLABAllocator::alloc_buffer(region_type_t dest, uint node_index) const {84assert(dest < G1HeapRegionAttr::Num,85"Allocation buffer index out of bounds: %u", dest);8687if (dest == G1HeapRegionAttr::Young) {88assert(node_index < alloc_buffers_length(dest),89"Allocation buffer index out of bounds: %u, %u", dest, node_index);90return _alloc_buffers[dest][node_index];91} else {92return _alloc_buffers[dest][0];93}94}9596inline uint G1PLABAllocator::alloc_buffers_length(region_type_t dest) const {97if (dest == G1HeapRegionAttr::Young) {98return _allocator->num_nodes();99} else {100return 1;101}102}103104inline HeapWord* G1PLABAllocator::plab_allocate(G1HeapRegionAttr dest,105size_t word_sz,106uint node_index) {107PLAB* buffer = alloc_buffer(dest, node_index);108return buffer->allocate(word_sz);109}110111inline HeapWord* G1PLABAllocator::allocate(G1HeapRegionAttr dest,112size_t word_sz,113bool* refill_failed,114uint node_index) {115HeapWord* const obj = plab_allocate(dest, word_sz, node_index);116if (obj != NULL) {117return obj;118}119return allocate_direct_or_new_plab(dest, word_sz, refill_failed, node_index);120}121122#endif // SHARE_GC_G1_G1ALLOCATOR_INLINE_HPP123124125