Path: blob/master/src/hotspot/share/gc/shenandoah/shenandoahAllocRequest.hpp
40960 views
/*1* Copyright (c) 2018, 2019, Red Hat, Inc. 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_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP25#define SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP2627#include "memory/allocation.hpp"2829class ShenandoahAllocRequest : StackObj {30public:31enum Type {32_alloc_shared, // Allocate common, outside of TLAB33_alloc_shared_gc, // Allocate common, outside of GCLAB34_alloc_tlab, // Allocate TLAB35_alloc_gclab, // Allocate GCLAB36_ALLOC_LIMIT37};3839static const char* alloc_type_to_string(Type type) {40switch (type) {41case _alloc_shared:42return "Shared";43case _alloc_shared_gc:44return "Shared GC";45case _alloc_tlab:46return "TLAB";47case _alloc_gclab:48return "GCLAB";49default:50ShouldNotReachHere();51return "";52}53}5455private:56size_t _min_size;57size_t _requested_size;58size_t _actual_size;59Type _alloc_type;60#ifdef ASSERT61bool _actual_size_set;62#endif6364ShenandoahAllocRequest(size_t _min_size, size_t _requested_size, Type _alloc_type) :65_min_size(_min_size), _requested_size(_requested_size),66_actual_size(0), _alloc_type(_alloc_type)67#ifdef ASSERT68, _actual_size_set(false)69#endif70{}7172public:73static inline ShenandoahAllocRequest for_tlab(size_t min_size, size_t requested_size) {74return ShenandoahAllocRequest(min_size, requested_size, _alloc_tlab);75}7677static inline ShenandoahAllocRequest for_gclab(size_t min_size, size_t requested_size) {78return ShenandoahAllocRequest(min_size, requested_size, _alloc_gclab);79}8081static inline ShenandoahAllocRequest for_shared_gc(size_t requested_size) {82return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc);83}8485static inline ShenandoahAllocRequest for_shared(size_t requested_size) {86return ShenandoahAllocRequest(0, requested_size, _alloc_shared);87}8889inline size_t size() {90return _requested_size;91}9293inline Type type() {94return _alloc_type;95}9697inline const char* type_string() {98return alloc_type_to_string(_alloc_type);99}100101inline size_t min_size() {102assert (is_lab_alloc(), "Only access for LAB allocs");103return _min_size;104}105106inline size_t actual_size() {107assert (_actual_size_set, "Should be set");108return _actual_size;109}110111inline void set_actual_size(size_t v) {112#ifdef ASSERT113assert (!_actual_size_set, "Should not be set");114_actual_size_set = true;115#endif116_actual_size = v;117}118119inline bool is_mutator_alloc() {120switch (_alloc_type) {121case _alloc_tlab:122case _alloc_shared:123return true;124case _alloc_gclab:125case _alloc_shared_gc:126return false;127default:128ShouldNotReachHere();129return false;130}131}132133inline bool is_gc_alloc() {134switch (_alloc_type) {135case _alloc_tlab:136case _alloc_shared:137return false;138case _alloc_gclab:139case _alloc_shared_gc:140return true;141default:142ShouldNotReachHere();143return false;144}145}146147inline bool is_lab_alloc() {148switch (_alloc_type) {149case _alloc_tlab:150case _alloc_gclab:151return true;152case _alloc_shared:153case _alloc_shared_gc:154return false;155default:156ShouldNotReachHere();157return false;158}159}160};161162#endif // SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP163164165