harpoon.IR.RawClass
Class AttributeCode

java.lang.Object
  extended by harpoon.IR.RawClass.Attribute
      extended by harpoon.IR.RawClass.AttributeCode

public class AttributeCode
extends Attribute

The Code attribute is a variable-length attribute used in the attributes table of method_info structures. A Code attribute contains the Java Virtual Machine instructions and auxilliary information for a single Java method, instance initialization method, or class or interface initialization method. There must be exactly one Code attribute in each method_info structure.

Version:
$Id: AttributeCode.java,v 1.4 2003/09/05 22:09:59 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
"The Java Virtual Machine Specification, section 4.7.4", AttributeLineNumberTable, AttributeLocalVariableTable, Attribute, MethodInfo, ClassFile

Field Summary
static String ATTRIBUTE_NAME
          The string naming this Attribute type.
 Attribute[] attributes
          Each value of the attributes table must be a variable-length attribute structure.
 byte[] code
          The code array gives the actual bytes of Java Virtual Machine code that implement the method.
 ExceptionTable[] exception_table
          Each entry in the exception_table array describes one exception handler in the code array.
 int max_locals
          The value of the max_locals item gives the number of local variables used by this method, including the parameters passed to the method on invocation.
 int max_stack
          The value of the max_stack item gives the maximum number of words on the operand stack at any point during execution of this method.
 
Fields inherited from class harpoon.IR.RawClass.Attribute
attribute_name_index, parent
 
Constructor Summary
AttributeCode(ClassFile parent, int attribute_name_index, int max_stack, int max_locals, byte[] code, ExceptionTable[] exception_table, Attribute[] attributes)
          Constructor.
 
Method Summary
 long attribute_length()
          The value of the attribute_length item indicates the length of the attribute, excluding the initial six bytes.
 int attributes_count()
           
 long code_length()
           
 Constant constant(int index)
          Lookup a Constant in the constant_pool.
 int exception_table_length()
           
 String localName(int pc, int index)
          Return the symbolic name of a local variable, or null if one cannot be found.
 void print(PrintWriter pw, int indent)
          Pretty-print the contents of this attribute.
 void write(ClassDataOutputStream out)
          Write to bytecode stream.
 
Methods inherited from class harpoon.IR.RawClass.Attribute
attribute_name_index, attribute_name, read, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ATTRIBUTE_NAME

public static final String ATTRIBUTE_NAME
The string naming this Attribute type.

See Also:
Constant Field Values

max_stack

public int max_stack
The value of the max_stack item gives the maximum number of words on the operand stack at any point during execution of this method.


max_locals

public int max_locals
The value of the max_locals item gives the number of local variables used by this method, including the parameters passed to the method on invocation. The index of the first local variable is 0.


code

public byte[] code
The code array gives the actual bytes of Java Virtual Machine code that implement the method.


exception_table

public ExceptionTable[] exception_table
Each entry in the exception_table array describes one exception handler in the code array.


attributes

public Attribute[] attributes
Each value of the attributes table must be a variable-length attribute structure. A Code attribute can have any number of optional attributes associated with it.

Currently, the LineNumberTable and LocalVariableTable attributes, both of which contain debugging information, are defined and used with the Code attribute.

Constructor Detail

AttributeCode

public AttributeCode(ClassFile parent,
                     int attribute_name_index,
                     int max_stack,
                     int max_locals,
                     byte[] code,
                     ExceptionTable[] exception_table,
                     Attribute[] attributes)
Constructor.

Method Detail

code_length

public long code_length()

exception_table_length

public int exception_table_length()

attributes_count

public int attributes_count()

attribute_length

public long attribute_length()
Description copied from class: Attribute
The value of the attribute_length item indicates the length of the attribute, excluding the initial six bytes.

Specified by:
attribute_length in class Attribute

write

public void write(ClassDataOutputStream out)
           throws IOException
Write to bytecode stream.

Specified by:
write in class Attribute
Throws:
IOException

localName

public String localName(int pc,
                        int index)
Return the symbolic name of a local variable, or null if one cannot be found.

Parameters:
index - the index of the local variable to look up.
Returns:
the name of the local, or null.

constant

public Constant constant(int index)
Lookup a Constant in the constant_pool. Provided for use of methods that parse the code array.


print

public void print(PrintWriter pw,
                  int indent)
Pretty-print the contents of this attribute.

Overrides:
print in class Attribute
Parameters:
indent - the indentation level to use.