1 /* 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 it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 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 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/shared/gcArguments.hpp" 27 #include "gc/serial/serialArguments.hpp" 28 #include "runtime/globals.hpp" 29 #include "runtime/globals_extension.hpp" 30 #include "runtime/java.hpp" 31 #include "runtime/os.hpp" 32 #include "utilities/macros.hpp" 33 34 #if INCLUDE_ALL_GCS 35 #include "gc/parallel/parallelArguments.hpp" 36 #include "gc/cms/cmsArguments.hpp" 37 #include "gc/g1/g1Arguments.hpp" 38 #endif 39 40 GCArguments* GCArguments::_instance = NULL; 41 42 GCArguments* GCArguments::instance() { 43 assert(is_initialized(), "Heap factory not yet created"); 44 return _instance; 45 } 46 47 bool GCArguments::is_initialized() { 48 return _instance != NULL; 49 } 50 51 bool GCArguments::gc_selected() { 52 #if INCLUDE_ALL_GCS 53 return UseSerialGC || UseParallelGC || UseParallelOldGC || UseConcMarkSweepGC || UseG1GC; 54 #else 55 return UseSerialGC; 56 #endif // INCLUDE_ALL_GCS 57 } 58 59 void GCArguments::select_gc() { 60 if (!gc_selected()) { 61 select_gc_ergonomically(); 62 if (!gc_selected()) { 63 vm_exit_during_initialization("Garbage collector not selected (default collector explicitly disabled)", NULL); 64 } 65 } 66 } 67 68 void GCArguments::select_gc_ergonomically() { 69 #if INCLUDE_ALL_GCS 70 if (os::is_server_class_machine()) { 71 FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true); 72 } else { 73 FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true); 74 } 75 #else 76 UNSUPPORTED_OPTION(UseG1GC); 77 UNSUPPORTED_OPTION(UseParallelGC); 78 UNSUPPORTED_OPTION(UseParallelOldGC); 79 UNSUPPORTED_OPTION(UseConcMarkSweepGC); 80 FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true); 81 #endif // INCLUDE_ALL_GCS 82 } 83 84 void GCArguments::initialize_flags() { 85 #if INCLUDE_ALL_GCS 86 if (AssumeMP && !UseSerialGC) { 87 if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) { 88 warning("If the number of processors is expected to increase from one, then" 89 " you should configure the number of parallel GC threads appropriately" 90 " using -XX:ParallelGCThreads=N"); 91 } 92 } 93 if (MinHeapFreeRatio == 100) { 94 // Keeping the heap 100% free is hard ;-) so limit it to 99%. 95 FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99); 96 } 97 98 // If class unloading is disabled, also disable concurrent class unloading. 99 if (!ClassUnloading) { 100 FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false); 101 FLAG_SET_CMDLINE(bool, ClassUnloadingWithConcurrentMark, false); 102 } 103 #endif // INCLUDE_ALL_GCS 104 } 105 106 jint GCArguments::create_instance() { 107 assert(!is_initialized(), "GC arguments already initialized"); 108 109 select_gc(); 110 111 #if !INCLUDE_ALL_GCS 112 if (UseParallelGC || UseParallelOldGC) { 113 jio_fprintf(defaultStream::error_stream(), "UseParallelGC not supported in this VM.\n"); 114 return JNI_ERR; 115 } else if (UseG1GC) { 116 jio_fprintf(defaultStream::error_stream(), "UseG1GC not supported in this VM.\n"); 117 return JNI_ERR; 118 } else if (UseConcMarkSweepGC) { 119 jio_fprintf(defaultStream::error_stream(), "UseConcMarkSweepGC not supported in this VM.\n"); 120 return JNI_ERR; 121 #else 122 if (UseParallelGC || UseParallelOldGC) { 123 _instance = new ParallelArguments(); 124 } else if (UseG1GC) { 125 _instance = new G1Arguments(); 126 } else if (UseConcMarkSweepGC) { 127 _instance = new CMSArguments(); 128 #endif 129 } else if (UseSerialGC) { 130 _instance = new SerialArguments(); 131 } else { 132 ShouldNotReachHere(); 133 } 134 return JNI_OK; 135 }