Java API by
Zvi Har’El

cf
Class CodeAttribute

java.lang.Object
  extended by cf.CodeAttribute

 class CodeAttribute
extends Object

An instance of class CodeAttribute is an in-core representation of a “Code” attribute of a method.

Version:
$Id: CodeAttribute.java,v 1.59 2004/04/28 14:01:41 rl Exp $
Author:
Zvi Har’El
See Also:
Class source code

Field Summary
(package private)  Vector attributes
          Attributes of this code.
(package private)  ClassFile cf
          The ClassFile object to which this code belongs.
(package private)  byte[] code
          The actual JVM bytecode for this method.
(package private)  int codeLength
          Number of bytes in the code array.
(package private)  Vector exceptionTable
          The exception table.
(package private)  short maxLocals
          Maximum number of words in the local variable pool of this method.
(package private)  short maxStack
          Maximum number of words on the operand stack during the method execution.
 
Constructor Summary
CodeAttribute(ClassFile cf)
          Constructs an empty CodeAttribute object for a new method.
CodeAttribute(DataInputStream in, ClassFile cf)
          Constructs a new CodeAttribute object by reading an input stream.
 
Method Summary
(package private)  void addException(int start, int end, int handler, String type)
          Adds an exception to the exception table of a method.
(package private)  void ldc(double c)
          Generates code to push a DOUBLE constant into the stack.
(package private)  void ldc(float c)
          Generates code to push a FLOAT constant into the stack.
(package private)  void ldc(int c)
          Generates code to push a INTEGER constant into the stack.
(package private)  void ldc(long c)
          Generates code to push a LONG constant into the stack.
private  void ldc(short i)
          Generates code to push an INTEGER, a FLOAT, or a STRING constant into the stack.
(package private)  void ldc(String c)
          Generates code to push null or a STRING constant into the stack.
(package private)  void move(int n, byte op)
          Generates byte code to move data to or from a local variable.
(package private)  void pad()
          Pads the code array with zero bytes.
(package private)  void pad(int n)
          Pads the code array with zero bytes.
(package private)  void put(byte i)
          Puts a byte in the first available location of the code array.
(package private)  void put(byte i, int l)
          Puts a byte in a specified location of the code array.
(package private)  void put(byte tag, short i, String s1, String s2)
          Puts an index to the constant pool in the first available location of the code array.
(package private)  void put(byte tag, String s)
          Puts an index to the constant pool in the first available location of the code array.
(package private)  void put(byte tag, String s1, String s2, String s3)
          Puts an index to the constant pool in the first available location of the code array.
(package private)  void put(short i)
          Puts two bytes in the first available location of the code array.
(package private)  void put(short i, int l)
          Puts two bytes in a specified location of the code array.
(package private)  void strip()
          Strip attributes.
(package private)  void trim()
          Trim the code array to actual code length.
(package private)  void write(DataOutputStream out)
          Writes the CodeAttribute object on an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxStack

short maxStack
Maximum number of words on the operand stack during the method execution.


maxLocals

short maxLocals
Maximum number of words in the local variable pool of this method.


codeLength

int codeLength
Number of bytes in the code array.


code

byte[] code
The actual JVM bytecode for this method.


exceptionTable

final Vector exceptionTable
The exception table. Each entry is an Long object, packing four short values, as follows: The start and end of the code for which the exception handler is active, the start of the exception handler, and the type of the handled exception given as an index to a CLASS constant.


attributes

final Vector attributes
Attributes of this code. The attributes possible at this level are “LineNumberTable” and “LocalVariableTable”. Each entry is a byte array.


cf

ClassFile cf
The ClassFile object to which this code belongs. Used to access the constant pool.

Constructor Detail

CodeAttribute

CodeAttribute(DataInputStream in,
              ClassFile cf)
        throws IOException
Constructs a new CodeAttribute object by reading an input stream.

Parameters:
in - the input stream
cf - the ClassFile object to which this CodeAttribute object belongs
Throws:
IOException - if input error occurs

CodeAttribute

CodeAttribute(ClassFile cf)
Constructs an empty CodeAttribute object for a new method. The code array initial allocation is 256 bytes.

Parameters:
cf - the ClassFile object to which this CodeAttribute object belongs
Method Detail

write

final void write(DataOutputStream out)
          throws IOException
Writes the CodeAttribute object on an output stream.

Parameters:
out - the output stream
Throws:
IOException - if output error occurs

strip

final void strip()
Strip attributes.


addException

final void addException(int start,
                        int end,
                        int handler,
                        String type)
Adds an exception to the exception table of a method.

Parameters:
start - the start of the code for which the handler is active
end - the end of the code for which the handler is active
handler - the start of the exception handler
type - the type of exception caught by this handler
See Also:
JVM Spec §4.7.4

trim

final void trim()
Trim the code array to actual code length.


put

final void put(byte i,
               int l)
        throws IndexOutOfBoundsException
Puts a byte in a specified location of the code array.

Parameters:
i - the byte
l - the location
Throws:
IndexOutOfBoundsException - if the reqested location is outside the code array

put

final void put(short i,
               int l)
        throws IndexOutOfBoundsException
Puts two bytes in a specified location of the code array.

Parameters:
i - the bytes
l - the location
Throws:
IndexOutOfBoundsException - if the reqested location is outside the code array

put

final void put(byte i)
Puts a byte in the first available location of the code array. If the code array becomes full, doubles its capacity.

Parameters:
i - the byte

put

final void put(short i)
Puts two bytes in the first available location of the code array.

Parameters:
i - the bytes

put

final void put(byte tag,
               String s)
Puts an index to the constant pool in the first available location of the code array.

Parameters:
tag - a constant pool tag
s - a String value
See Also:
ClassFile.cp(byte,String)

put

final void put(byte tag,
               String s1,
               String s2,
               String s3)
Puts an index to the constant pool in the first available location of the code array.

Parameters:
tag - a constant pool tag
s1 - a String value
s2 - a String value
s3 - a String value
See Also:
ClassFile.cp(byte,String,String,String)

put

final void put(byte tag,
               short i,
               String s1,
               String s2)
Puts an index to the constant pool in the first available location of the code array.

Parameters:
tag - a constant pool tag
i - a short value
s1 - a String value
s2 - a String value
See Also:
ClassFile.cp(byte,short,String,String)

pad

final void pad(int n)
Pads the code array with zero bytes.

Parameters:
n - the number of padding bytes

pad

final void pad()
Pads the code array with zero bytes. The next available location will be aligned to a multiple of four bytes.

See Also:
JVM Spec §6.4: tableswitch

ldc

private final void ldc(short i)
Generates code to push an INTEGER, a FLOAT, or a STRING constant into the stack. The JVM operation most efficient for the size of the index of the constant in the pool is selected.

Parameters:
i - an index to the constant pool
See Also:
JVM Spec §6.4: ldc, ldc_w

ldc

final void ldc(int c)
Generates code to push a INTEGER constant into the stack.

Parameters:
c - a int value
See Also:
ldc(short), JVM Spec §6.4: iconst_<i>, bipush, sipush

ldc

final void ldc(long c)
Generates code to push a LONG constant into the stack.

Parameters:
c - a long value
See Also:
JVM Spec §6.4: lconst_<l>, ldc2_w

ldc

final void ldc(float c)
Generates code to push a FLOAT constant into the stack.

Parameters:
c - a float value
See Also:
ldc(short), JVM Spec §6.4: fconst_<f>

ldc

final void ldc(double c)
Generates code to push a DOUBLE constant into the stack.

Parameters:
c - a double value
See Also:
JVM Spec §6.4: dconst_<d>, ldc2_w

ldc

final void ldc(String c)
Generates code to push null or a STRING constant into the stack.

Parameters:
c - null or a String value
See Also:
ldc(short), JVM Spec §6.4: aconst_null

move

final void move(int n,
                byte op)
Generates byte code to move data to or from a local variable. The JVM operation most efficient for the given local variable is selected.

Parameters:
n - the local variable
op - the opcode: ILOAD, ISTORE, etc.
See Also:
JVM Spec §6.4: iload, iload_<n>, wide

Java API by
Zvi Har’El

Copyright © Zvi Har’El
$Date: 2007/10/15 13:50:30$