langtools/test/tools/javap/T6824493.java
changeset 2979 ea39317acd3d
child 5520 86e4b9a9da40
equal deleted inserted replaced
2978:a72220103e31 2979:ea39317acd3d
       
     1 /*
       
     2  * Copyright 2009 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 import java.io.*;
       
    25 import java.util.*;
       
    26 
       
    27 /*
       
    28  * @test
       
    29  * @bug 6824493
       
    30  * @summary experimental support for additional info for instructions
       
    31  * @compile -g T6824493.java
       
    32  * @run main T6824493
       
    33  */
       
    34 public class T6824493 {
       
    35     public static void main(String... args) {
       
    36         new T6824493().run();
       
    37     }
       
    38 
       
    39     void run() {
       
    40         // for each of the options, we run javap and check for some
       
    41         // marker strings in the output that generally indicate the
       
    42         // presence of the expected output, without being as specific
       
    43         // as a full golden file test.
       
    44         test("-XDdetails:source",
       
    45             "for (int i = 0; i < 10; i++) {",
       
    46             "System.out.println(s + i);");
       
    47 
       
    48         test("-XDdetails:tryBlocks",
       
    49                 "try[0]",
       
    50                 "end try[0]",
       
    51                 "catch[0]");
       
    52 
       
    53         test("-XDdetails:stackMaps",
       
    54                 "StackMap locals:  this java/lang/String int",
       
    55                 "StackMap stack:  java/lang/Throwable");
       
    56 
       
    57         test("-XDdetails:localVariables",
       
    58                 "start local 3 // java.util.List list",
       
    59                 "end local 3 // java.util.List list");
       
    60 
       
    61         test("-XDdetails:localVariableTypes",
       
    62                 "start generic local 3 // java.util.List<java.lang.String> list",
       
    63                 "end generic local 3 // java.util.List<java.lang.String> list");
       
    64 
       
    65         if (errors > 0)
       
    66             throw new Error(errors + " errors found");
       
    67     }
       
    68 
       
    69     void test(String option, String... expect) {
       
    70         String[] args = {
       
    71             "-c",
       
    72             "-classpath",
       
    73             testSrc + File.pathSeparator + testClasses,
       
    74             option,
       
    75             "Test"
       
    76         };
       
    77         StringWriter sw = new StringWriter();
       
    78         PrintWriter pw = new PrintWriter(sw);
       
    79         int rc = com.sun.tools.javap.Main.run(args, pw);
       
    80         if (rc != 0) {
       
    81             error("unexpected return code from javap: " + rc);
       
    82             return;
       
    83         }
       
    84 
       
    85         String out = sw.toString();
       
    86         System.out.println(out);
       
    87         for (String e: expect) {
       
    88             if (!out.contains(e))
       
    89                 error("Not found: " + e);
       
    90         }
       
    91     }
       
    92 
       
    93     void error(String msg) {
       
    94         System.err.println("Error: " + msg);
       
    95         errors++;
       
    96     }
       
    97 
       
    98     private int errors;
       
    99     private String testSrc = System.getProperty("test.src", ".");
       
   100     private String testClasses = System.getProperty("test.classes", ".");
       
   101 }
       
   102 
       
   103 class Test {
       
   104     void m(String s) {
       
   105         for (int i = 0; i < 10; i++) {
       
   106             try {
       
   107                 List<String> list = null;
       
   108                 System.out.println(s + i);
       
   109             } catch (NullPointerException e) {
       
   110                 System.out.println("catch NPE");
       
   111             } finally {
       
   112                 System.out.println("finally");
       
   113             }
       
   114         }
       
   115     }
       
   116 }