langtools/test/tools/javap/StackMapTableTest.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30730 d3ce7619db2c
child 36526 3b41f1c69604
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23112
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 23112
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
23112
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
     4
 *
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
     8
 *
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    13
 * accompanied this code).
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    14
 *
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    18
 *
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    21
 * questions.
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    22
 */
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    23
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    24
/*
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    25
 * @test
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    26
 * @bug 8033930 8033913
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    27
 * @summary bad formatting of StackMapTable entries
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    28
 * @modules jdk.jdeps
23112
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    29
 */
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    30
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    31
import java.io.*;
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    32
import java.util.*;
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    33
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    34
public class StackMapTableTest {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    35
    public static void main(String... args) throws Exception {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    36
        new StackMapTableTest().run();
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    37
    }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    38
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    39
    void run() throws Exception {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    40
        String testClasses = System.getProperty("test.classes");
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    41
        String out = javap("-v", "-classpath", testClasses, A.class.getName());
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    42
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    43
        String nl = System.getProperty("line.separator");
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    44
        out = out.replaceAll(nl, "\n");
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    45
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    46
        if (out.contains("\n\n\n"))
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    47
            error("double blank line found");
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    48
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    49
        String expect =
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    50
            "      StackMapTable: number_of_entries = 2\n" +
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    51
            "        frame_type = 252 /* append */\n" +
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    52
            "          offset_delta = 2\n" +
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    53
            "          locals = [ int ]\n" +
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    54
            "        frame_type = 250 /* chop */\n" +
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    55
            "          offset_delta = 18\n";
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    56
        if (!out.contains(expect))
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    57
            error("expected text not found");
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    58
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    59
        if (errors > 0)
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    60
            throw new Exception(errors + " errors found");
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    61
    }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    62
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    63
    String javap(String... args) throws Exception {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    64
        StringWriter sw = new StringWriter();
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    65
        PrintWriter out = new PrintWriter(sw);
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    66
        int rc = com.sun.tools.javap.Main.run(args, out);
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    67
        out.close();
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    68
        System.out.println(sw.toString());
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    69
        if (rc < 0)
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    70
            throw new Exception("javap exited, rc=" + rc);
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    71
        return sw.toString();
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    72
    }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    73
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    74
    void error(String msg) {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    75
        System.out.println("Error: " + msg);
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    76
        errors++;
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    77
    }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    78
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    79
    int errors;
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    80
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    81
    /** Simple test class to run through javap. */
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    82
    public class A {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    83
        public void a() {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    84
            for (int i = 0; i < 10; i++) {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    85
                System.out.println(i);
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    86
            }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    87
        }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    88
        public void b() {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    89
        }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    90
        public void c() {
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    91
        }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    92
    }
4fa26477332d 8033930: Unnecessary new line after the StackMapTable
jjg
parents:
diff changeset
    93
}