2017-11-07 11:58:52 +01:00
|
|
|
/*
|
2018-03-26 12:44:39 +02:00
|
|
|
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
2017-11-07 11:58:52 +01:00
|
|
|
* Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "gc/g1/g1Arguments.hpp"
|
2017-11-16 12:53:29 +01:00
|
|
|
#include "gc/g1/g1CollectedHeap.inline.hpp"
|
2017-12-01 08:56:22 +01:00
|
|
|
#include "gc/g1/g1HeapVerifier.hpp"
|
2017-11-07 11:58:52 +01:00
|
|
|
#include "gc/g1/heapRegion.hpp"
|
2019-04-15 11:47:46 +02:00
|
|
|
#include "gc/g1/heapRegionRemSet.hpp"
|
|
|
|
#include "gc/shared/cardTableRS.hpp"
|
|
|
|
#include "gc/shared/gcArguments.hpp"
|
2018-12-07 12:46:31 +08:00
|
|
|
#include "gc/shared/workerPolicy.hpp"
|
2017-11-07 11:58:52 +01:00
|
|
|
#include "runtime/globals.hpp"
|
|
|
|
#include "runtime/globals_extension.hpp"
|
|
|
|
|
2019-04-15 11:47:46 +02:00
|
|
|
static const double MaxRamFractionForYoung = 0.8;
|
|
|
|
size_t G1Arguments::MaxMemoryForYoung;
|
|
|
|
|
|
|
|
static size_t calculate_heap_alignment(size_t space_alignment) {
|
|
|
|
size_t card_table_alignment = CardTableRS::ct_max_alignment_constraint();
|
|
|
|
size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
|
|
|
|
return MAX3(card_table_alignment, space_alignment, page_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void G1Arguments::initialize_alignments() {
|
|
|
|
// Set up the region size and associated fields.
|
|
|
|
//
|
|
|
|
// There is a circular dependency here. We base the region size on the heap
|
|
|
|
// size, but the heap size should be aligned with the region size. To get
|
|
|
|
// around this we use the unaligned values for the heap.
|
|
|
|
HeapRegion::setup_heap_region_size(InitialHeapSize, MaxHeapSize);
|
|
|
|
HeapRegionRemSet::setup_remset_size();
|
|
|
|
|
|
|
|
SpaceAlignment = HeapRegion::GrainBytes;
|
|
|
|
HeapAlignment = calculate_heap_alignment(SpaceAlignment);
|
|
|
|
}
|
|
|
|
|
2017-11-07 11:58:52 +01:00
|
|
|
size_t G1Arguments::conservative_max_heap_alignment() {
|
|
|
|
return HeapRegion::max_region_size();
|
|
|
|
}
|
|
|
|
|
2018-03-26 12:44:39 +02:00
|
|
|
void G1Arguments::initialize_verification_types() {
|
|
|
|
if (strlen(VerifyGCType) > 0) {
|
|
|
|
const char delimiter[] = " ,\n";
|
|
|
|
size_t length = strlen(VerifyGCType);
|
|
|
|
char* type_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal);
|
|
|
|
strncpy(type_list, VerifyGCType, length + 1);
|
2018-12-04 18:55:06 +01:00
|
|
|
char* save_ptr;
|
|
|
|
|
|
|
|
char* token = strtok_r(type_list, delimiter, &save_ptr);
|
2018-03-26 12:44:39 +02:00
|
|
|
while (token != NULL) {
|
|
|
|
parse_verification_type(token);
|
2018-12-04 18:55:06 +01:00
|
|
|
token = strtok_r(NULL, delimiter, &save_ptr);
|
2018-03-26 12:44:39 +02:00
|
|
|
}
|
|
|
|
FREE_C_HEAP_ARRAY(char, type_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void G1Arguments::parse_verification_type(const char* type) {
|
2018-06-26 11:09:42 +02:00
|
|
|
if (strcmp(type, "young-normal") == 0) {
|
|
|
|
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyYoungNormal);
|
|
|
|
} else if (strcmp(type, "concurrent-start") == 0) {
|
|
|
|
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyConcurrentStart);
|
2018-03-26 12:44:39 +02:00
|
|
|
} else if (strcmp(type, "mixed") == 0) {
|
|
|
|
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyMixed);
|
|
|
|
} else if (strcmp(type, "remark") == 0) {
|
|
|
|
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyRemark);
|
|
|
|
} else if (strcmp(type, "cleanup") == 0) {
|
|
|
|
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyCleanup);
|
|
|
|
} else if (strcmp(type, "full") == 0) {
|
|
|
|
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyFull);
|
|
|
|
} else {
|
|
|
|
log_warning(gc, verify)("VerifyGCType: '%s' is unknown. Available types are: "
|
2018-06-26 11:09:42 +02:00
|
|
|
"young-normal, concurrent-start, mixed, remark, cleanup and full", type);
|
2018-03-26 12:44:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 11:38:47 +02:00
|
|
|
void G1Arguments::initialize() {
|
|
|
|
GCArguments::initialize();
|
2017-11-07 11:58:52 +01:00
|
|
|
assert(UseG1GC, "Error");
|
2018-12-07 12:46:31 +08:00
|
|
|
FLAG_SET_DEFAULT(ParallelGCThreads, WorkerPolicy::parallel_worker_threads());
|
2017-11-07 11:58:52 +01:00
|
|
|
if (ParallelGCThreads == 0) {
|
|
|
|
assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0.");
|
|
|
|
vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL);
|
|
|
|
}
|
|
|
|
|
2018-12-03 22:27:24 -08:00
|
|
|
// When dumping the CDS archive we want to reduce fragmentation by
|
|
|
|
// triggering a full collection. To get as low fragmentation as
|
|
|
|
// possible we only use one worker thread.
|
|
|
|
if (DumpSharedSpaces) {
|
2019-05-22 13:06:31 +02:00
|
|
|
FLAG_SET_ERGO(ParallelGCThreads, 1);
|
2018-12-03 22:27:24 -08:00
|
|
|
}
|
|
|
|
|
2017-11-07 11:58:52 +01:00
|
|
|
if (FLAG_IS_DEFAULT(G1ConcRefinementThreads)) {
|
2019-05-22 13:06:31 +02:00
|
|
|
FLAG_SET_ERGO(G1ConcRefinementThreads, ParallelGCThreads);
|
2017-11-07 11:58:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// MarkStackSize will be set (if it hasn't been set by the user)
|
|
|
|
// when concurrent marking is initialized.
|
|
|
|
// Its value will be based upon the number of parallel marking threads.
|
|
|
|
// But we do set the maximum mark stack size here.
|
|
|
|
if (FLAG_IS_DEFAULT(MarkStackSizeMax)) {
|
|
|
|
FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
|
|
|
|
// In G1, we want the default GC overhead goal to be higher than
|
|
|
|
// it is for PS, or the heap might be expanded too aggressively.
|
|
|
|
// We set it here to ~8%.
|
|
|
|
FLAG_SET_DEFAULT(GCTimeRatio, 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Below, we might need to calculate the pause time interval based on
|
|
|
|
// the pause target. When we do so we are going to give G1 maximum
|
|
|
|
// flexibility and allow it to do pauses when it needs to. So, we'll
|
|
|
|
// arrange that the pause interval to be pause time target + 1 to
|
|
|
|
// ensure that a) the pause time target is maximized with respect to
|
|
|
|
// the pause interval and b) we maintain the invariant that pause
|
|
|
|
// time target < pause interval. If the user does not want this
|
|
|
|
// maximum flexibility, they will have to set the pause interval
|
|
|
|
// explicitly.
|
|
|
|
|
|
|
|
if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
|
|
|
|
// The default pause time target in G1 is 200ms
|
|
|
|
FLAG_SET_DEFAULT(MaxGCPauseMillis, 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then, if the interval parameter was not set, set it according to
|
|
|
|
// the pause time target (this will also deal with the case when the
|
|
|
|
// pause time target is the default value).
|
|
|
|
if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
|
|
|
|
FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
|
|
|
|
}
|
|
|
|
|
2018-06-19 09:34:39 +02:00
|
|
|
if (FLAG_IS_DEFAULT(ParallelRefProcEnabled) && ParallelGCThreads > 1) {
|
|
|
|
FLAG_SET_DEFAULT(ParallelRefProcEnabled, true);
|
|
|
|
}
|
|
|
|
|
2017-11-07 11:58:52 +01:00
|
|
|
log_trace(gc)("MarkStackSize: %uk MarkStackSizeMax: %uk", (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
|
2017-11-28 11:59:16 +01:00
|
|
|
|
2018-04-27 12:06:46 +02:00
|
|
|
// By default do not let the target stack size to be more than 1/4 of the entries
|
|
|
|
if (FLAG_IS_DEFAULT(GCDrainStackTargetSize)) {
|
2019-05-22 13:06:31 +02:00
|
|
|
FLAG_SET_ERGO(GCDrainStackTargetSize, MIN2(GCDrainStackTargetSize, (uintx)TASKQUEUE_SIZE / 4));
|
2018-04-27 12:06:46 +02:00
|
|
|
}
|
|
|
|
|
2017-11-28 11:59:16 +01:00
|
|
|
#ifdef COMPILER2
|
|
|
|
// Enable loop strip mining to offer better pause time guarantees
|
|
|
|
if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) {
|
|
|
|
FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true);
|
2017-12-07 15:52:46 +01:00
|
|
|
if (FLAG_IS_DEFAULT(LoopStripMiningIter)) {
|
|
|
|
FLAG_SET_DEFAULT(LoopStripMiningIter, 1000);
|
|
|
|
}
|
2017-11-28 11:59:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
2017-11-16 12:53:29 +01:00
|
|
|
|
2018-03-26 12:44:39 +02:00
|
|
|
initialize_verification_types();
|
2017-12-01 08:56:22 +01:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:47:46 +02:00
|
|
|
static size_t calculate_reasonable_max_memory_for_young(FormatBuffer<100> &calc_str, double max_ram_fraction_for_young) {
|
|
|
|
julong phys_mem;
|
|
|
|
// If MaxRam is specified, we use that as maximum physical memory available.
|
|
|
|
if (FLAG_IS_DEFAULT(MaxRAM)) {
|
|
|
|
phys_mem = os::physical_memory();
|
|
|
|
calc_str.append("Physical_Memory");
|
2018-12-21 08:18:59 -08:00
|
|
|
} else {
|
2019-04-15 11:47:46 +02:00
|
|
|
phys_mem = (julong)MaxRAM;
|
|
|
|
calc_str.append("MaxRAM");
|
|
|
|
}
|
|
|
|
|
|
|
|
julong reasonable_max = phys_mem;
|
|
|
|
|
|
|
|
// If either MaxRAMFraction or MaxRAMPercentage is specified, we use them to calculate
|
|
|
|
// reasonable max size of young generation.
|
|
|
|
if (!FLAG_IS_DEFAULT(MaxRAMFraction)) {
|
|
|
|
reasonable_max = (julong)(phys_mem / MaxRAMFraction);
|
|
|
|
calc_str.append(" / MaxRAMFraction");
|
|
|
|
} else if (!FLAG_IS_DEFAULT(MaxRAMPercentage)) {
|
|
|
|
reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / 100);
|
|
|
|
calc_str.append(" * MaxRAMPercentage / 100");
|
|
|
|
} else {
|
|
|
|
// We use our own fraction to calculate max size of young generation.
|
|
|
|
reasonable_max = phys_mem * max_ram_fraction_for_young;
|
|
|
|
calc_str.append(" * %0.2f", max_ram_fraction_for_young);
|
2018-12-21 08:18:59 -08:00
|
|
|
}
|
2019-04-15 11:47:46 +02:00
|
|
|
|
|
|
|
return (size_t)reasonable_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
void G1Arguments::initialize_heap_flags_and_sizes() {
|
|
|
|
if (AllocateOldGenAt != NULL) {
|
|
|
|
initialize_heterogeneous();
|
|
|
|
}
|
|
|
|
|
|
|
|
GCArguments::initialize_heap_flags_and_sizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void G1Arguments::initialize_heterogeneous() {
|
|
|
|
FormatBuffer<100> calc_str("");
|
|
|
|
|
|
|
|
MaxMemoryForYoung = calculate_reasonable_max_memory_for_young(calc_str, MaxRamFractionForYoung);
|
|
|
|
|
|
|
|
if (MaxNewSize > MaxMemoryForYoung) {
|
|
|
|
if (FLAG_IS_CMDLINE(MaxNewSize)) {
|
|
|
|
log_warning(gc, ergo)("Setting MaxNewSize to " SIZE_FORMAT " based on dram available (calculation = align(%s))",
|
|
|
|
MaxMemoryForYoung, calc_str.buffer());
|
|
|
|
} else {
|
|
|
|
log_info(gc, ergo)("Setting MaxNewSize to " SIZE_FORMAT " based on dram available (calculation = align(%s)). "
|
|
|
|
"Dram usage can be lowered by setting MaxNewSize to a lower value", MaxMemoryForYoung, calc_str.buffer());
|
|
|
|
}
|
|
|
|
MaxNewSize = MaxMemoryForYoung;
|
|
|
|
}
|
|
|
|
if (NewSize > MaxMemoryForYoung) {
|
|
|
|
if (FLAG_IS_CMDLINE(NewSize)) {
|
|
|
|
log_warning(gc, ergo)("Setting NewSize to " SIZE_FORMAT " based on dram available (calculation = align(%s))",
|
|
|
|
MaxMemoryForYoung, calc_str.buffer());
|
|
|
|
}
|
|
|
|
NewSize = MaxMemoryForYoung;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectedHeap* G1Arguments::create_heap() {
|
|
|
|
return new G1CollectedHeap();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool G1Arguments::is_heterogeneous_heap() {
|
|
|
|
return AllocateOldGenAt != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t G1Arguments::reasonable_max_memory_for_young() {
|
|
|
|
return MaxMemoryForYoung;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t G1Arguments::heap_reserved_size_bytes() {
|
|
|
|
return (is_heterogeneous_heap() ? 2 : 1) * MaxHeapSize;
|
2017-11-16 12:53:29 +01:00
|
|
|
}
|
2019-06-03 11:04:24 -07:00
|
|
|
|
|
|
|
size_t G1Arguments::heap_max_size_bytes() {
|
|
|
|
return MaxHeapSize;
|
|
|
|
}
|