--- old/src/share/vm/runtime/arguments.cpp 2016-03-17 14:19:23.492652224 +0100 +++ new/src/share/vm/runtime/arguments.cpp 2016-03-17 14:19:23.364646850 +0100 @@ -66,16 +66,6 @@ #define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp" #define DEFAULT_JAVA_LAUNCHER "generic" -#define UNSUPPORTED_GC_OPTION(gc) \ -do { \ - if (gc) { \ - if (FLAG_IS_CMDLINE(gc)) { \ - warning(#gc " is not supported in this VM. Using Serial GC."); \ - } \ - FLAG_SET_DEFAULT(gc, false); \ - } \ -} while(0) - char* Arguments::_jvm_flags_file = NULL; char** Arguments::_jvm_flags_array = NULL; int Arguments::_num_jvm_flags = 0; @@ -1834,26 +1824,45 @@ CollectorPolicy::compute_heap_alignment()); } +bool Arguments::gc_selected() { +#if INCLUDE_ALL_GCS + return UseSerialGC || UseParallelGC || UseParallelOldGC || UseConcMarkSweepGC || UseG1GC; +#else + return UseSerialGC; +#endif // INCLUDE_ALL_GCS +} + void Arguments::select_gc_ergonomically() { +#if INCLUDE_ALL_GCS if (os::is_server_class_machine()) { if (should_auto_select_low_pause_collector()) { - FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true); + FLAG_SET_ERGO_IF_DEFAULT(bool, UseConcMarkSweepGC, true); } else { #if defined(JAVASE_EMBEDDED) - FLAG_SET_ERGO(bool, UseParallelGC, true); + FLAG_SET_ERGO_IF_DEFAULT(bool, UseParallelGC, true); #else - FLAG_SET_ERGO(bool, UseG1GC, true); + FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true); #endif } } else { - FLAG_SET_ERGO(bool, UseSerialGC, true); + FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true); } +#else + UNSUPPORTED_OPTION(UseG1GC); + UNSUPPORTED_OPTION(UseParallelGC); + UNSUPPORTED_OPTION(UseParallelOldGC); + UNSUPPORTED_OPTION(UseConcMarkSweepGC); + UNSUPPORTED_OPTION(UseParNewGC); + FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true); +#endif // INCLUDE_ALL_GCS } void Arguments::select_gc() { if (!gc_selected()) { select_gc_ergonomically(); - guarantee(gc_selected(), "No GC selected"); + if (!gc_selected()) { + vm_exit_during_initialization("Garbage collector not selected (default collector explicitly disabled)", NULL); + } } } @@ -1978,16 +1987,6 @@ log_trace(gc)("ConcGCThreads: %u", ConcGCThreads); } -#if !INCLUDE_ALL_GCS -#ifdef ASSERT -static bool verify_serial_gc_flags() { - return (UseSerialGC && - !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC || - UseParallelGC || UseParallelOldGC)); -} -#endif // ASSERT -#endif // INCLUDE_ALL_GCS - void Arguments::set_gc_specific_flags() { #if INCLUDE_ALL_GCS // Set per-collector flags @@ -2009,8 +2008,6 @@ // Keeping the heap 100% free is hard ;-) so limit it to 99%. FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99); } -#else // INCLUDE_ALL_GCS - assert(verify_serial_gc_flags(), "SerialGC unset"); #endif // INCLUDE_ALL_GCS } @@ -3463,7 +3460,7 @@ #ifndef TIERED // Tiered compilation is undefined. - UNSUPPORTED_OPTION(TieredCompilation, "TieredCompilation"); + UNSUPPORTED_OPTION(TieredCompilation); #endif // If we are running in a headless jre, force java.awt.headless property @@ -3784,17 +3781,6 @@ } } -#if !INCLUDE_ALL_GCS -static void force_serial_gc() { - FLAG_SET_DEFAULT(UseSerialGC, true); - UNSUPPORTED_GC_OPTION(UseG1GC); - UNSUPPORTED_GC_OPTION(UseParallelGC); - UNSUPPORTED_GC_OPTION(UseParallelOldGC); - UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC); - UNSUPPORTED_GC_OPTION(UseParNewGC); -} -#endif // INCLUDE_ALL_GCS - // Sharing support // Construct the path to the archive static char* get_shared_archive_path() { @@ -4158,7 +4144,7 @@ } #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX. - UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages"); + UNSUPPORTED_OPTION(UseLargePages); #endif ArgumentsExt::report_unsupported_options(); @@ -4189,9 +4175,6 @@ // Set object alignment values. set_object_alignment(); -#if !INCLUDE_ALL_GCS - force_serial_gc(); -#endif // INCLUDE_ALL_GCS #if !INCLUDE_CDS if (DumpSharedSpaces || RequireSharedSpaces) { jio_fprintf(defaultStream::error_stream(), --- old/src/share/vm/runtime/arguments.hpp 2016-03-17 14:19:23.799665114 +0100 +++ new/src/share/vm/runtime/arguments.hpp 2016-03-17 14:19:23.658659194 +0100 @@ -508,7 +508,7 @@ static jint adjust_after_os(); static void set_gc_specific_flags(); - static inline bool gc_selected(); // whether a gc has been selected + static bool gc_selected(); // whether a gc has been selected static void select_gc_ergonomically(); #if INCLUDE_JVMCI // Check consistency of jvmci vm argument settings. @@ -650,20 +650,16 @@ static bool copy_expand_pid(const char* src, size_t srclen, char* buf, size_t buflen); }; -bool Arguments::gc_selected() { - return UseConcMarkSweepGC || UseG1GC || UseParallelGC || UseParallelOldGC || UseSerialGC; -} - // Disable options not supported in this release, with a warning if they // were explicitly requested on the command-line -#define UNSUPPORTED_OPTION(opt, description) \ -do { \ - if (opt) { \ - if (FLAG_IS_CMDLINE(opt)) { \ - warning(description " is disabled in this release."); \ - } \ - FLAG_SET_DEFAULT(opt, false); \ - } \ +#define UNSUPPORTED_OPTION(opt) \ +do { \ + if (opt) { \ + if (FLAG_IS_CMDLINE(opt)) { \ + warning("-XX:+" #opt " not supported in this VM"); \ + } \ + FLAG_SET_DEFAULT(opt, false); \ + } \ } while(0) #endif // SHARE_VM_RUNTIME_ARGUMENTS_HPP --- old/src/share/vm/runtime/globals_extension.hpp 2016-03-17 14:19:24.022674477 +0100 +++ new/src/share/vm/runtime/globals_extension.hpp 2016-03-17 14:19:23.878668431 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -290,6 +290,12 @@ #define FLAG_SET_CMDLINE(type, name, value) (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), Flag::COMMAND_LINE)) #define FLAG_SET_ERGO(type, name, value) (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), Flag::ERGONOMIC)) +#define FLAG_SET_ERGO_IF_DEFAULT(type, name, value) \ + do { \ + if (FLAG_IS_DEFAULT(name)) { \ + FLAG_SET_ERGO(type, name, value); \ + } \ + } while (0) // Can't put the following in CommandLineFlags because // of a circular dependency on the enum definition. --- old/test/compiler/arguments/CheckCICompilerCount.java 2016-03-17 14:19:24.233683336 +0100 +++ new/test/compiler/arguments/CheckCICompilerCount.java 2016-03-17 14:19:24.101677794 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -160,7 +160,7 @@ } catch (RuntimeException e) { // Check if tiered compilation is available in this JVM // Version. Throw exception only if it is available. - if (!(tiered && out.getOutput().contains("TieredCompilation is disabled in this release."))) { + if (!(tiered && out.getOutput().contains("-XX:+TieredCompilation not supported in this VM"))) { throw new RuntimeException(e); } } --- old/test/compiler/arguments/CheckCompileThresholdScaling.java 2016-03-17 14:19:24.416691020 +0100 +++ new/test/compiler/arguments/CheckCompileThresholdScaling.java 2016-03-17 14:19:24.303686275 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -344,7 +344,7 @@ } catch (RuntimeException e) { // Check if tiered compilation is available in this JVM // Version. Throw exception only if it is available. - if (!(tiered && out.getOutput().contains("TieredCompilation is disabled in this release."))) { + if (!(tiered && out.getOutput().contains("-XX:+TieredCompilation not supported in this VM"))) { throw new RuntimeException(e); } } --- old/test/compiler/codecache/CheckSegmentedCodeCache.java 2016-03-17 14:19:24.609699123 +0100 +++ new/test/compiler/codecache/CheckSegmentedCodeCache.java 2016-03-17 14:19:24.493694253 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -52,7 +52,7 @@ out.shouldContain(NON_METHOD); } catch (RuntimeException e) { // Check if TieredCompilation is disabled (in a client VM) - if(!out.getOutput().contains("TieredCompilation is disabled in this release.")) { + if(!out.getOutput().contains("-XX:+TieredCompilation not supported in this VM")) { // Code cache is not segmented throw new RuntimeException("No code cache segmentation."); } --- old/test/gc/g1/Test2GbHeap.java 2016-03-17 14:19:24.795706933 +0100 +++ new/test/gc/g1/Test2GbHeap.java 2016-03-17 14:19:24.679702062 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,7 +53,7 @@ if (output.getOutput().contains("Could not reserve enough space for 2097152KB object heap")) { // Will fail on machines with too little memory (and Windows 32-bit VM), ignore such failures. output.shouldHaveExitValue(1); - } else if (output.getOutput().contains("G1 GC is disabled in this release")) { + } else if (output.getOutput().contains("-XX:+UseG1GC not supported in this VM")) { // G1 is not supported on embedded, ignore such failures. output.shouldHaveExitValue(1); } else { --- /dev/null 2016-03-14 09:47:41.633860807 +0100 +++ new/test/gc/arguments/TestDisableDefaultGC.java 2016-03-17 14:19:24.867709956 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * 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. + */ + +/* + * @test TestDisableDefaultGC + * @summary Test that the VM complains when the default GC is disabled and no other GC is specified + * @bug 8068579 + * @key gc + * @library /testlibrary + * @requires vm.gc=="null" + * @modules java.base/sun.misc + * java.management + * @run driver TestDisableDefaultGC + */ + +import jdk.test.lib.*; + +public class TestDisableDefaultGC { + public static void main(String[] args) throws Exception { + // Start VM, disabling all possible default GCs + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:-UseSerialGC", + "-XX:-UseParallelGC", + "-XX:-UseG1GC", + "-XX:-UseConcMarkSweepGC", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Garbage collector not selected"); + output.shouldHaveExitValue(1); + } +}