langtools/test/tools/javap/T6824493.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 5520 86e4b9a9da40
child 30846 2b3f379840f0
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     4
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     8
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    13
 * accompanied this code).
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    14
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2979
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2979
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2979
diff changeset
    21
 * questions.
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    22
 */
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    23
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    24
import java.io.*;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    25
import java.util.*;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    26
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    27
/*
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    28
 * @test
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    29
 * @bug 6824493
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    30
 * @summary experimental support for additional info for instructions
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
    31
 * @modules jdk.compiler
2979
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    32
 * @compile -g T6824493.java
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    33
 * @run main T6824493
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    34
 */
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    35
public class T6824493 {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    36
    public static void main(String... args) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    37
        new T6824493().run();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    38
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    39
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    40
    void run() {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    41
        // for each of the options, we run javap and check for some
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    42
        // marker strings in the output that generally indicate the
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    43
        // presence of the expected output, without being as specific
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    44
        // as a full golden file test.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    45
        test("-XDdetails:source",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    46
            "for (int i = 0; i < 10; i++) {",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    47
            "System.out.println(s + i);");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    48
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    49
        test("-XDdetails:tryBlocks",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    50
                "try[0]",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    51
                "end try[0]",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    52
                "catch[0]");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    53
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    54
        test("-XDdetails:stackMaps",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    55
                "StackMap locals:  this java/lang/String int",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    56
                "StackMap stack:  java/lang/Throwable");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    57
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    58
        test("-XDdetails:localVariables",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    59
                "start local 3 // java.util.List list",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    60
                "end local 3 // java.util.List list");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    61
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    62
        test("-XDdetails:localVariableTypes",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    63
                "start generic local 3 // java.util.List<java.lang.String> list",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    64
                "end generic local 3 // java.util.List<java.lang.String> list");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    65
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    66
        if (errors > 0)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    67
            throw new Error(errors + " errors found");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    68
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    69
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    70
    void test(String option, String... expect) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    71
        String[] args = {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    72
            "-c",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    73
            "-classpath",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    74
            testSrc + File.pathSeparator + testClasses,
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    75
            option,
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    76
            "Test"
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    77
        };
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    78
        StringWriter sw = new StringWriter();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    79
        PrintWriter pw = new PrintWriter(sw);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    80
        int rc = com.sun.tools.javap.Main.run(args, pw);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    81
        if (rc != 0) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    82
            error("unexpected return code from javap: " + rc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    83
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    84
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    85
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    86
        String out = sw.toString();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    87
        System.out.println(out);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    88
        for (String e: expect) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    89
            if (!out.contains(e))
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    90
                error("Not found: " + e);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    91
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    92
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    93
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    94
    void error(String msg) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    95
        System.err.println("Error: " + msg);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    96
        errors++;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    97
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    98
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    99
    private int errors;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   100
    private String testSrc = System.getProperty("test.src", ".");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   101
    private String testClasses = System.getProperty("test.classes", ".");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   102
}
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   103
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   104
class Test {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   105
    void m(String s) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   106
        for (int i = 0; i < 10; i++) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   107
            try {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   108
                List<String> list = null;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   109
                System.out.println(s + i);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   110
            } catch (NullPointerException e) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   111
                System.out.println("catch NPE");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   112
            } finally {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   113
                System.out.println("finally");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   114
            }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   115
        }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   116
    }
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   117
}