langtools/test/tools/javap/T6824493.java
author jjg
Tue, 19 May 2009 11:50:54 -0700
changeset 2979 ea39317acd3d
child 5520 86e4b9a9da40
permissions -rw-r--r--
6824493: experimental support for additional info for instructions Reviewed-by: mcimadamore
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
/*
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    21
 * have any questions.
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
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    31
 * @compile -g T6824493.java
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    32
 * @run main T6824493
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    33
 */
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    34
public class T6824493 {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    35
    public static void main(String... args) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    36
        new T6824493().run();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    37
    }
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
    void run() {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    40
        // 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
    41
        // marker strings in the output that generally indicate the
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    42
        // presence of the expected output, without being as specific
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    43
        // as a full golden file test.
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    44
        test("-XDdetails:source",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    45
            "for (int i = 0; i < 10; i++) {",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    46
            "System.out.println(s + i);");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    47
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    48
        test("-XDdetails:tryBlocks",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    49
                "try[0]",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    50
                "end try[0]",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    51
                "catch[0]");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    52
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    53
        test("-XDdetails:stackMaps",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    54
                "StackMap locals:  this java/lang/String int",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    55
                "StackMap stack:  java/lang/Throwable");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    56
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    57
        test("-XDdetails:localVariables",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    58
                "start local 3 // java.util.List list",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    59
                "end local 3 // java.util.List list");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    60
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    61
        test("-XDdetails:localVariableTypes",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    62
                "start generic local 3 // java.util.List<java.lang.String> list",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    63
                "end generic local 3 // java.util.List<java.lang.String> list");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    64
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    65
        if (errors > 0)
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    66
            throw new Error(errors + " errors found");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    67
    }
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
    void test(String option, String... expect) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    70
        String[] args = {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    71
            "-c",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    72
            "-classpath",
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    73
            testSrc + File.pathSeparator + testClasses,
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    74
            option,
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    75
            "Test"
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    76
        };
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    77
        StringWriter sw = new StringWriter();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    78
        PrintWriter pw = new PrintWriter(sw);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    79
        int rc = com.sun.tools.javap.Main.run(args, pw);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    80
        if (rc != 0) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    81
            error("unexpected return code from javap: " + rc);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    82
            return;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    83
        }
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
        String out = sw.toString();
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    86
        System.out.println(out);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    87
        for (String e: expect) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    88
            if (!out.contains(e))
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    89
                error("Not found: " + e);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    90
        }
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
    void error(String msg) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    94
        System.err.println("Error: " + msg);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    95
        errors++;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    96
    }
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
    private int errors;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
    99
    private String testSrc = System.getProperty("test.src", ".");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   100
    private String testClasses = System.getProperty("test.classes", ".");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   101
}
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
class Test {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   104
    void m(String s) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   105
        for (int i = 0; i < 10; i++) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   106
            try {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   107
                List<String> list = null;
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   108
                System.out.println(s + i);
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   109
            } catch (NullPointerException e) {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   110
                System.out.println("catch NPE");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   111
            } finally {
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   112
                System.out.println("finally");
ea39317acd3d 6824493: experimental support for additional info for instructions
jjg
parents:
diff changeset
   113
            }
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
}