Path: blob/master/test/langtools/tools/javap/StackMapTableTest.java
41144 views
/*1* Copyright (c) 2014, 2016, 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 8033930 803391326* @summary bad formatting of StackMapTable entries27* @modules jdk.jdeps/com.sun.tools.javap28*/2930import java.io.*;31import java.util.*;3233public class StackMapTableTest {34public static void main(String... args) throws Exception {35new StackMapTableTest().run();36}3738void run() throws Exception {39String testClasses = System.getProperty("test.classes");40String out = javap("-v", "-classpath", testClasses, A.class.getName());4142String nl = System.getProperty("line.separator");43out = out.replaceAll(nl, "\n");4445if (out.contains("\n\n\n"))46error("double blank line found");4748String expect =49" StackMapTable: number_of_entries = 2\n" +50" frame_type = 252 /* append */\n" +51" offset_delta = 2\n" +52" locals = [ int ]\n" +53" frame_type = 250 /* chop */\n" +54" offset_delta = 18\n";55if (!out.contains(expect))56error("expected text not found");5758if (errors > 0)59throw new Exception(errors + " errors found");60}6162String javap(String... args) throws Exception {63StringWriter sw = new StringWriter();64PrintWriter out = new PrintWriter(sw);65int rc = com.sun.tools.javap.Main.run(args, out);66out.close();67System.out.println(sw.toString());68if (rc < 0)69throw new Exception("javap exited, rc=" + rc);70return sw.toString();71}7273void error(String msg) {74System.out.println("Error: " + msg);75errors++;76}7778int errors;7980/** Simple test class to run through javap. */81public class A {82public void a() {83for (int i = 0; i < 10; i++) {84System.out.println(i);85}86}87public void b() {88}89public void c() {90}91}92}939495