ibis.satin.impl.syncrewriter.bcel
Class MethodGen

java.lang.Object
  extended by org.apache.bcel.classfile.AccessFlags
      extended by org.apache.bcel.generic.FieldGenOrMethodGen
          extended by org.apache.bcel.generic.MethodGen
              extended by ibis.satin.impl.syncrewriter.bcel.MethodGen
All Implemented Interfaces:
Serializable, Cloneable, org.apache.bcel.generic.NamedAndTyped
Direct Known Subclasses:
SpawningMethod

public class MethodGen
extends org.apache.bcel.generic.MethodGen

An extension on the MethodGen of the bcel library containing a little bit more information about which instruction consumes what another produced on the stack.

See Also:
Serialized Form

Constructor Summary
MethodGen(org.apache.bcel.classfile.Method method, String className, org.apache.bcel.generic.ConstantPoolGen constantPoolGen)
          Instantiate from an existing method.
 
Method Summary
 boolean consumes(org.apache.bcel.generic.InstructionHandle consumer, org.apache.bcel.generic.InstructionHandle consumee)
          Tests whether an instruction consumes what another instruction puts onto the stack.
 boolean consumesExtensively(org.apache.bcel.generic.InstructionHandle consumer, org.apache.bcel.generic.InstructionHandle consumee)
          Tests whether an instruction consumes what another instruction puts onto the stack.
 org.apache.bcel.generic.InstructionHandle[] findExactInstructionConsumers(org.apache.bcel.generic.InstructionHandle ih)
          Returns the instruction handles that consume what instructionHandle ih put onto the stack.
 org.apache.bcel.generic.InstructionHandle[] findInstructionConsumers(org.apache.bcel.generic.InstructionHandle ih)
          Returns the instruction handles that consume what instructionHandle ih put onto the stack.
 org.apache.bcel.generic.InstructionHandle getEndExceptionHandler(org.apache.bcel.generic.CodeExceptionGen codeException)
          Returns the end of an exception handler.
 int getIndexStore(org.apache.bcel.generic.InstructionHandle instructionHandle)
          Returns the index of the variable of a store instruction.
 org.apache.bcel.generic.InstructionHandle getObjectReferenceLoadInstruction(org.apache.bcel.generic.InstructionHandle ih)
          Get the object reference load instruction of an instruction invoked on an object.
 boolean instructionLoadsTo(org.apache.bcel.generic.InstructionHandle ih, int localVarIndex)
          Tests whether an instruction loads to a local variable with a certain index.
 boolean isUsedForArrayStore(org.apache.bcel.generic.InstructionHandle loadInstruction)
          Tests whether an object load instruction is used for storing something in an array.
 boolean isUsedForPutField(org.apache.bcel.generic.InstructionHandle loadInstruction)
          Tests whether an object load instruction is used for puting something in a field of an object.
 
Methods inherited from class org.apache.bcel.generic.MethodGen
addCodeAttribute, addException, addExceptionHandler, addLineNumber, addLocalVariable, addLocalVariable, addObserver, copy, getArgumentName, getArgumentNames, getArgumentType, getArgumentTypes, getClassName, getCodeAttributes, getExceptionHandlers, getExceptions, getInstructionList, getLineNumbers, getLineNumberTable, getLocalVariables, getLocalVariableTable, getMaxLocals, getMaxStack, getMaxStack, getMethod, getReturnType, getSignature, removeCodeAttribute, removeCodeAttributes, removeException, removeExceptionHandler, removeExceptionHandlers, removeExceptions, removeLineNumber, removeLineNumbers, removeLocalVariable, removeLocalVariables, removeNOPs, removeObserver, setArgumentName, setArgumentNames, setArgumentType, setArgumentTypes, setClassName, setInstructionList, setMaxLocals, setMaxLocals, setMaxStack, setMaxStack, setReturnType, stripAttributes, toString, update
 
Methods inherited from class org.apache.bcel.generic.FieldGenOrMethodGen
addAttribute, clone, getAttributes, getConstantPool, getName, getType, removeAttribute, removeAttributes, setConstantPool, setName, setType
 
Methods inherited from class org.apache.bcel.classfile.AccessFlags
getAccessFlags, getModifiers, isAbstract, isAbstract, isFinal, isFinal, isInterface, isInterface, isNative, isNative, isPrivate, isPrivate, isProtected, isProtected, isPublic, isPublic, isStatic, isStatic, isStrictfp, isStrictfp, isSynchronized, isSynchronized, isTransient, isTransient, isVolatile, isVolatile, setAccessFlags, setModifiers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodGen

public MethodGen(org.apache.bcel.classfile.Method method,
                 String className,
                 org.apache.bcel.generic.ConstantPoolGen constantPoolGen)
Instantiate from an existing method.

Parameters:
method - method
className - class name containing this method
constantPoolGen - constant pool
Method Detail

findExactInstructionConsumers

public org.apache.bcel.generic.InstructionHandle[] findExactInstructionConsumers(org.apache.bcel.generic.InstructionHandle ih)
Returns the instruction handles that consume what instructionHandle ih put onto the stack. When a branch instruction is found, this method may return multiple instructions that consume the result of ih.

Parameters:
ih - The instructionHandle that produced something on the stack
Returns:
The instruction handles that consume what ih produced on the stack.

findInstructionConsumers

public org.apache.bcel.generic.InstructionHandle[] findInstructionConsumers(org.apache.bcel.generic.InstructionHandle ih)
Returns the instruction handles that consume what instructionHandle ih put onto the stack. When a branch instruction is found, this method may return multiple instructions that consume the result of ih.

Parameters:
ih - The instructionHandle that produced something on the stack
Returns:
The instruction handles that consume what ih produced on the stack.

isUsedForPutField

public boolean isUsedForPutField(org.apache.bcel.generic.InstructionHandle loadInstruction)
Tests whether an object load instruction is used for puting something in a field of an object.

Parameters:
loadInstruction - the load instruction that loads the object reference onto the stack.
Returns:
true if the instruction is a load instruction of an object which is used for puting something in a field.

isUsedForArrayStore

public boolean isUsedForArrayStore(org.apache.bcel.generic.InstructionHandle loadInstruction)
Tests whether an object load instruction is used for storing something in an array.

Parameters:
loadInstruction - the load instruction that loads the object reference onto the stack.
Returns:
true if the instruction is a load instruction of an object which is used for storing something in an array.

instructionLoadsTo

public boolean instructionLoadsTo(org.apache.bcel.generic.InstructionHandle ih,
                                  int localVarIndex)
Tests whether an instruction loads to a local variable with a certain index. When the load is used for an array store or a putfield, the result will be false. It uses isUsedForArrayStore(InstructionHandle) and isUsedForPutField(InstructionHandle).

Parameters:
ih - The instruction that is tested to load to a local variable index.
localVarIndex - The local variable index to which the instruction may load
Returns:
true if the instruction loads to the local variable index, false otherwise.
See Also:
isUsedForArrayStore(InstructionHandle), isUsedForPutField(InstructionHandle)

consumes

public boolean consumes(org.apache.bcel.generic.InstructionHandle consumer,
                        org.apache.bcel.generic.InstructionHandle consumee)
Tests whether an instruction consumes what another instruction puts onto the stack.

Parameters:
consumer - The instruction that consumes what consumee produces
consumee - The instruction of which the stack production is consumed.
Returns:
true if consumer consumes what consumee produces on the stack, false otherwise.

consumesExtensively

public boolean consumesExtensively(org.apache.bcel.generic.InstructionHandle consumer,
                                   org.apache.bcel.generic.InstructionHandle consumee)
Tests whether an instruction consumes what another instruction puts onto the stack. This function also tries beyond multidimensional arrays and dup instructions.

Parameters:
consumer - The instruction that consumes what consumee produces
consumee - The instruction of which the stack production is consumed.
Returns:
true if consumer consumes what consumee produces on the stack, false otherwise.

getObjectReferenceLoadInstruction

public org.apache.bcel.generic.InstructionHandle getObjectReferenceLoadInstruction(org.apache.bcel.generic.InstructionHandle ih)
Get the object reference load instruction of an instruction invoked on an object. A putfield, arraystore or an invoke instruction, etc. are invoked on an object. This method returns the instruction handle in which the object reference was loaded. It uses consumesExtensively(InstructionHandle, InstructionHandle) to find out which instruction consumes another. There may be cases, for example with complicated DUP structures where the analysis can't find out where object reference is, the method will then throw an error. These cases should be added to the code then...

Parameters:
ih - The instructionHandle that invokes something on an object.
Returns:
The instruction handle which loads the object reference that is used by instruction handle ih.
See Also:
consumesExtensively(InstructionHandle, InstructionHandle)

getIndexStore

public int getIndexStore(org.apache.bcel.generic.InstructionHandle instructionHandle)
                  throws ClassCastException
Returns the index of the variable of a store instruction. When the store is a store into an array or a putfield instruction, then the index of the local variable which contains the object reference is returned. It may use getObjectReferenceLoadInstruction(InstructionHandle).

Parameters:
instructionHandle - The instruction that is a store instruction.
Returns:
The index of the local variable in which is stored.
Throws:
ClassCastException - The instructionHandle is not a store instruction.
See Also:
getObjectReferenceLoadInstruction(InstructionHandle)

getEndExceptionHandler

public org.apache.bcel.generic.InstructionHandle getEndExceptionHandler(org.apache.bcel.generic.CodeExceptionGen codeException)
Returns the end of an exception handler.

Parameters:
codeException - The codeException which end is returned.
Returns:
The instructionHandle that is the end of the exception handler.


The Ibis project