jdk/test/java/lang/instrument/ilib/ClassDump.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
package ilib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.DataOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.PrintWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.CharArrayWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class ClassDump implements RuntimeConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  public static void dump(Options opt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                                       ClassLoader loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                                       String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                                       byte[] classfileBuffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    ClassReaderWriter c = new ClassReaderWriter(classfileBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    (new ClassDump(className, c)).doit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static boolean verbose = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    final String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    final ClassReaderWriter c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final PrintStream output;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    int constantPoolCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int methodsCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    ClassDump(String className, ClassReaderWriter c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.c = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.output = System.err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    void doit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        c.copy(4 + 2 + 2); // magic min/maj version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        constantPoolCount = c.copyU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        // copy old constant pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        c.copyConstantPool(constantPoolCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        traceln("ConstantPool size: " + constantPoolCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        c.copy(2 + 2 + 2);  // access, this, super
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        int interfaceCount = c.copyU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        traceln("interfaceCount: " + interfaceCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        c.copy(interfaceCount * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        copyFields(); // fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        copyMethods(); // methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        int attrCount = c.copyU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        traceln("class attrCount: " + attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // copy the class attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        copyAttrs(attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    void copyFields() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        int count = c.copyU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            System.out.println("fields count: " + count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        for (int i = 0; i < count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            c.copy(6); // access, name, descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            int attrCount = c.copyU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                System.out.println("field attr count: " + attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            copyAttrs(attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    void copyMethods() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        methodsCount = c.copyU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            System.out.println("methods count: " + methodsCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        for (int i = 0; i < methodsCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            copyMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    void copyMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        int accessFlags = c.copyU2();// access flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        int nameIndex = c.copyU2();  // name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        checkIndex(nameIndex, "Method name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        String methodName = c.constantPoolString(nameIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        traceln("method: " + methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        int descriptorIndex = c.copyU2();                  // descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        checkIndex(descriptorIndex, "Method descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        int attrCount = c.copyU2();  // attribute count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            System.out.println("method attr count: " + attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        for (int i = 0; i < attrCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            copyAttrForMethod(methodName, accessFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    void copyAttrs(int attrCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        for (int i = 0; i < attrCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            copyAttr();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    void copyAttr() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        c.copy(2);             // name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        int len = c.copyU4();  // attr len
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            System.out.println("attr len: " + len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        c.copy(len);           // attribute info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    void copyAttrForMethod(String methodName, int accessFlags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        int nameIndex = c.copyU2();   // name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // check for Code attr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        checkIndex(nameIndex, "Method attr name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (nameIndex == c.codeAttributeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                copyCodeAttr(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            } catch (IOException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                System.err.println("Code Exception - " + exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            int len = c.copyU4();     // attr len
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            traceln("method attr len: " + len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            c.copy(len);              // attribute info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    void copyAttrForCode() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        int nameIndex = c.copyU2();   // name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        checkIndex(nameIndex, "Code attr name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        int len = c.copyU4();     // attr len
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        traceln("code attr len: " + len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        c.copy(len);              // attribute info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    void copyCodeAttr(String methodName) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        traceln("Code attr found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        int attrLength = c.copyU4();        // attr len
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        checkLength(attrLength, "Code attr length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        int maxStack = c.readU2();          // max stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        c.copyU2();                         // max locals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        int codeLength = c.copyU4();        // code length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        checkLength(codeLength, "Code length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        copyExceptionTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        int attrCount = c.copyU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        checkLength(attrCount, "Code attr count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        for (int i = 0; i < attrCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            copyAttrForCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Copy the exception table for this method code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    void copyExceptionTable() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        int tableLength = c.copyU2();   // exception table len
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        checkLength(tableLength, "Exception Table length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (tableLength > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            traceln();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            traceln("Exception table:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            traceln(" from:old/new  to:old/new target:old/new type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            for (int tcnt = tableLength; tcnt > 0; --tcnt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                int startPC = c.readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                int endPC = c.readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                int handlerPC = c.readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                int catchType = c.copyU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    traceFixedWidthInt(startPC, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    traceFixedWidthInt(endPC, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    traceFixedWidthInt(handlerPC, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    trace("    ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    if (catchType == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        traceln("any");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        traceln("" + catchType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private void checkIndex(int index, String comment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (index > constantPoolCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            output.println("ERROR BAD INDEX " + comment + " : " + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            traceln(comment + " : " + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    private void checkLength(int length, String comment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (length > c.inputBytes().length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            output.println("ERROR BAD LENGTH " + comment + " : " + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            traceln(comment + " : " + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private void trace(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            output.print(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private void traceln(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            output.println(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    private void traceln() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            output.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    private void trace(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            output.print(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Print an integer so that it takes 'length' characters in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * the output.  Temporary until formatting code is stable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private void traceFixedWidthInt(int x, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            CharArrayWriter baStream = new CharArrayWriter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            PrintWriter pStream = new PrintWriter(baStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            pStream.print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            String str = baStream.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            for (int cnt = length - str.length(); cnt > 0; --cnt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                trace(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            trace(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}