Mon, 19 Jun 2017 14:51:25 -0700
Added tag jdk8u151-b02 for changeset 732e1bab2660
1 /*
2 * Copyright (c) 2013, 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 */
24 /*
25 * @test
26 * @bug 6271292
27 * @summary Verify that javap prints StackMapTable attribute contents
28 * @library /tools/javac/lib
29 * @build ToolBox
30 * @run main StackmapTest
31 */
33 import java.util.Arrays;
34 import java.util.List;
36 //original test: test/tools/javap/stackmap/T6271292.sh
37 public class StackmapTest {
39 private static final String TestSrc =
40 "public class Test extends SuperClass {\n" +
41 " public static void main(String[] args) {\n" +
42 " new SuperClass((args[0].equals(\"0\")) ? 0 : 1)\n" +
43 " .test();\n" +
44 " }\n" +
45 " Test(boolean b) {\n" +
46 " super(b ? 1 : 2);\n" +
47 " }\n" +
48 "}\n" +
49 "class SuperClass {\n" +
50 " double d;\n" +
51 " SuperClass(double dd) { d = dd; }\n" +
52 " double test() {\n" +
53 " if (d == 0)\n" +
54 " return d;\n" +
55 " else\n" +
56 " return d > 0 ? d++ : d--;\n" +
57 " }\n" +
58 "}\n";
60 private static final String goldenOut =
61 "frame_type = 255 /* full_frame */\n" +
62 "frame_type = 255 /* full_frame */\n" +
63 "frame_type = 73 /* same_locals_1_stack_item */\n" +
64 "frame_type = 255 /* full_frame */\n" +
65 "offset_delta = 19\n" +
66 "offset_delta = 0\n" +
67 "offset_delta = 2\n" +
68 "stack = [ uninitialized 0, uninitialized 0 ]\n" +
69 "stack = [ uninitialized 0, uninitialized 0, double ]\n" +
70 "stack = [ this ]\n" +
71 "stack = [ this, double ]\n" +
72 "locals = [ class \"[Ljava/lang/String;\" ]\n" +
73 "locals = [ class \"[Ljava/lang/String;\" ]\n" +
74 "locals = [ this, int ]\n";
76 public static void main(String[] args) throws Exception {
77 // @compile T6271292.java
78 ToolBox.JavaToolArgs javacParams =
79 new ToolBox.JavaToolArgs().setSources(TestSrc);
80 ToolBox.javac(javacParams);
82 // "${TESTJAVA}${FS}bin${FS}javap" ${TESTTOOLVMOPTS} -classpath "${TESTCLASSES}" -verbose T6271292 > "${JAVAPFILE}"
83 ToolBox.JavaToolArgs javapParams =
84 new ToolBox.JavaToolArgs()
85 .setAllArgs("-v", "Test.class");
86 String out = ToolBox.javap(javapParams);
87 List<String> grepResult = ToolBox.grep("frame_type", out,
88 ToolBox.lineSeparator);
89 grepResult.addAll(ToolBox.grep("offset_delta", out, ToolBox.lineSeparator));
90 grepResult.addAll(ToolBox.grep("stack = ", out, ToolBox.lineSeparator));
91 grepResult.addAll(ToolBox.grep("locals = ", out, ToolBox.lineSeparator));
92 List<String> goldenList = Arrays.asList(goldenOut.split("\n"));
94 // diff -w "${OUTFILE}" "${TESTSRC}${FS}T6271292.out"
95 ToolBox.compareLines(goldenList, grepResult, true);
96 }
98 }