Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T4459541.java
32285 views
/*1* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 445954126* @summary "javap -l" shows line numbers as signed short; they should be unsigned.27*/2829import java.io.*;3031public class T4459541 {32public static void main(String[] args) throws Exception {33new T4459541().run();34}3536public void run() throws IOException {37File javaFile = writeTestFile();38File classFile = compileTestFile(javaFile);39String output = javap(classFile);40verify(output);41}4243File writeTestFile() throws IOException {44File f = new File("Test.java");45out = new PrintWriter(new BufferedWriter(new FileWriter(f)));46println("class Test {");47println("void begin(int i) {");48println("i++;");49println("i++;");50println("}");51while (line < 32750)52println("// " + line);53println("void before_32767(int i) {");54println("i++;");55println("i++;");56println("}");57while (line < 32768-4)58println("// " + line);59println("void straddle_32768(int i) {");60while (line < 32768+4)61println("i++;");62println("}");63while (line < 65520)64println("// " + line);65println("void between_32768_and_65536(int i) {");66println("i++;");67println("i++;");68println("}");69while (line < 65536-4)70println("// " + line);71println("void straddle_65536(int i) {");72while (line < 65536+4)73println("i++;");74println("}");75println("}");76out.close();77return f;78}7980File compileTestFile(File f) {81int rc = com.sun.tools.javac.Main.compile(new String[] { f.getPath() });82if (rc != 0)83throw new Error("compilation failed. rc=" + rc);84String path = f.getPath();85return new File(path.substring(0, path.length() - 5) + ".class");86}8788String javap(File f) {89StringWriter sw = new StringWriter();90PrintWriter out = new PrintWriter(sw);91int rc = com.sun.tools.javap.Main.run(new String[] { "-l", f.getPath() }, out);92if (rc != 0)93throw new Error("javap failed. rc=" + rc);94out.close();95return sw.toString();96}9798void verify(String output) {99System.out.println(output);100if (output.indexOf("-") >= 0)101throw new Error("- found in output");102}103104void println(String text) {105out.println(text);106line++;107}108109PrintWriter out;110int line = 1;111}112113114