Path: blob/master/src/hotspot/share/gc/shared/gcArguments.cpp
40957 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/shared/cardTableRS.hpp"27#include "gc/shared/gcArguments.hpp"28#include "logging/log.hpp"29#include "runtime/arguments.hpp"30#include "runtime/globals.hpp"31#include "runtime/globals_extension.hpp"32#include "utilities/macros.hpp"3334size_t HeapAlignment = 0;35size_t SpaceAlignment = 0;3637void GCArguments::initialize() {38if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {39MarkSweepAlwaysCompactCount = 1; // Move objects every gc.40}4142if (!UseParallelGC && FLAG_IS_DEFAULT(ScavengeBeforeFullGC)) {43FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false);44}4546if (GCTimeLimit == 100) {47// Turn off gc-overhead-limit-exceeded checks48FLAG_SET_DEFAULT(UseGCOverheadLimit, false);49}5051if (MinHeapFreeRatio == 100) {52// Keeping the heap 100% free is hard ;-) so limit it to 99%.53FLAG_SET_ERGO(MinHeapFreeRatio, 99);54}5556if (!ClassUnloading) {57// If class unloading is disabled, also disable concurrent class unloading.58FLAG_SET_CMDLINE(ClassUnloadingWithConcurrentMark, false);59}60}6162void GCArguments::initialize_heap_sizes() {63initialize_alignments();64initialize_heap_flags_and_sizes();65initialize_size_info();66}6768size_t GCArguments::compute_heap_alignment() {69// The card marking array and the offset arrays for old generations are70// committed in os pages as well. Make sure they are entirely full (to71// avoid partial page problems), e.g. if 512 bytes heap corresponds to 172// byte entry and the os page size is 4096, the maximum heap size should73// be 512*4096 = 2MB aligned.7475size_t alignment = CardTableRS::ct_max_alignment_constraint();7677if (UseLargePages) {78// In presence of large pages we have to make sure that our79// alignment is large page aware.80alignment = lcm(os::large_page_size(), alignment);81}8283return alignment;84}8586#ifdef ASSERT87void GCArguments::assert_flags() {88assert(InitialHeapSize <= MaxHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");89assert(InitialHeapSize % HeapAlignment == 0, "InitialHeapSize alignment");90assert(MaxHeapSize % HeapAlignment == 0, "MaxHeapSize alignment");91}9293void GCArguments::assert_size_info() {94assert(MaxHeapSize >= MinHeapSize, "Ergonomics decided on incompatible minimum and maximum heap sizes");95assert(InitialHeapSize >= MinHeapSize, "Ergonomics decided on incompatible initial and minimum heap sizes");96assert(MaxHeapSize >= InitialHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");97assert(MinHeapSize % HeapAlignment == 0, "MinHeapSize alignment");98assert(InitialHeapSize % HeapAlignment == 0, "InitialHeapSize alignment");99assert(MaxHeapSize % HeapAlignment == 0, "MaxHeapSize alignment");100}101#endif // ASSERT102103void GCArguments::initialize_size_info() {104log_debug(gc, heap)("Minimum heap " SIZE_FORMAT " Initial heap " SIZE_FORMAT " Maximum heap " SIZE_FORMAT,105MinHeapSize, InitialHeapSize, MaxHeapSize);106107DEBUG_ONLY(assert_size_info();)108}109110void GCArguments::initialize_heap_flags_and_sizes() {111assert(SpaceAlignment != 0, "Space alignment not set up properly");112assert(HeapAlignment != 0, "Heap alignment not set up properly");113assert(HeapAlignment >= SpaceAlignment,114"HeapAlignment: " SIZE_FORMAT " less than SpaceAlignment: " SIZE_FORMAT,115HeapAlignment, SpaceAlignment);116assert(HeapAlignment % SpaceAlignment == 0,117"HeapAlignment: " SIZE_FORMAT " not aligned by SpaceAlignment: " SIZE_FORMAT,118HeapAlignment, SpaceAlignment);119120if (FLAG_IS_CMDLINE(MaxHeapSize)) {121if (FLAG_IS_CMDLINE(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {122vm_exit_during_initialization("Initial heap size set to a larger value than the maximum heap size");123}124if (FLAG_IS_CMDLINE(MinHeapSize) && MaxHeapSize < MinHeapSize) {125vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified");126}127}128129// Check heap parameter properties130if (MaxHeapSize < 2 * M) {131vm_exit_during_initialization("Too small maximum heap");132}133if (InitialHeapSize < M) {134vm_exit_during_initialization("Too small initial heap");135}136if (MinHeapSize < M) {137vm_exit_during_initialization("Too small minimum heap");138}139140// User inputs from -Xmx and -Xms must be aligned141// Write back to flags if the values changed142if (!is_aligned(MinHeapSize, HeapAlignment)) {143FLAG_SET_ERGO(MinHeapSize, align_up(MinHeapSize, HeapAlignment));144}145if (!is_aligned(InitialHeapSize, HeapAlignment)) {146FLAG_SET_ERGO(InitialHeapSize, align_up(InitialHeapSize, HeapAlignment));147}148if (!is_aligned(MaxHeapSize, HeapAlignment)) {149FLAG_SET_ERGO(MaxHeapSize, align_up(MaxHeapSize, HeapAlignment));150}151152if (FLAG_IS_CMDLINE(InitialHeapSize) && FLAG_IS_CMDLINE(MinHeapSize) &&153InitialHeapSize < MinHeapSize) {154vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified");155}156157if (!FLAG_IS_DEFAULT(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {158FLAG_SET_ERGO(MaxHeapSize, InitialHeapSize);159} else if (!FLAG_IS_DEFAULT(MaxHeapSize) && InitialHeapSize > MaxHeapSize) {160FLAG_SET_ERGO(InitialHeapSize, MaxHeapSize);161if (InitialHeapSize < MinHeapSize) {162FLAG_SET_ERGO(MinHeapSize, InitialHeapSize);163}164}165166if (FLAG_IS_DEFAULT(SoftMaxHeapSize)) {167FLAG_SET_ERGO(SoftMaxHeapSize, MaxHeapSize);168}169170FLAG_SET_ERGO(MinHeapDeltaBytes, align_up(MinHeapDeltaBytes, SpaceAlignment));171172DEBUG_ONLY(assert_flags();)173}174175size_t GCArguments::heap_virtual_to_physical_ratio() {176return 1;177}178179180