com.vladium.jcd.cls.attribute
Class CodeAttribute_info

java.lang.Object
  extended bycom.vladium.jcd.cls.attribute.Attribute_info
      extended bycom.vladium.jcd.cls.attribute.CodeAttribute_info
All Implemented Interfaces:
java.lang.Cloneable, IClassFormatOutput

public final class CodeAttribute_info
extends Attribute_info

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

The Code attribute has the format

  Code_attribute {
          u2 attribute_name_index;
          u4 attribute_length;
          u2 max_stack;
          u2 max_locals;
          u4 code_length;
          u1 code[code_length];
          u2 exception_table_length;
          {            u2 start_pc;
                        u2 end_pc;
                        u2  handler_pc;
                        u2  catch_type;
          }        exception_table[exception_table_length];

          u2 attributes_count;
          attribute_info attributes[attributes_count];
  }
 
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.

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 . The greatest local variable index for a one-word value is max_locals-1 . The greatest local variable index for a two-word value is max_locals-2.

The value of the code_length item gives the number of bytes in the code array for this method. The value of code_length must be greater than zero; the code array must not be empty.The code array gives the actual bytes of Java Virtual Machine code that implement the method.

The value of the exception_table_length item gives the number of entries in the exception_table table. Each entry in the exception_table array describes one exception handler in the code array: see Exception_info.

The value of the attributes_count item indicates the number of attributes of the Code attribute. 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.

Author:
(C) 2001, Vlad Roubtsov

Field Summary
private static boolean DEBUG
           
static byte[] EMPTY_BYTE_ARRAY
           
private  IAttributeCollection m_attributes
           
private  byte[] m_code
           
private  int m_codeSize
           
private  IExceptionHandlerTable m_exceptionHandlerTable
           
 int m_max_locals
           
 int m_max_stack
           
 
Fields inherited from class com.vladium.jcd.cls.attribute.Attribute_info
ATTRIBUTE_BRIDGE, ATTRIBUTE_CODE, ATTRIBUTE_CONSTANT_VALUE, ATTRIBUTE_EXCEPTIONS, ATTRIBUTE_INNERCLASSES, ATTRIBUTE_LINE_NUMBER_TABLE, ATTRIBUTE_SOURCEFILE, ATTRIBUTE_SYNTHETIC, m_attribute_length, m_name_index
 
Constructor Summary
(package private) CodeAttribute_info(IConstantCollection constants, int attribute_name_index, long attribute_length, UDataInputStream bytes)
           
  CodeAttribute_info(int attribute_name_index, int max_stack, int max_locals, byte[] code, IExceptionHandlerTable exceptionHandlerTable, IAttributeCollection attributes)
           
 
Method Summary
 void accept(IAttributeVisitor visitor, java.lang.Object ctx)
           
 java.lang.Object clone()
          Performs a deep copy.
 IAttributeCollection getAttributes()
           
 byte[] getCode()
          NOTE: must also use getCodeSize()
 int getCodeSize()
           
 IExceptionHandlerTable getExceptionTable()
           
 long length()
          Returns the total length of this attribute when converted to .class format [including the 6-byte header]
 void setCode(byte[] code, int codeSize)
           
 java.lang.String toString()
           
 void writeInClassFormat(UDataOutputStream out)
           
 
Methods inherited from class com.vladium.jcd.cls.attribute.Attribute_info
getName, new_Attribute_info
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_BYTE_ARRAY

public static final byte[] EMPTY_BYTE_ARRAY

m_max_stack

public int m_max_stack

m_max_locals

public int m_max_locals

m_code

private byte[] m_code

m_codeSize

private int m_codeSize

m_exceptionHandlerTable

private IExceptionHandlerTable m_exceptionHandlerTable

m_attributes

private IAttributeCollection m_attributes

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values
Constructor Detail

CodeAttribute_info

public CodeAttribute_info(int attribute_name_index,
                          int max_stack,
                          int max_locals,
                          byte[] code,
                          IExceptionHandlerTable exceptionHandlerTable,
                          IAttributeCollection attributes)

CodeAttribute_info

CodeAttribute_info(IConstantCollection constants,
                   int attribute_name_index,
                   long attribute_length,
                   UDataInputStream bytes)
             throws java.io.IOException
Method Detail

getCode

public final byte[] getCode()
NOTE: must also use getCodeSize()

Returns:

getCodeSize

public final int getCodeSize()

getAttributes

public IAttributeCollection getAttributes()

getExceptionTable

public IExceptionHandlerTable getExceptionTable()

length

public long length()
Description copied from class: Attribute_info
Returns the total length of this attribute when converted to .class format [including the 6-byte header]

Specified by:
length in class Attribute_info

accept

public void accept(IAttributeVisitor visitor,
                   java.lang.Object ctx)
Specified by:
accept in class Attribute_info

toString

public java.lang.String toString()
Specified by:
toString in class Attribute_info

clone

public java.lang.Object clone()
Performs a deep copy.

Overrides:
clone in class Attribute_info

writeInClassFormat

public void writeInClassFormat(UDataOutputStream out)
                        throws java.io.IOException
Specified by:
writeInClassFormat in interface IClassFormatOutput
Overrides:
writeInClassFormat in class Attribute_info
Throws:
java.io.IOException

setCode

public void setCode(byte[] code,
                    int codeSize)