1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "gc/g1/g1Arguments.hpp" 28 #include "gc/g1/g1CollectedHeap.inline.hpp" 29 #include "gc/g1/g1CollectorPolicy.hpp" 30 #include "gc/g1/g1HeapVerifier.hpp" 31 #include "gc/g1/heapRegion.hpp" 32 #include "gc/shared/gcArguments.inline.hpp" 33 #include "runtime/globals.hpp" 34 #include "runtime/globals_extension.hpp" 35 #include "runtime/os.inline.hpp" 36 #include "runtime/vm_version.hpp" 37 38 size_t G1Arguments::conservative_max_heap_alignment() { 39 return HeapRegion::max_region_size(); 40 } 41 42 void G1Arguments::initialize_verification_types() { 43 if (strlen(VerifyGCType) > 0) { 44 const char delimiter[] = " ,\n"; 45 char *save_ptr; 46 size_t length = strlen(VerifyGCType); 47 char* type_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal); 48 strncpy(type_list, VerifyGCType, length + 1); 49 char* token = os::strtok(type_list, delimiter, &save_ptr); 50 while (token != NULL) { 51 parse_verification_type(token); 52 token = os::strtok(NULL, delimiter, &save_ptr); 53 } 54 FREE_C_HEAP_ARRAY(char, type_list); 55 } 56 } 57 58 void G1Arguments::parse_verification_type(const char* type) { 59 if (strcmp(type, "young-normal") == 0) { 60 G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyYoungNormal); 61 } else if (strcmp(type, "concurrent-start") == 0) { 62 G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyConcurrentStart); 63 } else if (strcmp(type, "mixed") == 0) { 64 G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyMixed); 65 } else if (strcmp(type, "remark") == 0) { 66 G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyRemark); 67 } else if (strcmp(type, "cleanup") == 0) { 68 G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyCleanup); 69 } else if (strcmp(type, "full") == 0) { 70 G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyFull); 71 } else { 72 log_warning(gc, verify)("VerifyGCType: '%s' is unknown. Available types are: " 73 "young-normal, concurrent-start, mixed, remark, cleanup and full", type); 74 } 75 } 76 77 void G1Arguments::initialize() { 78 GCArguments::initialize(); 79 assert(UseG1GC, "Error"); 80 FLAG_SET_DEFAULT(ParallelGCThreads, VM_Version::parallel_worker_threads()); 81 if (ParallelGCThreads == 0) { 82 assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0."); 83 vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL); 84 } 85 86 // When dumping the CDS archive we want to reduce fragmentation by 87 // triggering a full collection. To get as low fragmentation as 88 // possible we only use one worker thread. 89 if (DumpSharedSpaces) { 90 FLAG_SET_ERGO(uint, ParallelGCThreads, 1); 91 } 92 93 if (FLAG_IS_DEFAULT(G1ConcRefinementThreads)) { 94 FLAG_SET_ERGO(uint, G1ConcRefinementThreads, ParallelGCThreads); 95 } 96 97 // MarkStackSize will be set (if it hasn't been set by the user) 98 // when concurrent marking is initialized. 99 // Its value will be based upon the number of parallel marking threads. 100 // But we do set the maximum mark stack size here. 101 if (FLAG_IS_DEFAULT(MarkStackSizeMax)) { 102 FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE); 103 } 104 105 if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) { 106 // In G1, we want the default GC overhead goal to be higher than 107 // it is for PS, or the heap might be expanded too aggressively. 108 // We set it here to ~8%. 109 FLAG_SET_DEFAULT(GCTimeRatio, 12); 110 } 111 112 // Below, we might need to calculate the pause time interval based on 113 // the pause target. When we do so we are going to give G1 maximum 114 // flexibility and allow it to do pauses when it needs to. So, we'll 115 // arrange that the pause interval to be pause time target + 1 to 116 // ensure that a) the pause time target is maximized with respect to 117 // the pause interval and b) we maintain the invariant that pause 118 // time target < pause interval. If the user does not want this 119 // maximum flexibility, they will have to set the pause interval 120 // explicitly. 121 122 if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) { 123 // The default pause time target in G1 is 200ms 124 FLAG_SET_DEFAULT(MaxGCPauseMillis, 200); 125 } 126 127 // Then, if the interval parameter was not set, set it according to 128 // the pause time target (this will also deal with the case when the 129 // pause time target is the default value). 130 if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) { 131 FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1); 132 } 133 134 if (FLAG_IS_DEFAULT(ParallelRefProcEnabled) && ParallelGCThreads > 1) { 135 FLAG_SET_DEFAULT(ParallelRefProcEnabled, true); 136 } 137 138 log_trace(gc)("MarkStackSize: %uk MarkStackSizeMax: %uk", (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K)); 139 140 // By default do not let the target stack size to be more than 1/4 of the entries 141 if (FLAG_IS_DEFAULT(GCDrainStackTargetSize)) { 142 FLAG_SET_ERGO(uintx, GCDrainStackTargetSize, MIN2(GCDrainStackTargetSize, (uintx)TASKQUEUE_SIZE / 4)); 143 } 144 145 #ifdef COMPILER2 146 // Enable loop strip mining to offer better pause time guarantees 147 if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) { 148 FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true); 149 if (FLAG_IS_DEFAULT(LoopStripMiningIter)) { 150 FLAG_SET_DEFAULT(LoopStripMiningIter, 1000); 151 } 152 } 153 #endif 154 155 initialize_verification_types(); 156 } 157 158 CollectedHeap* G1Arguments::create_heap() { 159 return create_heap_with_policy<G1CollectedHeap, G1CollectorPolicy>(); 160 }