1 /* 2 * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. 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 * @test 26 * @key randomness 27 * @bug 8026949 8164091 28 * @summary Test ensures correct VM output during startup 29 * @library /test/lib 30 * @requires vm.flagless 31 * @modules java.base/jdk.internal.misc 32 * java.management 33 * 34 * @run driver compiler.startup.StartupOutput 35 */ 36 37 package compiler.startup; 38 39 import jdk.test.lib.process.OutputAnalyzer; 40 import jdk.test.lib.process.ProcessTools; 41 import jdk.test.lib.Utils; 42 import java.util.Random; 43 44 public class StartupOutput { 45 public static void main(String[] args) throws Exception { 46 ProcessBuilder pb; 47 OutputAnalyzer out; 48 Random rand = Utils.getRandomInstance(); 49 50 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-Xint", "-XX:+DisplayVMOutputToStdout", "-version"); 51 out = new OutputAnalyzer(pb.start()); 52 out.shouldNotContain("no space to run compilers"); 53 out.shouldHaveExitValue(0); 54 55 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-Xint", "-XX:ReservedCodeCacheSize=1770K", "-XX:InitialCodeCacheSize=4K", "-version"); 56 out = new OutputAnalyzer(pb.start()); 57 // The VM should not crash but may return an error message because we don't have enough space for adapters 58 int exitCode = out.getExitValue(); 59 if (exitCode != 1 && exitCode != 0) { 60 throw new Exception("VM crashed with exit code " + exitCode); 61 } 62 63 Process[] pr = new Process[200]; 64 for (int i = 0; i < 200; i++) { 65 int initialCodeCacheSizeInKb = 800 + rand.nextInt(400); 66 int reservedCodeCacheSizeInKb = initialCodeCacheSizeInKb + rand.nextInt(200); 67 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:InitialCodeCacheSize=" + initialCodeCacheSizeInKb + "K", "-XX:ReservedCodeCacheSize=" + reservedCodeCacheSizeInKb + "k", "-version"); 68 pr[i] = pb.start(); 69 } 70 for (int i = 0; i < 200; i++) { 71 out = new OutputAnalyzer(pr[i]); 72 // The VM should not crash but will probably fail with a "CodeCache is full. Compiler has been disabled." message 73 out.stdoutShouldNotContain("# A fatal error"); 74 exitCode = out.getExitValue(); 75 if (exitCode != 1 && exitCode != 0) { 76 throw new Exception("VM crashed with exit code " + exitCode); 77 } 78 } 79 } 80 }