|
| 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