Path: blob/master/src/hotspot/share/gc/parallel/parallelArguments.cpp
66644 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}8788if (FLAG_IS_DEFAULT(ParallelRefProcEnabled) && ParallelGCThreads > 1) {89FLAG_SET_DEFAULT(ParallelRefProcEnabled, true);90}91}9293// The alignment used for boundary between young gen and old gen94static size_t default_gen_alignment() {95return 64 * K * HeapWordSize;96}9798void ParallelArguments::initialize_alignments() {99SpaceAlignment = GenAlignment = default_gen_alignment();100HeapAlignment = compute_heap_alignment();101}102103void ParallelArguments::initialize_heap_flags_and_sizes_one_pass() {104// Do basic sizing work105GenArguments::initialize_heap_flags_and_sizes();106107// The survivor ratio's are calculated "raw", unlike the108// default gc, which adds 2 to the ratio value. We need to109// make sure the values are valid before using them.110if (MinSurvivorRatio < 3) {111FLAG_SET_ERGO(MinSurvivorRatio, 3);112}113114if (InitialSurvivorRatio < 3) {115FLAG_SET_ERGO(InitialSurvivorRatio, 3);116}117}118119void ParallelArguments::initialize_heap_flags_and_sizes() {120initialize_heap_flags_and_sizes_one_pass();121122const size_t min_pages = 4; // 1 for eden + 1 for each survivor + 1 for old123const size_t page_sz = os::page_size_for_region_aligned(MinHeapSize, min_pages);124125// Can a page size be something else than a power of two?126assert(is_power_of_2((intptr_t)page_sz), "must be a power of 2");127size_t new_alignment = align_up(page_sz, GenAlignment);128if (new_alignment != GenAlignment) {129GenAlignment = new_alignment;130SpaceAlignment = new_alignment;131// Redo everything from the start132initialize_heap_flags_and_sizes_one_pass();133}134}135136size_t ParallelArguments::heap_reserved_size_bytes() {137return MaxHeapSize;138}139140size_t ParallelArguments::heap_max_size_bytes() {141return MaxHeapSize;142}143144CollectedHeap* ParallelArguments::create_heap() {145return new ParallelScavengeHeap();146}147148149