home *** CD-ROM | disk | FTP | other *** search
- package sun.tools.javap;
-
- import java.io.ByteArrayInputStream;
- import java.io.CharArrayWriter;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.io.PrintWriter;
- import sun.tools.java.BinaryAttribute;
- import sun.tools.java.BinaryCode;
- import sun.tools.java.BinaryConstantPool;
- import sun.tools.java.BinaryExceptionHandler;
- import sun.tools.java.ClassDeclaration;
- import sun.tools.java.Constants;
- import sun.tools.java.FieldDefinition;
- import sun.tools.java.Identifier;
- import sun.tools.java.MethodType;
- import sun.tools.java.RuntimeConstants;
- import sun.tools.util.ConstantPrinter;
-
- class JavaPBinaryCode extends BinaryCode implements Constants {
- private JavaPEnvironment env;
- private PrintWriter output;
- private byte[] codeBytes;
- private BinaryConstantPool cpool;
- private ConstantPrinter constPrint;
- private FieldDefinition fieldDef;
- private String methodName;
- private int offset;
-
- JavaPBinaryCode(byte[] var1, BinaryConstantPool var2, JavaPEnvironment var3, FieldDefinition var4) {
- super(var1, var2, var3);
- this.output = var3.output;
- this.codeBytes = ((BinaryCode)this).getCode();
- this.cpool = var2;
- this.constPrint = new ConstantPrinter(var2, var3, !var3.showBackwardCompatible);
- this.fieldDef = var4;
- this.methodName = var4.toString();
- }
-
- FieldDefinition fieldDefinition() {
- return this.fieldDef;
- }
-
- // $FF: renamed from: at (int) int
- private final int method_0(int var1) {
- return this.codeBytes[this.offset + var1] & 255;
- }
-
- private final int shortAt(int var1) {
- int var2 = this.offset + var1;
- return (this.codeBytes[var2] & 255) << 8 | this.codeBytes[var2 + 1] & 255;
- }
-
- private final int intAt(int var1, int var2) {
- int var3 = var1 + (var2 << 2);
- return this.codeBytes[var3] << 24 | (this.codeBytes[var3 + 1] & 255) << 16 | (this.codeBytes[var3 + 2] & 255) << 8 | this.codeBytes[var3 + 3] & 255;
- }
-
- private void printFixedWidthInt(int var1, int var2) {
- CharArrayWriter var3 = new CharArrayWriter();
- PrintWriter var4 = new PrintWriter(var3);
- var4.print(var1);
- String var5 = var3.toString();
-
- for(int var6 = var2 - var5.length(); var6 > 0; --var6) {
- this.output.print(' ');
- }
-
- this.output.print(var5);
- }
-
- void printCodeSequence() throws IOException {
- this.output.println("");
- this.output.println("Method " + this.methodName);
- this.offset = 0;
-
- while(this.offset < this.codeBytes.length) {
- int var1 = this.method_0(0);
- this.printFixedWidthInt(this.offset, 4);
- this.output.print(" ");
- if (var1 == 196) {
- var1 = this.method_0(1);
- this.output.print(RuntimeConstants.opcNames[var1] + "_w ");
- int var18 = this.shortAt(2);
- switch (var1) {
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- case 54:
- case 55:
- case 56:
- case 57:
- case 58:
- case 169:
- this.output.print(var18);
- this.offset += 4;
- break;
- case 132:
- this.output.print(var18 + " " + (short)this.shortAt(4));
- this.offset += 6;
- break;
- default:
- this.output.print("Invalid opcode");
- ++this.offset;
- }
- } else {
- this.output.print(RuntimeConstants.opcNames[var1]);
- switch (var1) {
- case 16:
- this.output.print(" " + (byte)this.method_0(1));
- this.offset += 2;
- break;
- case 17:
- this.output.print(" " + (short)this.shortAt(1));
- this.offset += 3;
- break;
- case 18:
- int var17 = this.method_0(1);
- this.output.print(" #" + var17 + " ");
- this.constPrint.printConstant(var17);
- this.offset += 2;
- break;
- case 19:
- case 20:
- case 178:
- case 179:
- case 180:
- case 181:
- case 182:
- case 183:
- case 184:
- case 187:
- case 192:
- case 193:
- int var16 = this.shortAt(1);
- this.output.print(" #" + var16 + " ");
- this.constPrint.printConstant(var16);
- this.offset += 3;
- break;
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- case 54:
- case 55:
- case 56:
- case 57:
- case 58:
- case 169:
- this.output.print(" " + this.method_0(1));
- this.offset += 2;
- break;
- case 132:
- this.output.print(" " + this.method_0(1) + " " + (byte)this.method_0(2));
- this.offset += 3;
- break;
- case 153:
- case 154:
- case 155:
- case 156:
- case 157:
- case 158:
- case 159:
- case 160:
- case 161:
- case 162:
- case 163:
- case 164:
- case 165:
- case 166:
- case 167:
- case 168:
- case 198:
- case 199:
- int var15 = this.offset + (short)this.shortAt(1);
- this.output.print(" " + var15);
- this.offset += 3;
- break;
- case 170:
- int var13 = this.offset + 1 + 3 & -4;
- int var19 = this.intAt(var13, 0);
- int var20 = this.intAt(var13, 1);
- int var21 = this.intAt(var13, 2);
- this.output.print(" " + var20 + " to " + var21 + ": default=");
- this.output.print(this.offset + var19);
- var13 += 12;
-
- for(int var22 = var20; var22 <= var21; ++var22) {
- this.output.println("");
- this.output.print('\t');
- this.printFixedWidthInt(var22, 5);
- this.output.print(": " + (this.offset + this.intAt(var13, var22 - var20)));
- }
-
- this.offset = var13 + (var21 - var20 + 1 << 2);
- break;
- case 171:
- int var11 = this.offset + 1 + 3 & -4;
- int var3 = this.intAt(var11, 0);
- int var4 = this.intAt(var11, 1);
- int var5 = var4 * 2;
- this.output.print(" " + var4);
- this.output.print(": default=" + (this.offset + var3));
- var11 += 8;
-
- for(int var6 = 0; var6 < var5; var6 += 2) {
- this.output.println("");
- this.output.print('\t');
- this.printFixedWidthInt(this.intAt(var11, var6), 5);
- this.output.print(": " + (this.offset + this.intAt(var11, var6 + 1)));
- }
-
- this.offset = var11 + (var5 << 2);
- break;
- case 185:
- int var10 = this.shortAt(1);
- this.output.print(" (args " + this.method_0(3) + ") #" + var10 + " ");
- this.constPrint.printConstant(var10);
- this.offset += 5;
- break;
- case 188:
- switch (this.method_0(1)) {
- case 4:
- this.output.print(" boolean");
- break;
- case 5:
- this.output.print(" char");
- break;
- case 6:
- this.output.print(" float");
- break;
- case 7:
- this.output.print(" double");
- break;
- case 8:
- this.output.print(" byte");
- break;
- case 9:
- this.output.print(" short");
- break;
- case 10:
- this.output.print(" int");
- break;
- case 11:
- this.output.print(" long");
- break;
- default:
- this.output.print(" BOGUS TYPE");
- }
-
- this.offset += 2;
- break;
- case 189:
- int var9 = this.shortAt(1);
- this.output.print(" class #" + var9 + " ");
- this.constPrint.printConstant(var9);
- this.offset += 3;
- break;
- case 197:
- int var8 = this.shortAt(1);
- this.output.print(" #" + var8 + " dim #" + this.method_0(3) + " ");
- this.constPrint.printConstant(var8);
- this.offset += 4;
- break;
- case 200:
- case 201:
- int var2 = this.offset + this.intAt(this.offset + 1, 0);
- this.output.print(" " + var2);
- this.offset += 5;
- break;
- default:
- ++this.offset;
- }
-
- this.output.println("");
- }
- }
-
- }
-
- void printExceptionTable() throws IOException {
- BinaryExceptionHandler[] var1 = ((BinaryCode)this).getExceptionHandlers();
- if (var1.length > 0) {
- this.output.print("Exception table:\n from to target type\n");
-
- for(int var2 = 0; var2 < var1.length; ++var2) {
- BinaryExceptionHandler var3 = var1[var2];
- this.printFixedWidthInt(var3.startPC, 6);
- this.printFixedWidthInt(var3.endPC, 6);
- this.printFixedWidthInt(var3.handlerPC, 6);
- this.output.print(" ");
- ClassDeclaration var4 = var3.exceptionClass;
- if (var4 == null) {
- this.output.println("any");
- } else {
- this.constPrint.printClassDeclaration(var4);
- this.output.println("");
- }
- }
- }
-
- }
-
- private DataInputStream findAttribute(Identifier var1) {
- for(BinaryAttribute var2 = ((BinaryCode)this).getAttributes(); var2 != null; var2 = var2.getNextAttribute()) {
- if (var2.getName().equals(var1)) {
- ByteArrayInputStream var3 = new ByteArrayInputStream(var2.getData());
- return new DataInputStream(var3);
- }
- }
-
- return null;
- }
-
- void printLineNumberTable() throws IOException {
- DataInputStream var1 = this.findAttribute(Constants.idLineNumberTable);
- short var2;
- if (var1 != null && (var2 = var1.readShort()) > 0) {
- this.output.println("");
- this.output.println("Line numbers for method " + this.methodName);
-
- for(int var3 = var2; var3 > 0; --var3) {
- short var4 = var1.readShort();
- short var5 = var1.readShort();
- this.output.println(" line " + var5 + ": " + var4);
- }
- }
-
- }
-
- void printLocalVariableTable() throws IOException {
- DataInputStream var1 = this.findAttribute(Constants.idLocalVariableTable);
- short var2;
- if (var1 != null && (var2 = var1.readShort()) > 0) {
- this.output.println("");
- this.output.println("Local variables for method " + this.methodName);
-
- for(int var3 = var2; var3 > 0; --var3) {
- short var4 = var1.readShort();
- short var5 = var1.readShort();
- short var6 = var1.readShort();
- short var7 = var1.readShort();
- short var8 = var1.readShort();
- this.output.print(" ");
- this.output.print(this.cpool.getType(var7));
- this.output.print(" ");
- this.output.print(this.cpool.getString(var6));
- this.output.println(" pc=" + var4 + ", length=" + var5 + ", slot=" + var8);
- }
- }
-
- }
-
- void printVerboseHeader() {
- MethodType var1 = (MethodType)this.fieldDef.getType();
- int var2 = var1.getArgumentTypes().length;
- if (!this.fieldDef.isStatic()) {
- ++var2;
- }
-
- this.output.println("\t/* Stack=" + ((BinaryCode)this).getMaxStack() + ", Locals=" + ((BinaryCode)this).getMaxLocals() + ", Args_size=" + var2 + " */");
- }
- }
-