jasm.attributes
Class Code

java.lang.Object
  extended by jasm.attributes.Code
All Implemented Interfaces:
BytecodeAttribute

public class Code
extends java.lang.Object
implements BytecodeAttribute

This represents the Code attribute from the JVM Specification.

Author:
David J. Pearce

Nested Class Summary
static interface Code.BytecodeMapAttribute
           Maps bytecodes to some kind of attribute.
static class Code.Handler
          The exception handler class is used to store the necessary information about where control-flow is directed when an exception is raised.
static class Code.Rewrite
          A rewrite defines a sequence of bytecodes that are to be rewritten as a (potentially) smaller sequence.
 
Nested classes/interfaces inherited from interface jasm.lang.BytecodeAttribute
BytecodeAttribute.Fn, BytecodeAttribute.Reader, BytecodeAttribute.Unknown
 
Field Summary
protected  java.util.ArrayList<BytecodeAttribute> attributes
           
protected  java.util.ArrayList<Bytecode> bytecodes
           
protected  java.util.ArrayList<Code.Handler> handlers
           
protected  ClassFile.Method method
           
 
Constructor Summary
Code(java.util.Collection<Bytecode> bytecodes, java.util.Collection<Code.Handler> handlers, ClassFile.Method method)
           
 
Method Summary
 void addPoolItems(java.util.Set<Constant.Info> constantPool)
          When this method is called, the attribute must add all items that it needs to the constant pool.
 void apply(java.util.List<Code.Rewrite> rewrites)
          This method accepts a list of rewrites which should be applied.
<T extends BytecodeAttribute>
T
attribute(java.lang.Class<T> c)
           
 java.util.List<BytecodeAttribute> attributes()
           
 java.util.List<Bytecode> bytecodes()
           
 java.util.List<Code.Handler> handlers()
           
 int maxLocals()
          Determine the maximum number of local variable slots required for this method.
 int maxStack()
          Determine the maximum number of stack slots required for this method.
 java.lang.String name()
           
 void print(java.io.PrintWriter output, java.util.Map<Constant.Info,java.lang.Integer> constantPool)
          This method is used to print the contents of the attribute in human-readable form, similar to that produced by "javap".
 void validate(java.util.List<Code.Rewrite> rewrites)
          The purpose of this method is to validate a candidate list of rewrites.
 void write(BinaryOutputStream writer, java.util.Map<Constant.Info,java.lang.Integer> constantPool)
          This method requires the attribute to write itself to the binary stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bytecodes

protected java.util.ArrayList<Bytecode> bytecodes

handlers

protected java.util.ArrayList<Code.Handler> handlers

attributes

protected java.util.ArrayList<BytecodeAttribute> attributes

method

protected ClassFile.Method method
Constructor Detail

Code

public Code(java.util.Collection<Bytecode> bytecodes,
            java.util.Collection<Code.Handler> handlers,
            ClassFile.Method method)
Method Detail

name

public java.lang.String name()
Specified by:
name in interface BytecodeAttribute

attributes

public java.util.List<BytecodeAttribute> attributes()

attribute

public <T extends BytecodeAttribute> T attribute(java.lang.Class<T> c)

maxLocals

public int maxLocals()
Determine the maximum number of local variable slots required for this method.

Returns:

maxStack

public int maxStack()
Determine the maximum number of stack slots required for this method.

Returns:

bytecodes

public java.util.List<Bytecode> bytecodes()

handlers

public java.util.List<Code.Handler> handlers()

addPoolItems

public void addPoolItems(java.util.Set<Constant.Info> constantPool)
Description copied from interface: BytecodeAttribute
When this method is called, the attribute must add all items that it needs to the constant pool.

Specified by:
addPoolItems in interface BytecodeAttribute

write

public void write(BinaryOutputStream writer,
                  java.util.Map<Constant.Info,java.lang.Integer> constantPool)
           throws java.io.IOException
Description copied from interface: BytecodeAttribute
This method requires the attribute to write itself to the binary stream.

Specified by:
write in interface BytecodeAttribute
Throws:
java.io.IOException

validate

public void validate(java.util.List<Code.Rewrite> rewrites)
The purpose of this method is to validate a candidate list of rewrites. More specifically, a rewrite is considered to be invalid if it crosses an exception handler boundary. Such rewrites are automatically removed from the list.

Parameters:
rewrites -

apply

public void apply(java.util.List<Code.Rewrite> rewrites)
This method accepts a list of rewrites which should be applied. For efficiency reasons, several constraints are made on the list:
  1. The rewrites are ordered by their start location, such that the first rewrite has the lowest start location
  2. The rewrites don't overlap. That is, we assume only one rewrite can be applied to any given region of bytecodes.
If the complete set of rewrites cannot be constructed according to these constraints, then it needs to be split up into several calls to this method.

Parameters:
rewrites -

print

public void print(java.io.PrintWriter output,
                  java.util.Map<Constant.Info,java.lang.Integer> constantPool)
Description copied from interface: BytecodeAttribute
This method is used to print the contents of the attribute in human-readable form, similar to that produced by "javap".

Specified by:
print in interface BytecodeAttribute


Copyright © 2013 David J. Pearce. All Rights Reserved.