829N/A/*
6321N/A * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
829N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
829N/A *
829N/A * This code is free software; you can redistribute it and/or modify it
829N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
829N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
829N/A *
829N/A * This code is distributed in the hope that it will be useful, but WITHOUT
829N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
829N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
829N/A * version 2 for more details (a copy is included in the LICENSE file that
829N/A * accompanied this code).
829N/A *
829N/A * You should have received a copy of the GNU General Public License version
829N/A * 2 along with this work; if not, write to the Free Software Foundation,
829N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
829N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
829N/A */
829N/A
829N/A
829N/Apackage sun.tools.java;
829N/A
829N/Aimport java.io.*;
829N/A
829N/A/**
6321N/A * WARNING: The contents of this source file are not part of any
829N/A * supported API. Code that depends on them does so at its own risk:
829N/A * they are subject to change or removal without notice.
829N/A */
6321N/Apublic class BinaryCode implements Constants {
6321N/A int maxStack; // maximum stack used by code
6321N/A int maxLocals; // maximum locals used by code
829N/A BinaryExceptionHandler exceptionHandlers[];
829N/A BinaryAttribute atts; // code attributes
829N/A BinaryConstantPool cpool; // constant pool of the class
829N/A byte code[]; // the byte code
829N/A
829N/A /**
829N/A * Construct the binary code from the code attribute
829N/A */
829N/A
829N/A public
829N/A BinaryCode(byte data[], BinaryConstantPool cpool, Environment env) {
829N/A DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
829N/A try {
829N/A this.cpool = cpool;
829N/A // JVM 4.7.4 CodeAttribute.max_stack
829N/A this.maxStack = in.readUnsignedShort();
829N/A // JVM 4.7.4 CodeAttribute.max_locals
829N/A this.maxLocals = in.readUnsignedShort();
829N/A // JVM 4.7.4 CodeAttribute.code_length
829N/A int code_length = in.readInt();
829N/A this.code = new byte[code_length];
829N/A // JVM 4.7.4 CodeAttribute.code[]
829N/A in.read(this.code);
829N/A // JVM 4.7.4 CodeAttribute.exception_table_length
829N/A int exception_count = in.readUnsignedShort();
this.exceptionHandlers = new BinaryExceptionHandler[exception_count];
for (int i = 0; i < exception_count; i++) {
// JVM 4.7.4 CodeAttribute.exception_table.start_pc
int start = in.readUnsignedShort();
// JVM 4.7.4 CodeAttribute.exception_table.end_pc
int end = in.readUnsignedShort();
// JVM 4.7.4 CodeAttribute.exception_table.handler_pc
int handler = in.readUnsignedShort();
// JVM 4.7.4 CodeAttribute.exception_table.catch_type
ClassDeclaration xclass = cpool.getDeclaration(env, in.readUnsignedShort());
this.exceptionHandlers[i] =
new BinaryExceptionHandler(start, end, handler, xclass);
}
this.atts = BinaryAttribute.load(in, cpool, ~0);
if (in.available() != 0) {
System.err.println("Should have exhausted input stream!");
}
} catch (IOException e) {
throw new CompilerError(e);
}
}
/**
* Accessors
*/
public BinaryExceptionHandler getExceptionHandlers()[] {
return exceptionHandlers;
}
public byte getCode()[] { return code; }
public int getMaxStack() { return maxStack; }
public int getMaxLocals() { return maxLocals; }
public BinaryAttribute getAttributes() { return atts; }
/**
* Load a binary class
*/
public static
BinaryCode load(BinaryMember bf, BinaryConstantPool cpool, Environment env) {
byte code[] = bf.getAttribute(idCode);
return (code != null) ? new BinaryCode(code, cpool, env) : null;
}
}