6868539: javap should use current names for constant pool tags

Sat, 08 Aug 2009 17:56:37 -0700

author
jjg
date
Sat, 08 Aug 2009 17:56:37 -0700
changeset 355
961dc3acdb06
parent 354
cba827f72977
child 356
d5f6c475f475
child 364
91852fb12e2e

6868539: javap should use current names for constant pool tags
Reviewed-by: ksrini

src/share/classes/com/sun/tools/javap/CodeWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/ConstantWriter.java file | annotate | diff | comparison | revisions
test/tools/javap/T6868539.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javap/CodeWriter.java	Sat Aug 08 17:50:57 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javap/CodeWriter.java	Sat Aug 08 17:56:37 2009 -0700
     1.3 @@ -117,7 +117,7 @@
     1.4      }
     1.5  
     1.6      public void writeInstr(Instruction instr) {
     1.7 -        print(String.format("%4d: %-12s ", instr.getPC(), instr.getMnemonic()));
     1.8 +        print(String.format("%4d: %-13s ", instr.getPC(), instr.getMnemonic()));
     1.9          instr.accept(instructionPrinter, null);
    1.10          println();
    1.11      }
     2.1 --- a/src/share/classes/com/sun/tools/javap/ConstantWriter.java	Sat Aug 08 17:50:57 2009 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javap/ConstantWriter.java	Sat Aug 08 17:56:37 2009 -0700
     2.3 @@ -134,10 +134,10 @@
     2.4          int width = String.valueOf(constant_pool.size()).length() + 1;
     2.5          int cpx = 1;
     2.6          while (cpx < constant_pool.size()) {
     2.7 -            print(String.format("const %" + width + "s", ("#" + cpx)));
     2.8 +            print(String.format("%" + width + "s", ("#" + cpx)));
     2.9              try {
    2.10                  CPInfo cpInfo = constant_pool.get(cpx);
    2.11 -                print(String.format(" = %-15s ", tagName(cpInfo.getTag())));
    2.12 +                print(String.format(" = %-18s ", cpTagName(cpInfo)));
    2.13                  cpx += cpInfo.accept(v, null);
    2.14              } catch (ConstantPool.InvalidIndex ex) {
    2.15                  // should not happen
    2.16 @@ -178,10 +178,15 @@
    2.17          print(tagName(tag) + " " + stringValue(cpInfo));
    2.18      }
    2.19  
    2.20 +    String cpTagName(CPInfo cpInfo) {
    2.21 +        String n = cpInfo.getClass().getSimpleName();
    2.22 +        return n.replace("CONSTANT_", "").replace("_info", "");
    2.23 +    }
    2.24 +
    2.25      String tagName(int tag) {
    2.26          switch (tag) {
    2.27              case CONSTANT_Utf8:
    2.28 -                return "Asciz";
    2.29 +                return "Utf8";
    2.30              case CONSTANT_Integer:
    2.31                  return "int";
    2.32              case CONSTANT_Float:
    2.33 @@ -203,7 +208,7 @@
    2.34              case CONSTANT_NameAndType:
    2.35                  return "NameAndType";
    2.36              default:
    2.37 -                return "unknown tag";
    2.38 +                return "(unknown tag)";
    2.39          }
    2.40      }
    2.41  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javap/T6868539.java	Sat Aug 08 17:56:37 2009 -0700
     3.3 @@ -0,0 +1,96 @@
     3.4 +/*
     3.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.24 + * have any questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug 6868539 6868548
    3.30 + * @summary javap should use current names for constant pool entries,
    3.31 + *              remove spurious ';' from constant pool entries
    3.32 + */
    3.33 +
    3.34 +import java.io.*;
    3.35 +import java.util.*;
    3.36 +
    3.37 +public class T6868539
    3.38 +
    3.39 +{
    3.40 +    public static void main(String... args) {
    3.41 +        new T6868539().run();
    3.42 +    }
    3.43 +
    3.44 +    void run() {
    3.45 +        verify("T6868539", "Utf8 +java/lang/String");                                   // 1: Utf8
    3.46 +                                                                                        // 2: currently unused
    3.47 +        verify("T6868539", "Integer +123456");                                          // 3: Integer
    3.48 +        verify("T6868539", "Float +123456.0f");                                         // 4: Float
    3.49 +        verify("T6868539", "Long +123456l");                                            // 5: Long
    3.50 +        verify("T6868539", "Double +123456.0d");                                        // 6: Double
    3.51 +        verify("T6868539", "Class +#[0-9]+ +// + T6868539");                            // 7: Class
    3.52 +        verify("T6868539", "String +#[0-9]+ +// + not found");                          // 8: String
    3.53 +        verify("T6868539", "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I");       // 9: Fieldref
    3.54 +        verify("T6868539", "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V");   // 10: Methodref
    3.55 +        verify("T6868539", "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
    3.56 +                                                                                        // 11: InterfaceMethodref
    3.57 +        verify("T6868539", "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V");            // 12: NameAndType
    3.58 +        if (errors > 0)
    3.59 +            throw new Error(errors + " found.");
    3.60 +    }
    3.61 +
    3.62 +    void verify(String className, String... expects) {
    3.63 +        String output = javap(className);
    3.64 +        for (String expect: expects) {
    3.65 +            if (!output.matches("(?s).*" + expect + ".*"))
    3.66 +                error(expect + " not found");
    3.67 +        }
    3.68 +    }
    3.69 +
    3.70 +    void error(String msg) {
    3.71 +        System.err.println(msg);
    3.72 +        errors++;
    3.73 +    }
    3.74 +
    3.75 +    int errors;
    3.76 +
    3.77 +    String javap(String className) {
    3.78 +        String testClasses = System.getProperty("test.classes", ".");
    3.79 +        StringWriter sw = new StringWriter();
    3.80 +        PrintWriter out = new PrintWriter(sw);
    3.81 +        String[] args = { "-v", "-classpath", testClasses, className };
    3.82 +        int rc = com.sun.tools.javap.Main.run(args, out);
    3.83 +        if (rc != 0)
    3.84 +            throw new Error("javap failed. rc=" + rc);
    3.85 +        out.close();
    3.86 +        String output = sw.toString();
    3.87 +        System.out.println("class " + className);
    3.88 +        System.out.println(output);
    3.89 +        return output;
    3.90 +    }
    3.91 +
    3.92 +    int i = 123456;
    3.93 +    float f = 123456.f;
    3.94 +    double d = 123456.;
    3.95 +    long l = 123456L;
    3.96 +
    3.97 +    void m(Runnable r) { r.run(); }
    3.98 +}
    3.99 +

mercurial