langtools/src/share/classes/sun/tools/javap/JavapPrinter.java
author jjg
Tue, 20 Jan 2009 18:23:13 -0800
changeset 1870 57a1138dffc8
parent 1789 7ac8c0815000
child 2212 1d3dc0e0ba0c
permissions -rw-r--r--
6795903: fix latent build warnings in langtools repository Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
735
372aa565a221 6719955: Update copyright year
xdono
parents: 656
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
package sun.tools.javap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import static sun.tools.javap.RuntimeConstants.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * Program to print information about class files
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * @author  Sucheta Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
public class JavapPrinter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
    JavapEnvironment env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
    ClassData cls;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    byte[] code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    String lP= "";
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    PrintWriter out;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    public JavapPrinter(InputStream cname, PrintWriter out, JavapEnvironment env){
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        this.out = out;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
        this.cls =  new ClassData(cname);
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
        this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     *  Entry point to print class file information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    public void print(){
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
        printclassHeader();
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        printfields();
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        printMethods();
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        printend();
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * Print a description of the class (not members).
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    public void printclassHeader(){
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        String srcName="";
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        if ((srcName = cls.getSourceName()) != "null") // requires debug info
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
            out.println("Compiled from " + javaclassname(srcName));
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        if(cls.isInterface())   {
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
            // The only useful access modifier of an interface is
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
            // public; interfaces are always marked as abstract and
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
            // cannot be final.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
            out.print((cls.isPublic()?"public ":"") +
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
                      "interface "+ javaclassname(cls.getClassName()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        else if(cls.isClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
            String []accflags =  cls.getAccess();
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            printAccess(accflags);
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
            out.print("class "+ javaclassname(cls.getClassName()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            if(cls.getSuperClassName() != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                out.print(" extends " + javaclassname(cls.getSuperClassName()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        String []interfacelist =  cls.getSuperInterfaces();
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        if(interfacelist.length > 0){
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
            if(cls.isClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                out.print(" implements ");
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
            else if(cls.isInterface()){
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
                out.print(" extends ");
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            for(int j = 0; j < interfacelist.length; j++){
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
                out.print(javaclassname(interfacelist[j]));
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
                if((j+1) < interfacelist.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                    out.print(",");
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        // Print class attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        if((env.showallAttr) || (env.showVerbose)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
            printClassAttributes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        // Print verbose output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        if(env.showVerbose){
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            printverbosecls();
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        out.println("{");
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * Print verbose output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    public void printverbosecls(){
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        out.println("  minor version: "+cls.getMinor_version());
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        out.println("  major version: "+cls.getMajor_version());
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        out.println("  Constant pool:");
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        printcp();
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        env.showallAttr = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * Print class attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    public void printClassAttributes(){
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        AttrData[] clsattrs = cls.getAttributes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        for(int i = 0; i < clsattrs.length; i++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            String clsattrname = clsattrs[i].getAttrName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            if(clsattrname.equals("SourceFile")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
                out.println("  SourceFile: "+ cls.getSourceName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
            }else if(clsattrname.equals("InnerClasses")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
                printInnerClasses();
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            }else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                printAttrData(clsattrs[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * Print the fields
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    public void printfields(){
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        FieldData[] fields = cls.getFields();
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        for(int f = 0; f < fields.length; f++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
            String[] accflags = fields[f].getAccess();
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
            if(checkAccess(accflags)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                     ||  env.showInternalSigs || env.showallAttr)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                    out.print("    ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                printAccess(accflags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                out.println(fields[f].getType()+" " +fields[f].getName()+";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                if (env.showInternalSigs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                    out.println("  Signature: " + (fields[f].getInternalSig()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                // print field attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                if (env.showallAttr){
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                    printFieldAttributes(fields[f]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                if((env.showDisassembled) || (env.showLineAndLocal)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                    out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /* print field attribute information. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    public void printFieldAttributes(FieldData field){
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 735
diff changeset
   178
        Vector<?> fieldattrs = field.getAttributes();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        for(int j = 0; j < fieldattrs.size(); j++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            String fieldattrname = ((AttrData)fieldattrs.elementAt(j)).getAttrName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            if(fieldattrname.equals("ConstantValue")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
                printConstantValue(field);
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            }else if (fieldattrname.equals("Deprecated")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                out.println("Deprecated: "+ field.isDeprecated());
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            }else if (fieldattrname.equals("Synthetic")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                out.println("  Synthetic: "+ field.isSynthetic());
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
            }else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                printAttrData((AttrData)fieldattrs.elementAt(j));
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * Print the methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    public void printMethods(){
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        MethodData[] methods = cls.getMethods();
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        for(int m = 0; m < methods.length; m++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
            String[] accflags = methods[m].getAccess();
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            if(checkAccess(accflags)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
                     ||  env.showInternalSigs || env.showallAttr)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
                    out.print("    ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                printMethodSignature(methods[m], accflags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                printExceptions(methods[m]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                out.println(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
                // Print internal signature of method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                if (env.showInternalSigs){
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                    out.println("  Signature: " + (methods[m].getInternalSig()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                //Print disassembled code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
                if(env.showDisassembled && ! env.showallAttr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                    printcodeSequence(methods[m]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                    printExceptionTable(methods[m]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
                    out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                // Print line and local variable attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                if (env.showLineAndLocal) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                    printLineNumTable(methods[m]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                    printLocVarTable(methods[m]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                    out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
                // Print  method attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
                if (env.showallAttr){
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
                    printMethodAttributes(methods[m]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     * Print method signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    public void printMethodSignature(MethodData method, String[] accflags){
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        printAccess(accflags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        if((method.getName()).equals("<init>")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            out.print(javaclassname(cls.getClassName()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
            out.print(method.getParameters());
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        }else if((method.getName()).equals("<clinit>")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            out.print("{}");
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        }else{
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            out.print(method.getReturnType()+" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            out.print(method.getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            out.print(method.getParameters());
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     * print method attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    public void printMethodAttributes(MethodData method){
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 735
diff changeset
   259
        Vector<?> methodattrs = method.getAttributes();
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 735
diff changeset
   260
        Vector<?> codeattrs =  method.getCodeAttributes();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        for(int k = 0; k < methodattrs.size(); k++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            String methodattrname = ((AttrData)methodattrs.elementAt(k)).getAttrName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
            if(methodattrname.equals("Code")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
                printcodeSequence(method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
                printExceptionTable(method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                for(int c = 0; c < codeattrs.size(); c++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
                    String codeattrname = ((AttrData)codeattrs.elementAt(c)).getAttrName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                    if(codeattrname.equals("LineNumberTable")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                        printLineNumTable(method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                    }else if(codeattrname.equals("LocalVariableTable")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
                        printLocVarTable(method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
                    }else if(codeattrname.equals("StackMapTable")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
                        // Java SE JSR 202 stack map tables
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
                        printStackMapTable(method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
                    }else if(codeattrname.equals("StackMap")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                        // Java ME CLDC stack maps
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
                        printStackMap(method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                        printAttrData((AttrData)codeattrs.elementAt(c));
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            }else if(methodattrname.equals("Exceptions")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                out.println("  Exceptions: ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                printExceptions(method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            }else if (methodattrname.equals("Deprecated")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                out.println("  Deprecated: "+ method.isDeprecated());
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            }else if (methodattrname.equals("Synthetic")){
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
                out.println("  Synthetic: "+ method.isSynthetic());
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            }else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
                printAttrData((AttrData)methodattrs.elementAt(k));
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     * Print exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    public void printExceptions(MethodData method){
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        int []exc_index_table = method.get_exc_index_table();
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        if (exc_index_table != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                 ||  env.showInternalSigs || env.showallAttr)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                out.print("    ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            out.print("   throws ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            int k;
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
            int l = exc_index_table.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
            for (k=0; k<l; k++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
                out.print(javaclassname(cls.getClassName(exc_index_table[k])));
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                if (k<l-1) out.print(", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     * Print code sequence.
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    public void  printcodeSequence(MethodData method){
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        code = method.getCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        if(code != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            out.println("  Code:");
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
            if(env.showVerbose){
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
                printVerboseHeader(method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            for (int pc=0; pc < code.length; ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                out.print("   "+pc+":\t");
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                pc=pc+printInstr(pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
     * Print instructions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
    public int printInstr(int pc){
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        int opcode = getUbyte(pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        int opcode2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        String mnem;
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        switch (opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
        case opc_nonpriv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
        case opc_priv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
            opcode2 = getUbyte(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            mnem=Tables.opcName((opcode<<8)+opcode2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            if (mnem==null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
                // assume all (even nonexistent) priv and nonpriv instructions
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
                // are 2 bytes long
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                mnem=Tables.opcName(opcode)+" "+opcode2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            out.print(mnem);
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
            return 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        case opc_wide: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            opcode2 = getUbyte(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            mnem=Tables.opcName((opcode<<8)+opcode2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            if (mnem==null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                // nonexistent opcode - but we have to print something
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                out.print("bytecode "+opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            out.print(mnem+" "+getUShort(pc+2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
            if (opcode2==opc_iinc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                out.print(", "+getShort(pc+4));
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
                return 6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            return 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        mnem=Tables.opcName(opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        if (mnem==null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
            // nonexistent opcode - but we have to print something
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
            out.print("bytecode "+opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
            return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        if (opcode>opc_jsr_w) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
            // pseudo opcodes should be printed as bytecodes
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            out.print("bytecode "+opcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
            return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
        out.print(Tables.opcName(opcode));
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        switch (opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        case opc_aload: case opc_astore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        case opc_fload: case opc_fstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        case opc_iload: case opc_istore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        case opc_lload: case opc_lstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        case opc_dload: case opc_dstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        case opc_ret:
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            out.print("\t"+getUbyte(pc+1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
            return  2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        case opc_iinc:
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
            out.print("\t"+getUbyte(pc+1)+", "+getbyte(pc+2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
            return  3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        case opc_tableswitch:{
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            int tb=align(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            int default_skip = getInt(tb); /* default skip pamount */
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            int low = getInt(tb+4);
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            int high = getInt(tb+8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
            int count = high - low;
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            out.print("{ //"+low+" to "+high);
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            for (int i = 0; i <= count; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
                out.print( "\n\t\t" + (i+low) + ": "+lP+(pc+getInt(tb+12+4*i))+";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }");
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            return tb-pc+16+count*4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        case opc_lookupswitch:{
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
            int tb=align(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
            int default_skip = getInt(tb);
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            int npairs = getInt(tb+4);
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            out.print("{ //"+npairs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
            for (int i = 1; i <= npairs; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                out.print("\n\t\t"+getInt(tb+i*8)
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
                                 +": "+lP+(pc+getInt(tb+4+i*8))+";"
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
                                 );
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
            out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }");
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
            return tb-pc+(npairs+1)*8;
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        case opc_newarray:
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            int type=getUbyte(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
            switch (type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            case T_BOOLEAN:out.print(" boolean");break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
            case T_BYTE:   out.print(" byte");   break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            case T_CHAR:   out.print(" char");   break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            case T_SHORT:  out.print(" short");  break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
            case T_INT:    out.print(" int");    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            case T_LONG:   out.print(" long");   break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
            case T_FLOAT:  out.print(" float");  break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
            case T_DOUBLE: out.print(" double"); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            case T_CLASS:  out.print(" class"); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
            default:       out.print(" BOGUS TYPE:"+type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
            return 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        case opc_anewarray: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
            int index =  getUShort(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
            out.print("\t#"+index+"; //");
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
            PrintConstant(index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
            return 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        case opc_sipush:
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
            out.print("\t"+getShort(pc+1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            return 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        case opc_bipush:
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
            out.print("\t"+getbyte(pc+1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
            return 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        case opc_ldc: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
            int index = getUbyte(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            out.print("\t#"+index+"; //");
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            PrintConstant(index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            return 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        case opc_ldc_w: case opc_ldc2_w:
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
        case opc_instanceof: case opc_checkcast:
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        case opc_new:
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        case opc_putstatic: case opc_getstatic:
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        case opc_putfield: case opc_getfield:
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        case opc_invokevirtual:
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        case opc_invokespecial:
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        case opc_invokestatic: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
            int index = getUShort(pc+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
            out.print("\t#"+index+"; //");
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
            PrintConstant(index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
            return 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
        case opc_invokeinterface: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
            int index = getUShort(pc+1), nargs=getUbyte(pc+3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
            out.print("\t#"+index+",  "+nargs+"; //");
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
            PrintConstant(index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
            return 5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        case opc_multianewarray: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
            int index = getUShort(pc+1), dimensions=getUbyte(pc+3);
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
            out.print("\t#"+index+",  "+dimensions+"; //");
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
            PrintConstant(index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
            return 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        case opc_jsr: case opc_goto:
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        case opc_ifeq: case opc_ifge: case opc_ifgt:
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        case opc_ifle: case opc_iflt: case opc_ifne:
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpge:
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        case opc_if_icmpgt: case opc_if_icmple: case opc_if_icmplt:
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        case opc_if_acmpeq: case opc_if_acmpne:
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        case opc_ifnull: case opc_ifnonnull:
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
            out.print("\t"+lP+(pc + getShort(pc+1)) );
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
            return 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
        case opc_jsr_w:
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        case opc_goto_w:
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
            out.print("\t"+lP+(pc + getInt(pc+1)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
            return 5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
            return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
     * Print code attribute details.
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
    public void printVerboseHeader(MethodData method) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        int argCount = method.getArgumentlength();
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
        if (!method.isStatic())
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
            ++argCount;  // for 'this'
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        out.println("   Stack=" + method.getMaxStack()
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
                           + ", Locals=" + method.getMaxLocals()
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
                           + ", Args_size=" + argCount);
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
     * Print the exception table for this method code
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
    void printExceptionTable(MethodData method){//throws IOException
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 735
diff changeset
   522
        Vector<?> exception_table = method.getexception_table();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
        if (exception_table.size() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            out.println("  Exception table:");
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            out.println("   from   to  target type");
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            for (int idx = 0; idx < exception_table.size(); ++idx) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
                TrapData handler = (TrapData)exception_table.elementAt(idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
                printFixedWidthInt(handler.start_pc, 6);
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
                printFixedWidthInt(handler.end_pc, 6);
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
                printFixedWidthInt(handler.handler_pc, 6);
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
                out.print("   ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                int catch_cpx = handler.catch_cpx;
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
                if (catch_cpx == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
                    out.println("any");
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                }else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
                    out.print("Class ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                    out.println(cls.getClassName(catch_cpx));
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
                    out.println("");
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
     * Print LineNumberTable attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
    public void printLineNumTable(MethodData method) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        int numlines = method.getnumlines();
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 735
diff changeset
   549
        Vector<?> lin_num_tb = method.getlin_num_tb();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
        if( lin_num_tb.size() > 0){
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
            out.println("  LineNumberTable: ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            for (int i=0; i<numlines; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
                LineNumData linnumtb_entry=(LineNumData)lin_num_tb.elementAt(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                out.println("   line " + linnumtb_entry.line_number + ": "
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
                               + linnumtb_entry.start_pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
     * Print LocalVariableTable attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
    public void printLocVarTable(MethodData method){
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        int siz = method.getloc_var_tbsize();
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        if(siz > 0){
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            out.println("  LocalVariableTable: ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
            out.print("   ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            out.println("Start  Length  Slot  Name   Signature");
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
        }
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 735
diff changeset
   571
        Vector<?> loc_var_tb = method.getloc_var_tb();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
        for (int i=0; i<siz; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
            LocVarData entry=(LocVarData)loc_var_tb.elementAt(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
            out.println("   "+entry.start_pc+"      "+entry.length+"      "+
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
                               entry.slot+"    "+cls.StringValue(entry.name_cpx)  +
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
                               "       "+cls.StringValue(entry.sig_cpx));
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
     * Print StackMap attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
    public void printStackMap(MethodData method) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        StackMapData[] stack_map_tb = method.getStackMap();
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        int number_of_entries = stack_map_tb.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        if (number_of_entries > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
            out.println("  StackMap: number_of_entries = " + number_of_entries);
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
            for (StackMapData frame : stack_map_tb) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
                frame.print(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
       out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
     * Print StackMapTable attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
    public void printStackMapTable(MethodData method) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        StackMapTableData[] stack_map_tb = method.getStackMapTable();
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        int number_of_entries = stack_map_tb.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
        if (number_of_entries > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            out.println("  StackMapTable: number_of_entries = " + number_of_entries);
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
            for (StackMapTableData frame : stack_map_tb) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
                frame.print(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
    void printMap(String name, int[] map) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
        out.print(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
        for (int i=0; i<map.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
            int fulltype = map[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            int type = fulltype & 0xFF;
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
            int argument = fulltype >> 8;
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
            switch (type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
                case ITEM_Object:
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
                    out.print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
                    PrintConstant(argument);
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
                case ITEM_NewObject:
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
                    out.print(" " + Tables.mapTypeName(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
                    out.print(" " + argument);
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
                    out.print(" " + Tables.mapTypeName(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            out.print( (i==(map.length-1)? ' ' : ','));
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
        out.println("]");
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
     * Print ConstantValue attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
    public void printConstantValue(FieldData field){
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        out.print("  Constant value: ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        int cpx = (field.getConstantValueIndex());
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        byte tag=0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
            tag=cls.getTag(cpx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
        } catch (IndexOutOfBoundsException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
            out.print("Error:");
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
        switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
        case CONSTANT_METHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
        case CONSTANT_INTERFACEMETHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
        case CONSTANT_FIELD: {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   656
            CPX2 x = cls.getCpoolEntry(cpx);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
            if (x.cpx1 == cls.getthis_cpx()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
                // don't print class part for local references
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
                cpx=x.cpx2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
        out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx));
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
     * Print InnerClass attribute information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
    public void printInnerClasses(){//throws ioexception
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
        InnerClassData[] innerClasses = cls.getInnerClasses();
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
        if(innerClasses != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
            if(innerClasses.length > 0){
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
                out.print("  ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
                out.println("InnerClass: ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
                for(int i = 0 ; i < innerClasses.length; i++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
                    out.print("   ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
                    //access
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                    String[] accflags = innerClasses[i].getAccess();
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                    if(checkAccess(accflags)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
                        printAccess(accflags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
                        if (innerClasses[i].inner_name_index!=0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
                            out.print("#"+innerClasses[i].inner_name_index+"= ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
                        out.print("#"+innerClasses[i].inner_class_info_index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
                        if (innerClasses[i].outer_class_info_index!=0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
                            out.print(" of #"+innerClasses[i].outer_class_info_index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
                        out.print("; //");
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
                        if (innerClasses[i].inner_name_index!=0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
                            out.print(cls.getName(innerClasses[i].inner_name_index)+"=");
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
                        PrintConstant(innerClasses[i].inner_class_info_index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
                        if (innerClasses[i].outer_class_info_index!=0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
                            out.print(" of ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
                            PrintConstant(innerClasses[i].outer_class_info_index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
                        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
     * Print constant pool information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
    public void printcp(){
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
        int cpx = 1 ;
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
        while (cpx < cls.getCpoolCount()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
            out.print("const #"+cpx+" = ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
            cpx+=PrintlnConstantEntry(cpx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
     * Print constant pool entry information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
     */
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   722
    @SuppressWarnings("fallthrough")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
    public int PrintlnConstantEntry(int cpx) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        int size=1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
        byte tag=0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
            tag=cls.getTag(cpx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
        } catch (IndexOutOfBoundsException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
            out.println("  <Incorrect CP index>");
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
            return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        out.print(cls.StringTag(cpx)+"\t");
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
        Object x=cls.getCpoolEntryobj(cpx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
        if (x==null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
            switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
            case CONSTANT_LONG:
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
            case CONSTANT_DOUBLE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
                size=2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
            out.println("null;");
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
            return size;
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
        String str=cls.StringValue(cpx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
        switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
        case CONSTANT_CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
        case CONSTANT_STRING:
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
            out.println("#"+(((CPX)x).cpx)+";\t//  "+str);
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
        case CONSTANT_FIELD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
        case CONSTANT_METHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
        case CONSTANT_INTERFACEMETHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
            out.println("#"+((CPX2)x).cpx1+".#"+((CPX2)x).cpx2+";\t//  "+str);
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
        case CONSTANT_NAMEANDTYPE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
            out.println("#"+((CPX2)x).cpx1+":#"+((CPX2)x).cpx2+";//  "+str);
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
        case CONSTANT_LONG:
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
        case CONSTANT_DOUBLE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
            size=2;
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 1789
diff changeset
   761
            // fall through
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
            out.println(str+";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
        return size;
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
     * Checks access of class, field or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
    public boolean checkAccess(String accflags[]){
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
        boolean ispublic = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
        boolean isprotected = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
        boolean isprivate = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
        boolean ispackage = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
        for(int i= 0; i < accflags.length; i++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
            if(accflags[i].equals("public")) ispublic = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            else if (accflags[i].equals("protected")) isprotected = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
            else if (accflags[i].equals("private")) isprivate = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
        if(!(ispublic || isprotected || isprivate)) ispackage = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
        if((env.showAccess == env.PUBLIC) && (isprotected || isprivate || ispackage)) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
        else if((env.showAccess == env.PROTECTED) && (isprivate || ispackage)) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
        else if((env.showAccess == env.PACKAGE) && (isprivate)) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
        else return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
     * Prints access of class, field or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
    public void printAccess(String []accflags){
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
        for(int j = 0; j < accflags.length; j++){
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            out.print(accflags[j]+" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
     * Print an integer so that it takes 'length' characters in
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
     * the output.  Temporary until formatting code is stable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
    public void printFixedWidthInt(long x, int length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
        CharArrayWriter baStream = new CharArrayWriter();
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
        PrintWriter pStream = new PrintWriter(baStream);
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
        pStream.print(x);
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
        String str = baStream.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
        for (int cnt = length - str.length(); cnt > 0; --cnt)
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
            out.print(' ');
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        out.print(str);
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
    protected int getbyte (int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
        return code[pc];
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
    protected int getUbyte (int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
        return code[pc]&0xFF;
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
    int getShort (int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
        return (code[pc]<<8) | (code[pc+1]&0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
    int getUShort (int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
        return ((code[pc]<<8) | (code[pc+1]&0xFF))&0xFFFF;
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
    protected int getInt (int pc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
        return (getShort(pc)<<16) | (getShort(pc+2)&0xFFFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
     * Print constant value at that index.
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
    void PrintConstant(int cpx) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
        if (cpx==0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
            out.print("#0");
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
        byte tag=0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
            tag=cls.getTag(cpx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
        } catch (IndexOutOfBoundsException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
            out.print("#"+cpx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
        switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
        case CONSTANT_METHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
        case CONSTANT_INTERFACEMETHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
        case CONSTANT_FIELD: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
            // CPX2 x=(CPX2)(cpool[cpx]);
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   856
            CPX2 x = cls.getCpoolEntry(cpx);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
            if (x.cpx1 == cls.getthis_cpx()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
                // don't print class part for local references
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
                cpx=x.cpx2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
        out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx));
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
    protected static int  align (int n) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
        return (n+3) & ~3 ;
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
    public void printend(){
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
        out.println("}");
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
    public String javaclassname(String name){
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
        return name.replace('/','.');
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
     * Print attribute data in hex.
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
    public void printAttrData(AttrData attr){
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
        byte []data = attr.getData();
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
        int i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
        int j = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
        out.print("  "+attr.getAttrName()+": ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
        out.println("length = " + cls.toHex(attr.datalen));
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
        out.print("   ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
        while (i < data.length){
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
            String databytestring = cls.toHex(data[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
            if(databytestring.equals("0x")) out.print("00");
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
            else if(databytestring.substring(2).length() == 1){
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
                out.print("0"+databytestring.substring(2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
            } else{
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
                out.print(databytestring.substring(2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
             j++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
            if(j == 16) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
                out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
                out.print("   ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
                j = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
            else out.print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
            i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
}