Path: blob/master/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp
66644 views
/*1* Copyright (c) 2018, 2021, 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#include "precompiled.hpp"25#include "gc/shared/gcArguments.hpp"26#include "gc/shared/tlab_globals.hpp"27#include "gc/shared/workerPolicy.hpp"28#include "gc/shenandoah/shenandoahArguments.hpp"29#include "gc/shenandoah/shenandoahCollectorPolicy.hpp"30#include "gc/shenandoah/shenandoahHeap.inline.hpp"31#include "gc/shenandoah/shenandoahHeapRegion.hpp"32#include "runtime/globals_extension.hpp"33#include "runtime/java.hpp"34#include "utilities/defaultStream.hpp"3536void ShenandoahArguments::initialize() {37#if !(defined AARCH64 || defined AMD64 || defined IA32 || defined PPC64)38vm_exit_during_initialization("Shenandoah GC is not supported on this platform.");39#endif4041#if 0 // leave this block as stepping stone for future platforms42log_warning(gc)("Shenandoah GC is not fully supported on this platform:");43log_warning(gc)(" concurrent modes are not supported, only STW cycles are enabled;");44log_warning(gc)(" arch-specific barrier code is not implemented, disabling barriers;");4546FLAG_SET_DEFAULT(ShenandoahGCHeuristics, "passive");4748FLAG_SET_DEFAULT(ShenandoahSATBBarrier, false);49FLAG_SET_DEFAULT(ShenandoahLoadRefBarrier, false);50FLAG_SET_DEFAULT(ShenandoahIUBarrier, false);51FLAG_SET_DEFAULT(ShenandoahCASBarrier, false);52FLAG_SET_DEFAULT(ShenandoahCloneBarrier, false);5354FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);55#endif56if (UseLargePages) {57size_t large_page_size = os::large_page_size();58if ((align_up(MaxHeapSize, large_page_size) / large_page_size) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {59warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",60os::large_page_size() / K);61FLAG_SET_DEFAULT(ShenandoahUncommit, false);62}63}6465// Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes66// storage allocation code NUMA-aware.67if (FLAG_IS_DEFAULT(UseNUMA)) {68FLAG_SET_DEFAULT(UseNUMA, true);69}7071// Set up default number of concurrent threads. We want to have cycles complete fast72// enough, but we also do not want to steal too much CPU from the concurrently running73// application. Using 1/4 of available threads for concurrent GC seems a good74// compromise here.75bool ergo_conc = FLAG_IS_DEFAULT(ConcGCThreads);76if (ergo_conc) {77FLAG_SET_DEFAULT(ConcGCThreads, MAX2(1, os::initial_active_processor_count() / 4));78}7980if (ConcGCThreads == 0) {81vm_exit_during_initialization("Shenandoah expects ConcGCThreads > 0, check -XX:ConcGCThreads=#");82}8384// Set up default number of parallel threads. We want to have decent pauses performance85// which would use parallel threads, but we also do not want to do too many threads86// that will overwhelm the OS scheduler. Using 1/2 of available threads seems to be a fair87// compromise here. Due to implementation constraints, it should not be lower than88// the number of concurrent threads.89bool ergo_parallel = FLAG_IS_DEFAULT(ParallelGCThreads);90if (ergo_parallel) {91FLAG_SET_DEFAULT(ParallelGCThreads, MAX2(1, os::initial_active_processor_count() / 2));92}9394if (ParallelGCThreads == 0) {95vm_exit_during_initialization("Shenandoah expects ParallelGCThreads > 0, check -XX:ParallelGCThreads=#");96}9798// Make sure ergonomic decisions do not break the thread count invariants.99// This may happen when user overrides one of the flags, but not the other.100// When that happens, we want to adjust the setting that was set ergonomically.101if (ParallelGCThreads < ConcGCThreads) {102if (ergo_conc && !ergo_parallel) {103FLAG_SET_DEFAULT(ConcGCThreads, ParallelGCThreads);104} else if (!ergo_conc && ergo_parallel) {105FLAG_SET_DEFAULT(ParallelGCThreads, ConcGCThreads);106} else if (ergo_conc && ergo_parallel) {107// Should not happen, check the ergonomic computation above. Fail with relevant error.108vm_exit_during_initialization("Shenandoah thread count ergonomic error");109} else {110// User settings error, report and ask user to rectify.111vm_exit_during_initialization("Shenandoah expects ConcGCThreads <= ParallelGCThreads, check -XX:ParallelGCThreads, -XX:ConcGCThreads");112}113}114115if (ShenandoahRegionSampling && FLAG_IS_DEFAULT(PerfDataMemorySize)) {116// When sampling is enabled, max out the PerfData memory to get more117// Shenandoah data in, including Matrix.118FLAG_SET_DEFAULT(PerfDataMemorySize, 2048*K);119}120121#ifdef COMPILER2122// Shenandoah cares more about pause times, rather than raw throughput.123if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) {124FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true);125if (FLAG_IS_DEFAULT(LoopStripMiningIter)) {126FLAG_SET_DEFAULT(LoopStripMiningIter, 1000);127}128}129#ifdef ASSERT130// C2 barrier verification is only reliable when all default barriers are enabled131if (ShenandoahVerifyOptoBarriers &&132(!FLAG_IS_DEFAULT(ShenandoahSATBBarrier) ||133!FLAG_IS_DEFAULT(ShenandoahLoadRefBarrier) ||134!FLAG_IS_DEFAULT(ShenandoahIUBarrier) ||135!FLAG_IS_DEFAULT(ShenandoahCASBarrier) ||136!FLAG_IS_DEFAULT(ShenandoahCloneBarrier)137)) {138warning("Unusual barrier configuration, disabling C2 barrier verification");139FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);140}141#else142guarantee(!ShenandoahVerifyOptoBarriers, "Should be disabled");143#endif // ASSERT144#endif // COMPILER2145146// Record more information about previous cycles for improved debugging pleasure147if (FLAG_IS_DEFAULT(LogEventsBufferEntries)) {148FLAG_SET_DEFAULT(LogEventsBufferEntries, 250);149}150151if ((InitialHeapSize == MaxHeapSize) && ShenandoahUncommit) {152log_info(gc)("Min heap equals to max heap, disabling ShenandoahUncommit");153FLAG_SET_DEFAULT(ShenandoahUncommit, false);154}155156// If class unloading is disabled, no unloading for concurrent cycles as well.157if (!ClassUnloading) {158FLAG_SET_DEFAULT(ClassUnloadingWithConcurrentMark, false);159}160161// TLAB sizing policy makes resizing decisions before each GC cycle. It averages162// historical data, assigning more recent data the weight according to TLABAllocationWeight.163// Current default is good for generational collectors that run frequent young GCs.164// With Shenandoah, GC cycles are much less frequent, so we need we need sizing policy165// to converge faster over smaller number of resizing decisions.166if (FLAG_IS_DEFAULT(TLABAllocationWeight)) {167FLAG_SET_DEFAULT(TLABAllocationWeight, 90);168}169}170171size_t ShenandoahArguments::conservative_max_heap_alignment() {172size_t align = ShenandoahMaxRegionSize;173if (UseLargePages) {174align = MAX2(align, os::large_page_size());175}176return align;177}178179void ShenandoahArguments::initialize_alignments() {180// Need to setup sizes early to get correct alignments.181MaxHeapSize = ShenandoahHeapRegion::setup_sizes(MaxHeapSize);182183// This is expected by our algorithm for ShenandoahHeap::heap_region_containing().184size_t align = ShenandoahHeapRegion::region_size_bytes();185if (UseLargePages) {186align = MAX2(align, os::large_page_size());187}188SpaceAlignment = align;189HeapAlignment = align;190}191192CollectedHeap* ShenandoahArguments::create_heap() {193return new ShenandoahHeap(new ShenandoahCollectorPolicy());194}195196197