test/tools/javap/stackmap/StackmapTest.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test
aoqi@0 26 * @bug 6271292
aoqi@0 27 * @summary Verify that javap prints StackMapTable attribute contents
aoqi@0 28 * @library /tools/javac/lib
aoqi@0 29 * @build ToolBox
aoqi@0 30 * @run main StackmapTest
aoqi@0 31 */
aoqi@0 32
aoqi@0 33 import java.util.Arrays;
aoqi@0 34 import java.util.List;
aoqi@0 35
aoqi@0 36 //original test: test/tools/javap/stackmap/T6271292.sh
aoqi@0 37 public class StackmapTest {
aoqi@0 38
aoqi@0 39 private static final String TestSrc =
aoqi@0 40 "public class Test extends SuperClass {\n" +
aoqi@0 41 " public static void main(String[] args) {\n" +
aoqi@0 42 " new SuperClass((args[0].equals(\"0\")) ? 0 : 1)\n" +
aoqi@0 43 " .test();\n" +
aoqi@0 44 " }\n" +
aoqi@0 45 " Test(boolean b) {\n" +
aoqi@0 46 " super(b ? 1 : 2);\n" +
aoqi@0 47 " }\n" +
aoqi@0 48 "}\n" +
aoqi@0 49 "class SuperClass {\n" +
aoqi@0 50 " double d;\n" +
aoqi@0 51 " SuperClass(double dd) { d = dd; }\n" +
aoqi@0 52 " double test() {\n" +
aoqi@0 53 " if (d == 0)\n" +
aoqi@0 54 " return d;\n" +
aoqi@0 55 " else\n" +
aoqi@0 56 " return d > 0 ? d++ : d--;\n" +
aoqi@0 57 " }\n" +
aoqi@0 58 "}\n";
aoqi@0 59
aoqi@0 60 private static final String goldenOut =
aoqi@0 61 "frame_type = 255 /* full_frame */\n" +
aoqi@0 62 "frame_type = 255 /* full_frame */\n" +
aoqi@0 63 "frame_type = 73 /* same_locals_1_stack_item */\n" +
aoqi@0 64 "frame_type = 255 /* full_frame */\n" +
aoqi@0 65 "offset_delta = 19\n" +
aoqi@0 66 "offset_delta = 0\n" +
aoqi@0 67 "offset_delta = 2\n" +
aoqi@0 68 "stack = [ uninitialized 0, uninitialized 0 ]\n" +
aoqi@0 69 "stack = [ uninitialized 0, uninitialized 0, double ]\n" +
aoqi@0 70 "stack = [ this ]\n" +
aoqi@0 71 "stack = [ this, double ]\n" +
aoqi@0 72 "locals = [ class \"[Ljava/lang/String;\" ]\n" +
aoqi@0 73 "locals = [ class \"[Ljava/lang/String;\" ]\n" +
aoqi@0 74 "locals = [ this, int ]\n";
aoqi@0 75
aoqi@0 76 public static void main(String[] args) throws Exception {
aoqi@0 77 // @compile T6271292.java
aoqi@0 78 ToolBox.JavaToolArgs javacParams =
aoqi@0 79 new ToolBox.JavaToolArgs().setSources(TestSrc);
aoqi@0 80 ToolBox.javac(javacParams);
aoqi@0 81
aoqi@0 82 // "${TESTJAVA}${FS}bin${FS}javap" ${TESTTOOLVMOPTS} -classpath "${TESTCLASSES}" -verbose T6271292 > "${JAVAPFILE}"
aoqi@0 83 ToolBox.JavaToolArgs javapParams =
aoqi@0 84 new ToolBox.JavaToolArgs()
aoqi@0 85 .setAllArgs("-v", "Test.class");
aoqi@0 86 String out = ToolBox.javap(javapParams);
aoqi@0 87 List<String> grepResult = ToolBox.grep("frame_type", out,
aoqi@0 88 ToolBox.lineSeparator);
aoqi@0 89 grepResult.addAll(ToolBox.grep("offset_delta", out, ToolBox.lineSeparator));
aoqi@0 90 grepResult.addAll(ToolBox.grep("stack = ", out, ToolBox.lineSeparator));
aoqi@0 91 grepResult.addAll(ToolBox.grep("locals = ", out, ToolBox.lineSeparator));
aoqi@0 92 List<String> goldenList = Arrays.asList(goldenOut.split("\n"));
aoqi@0 93
aoqi@0 94 // diff -w "${OUTFILE}" "${TESTSRC}${FS}T6271292.out"
aoqi@0 95 ToolBox.compareLines(goldenList, grepResult, true);
aoqi@0 96 }
aoqi@0 97
aoqi@0 98 }

mercurial