|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright Red Hat, Inc. All Rights Reserved. |
| 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 | + * @test |
| 27 | + * @bug 8319301 |
| 28 | + * @summary Tests various ways to call memlimit |
| 29 | + * @library /test/lib / |
| 30 | + * |
| 31 | + * @run driver compiler.compilercontrol.commands.MemLimitTest |
| 32 | + */ |
| 33 | + |
| 34 | +package compiler.compilercontrol.commands; |
| 35 | + |
| 36 | +import jdk.test.lib.process.OutputAnalyzer; |
| 37 | +import jdk.test.lib.process.ProcessTools; |
| 38 | + |
| 39 | +public class MemLimitTest { |
| 40 | + |
| 41 | + static void do_test(String option, boolean expectSuccess, int expectedValue) throws Exception { |
| 42 | + OutputAnalyzer output = ProcessTools.executeTestJvm("-Xmx64m", "-XX:CompileCommand=" + option, "-version"); |
| 43 | + if (expectSuccess) { |
| 44 | + output.shouldHaveExitValue(0); |
| 45 | + output.shouldNotContain("error occurred"); |
| 46 | + // On success, we expect the command to be registered with the expected value |
| 47 | + output.shouldContain("CompileCommand: MemLimit *.* intx MemLimit = " + expectedValue); |
| 48 | + } else { |
| 49 | + // On error, we don't expec a command registered. |
| 50 | + output.shouldNotHaveExitValue(0); |
| 51 | + output.shouldNotMatch("# A fatal error.*"); |
| 52 | + output.shouldContain("CompileCommand: An error occurred during parsing"); |
| 53 | + output.shouldNotContain("CompileCommand: MemStat"); // on error, no command should be registered! |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + public static void main(String[] args) throws Exception { |
| 58 | + // Check parsing of the MemLimit option. For functional tests, please see |
| 59 | + // test/hotspot/jtreg/compiler/print/CompileCommandMemLimit.java |
| 60 | + |
| 61 | + // Negative tests |
| 62 | + |
| 63 | + // Missing value |
| 64 | + do_test("MemLimit,*.*", false, 0); |
| 65 | + |
| 66 | + // Not a parseable number. Should not crash |
| 67 | + do_test("MemLimit,*.*,hallo", false, 0); |
| 68 | + |
| 69 | + // Invalid option. |
| 70 | + do_test("MemLimit,*.*,444m~hallo", false, 0); |
| 71 | + |
| 72 | + // Positive tests |
| 73 | + |
| 74 | + // "stop" mode is encoded as positive size |
| 75 | + do_test("MemLimit,*.*,444m~stop", true, 465567744); |
| 76 | + |
| 77 | + // "crash" mode is encoded as negative size |
| 78 | + do_test("MemLimit,*.*,444m~crash", true, -465567744); |
| 79 | + |
| 80 | + // if omitted, stop is default |
| 81 | + do_test("MemLimit,*.*,444m", true, 465567744); |
| 82 | + |
| 83 | + } |
| 84 | +} |
0 commit comments