1 /* 2 * Copyright (c) 2013, 2016, Oracle and/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 6271292 27 * @summary Verify that javap prints StackMapTable attribute contents 28 * @library /tools/lib 29 * @modules jdk.compiler/com.sun.tools.javac.api 30 * jdk.compiler/com.sun.tools.javac.main 31 * jdk.jdeps/com.sun.tools.javap 32 * @build toolbox.ToolBox toolbox.JavacTask toolbox.JavapTask 33 * @run main StackmapTest 34 */ 35 36 import java.util.ArrayList; 37 import java.util.List; 38 39 import toolbox.JavacTask; 40 import toolbox.JavapTask; 41 import toolbox.Task; 42 import toolbox.ToolBox; 43 44 // Original test: test/tools/javap/stackmap/T6271292.sh 45 public class StackmapTest { 46 47 private static final String TestSrc = 48 "public class Test extends SuperClass {\n" + 49 " public static void main(String[] args) {\n" + 50 " new SuperClass((args[0].equals(\"0\")) ? 0 : 1)\n" + 51 " .test();\n" + 52 " }\n" + 53 " Test(boolean b) {\n" + 54 " super(b ? 1 : 2);\n" + 55 " }\n" + 56 "}\n" + 57 "class SuperClass {\n" + 58 " double d;\n" + 59 " SuperClass(double dd) { d = dd; }\n" + 60 " double test() {\n" + 61 " if (d == 0)\n" + 62 " return d;\n" + 63 " else\n" + 64 " return d > 0 ? d++ : d--;\n" + 65 " }\n" + 66 "}\n"; 67 68 private static final String goldenOut = 69 " frame_type = 255 /* full_frame */\n" + 70 " frame_type = 255 /* full_frame */\n" + 71 " frame_type = 73 /* same_locals_1_stack_item */\n" + 72 " frame_type = 255 /* full_frame */\n" + 73 " offset_delta = 19\n" + 74 " offset_delta = 0\n" + 75 " offset_delta = 2\n" + 76 " stack = [ uninitialized 0, uninitialized 0 ]\n" + 77 " stack = [ uninitialized 0, uninitialized 0, double ]\n" + 78 " stack = [ this ]\n" + 79 " stack = [ this, double ]\n" + 80 " locals = [ class \"[Ljava/lang/String;\" ]\n" + 81 " locals = [ class \"[Ljava/lang/String;\" ]\n" + 82 " locals = [ this, int ]\n"; 83 84 public static void main(String[] args) throws Exception { 85 ToolBox tb = new ToolBox(); 86 87 new JavacTask(tb) 88 .sources(TestSrc) 89 .run(); 90 91 List<String> out = new JavapTask(tb) 92 .options("-v") 93 .classes("Test.class") 94 .run() 95 .getOutputLines(Task.OutputKind.DIRECT); 96 97 List<String> grepResult = new ArrayList<>(); 98 grepResult.addAll(tb.grep("frame_type", out)); 99 grepResult.addAll(tb.grep("offset_delta", out)); 100 grepResult.addAll(tb.grep("stack = ", out)); 101 grepResult.addAll(tb.grep("locals = ", out)); 102 103 List<String> goldenList = tb.split(goldenOut, "\n"); 104 tb.checkEqual(goldenList, grepResult); 105 } 106 107 }