Skip to content

Commit a7c5d02

Browse files
author
duke
committedNov 16, 2023
Automatic merge of jdk:master into master
2 parents bfd3e5e + eaa4417 commit a7c5d02

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed
 

‎src/hotspot/share/compiler/compilerOracle.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ static bool parseMemLimit(const char* line, intx& value, int& bytes_read, char*
653653
char* end;
654654
if (!parse_integer<size_t>(line, &end, &s)) {
655655
jio_snprintf(errorbuf, buf_size, "MemLimit: invalid value");
656+
return false;
656657
}
657658
bytes_read = (int)(end - line);
658659

@@ -666,7 +667,7 @@ static bool parseMemLimit(const char* line, intx& value, int& bytes_read, char*
666667
bytes_read += 5;
667668
} else {
668669
jio_snprintf(errorbuf, buf_size, "MemLimit: invalid option");
669-
return true;
670+
return false;
670671
}
671672
}
672673
value = v;
@@ -705,9 +706,11 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read,
705706
total_bytes_read += skipped;
706707
if (type == OptionType::Intx) {
707708
intx value;
708-
// Special handling for memlimit
709-
bool success = (option == CompileCommand::MemLimit) && parseMemLimit(line, value, bytes_read, errorbuf, buf_size);
710-
if (!success) {
709+
bool success = false;
710+
if (option == CompileCommand::MemLimit) {
711+
// Special parsing for MemLimit
712+
success = parseMemLimit(line, value, bytes_read, errorbuf, buf_size);
713+
} else {
711714
// Is it a raw number?
712715
success = sscanf(line, "" INTX_FORMAT "%n", &value, &bytes_read) == 1;
713716
}
@@ -733,7 +736,6 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read,
733736
total_bytes_read += bytes_read;
734737
line += bytes_read;
735738
register_command(matcher, option, value);
736-
return;
737739
} else {
738740
jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str);
739741
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)
Please sign in to comment.