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.Platform;
40 import jdk.test.lib.process.OutputAnalyzer;
41 import jdk.test.lib.process.ProcessTools;
42 import jdk.test.lib.Utils;
43 import java.util.Random;
44
45 public class StartupOutput {
46 public static void main(String[] args) throws Exception {
47 ProcessBuilder pb;
48 OutputAnalyzer out;
49 Random rand = Utils.getRandomInstance();
50
51 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-Xint", "-XX:+DisplayVMOutputToStdout", "-version");
52 out = new OutputAnalyzer(pb.start());
53 out.shouldNotContain("no space to run compilers");
54 out.shouldHaveExitValue(0);
55
56 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-Xint", "-XX:ReservedCodeCacheSize=1770K", "-XX:InitialCodeCacheSize=4K", "-version");
57 out = new OutputAnalyzer(pb.start());
58 // The VM should not crash but may return an error message because we don't have enough space for adapters
59 int exitCode = out.getExitValue();
60 if (exitCode != 1 && exitCode != 0) {
61 throw new Exception("VM crashed with exit code " + exitCode);
62 }
63
64 // On s390x, generated code is ~6x larger in fastdebug and ~1.4x in release builds vs. other archs,
65 // hence we require slightly more minimum space.
66 int minInitialSize = 800 + (Platform.isS390x() ? 800 : 0);
67 for (int i = 0; i < 50; i++) {
68 int initialCodeCacheSizeInKb = minInitialSize + rand.nextInt(400);
69 int reservedCodeCacheSizeInKb = initialCodeCacheSizeInKb + rand.nextInt(200);
70 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:InitialCodeCacheSize=" + initialCodeCacheSizeInKb + "K", "-XX:ReservedCodeCacheSize=" + reservedCodeCacheSizeInKb + "k", "-version");
71 out = new OutputAnalyzer(pb.start());
72 exitCode = out.getExitValue();
73 if (exitCode != 1 && exitCode != 0) {
74 throw new Exception("VM crashed with exit code " + exitCode);
75 }
76 // The VM should not crash but will probably fail with a "CodeCache is full. Compiler has been disabled." message
77 out.stdoutShouldNotContain("# A fatal error");
78 }
79 }
80 }
--- EOF ---