Skip to content

Commit b99fd4c

Browse files
jasontatton-awsDamonFool
authored andcommitted
8033441: print line numbers with -XX:+PrintOptoAssembly
Reviewed-by: jiefu, thartmann
1 parent 266dea0 commit b99fd4c

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

src/hotspot/share/opto/callnode.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,23 @@ static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, c
406406
}
407407
}
408408

409+
//---------------------print_method_with_lineno--------------------------------
410+
void JVMState::print_method_with_lineno(outputStream* st, bool show_name) const {
411+
if (show_name) _method->print_short_name(st);
412+
413+
int lineno = _method->line_number_from_bci(_bci);
414+
if (lineno != -1) {
415+
st->print(" @ bci:%d (line %d)", _bci, lineno);
416+
} else {
417+
st->print(" @ bci:%d", _bci);
418+
}
419+
}
420+
409421
//------------------------------format-----------------------------------------
410422
void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const {
411423
st->print(" #");
412424
if (_method) {
413-
_method->print_short_name(st);
414-
st->print(" @ bci:%d ",_bci);
425+
print_method_with_lineno(st, true);
415426
} else {
416427
st->print_cr(" runtime stub ");
417428
return;
@@ -537,9 +548,7 @@ void JVMState::dump_spec(outputStream *st) const {
537548
printed = true;
538549
}
539550
}
540-
if (!printed)
541-
_method->print_short_name(st);
542-
st->print(" @ bci:%d",_bci);
551+
print_method_with_lineno(st, !printed);
543552
if(_reexecute == Reexecute_True)
544553
st->print(" reexecute");
545554
} else {

src/hotspot/share/opto/callnode.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class JVMState : public ResourceObj {
306306
int interpreter_frame_size() const;
307307

308308
#ifndef PRODUCT
309+
void print_method_with_lineno(outputStream* st, bool show_name) const;
309310
void format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const;
310311
void dump_spec(outputStream *st) const;
311312
void dump_on(outputStream* st) const;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright Amazon.com Inc. 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+
* @bug 8033441
27+
* @summary Test to ensure that line numbers are now present with the -XX:+PrintOptoAssembly command line option
28+
*
29+
* @requires vm.compiler2.enabled & vm.debug == true
30+
*
31+
* @library /compiler/patches /test/lib
32+
* @run main/othervm compiler.arguments.TestPrintOptoAssemblyLineNumbers
33+
*/
34+
35+
package compiler.arguments;
36+
37+
import jdk.test.lib.Asserts;
38+
import jdk.test.lib.process.OutputAnalyzer;
39+
import jdk.test.lib.process.ProcessTools;
40+
41+
public class TestPrintOptoAssemblyLineNumbers {
42+
public static void main(String[] args) throws Throwable {
43+
// create subprocess to run some code with -XX:+PrintOptoAssembly enabled
44+
String[] procArgs = new String[]{
45+
"-XX:+UnlockDiagnosticVMOptions",
46+
"-XX:-TieredCompilation",
47+
"-XX:+PrintOptoAssembly",
48+
"compiler.arguments.TestPrintOptoAssemblyLineNumbers$CheckC2OptoAssembly"
49+
};
50+
51+
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(procArgs);
52+
String output = new OutputAnalyzer(pb.start()).getOutput();
53+
54+
if(output.contains("TestPrintOptoAssemblyLineNumbers$CheckC2OptoAssembly::main @ bci:11")){
55+
// if C2 optimizer invoked ensure output includes line numbers:
56+
Asserts.assertTrue(output.contains("TestPrintOptoAssemblyLineNumbers$CheckC2OptoAssembly::main @ bci:11 (line 68)"));
57+
}
58+
}
59+
60+
public static class CheckC2OptoAssembly{ // contents of this class serves to just invoke C2
61+
public static boolean foo(String arg){
62+
return arg.contains("45");
63+
}
64+
65+
public static void main(String[] args){
66+
int count = 0;
67+
for(int x = 0; x < 200_000; x++){
68+
if(foo("something" + x)){ // <- test expects this line of code to be on line 68
69+
count += 1;
70+
}
71+
}
72+
System.out.println("count: " + count);
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)