Path: blob/master/src/hotspot/share/gc/g1/g1Arguments.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/g1/g1Arguments.hpp"27#include "gc/g1/g1CollectedHeap.inline.hpp"28#include "gc/g1/g1HeapVerifier.hpp"29#include "gc/g1/heapRegion.hpp"30#include "gc/g1/heapRegionRemSet.hpp"31#include "gc/shared/cardTableRS.hpp"32#include "gc/shared/gcArguments.hpp"33#include "gc/shared/workerPolicy.hpp"34#include "runtime/globals.hpp"35#include "runtime/globals_extension.hpp"36#include "runtime/java.hpp"3738static size_t calculate_heap_alignment(size_t space_alignment) {39size_t card_table_alignment = CardTableRS::ct_max_alignment_constraint();40size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();41return MAX3(card_table_alignment, space_alignment, page_size);42}4344void G1Arguments::initialize_alignments() {45// Set up the region size and associated fields.46//47// There is a circular dependency here. We base the region size on the heap48// size, but the heap size should be aligned with the region size. To get49// around this we use the unaligned values for the heap.50HeapRegion::setup_heap_region_size(MaxHeapSize);5152// The remembered set needs the heap regions set up.53HeapRegionRemSet::setup_remset_size();54// Needs remembered set initialization as the ergonomics are based55// on it.56if (FLAG_IS_DEFAULT(G1EagerReclaimRemSetThreshold)) {57FLAG_SET_ERGO(G1EagerReclaimRemSetThreshold, G1RSetSparseRegionEntries);58}5960SpaceAlignment = HeapRegion::GrainBytes;61HeapAlignment = calculate_heap_alignment(SpaceAlignment);62}6364size_t G1Arguments::conservative_max_heap_alignment() {65return HeapRegion::max_region_size();66}6768void G1Arguments::initialize_verification_types() {69if (strlen(VerifyGCType) > 0) {70const char delimiter[] = " ,\n";71size_t length = strlen(VerifyGCType);72char* type_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal);73strncpy(type_list, VerifyGCType, length + 1);74char* save_ptr;7576char* token = strtok_r(type_list, delimiter, &save_ptr);77while (token != NULL) {78parse_verification_type(token);79token = strtok_r(NULL, delimiter, &save_ptr);80}81FREE_C_HEAP_ARRAY(char, type_list);82}83}8485void G1Arguments::parse_verification_type(const char* type) {86if (strcmp(type, "young-normal") == 0) {87G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyYoungNormal);88} else if (strcmp(type, "concurrent-start") == 0) {89G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyConcurrentStart);90} else if (strcmp(type, "mixed") == 0) {91G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyMixed);92} else if (strcmp(type, "remark") == 0) {93G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyRemark);94} else if (strcmp(type, "cleanup") == 0) {95G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyCleanup);96} else if (strcmp(type, "full") == 0) {97G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyFull);98} else {99log_warning(gc, verify)("VerifyGCType: '%s' is unknown. Available types are: "100"young-normal, concurrent-start, mixed, remark, cleanup and full", type);101}102}103104// Returns the maximum number of workers to be used in a concurrent105// phase based on the number of GC workers being used in a STW106// phase.107static uint scale_concurrent_worker_threads(uint num_gc_workers) {108return MAX2((num_gc_workers + 2) / 4, 1U);109}110111void G1Arguments::initialize_mark_stack_size() {112if (FLAG_IS_DEFAULT(MarkStackSize)) {113size_t mark_stack_size = MIN2(MarkStackSizeMax,114MAX2(MarkStackSize, (size_t)ConcGCThreads * TASKQUEUE_SIZE));115FLAG_SET_ERGO(MarkStackSize, mark_stack_size);116}117118log_trace(gc)("MarkStackSize: %uk MarkStackSizeMax: %uk", (uint)(MarkStackSize / K), (uint)(MarkStackSizeMax / K));119}120121void G1Arguments::initialize() {122GCArguments::initialize();123assert(UseG1GC, "Error");124FLAG_SET_DEFAULT(ParallelGCThreads, WorkerPolicy::parallel_worker_threads());125if (ParallelGCThreads == 0) {126assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0.");127vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL);128}129130// When dumping the CDS archive we want to reduce fragmentation by131// triggering a full collection. To get as low fragmentation as132// possible we only use one worker thread.133if (DumpSharedSpaces) {134FLAG_SET_ERGO(ParallelGCThreads, 1);135}136137if (FLAG_IS_DEFAULT(G1ConcRefinementThreads)) {138FLAG_SET_ERGO(G1ConcRefinementThreads, ParallelGCThreads);139}140141if (FLAG_IS_DEFAULT(ConcGCThreads) || ConcGCThreads == 0) {142// Calculate the number of concurrent worker threads by scaling143// the number of parallel GC threads.144uint marking_thread_num = scale_concurrent_worker_threads(ParallelGCThreads);145FLAG_SET_ERGO(ConcGCThreads, marking_thread_num);146}147148if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {149// In G1, we want the default GC overhead goal to be higher than150// it is for PS, or the heap might be expanded too aggressively.151// We set it here to ~8%.152FLAG_SET_DEFAULT(GCTimeRatio, 12);153}154155// Below, we might need to calculate the pause time interval based on156// the pause target. When we do so we are going to give G1 maximum157// flexibility and allow it to do pauses when it needs to. So, we'll158// arrange that the pause interval to be pause time target + 1 to159// ensure that a) the pause time target is maximized with respect to160// the pause interval and b) we maintain the invariant that pause161// time target < pause interval. If the user does not want this162// maximum flexibility, they will have to set the pause interval163// explicitly.164165if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {166// The default pause time target in G1 is 200ms167FLAG_SET_DEFAULT(MaxGCPauseMillis, 200);168}169170// Then, if the interval parameter was not set, set it according to171// the pause time target (this will also deal with the case when the172// pause time target is the default value).173if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {174FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);175}176177if (FLAG_IS_DEFAULT(ParallelRefProcEnabled) && ParallelGCThreads > 1) {178FLAG_SET_DEFAULT(ParallelRefProcEnabled, true);179}180181// By default do not let the target stack size to be more than 1/4 of the entries182if (FLAG_IS_DEFAULT(GCDrainStackTargetSize)) {183FLAG_SET_ERGO(GCDrainStackTargetSize, MIN2(GCDrainStackTargetSize, (uintx)TASKQUEUE_SIZE / 4));184}185186#ifdef COMPILER2187// Enable loop strip mining to offer better pause time guarantees188if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) {189FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true);190if (FLAG_IS_DEFAULT(LoopStripMiningIter)) {191FLAG_SET_DEFAULT(LoopStripMiningIter, 1000);192}193}194#endif195196initialize_mark_stack_size();197initialize_verification_types();198}199200void G1Arguments::initialize_heap_flags_and_sizes() {201GCArguments::initialize_heap_flags_and_sizes();202}203204CollectedHeap* G1Arguments::create_heap() {205return new G1CollectedHeap();206}207208size_t G1Arguments::heap_reserved_size_bytes() {209return MaxHeapSize;210}211212213214