StackMapTableTest.java revision 2942:08092deced3f
1148459Spjd/* 2148459Spjd * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 3148459Spjd * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4148459Spjd * 5148459Spjd * This code is free software; you can redistribute it and/or modify it 6148459Spjd * under the terms of the GNU General Public License version 2 only, as 7148459Spjd * published by the Free Software Foundation. 8148459Spjd * 9148459Spjd * This code is distributed in the hope that it will be useful, but WITHOUT 10148459Spjd * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11148459Spjd * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12148459Spjd * version 2 for more details (a copy is included in the LICENSE file that 13148459Spjd * accompanied this code). 14148459Spjd * 15148459Spjd * You should have received a copy of the GNU General Public License version 16182452Spjd * 2 along with this work; if not, write to the Free Software Foundation, 17148459Spjd * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18148459Spjd * 19148459Spjd * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20148459Spjd * or visit www.oracle.com if you need additional information or have any 21148459Spjd * questions. 22148459Spjd */ 23148459Spjd 24148459Spjd/* 25148459Spjd * @test 26148459Spjd * @bug 8033930 8033913 27148459Spjd * @summary bad formatting of StackMapTable entries 28148459Spjd * @modules jdk.jdeps 29148459Spjd */ 30148459Spjd 31148459Spjdimport java.io.*; 32148459Spjdimport java.util.*; 33148459Spjd 34148459Spjdpublic class StackMapTableTest { 35148459Spjd public static void main(String... args) throws Exception { 36148459Spjd new StackMapTableTest().run(); 37148459Spjd } 38148459Spjd 39148459Spjd void run() throws Exception { 40148459Spjd String testClasses = System.getProperty("test.classes"); 41148459Spjd String out = javap("-v", "-classpath", testClasses, A.class.getName()); 42148459Spjd 43148459Spjd String nl = System.getProperty("line.separator"); 44148459Spjd out = out.replaceAll(nl, "\n"); 45148459Spjd 46148459Spjd if (out.contains("\n\n\n")) 47148459Spjd error("double blank line found"); 48148459Spjd 49148459Spjd String expect = 50148459Spjd " StackMapTable: number_of_entries = 2\n" + 51182452Spjd " frame_type = 252 /* append */\n" + 52148459Spjd " offset_delta = 2\n" + 53148459Spjd " locals = [ int ]\n" + 54148459Spjd " frame_type = 250 /* chop */\n" + 55148459Spjd " offset_delta = 18\n"; 56148459Spjd if (!out.contains(expect)) 57148459Spjd error("expected text not found"); 58148459Spjd 59148459Spjd if (errors > 0) 60148459Spjd throw new Exception(errors + " errors found"); 61148459Spjd } 62148459Spjd 63148459Spjd String javap(String... args) throws Exception { 64148459Spjd StringWriter sw = new StringWriter(); 65148459Spjd PrintWriter out = new PrintWriter(sw); 66148459Spjd int rc = com.sun.tools.javap.Main.run(args, out); 67148459Spjd out.close(); 68148459Spjd System.out.println(sw.toString()); 69148459Spjd if (rc < 0) 70148459Spjd throw new Exception("javap exited, rc=" + rc); 71148459Spjd return sw.toString(); 72148459Spjd } 73148459Spjd 74148459Spjd void error(String msg) { 75148459Spjd System.out.println("Error: " + msg); 76148459Spjd errors++; 77148459Spjd } 78148459Spjd 79148459Spjd int errors; 80148459Spjd 81148459Spjd /** Simple test class to run through javap. */ 82148459Spjd public class A { 83148459Spjd public void a() { 84148459Spjd for (int i = 0; i < 10; i++) { 85148459Spjd System.out.println(i); 86148459Spjd } 87148459Spjd } 88148459Spjd public void b() { 89148459Spjd } 90148459Spjd public void c() { 91148459Spjd } 92148459Spjd } 93148459Spjd} 94148459Spjd