org.jikesrvm.compilers.common
Class CompiledMethod

java.lang.Object
  extended by org.jikesrvm.compilers.common.CompiledMethod
All Implemented Interfaces:
SizeConstants
Direct Known Subclasses:
BaselineCompiledMethod, HardwareTrapCompiledMethod, JNICompiledMethod, OptCompiledMethod

public abstract class CompiledMethod
extends Object
implements SizeConstants

A method that has been compiled into machine code by one of our compilers.


Field Summary
private static byte ACTIVE_ON_STACK
           
static int BASELINE
           
private static byte BRIDGE_FROM_NATIVE
          Has bridge from native annotation, NB this makes the flags byte negative
protected  int cmid
          The compiled method id of this compiled method (index into CompiledMethods)
protected  float compilationTime
          The time in milliseconds taken to compile the method.
private static byte COMPILED
           
private  byte flags
          Flags bit field
protected  ArchitectureSpecific.CodeArray instructions
          The compiled machine code for said method.
private static byte INVALID
           
static int JNI
           
 RVMMethod method
          The RVMMethod that was compiled
static int NUM_COMPILER_TYPES
           
private static byte OBSOLETE
           
static int OPT
           
protected  int osrJTOCoffset
          the offset of instructions in JTOC, for osr-special compiled method only. all osr-ed method is treated like static.
private static byte OUTDATED
          flags the compiled method as outdated, needs OSR
private static byte SAMPLES_RESET
          Has the method sample data for this compiled method been reset?
private static byte SPECIAL_FOR_OSR
           
static int TRAP
           
 
Fields inherited from interface org.jikesrvm.SizeConstants
BITS_IN_ADDRESS, BITS_IN_BOOLEAN, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_DOUBLE, BITS_IN_EXTENT, BITS_IN_FLOAT, BITS_IN_INT, BITS_IN_LONG, BITS_IN_OFFSET, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_EXTENT, BYTES_IN_FLOAT, BYTES_IN_INT, BYTES_IN_LONG, BYTES_IN_OFFSET, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BOOLEAN, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_DOUBLE, LOG_BITS_IN_EXTENT, LOG_BITS_IN_FLOAT, LOG_BITS_IN_INT, LOG_BITS_IN_LONG, LOG_BITS_IN_OFFSET, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_BOOLEAN, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_DOUBLE, LOG_BYTES_IN_EXTENT, LOG_BYTES_IN_FLOAT, LOG_BYTES_IN_INT, LOG_BYTES_IN_LONG, LOG_BYTES_IN_OFFSET, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD
 
Constructor Summary
CompiledMethod(int id, RVMMethod m)
          Set the cmid and method fields
 
Method Summary
 void clearActiveOnStack()
           
 ArchitectureSpecific.CodeArray codeArrayForOffset(Offset offset)
          Return the code array for this method that contains the given offset.
 void compileComplete(ArchitectureSpecific.CodeArray code)
          Record that the compilation is complete.
static String compilerTypeToString(int compilerType)
           
 boolean containsReturnAddress(Address ip)
          Does the code for the compiled method contain the given return address?
abstract  int findCatchBlockForInstruction(Offset instructionOffset, RVMType exceptionType)
          Find "catch" block for a machine instruction of this method that might be guarded against specified class of exceptions by a "try" block.
 int findLineNumberForInstruction(Offset instructionOffset)
          Find source line number corresponding to one of this method's machine instructions.
 double getCompilationTime()
           
abstract  String getCompilerName()
           
abstract  int getCompilerType()
          Identify the compiler that produced this compiled method.
abstract  void getDynamicLink(DynamicLink dynamicLink, Offset instructionOffset)
          Fetch symbolic reference to a method that's called by one of this method's instructions.
 ArchitectureSpecific.CodeArray getEntryCodeArray()
           
abstract  ExceptionDeliverer getExceptionDeliverer()
          Get handler to deal with stack unwinding and exception delivery for this compiled method's stackframes.
 int getId()
          Return the compiled method id for this compiled method
 Address getInstructionAddress(Offset offset)
          Return the address of the instruction at offset offset in the method's instruction stream.
 Offset getInstructionOffset(Address ip)
          Return the offset in bytes of the given Address from the start of the machine code array.
 Offset getInstructionOffset(Address ip, boolean dieOnFailure)
          Return the offset in bytes of the given Address from the start of the machine code array.
 RVMMethod getMethod()
          Return the RVMMethod associated with this compiled method
 Offset getOsrJTOCoffset()
           
 boolean getSamplesReset()
           
 boolean hasBridgeFromNativeAnnotation()
          Does this method have a bridge from native annotation, important when walking the stack
 boolean isActiveOnStack()
           
 boolean isCompiled()
          Has compilation completed?
 boolean isInvalid()
          Is the compiled code invalid?
 boolean isObsolete()
          Is the compiled code obsolete?
 boolean isOutdated()
          Check if the compiled method is marked as outdated, called by Thread
 boolean isSpecialForOSR()
           
abstract  boolean isWithinUninterruptibleCode(Offset instructionOffset)
          Return whether or not the given address (which is purported to be inside of the compiled method's code array) corresponds to an uninterruptible context.
 int numberOfInstructions()
           
abstract  void printStackTrace(Offset instructionOffset, PrintLN out)
          Print this compiled method's portion of a stack trace
abstract  void set(StackBrowser browser, Offset instr)
          Set the stack browser to the innermost logical stack frame of this method
 void setActiveOnStack()
           
 void setCompilationTime(double ct)
           
 void setInvalid()
          Mark the compiled method as invalid
 void setObsolete()
          Mark the compiled method as obsolete (ie a candidate for eventual GC)
 void setOutdated()
          Mark the compiled method as outdated (i.e. requires OSR), the flag is set in AnalyticModel
 void setSamplesReset()
           
 void setSpecialForOSR()
           
 int size()
          Return the number of bytes used to encode the compiler-specific mapping information for this compiled method.
 boolean up(StackBrowser browser)
          Advance the StackBrowser up one internal stack frame, if possible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRAP

public static final int TRAP
See Also:
Constant Field Values

BASELINE

public static final int BASELINE
See Also:
Constant Field Values

OPT

public static final int OPT
See Also:
Constant Field Values

JNI

public static final int JNI
See Also:
Constant Field Values

NUM_COMPILER_TYPES

public static final int NUM_COMPILER_TYPES
See Also:
Constant Field Values

COMPILED

private static final byte COMPILED
See Also:
Constant Field Values

INVALID

private static final byte INVALID
See Also:
Constant Field Values

OBSOLETE

private static final byte OBSOLETE
See Also:
Constant Field Values

ACTIVE_ON_STACK

private static final byte ACTIVE_ON_STACK
See Also:
Constant Field Values

OUTDATED

private static final byte OUTDATED
flags the compiled method as outdated, needs OSR

See Also:
Constant Field Values

SAMPLES_RESET

private static final byte SAMPLES_RESET
Has the method sample data for this compiled method been reset?

See Also:
Constant Field Values

SPECIAL_FOR_OSR

private static final byte SPECIAL_FOR_OSR
See Also:
Constant Field Values

BRIDGE_FROM_NATIVE

private static final byte BRIDGE_FROM_NATIVE
Has bridge from native annotation, NB this makes the flags byte negative

See Also:
Constant Field Values

flags

private byte flags
Flags bit field


cmid

protected final int cmid
The compiled method id of this compiled method (index into CompiledMethods)


method

public final RVMMethod method
The RVMMethod that was compiled


instructions

protected ArchitectureSpecific.CodeArray instructions
The compiled machine code for said method.


osrJTOCoffset

protected int osrJTOCoffset
the offset of instructions in JTOC, for osr-special compiled method only. all osr-ed method is treated like static. TODO: OSR redesign: put in subclass? Stick somewhere else? Don't want to waste space for this on every compiled method.


compilationTime

protected float compilationTime
The time in milliseconds taken to compile the method.

Constructor Detail

CompiledMethod

public CompiledMethod(int id,
                      RVMMethod m)
Set the cmid and method fields

Method Detail

setSamplesReset

public void setSamplesReset()

getSamplesReset

public boolean getSamplesReset()

setSpecialForOSR

public void setSpecialForOSR()

isSpecialForOSR

public boolean isSpecialForOSR()

getOsrJTOCoffset

public final Offset getOsrJTOCoffset()

getId

public final int getId()
Return the compiled method id for this compiled method


getMethod

public final RVMMethod getMethod()
Return the RVMMethod associated with this compiled method


hasBridgeFromNativeAnnotation

public final boolean hasBridgeFromNativeAnnotation()
Does this method have a bridge from native annotation, important when walking the stack


getEntryCodeArray

public final ArchitectureSpecific.CodeArray getEntryCodeArray()
Returns:
the CodeArray to jump to to invoke this method (ie, code_array[0] contains the first instruction of the method's prologue).

numberOfInstructions

public final int numberOfInstructions()
Returns:
the number of machine instructions for compiled method; may be an overestimate if we have adding padding to machine code.

getInstructionOffset

public final Offset getInstructionOffset(Address ip)
Return the offset in bytes of the given Address from the start of the machine code array.

Parameters:
ip - a Address (should be an interior pointer to instructions)
Returns:
offset of addr from start of instructions in bytes

getInstructionOffset

public final Offset getInstructionOffset(Address ip,
                                         boolean dieOnFailure)
Return the offset in bytes of the given Address from the start of the machine code array.

Parameters:
ip - a Address (should be an interior pointer to instructions)
dieOnFailure - if ip is invalid should we kill the VM (we don't want to if already in the process of killing the VM)
Returns:
offset of addr from start of instructions in bytes

getInstructionAddress

public final Address getInstructionAddress(Offset offset)
Return the address of the instruction at offset offset in the method's instruction stream.

Parameters:
offset - the offset of the desired instruction (as returned by getInstructionOffset)
Returns:
Address of the specified instruction

codeArrayForOffset

public final ArchitectureSpecific.CodeArray codeArrayForOffset(Offset offset)
Return the code array for this method that contains the given offset.

Parameters:
offset - the offset of the desired instruction (as returned by getInstructionOffset)
Returns:
CodeArray that contains the specified instruction

containsReturnAddress

public final boolean containsReturnAddress(Address ip)
Does the code for the compiled method contain the given return address?

Parameters:
ip - a return address
Returns:
true if it belongs to this method's code, false otherwise.

compileComplete

public final void compileComplete(ArchitectureSpecific.CodeArray code)
Record that the compilation is complete.


setInvalid

public final void setInvalid()
Mark the compiled method as invalid


setObsolete

public final void setObsolete()
Mark the compiled method as obsolete (ie a candidate for eventual GC)


setActiveOnStack

public final void setActiveOnStack()

clearActiveOnStack

public final void clearActiveOnStack()

setOutdated

public final void setOutdated()
Mark the compiled method as outdated (i.e. requires OSR), the flag is set in AnalyticModel


isOutdated

public final boolean isOutdated()
Check if the compiled method is marked as outdated, called by Thread


isCompiled

public final boolean isCompiled()
Has compilation completed?


isInvalid

public final boolean isInvalid()
Is the compiled code invalid?


isObsolete

public final boolean isObsolete()
Is the compiled code obsolete?


isActiveOnStack

public final boolean isActiveOnStack()

getCompilationTime

public final double getCompilationTime()

setCompilationTime

public final void setCompilationTime(double ct)

getCompilerType

public abstract int getCompilerType()
Identify the compiler that produced this compiled method.

Returns:
one of TRAP, BASELINE, OPT, or JNI. Note: use this instead of "instanceof" when GC is disabled (i.e. during GC)

compilerTypeToString

public static String compilerTypeToString(int compilerType)

getCompilerName

public abstract String getCompilerName()
Returns:
Name of the compiler that produced this compiled method.

getExceptionDeliverer

public abstract ExceptionDeliverer getExceptionDeliverer()
Get handler to deal with stack unwinding and exception delivery for this compiled method's stackframes.


findCatchBlockForInstruction

public abstract int findCatchBlockForInstruction(Offset instructionOffset,
                                                 RVMType exceptionType)
Find "catch" block for a machine instruction of this method that might be guarded against specified class of exceptions by a "try" block.

Notes:

Parameters:
instructionOffset - offset of machine instruction from start of this method, in bytes
exceptionType - type of exception being thrown - something like "NullPointerException"
Returns:
offset of machine instruction for catch block (-1 --> no catch block)

getDynamicLink

public abstract void getDynamicLink(DynamicLink dynamicLink,
                                    Offset instructionOffset)
Fetch symbolic reference to a method that's called by one of this method's instructions.

Notes:


findLineNumberForInstruction

public int findLineNumberForInstruction(Offset instructionOffset)
Find source line number corresponding to one of this method's machine instructions.

Usage note: "instructionOffset" must point to the instruction following the actual instruction whose line number is sought. This allows us to properly handle the case where the only address we have to work with is a return address (ie. from a stackframe) or an exception address (ie. from a null pointer dereference, array bounds check, or divide by zero) on a machine architecture with variable length instructions. In such situations we'd have no idea how far to back up the instruction pointer to point to the "call site" or "exception site".

Parameters:
instructionOffset - of machine instruction from start of this method, in bytes
Returns:
source line number (0 == no line info available, 1 == first line of source file)

isWithinUninterruptibleCode

public abstract boolean isWithinUninterruptibleCode(Offset instructionOffset)
Return whether or not the given address (which is purported to be inside of the compiled method's code array) corresponds to an uninterruptible context.

Parameters:
instructionOffset - of addr from start of instructions in bytes
Returns:
true if the IP is within an Uninterruptible method, false otherwise.

printStackTrace

public abstract void printStackTrace(Offset instructionOffset,
                                     PrintLN out)
Print this compiled method's portion of a stack trace

Parameters:
instructionOffset - offset of machine instruction from start of method
out - the PrintLN to print the stack trace to.

set

public abstract void set(StackBrowser browser,
                         Offset instr)
Set the stack browser to the innermost logical stack frame of this method


up

public boolean up(StackBrowser browser)
Advance the StackBrowser up one internal stack frame, if possible


size

public int size()
Return the number of bytes used to encode the compiler-specific mapping information for this compiled method. Used to gather statistics on the space costs of mapping schemes.