langtools/test/tools/javap/T6868539.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
parent 35424 96661d1df628
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
     2
 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     4
 *
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     8
 *
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    13
 * accompanied this code).
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    14
 *
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3553
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3553
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3553
diff changeset
    21
 * questions.
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    22
 */
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    23
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    24
/*
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    25
 * @test
23120
6e12870d6652 8035364: An extra space in the comments of constant pool entries
jjg
parents: 7681
diff changeset
    26
 * @bug 6868539 6868548 8035364
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    27
 * @summary javap should use current names for constant pool entries,
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    28
 *              remove spurious ';' from constant pool entries
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35424
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.javap
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    30
 */
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    31
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    32
import java.io.*;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    33
import java.util.*;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    34
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    35
public class T6868539
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    36
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    37
{
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    38
    public static void main(String... args) {
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    39
        new T6868539().run();
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    40
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    41
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    42
    void run() {
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    43
        String output = javap("T6868539");
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    44
        verify(output, "Utf8 +java/lang/String");                                   // 1: Utf8
23120
6e12870d6652 8035364: An extra space in the comments of constant pool entries
jjg
parents: 7681
diff changeset
    45
                                                                                    // 2: currently unused
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    46
        verify(output, "Integer +123456");                                          // 3: Integer
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    47
        verify(output, "Float +123456.0f");                                         // 4: Float
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    48
        verify(output, "Long +123456l");                                            // 5: Long
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    49
        verify(output, "Double +123456.0d");                                        // 6: Double
23120
6e12870d6652 8035364: An extra space in the comments of constant pool entries
jjg
parents: 7681
diff changeset
    50
        verify(output, "Class +#[0-9]+ +// +T6868539");                             // 7: Class
6e12870d6652 8035364: An extra space in the comments of constant pool entries
jjg
parents: 7681
diff changeset
    51
        verify(output, "String +#[0-9]+ +// +not found");                           // 8: String
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    52
        verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I");       // 9: Fieldref
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    53
        verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V");   // 10: Methodref
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    54
        verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
23120
6e12870d6652 8035364: An extra space in the comments of constant pool entries
jjg
parents: 7681
diff changeset
    55
                                                                                    // 11: InterfaceMethodref
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    56
        verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V");            // 12: NameAndType
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    57
        if (errors > 0)
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    58
            throw new Error(errors + " found.");
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    59
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    60
35424
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 30846
diff changeset
    61
    String notFound = " not found";
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 30846
diff changeset
    62
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    63
    void verify(String output, String... expects) {
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    64
        for (String expect: expects) {
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    65
            if (!output.matches("(?s).*" + expect + ".*"))
35424
96661d1df628 8148483: JEP 280: Indify String Concatenation
shade
parents: 30846
diff changeset
    66
                error(expect + notFound);
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    67
        }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    68
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    69
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    70
    void error(String msg) {
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    71
        System.err.println(msg);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    72
        errors++;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    73
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    74
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    75
    int errors;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    76
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    77
    String javap(String className) {
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    78
        String testClasses = System.getProperty("test.classes", ".");
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    79
        StringWriter sw = new StringWriter();
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    80
        PrintWriter out = new PrintWriter(sw);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    81
        String[] args = { "-v", "-classpath", testClasses, className };
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    82
        int rc = com.sun.tools.javap.Main.run(args, out);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    83
        if (rc != 0)
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    84
            throw new Error("javap failed. rc=" + rc);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    85
        out.close();
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    86
        String output = sw.toString();
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    87
        System.out.println("class " + className);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    88
        System.out.println(output);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    89
        return output;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    90
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    91
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    92
    int i = 123456;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    93
    float f = 123456.f;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    94
    double d = 123456.;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    95
    long l = 123456L;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    96
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    97
    void m(Runnable r) { r.run(); }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    98
}
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    99