Path: blob/master/src/hotspot/share/gc/parallel/parallelArguments.cpp
41149 views
/*1* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "gc/parallel/parallelArguments.hpp"27#include "gc/parallel/parallelScavengeHeap.hpp"28#include "gc/shared/adaptiveSizePolicy.hpp"29#include "gc/shared/gcArguments.hpp"30#include "gc/shared/genArguments.hpp"31#include "gc/shared/workerPolicy.hpp"32#include "logging/log.hpp"33#include "runtime/globals.hpp"34#include "runtime/globals_extension.hpp"35#include "runtime/java.hpp"36#include "utilities/defaultStream.hpp"37#include "utilities/powerOfTwo.hpp"3839size_t ParallelArguments::conservative_max_heap_alignment() {40return compute_heap_alignment();41}4243void ParallelArguments::initialize() {44GCArguments::initialize();45assert(UseParallelGC, "Error");4647// If no heap maximum was requested explicitly, use some reasonable fraction48// of the physical memory, up to a maximum of 1GB.49FLAG_SET_DEFAULT(ParallelGCThreads,50WorkerPolicy::parallel_worker_threads());51if (ParallelGCThreads == 0) {52jio_fprintf(defaultStream::error_stream(),53"The Parallel GC can not be combined with -XX:ParallelGCThreads=0\n");54vm_exit(1);55}5657if (UseAdaptiveSizePolicy) {58// We don't want to limit adaptive heap sizing's freedom to adjust the heap59// unless the user actually sets these flags.60if (FLAG_IS_DEFAULT(MinHeapFreeRatio)) {61FLAG_SET_DEFAULT(MinHeapFreeRatio, 0);62}63if (FLAG_IS_DEFAULT(MaxHeapFreeRatio)) {64FLAG_SET_DEFAULT(MaxHeapFreeRatio, 100);65}66}6768// If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the69// SurvivorRatio has been set, reset their default values to SurvivorRatio +70// 2. By doing this we make SurvivorRatio also work for Parallel Scavenger.71// See CR 6362902 for details.72if (!FLAG_IS_DEFAULT(SurvivorRatio)) {73if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) {74FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2);75}76if (FLAG_IS_DEFAULT(MinSurvivorRatio)) {77FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2);78}79}8081// Par compact uses lower default values since they are treated as82// minimums. These are different defaults because of the different83// interpretation and are not ergonomically set.84if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) {85FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1);86}87}8889// The alignment used for boundary between young gen and old gen90static size_t default_gen_alignment() {91return 64 * K * HeapWordSize;92}9394void ParallelArguments::initialize_alignments() {95SpaceAlignment = GenAlignment = default_gen_alignment();96HeapAlignment = compute_heap_alignment();97}9899void ParallelArguments::initialize_heap_flags_and_sizes_one_pass() {100// Do basic sizing work101GenArguments::initialize_heap_flags_and_sizes();102103// The survivor ratio's are calculated "raw", unlike the104// default gc, which adds 2 to the ratio value. We need to105// make sure the values are valid before using them.106if (MinSurvivorRatio < 3) {107FLAG_SET_ERGO(MinSurvivorRatio, 3);108}109110if (InitialSurvivorRatio < 3) {111FLAG_SET_ERGO(InitialSurvivorRatio, 3);112}113}114115void ParallelArguments::initialize_heap_flags_and_sizes() {116initialize_heap_flags_and_sizes_one_pass();117118const size_t min_pages = 4; // 1 for eden + 1 for each survivor + 1 for old119const size_t page_sz = os::page_size_for_region_aligned(MinHeapSize, min_pages);120121// Can a page size be something else than a power of two?122assert(is_power_of_2((intptr_t)page_sz), "must be a power of 2");123size_t new_alignment = align_up(page_sz, GenAlignment);124if (new_alignment != GenAlignment) {125GenAlignment = new_alignment;126SpaceAlignment = new_alignment;127// Redo everything from the start128initialize_heap_flags_and_sizes_one_pass();129}130}131132size_t ParallelArguments::heap_reserved_size_bytes() {133return MaxHeapSize;134}135136size_t ParallelArguments::heap_max_size_bytes() {137return MaxHeapSize;138}139140CollectedHeap* ParallelArguments::create_heap() {141return new ParallelScavengeHeap();142}143144145