langtools/test/tools/javap/T8032814.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 22693 d9f55dfc5f3b
child 30730 d3ce7619db2c
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22693
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     1
/*
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     4
 *
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     8
 *
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    13
 * accompanied this code).
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    14
 *
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    18
 *
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    21
 * questions.
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    22
 */
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    23
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    24
/*
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    25
 * @test
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    26
 * @bug 8032814
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    27
 * @summary LineNumberTable/LocalVariableTable tables duplication for the
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    28
 *          "-v -l" combination of options
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    29
 * @compile -g T8032814.java
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    30
 * @run main T8032814
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    31
 */
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    32
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    33
import java.io.*;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    34
import java.util.*;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    35
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    36
public class T8032814 {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    37
    public static void main(String... args) throws Exception {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    38
        new T8032814().run();
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    39
    }
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    40
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    41
    void run() throws Exception {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    42
        Class<?> clazz = T8032814.class;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    43
        int count = clazz.getDeclaredConstructors().length
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    44
                + clazz.getDeclaredMethods().length;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    45
        test(clazz, 0);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    46
        test(clazz, count, "-v");
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    47
        test(clazz, count, "-l");
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    48
        test(clazz, count, "-v", "-l");
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    49
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    50
        if (errors > 0)
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    51
            throw new Exception(errors + " errors occurred");
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    52
    }
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    53
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    54
    void test(Class<?> clazz, int expectedCount, String... opts) throws Exception {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    55
        System.err.println("test class " + clazz.getName() + " " + Arrays.asList(opts) + ": expect: " + expectedCount);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    56
        List<String> args = new ArrayList<String>();
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    57
        args.addAll(Arrays.asList(opts));
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    58
        args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes")));
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    59
        args.add(clazz.getName());
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    60
        StringWriter sw = new StringWriter();
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    61
        PrintWriter pw = new PrintWriter(sw);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    62
        int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    63
        pw.close();
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    64
        String out = sw.toString();
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    65
        if (rc != 0)
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    66
            throw new Exception("javap failed unexpectedly: rc=" + rc);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    67
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    68
        int lntCount = 0, lvtCount = 0;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    69
        for (String line: out.split("[\r\n]+")) {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    70
            if (line.matches("^ *LineNumberTable:$"))
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    71
                lntCount++;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    72
            if (line.matches("^ *LocalVariableTable:$"))
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    73
                lvtCount++;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    74
        }
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    75
        checkEqual("LineNumberTable", lntCount, expectedCount);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    76
        checkEqual("LocalVariableTable", lvtCount, expectedCount);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    77
    }
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    78
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    79
    void checkEqual(String attr, int found, int expect) {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    80
        if (found != expect) {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    81
            error("Unexpected number of occurrences of " + attr + "\n" +
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    82
                "found: " + found + ", expected: " + expect);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    83
        }
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    84
    }
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    85
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    86
    void error(String msg) {
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    87
        System.err.println("Error: " + msg);
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    88
        errors++;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    89
    }
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    90
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    91
    int errors = 0;
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    92
}
d9f55dfc5f3b 8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
diff changeset
    93