public class RuntimeEntrypoints extends Object
These are "helper functions" called from machine code emitted by BaselineCompilerImpl. They implement functionality that cannot be mapped directly into a small inline sequence of machine instructions. See also: Linker.
Note #1: If you add, remove, or change the signature of any of these methods you may need to change Entrypoints to match.
Note #2: Code here must be carefully written to be gc-safe while manipulating stackframe and instruction addresses.
Any time we are holding interior pointers to objects that could be moved by a garbage collection cycle we must either avoid passing through gc-sites (by writing straight line code with no "non-magic" method invocations) or we must turn off the collector (so that a gc request initiated by another thread will not run until we're done manipulating the bare pointers). Furthermore, while the collector is turned off, we must be careful not to make any allocation requests ("new").
The interior pointers that we must worry about are:
Modifier and Type | Field and Description |
---|---|
(package private) static int |
allocationCountDownToGC
Number of allocations left before a GC is forced.
|
(package private) static int |
jniCountDownToGC
Number of c-to-java jni calls left before a GC is forced.
|
private static boolean |
traceAthrow |
static int |
TRAP_ARRAY_BOUNDS |
static int |
TRAP_CHECKCAST |
static int |
TRAP_DIVIDE_BY_ZERO |
static int |
TRAP_JNI_STACK |
static int |
TRAP_MUST_IMPLEMENT |
static int |
TRAP_NULL_POINTER |
static int |
TRAP_REGENERATE |
static int |
TRAP_STACK_OVERFLOW |
static int |
TRAP_STACK_OVERFLOW_FATAL |
static int |
TRAP_STORE_CHECK |
static int |
TRAP_UNKNOWN |
static int |
TRAP_UNREACHABLE_BYTECODE |
private static String |
UNREACHABLE_BC_MESSAGE |
Constructor and Description |
---|
RuntimeEntrypoints() |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
aastore(Object[] arrayRef,
int index,
Object value) |
(package private) static void |
aastoreUninterruptible(Object[] arrayRef,
int index,
Object value) |
static void |
athrow(Throwable exceptionObject)
Deliver a software exception to current java thread.
|
static Object |
buildMDAHelper(RVMMethod method,
int[] numElements,
int dimIndex,
RVMArray arrayType) |
static Object |
buildMultiDimensionalArray(int methodId,
int[] numElements,
RVMArray arrayType)
Build a multi-dimensional array.
|
static Object |
buildTwoDimensionalArray(int methodId,
int dim0,
int dim1,
RVMArray arrayType)
Build a two-dimensional array.
|
private static boolean |
canForceGC() |
private static void |
checkAllocationCountDownToGC()
Check to see if we are stress testing garbage collector and if another allocation should
trigger a GC then do so.
|
(package private) static void |
checkcast(Object object,
int id)
Throw exception unless object is instance of target
class/array or implements target interface.
|
static void |
checkJNICountDownToGC()
Check to see if we are stress testing garbage collector and if another JNI call should
trigger a gc then do so.
|
(package private) static void |
checkstore(Object array,
Object arrayElement) |
static Object |
clone(Object obj)
Clone a Scalar or Array Object.
|
private static Object |
cloneArray(Object obj,
RVMType type)
Clone an array
|
private static Object |
cloneClass(Object obj,
RVMType type)
Clone an object implementing a class - check that the class is cloneable
(we make this a small method with just a test so that the inliner will
inline it and hopefully eliminate the instanceof test).
|
private static Object |
cloneClass2(Object obj,
RVMType type)
Clone an object implementing a class - the actual clone
|
private static void |
deliverException(Throwable exceptionObject,
AbstractRegisters exceptionRegisters)
Deliver an exception to current java thread.
|
(package private) static void |
deliverHardwareException(int trapCode,
Word trapInfo)
Deliver a hardware exception to current java thread.
|
static int |
getObjectHashCode(Object object)
Get an object's "hashcode" value.
|
private static void |
handleUncaughtException(Throwable exceptionObject) |
static void |
init() |
static void |
initializeClassForDynamicLink(RVMClass cls)
Prepare a class for use prior to first allocation,
field access, or method invocation.
|
(package private) static boolean |
instanceOf(Object object,
int targetID)
Test if object is instance of target class/array or
implements target interface.
|
static boolean |
isAssignableWith(RVMType lhs,
RVMType rhs)
May a variable of type "lhs" be assigned a value of type "rhs"?
|
(package private) static void |
raiseAbstractMethodError()
Create and throw a java.lang.AbstractMethodError.
|
(package private) static void |
raiseArithmeticException()
Create and throw a java.lang.ArithmeticException.
|
(package private) static void |
raiseArrayIndexOutOfBoundsException()
Create and throw a java.lang.ArrayIndexOutOfBoundsException.
|
(package private) static void |
raiseArrayIndexOutOfBoundsException(int index)
Create and throw a java.lang.ArrayIndexOutOfBoundsException.
|
static void |
raiseArrayStoreException()
Create and throw a java.lang.ArrayStoreException.
|
(package private) static void |
raiseIllegalAccessError()
Create and throw a java.lang.IllegalAccessError.
|
private static void |
raiseNegativeArraySizeException()
Helper function to actually throw the required exception.
|
static void |
raiseNullPointerException()
Create and throw a java.lang.NullPointerException.
|
static Object |
resolvedNewArray(int numElements,
int logElementSize,
int headerSize,
TIB tib,
int allocator,
int align,
int offset,
int site)
Allocate something like "new int[cnt]" or "new Foo[cnt]".
|
static Object |
resolvedNewArray(int numElements,
RVMArray array)
Allocate something like "new Foo[]".
|
static Object |
resolvedNewArray(int numElements,
RVMArray array,
int site) |
static Object |
resolvedNewScalar(int size,
TIB tib,
boolean hasFinalizer,
int allocator,
int align,
int offset,
int site)
Allocate something like "new Foo()".
|
static Object |
resolvedNewScalar(RVMClass cls)
Allocate something like "new Foo()".
|
(package private) static void |
unexpectedAbstractMethodCall()
Report unexpected method call: abstract method (verification error).
|
(package private) static void |
unexpectedInterfaceMethodCall()
Report unexpected method call: interface method
(virtual machine dispatching error, shouldn't happen).
|
(package private) static void |
unlockAndThrow(Object objToUnlock,
Throwable objToThrow)
Unlock an object and then deliver a software exception
to current java thread.
|
static Object |
unresolvedNewArray(int numElements,
int id,
int site)
Allocate something like "new Foo[]".
|
(package private) static Object |
unresolvedNewScalar(int id,
int site)
Allocate something like "new Foo()".
|
private static void |
unwindInvisibleStackFrame(AbstractRegisters registers)
Unwind stack frame for an <invisible method>.
|
static Address |
unwindNativeStackFrame(Address currfp)
Skip over all frames below currfp with saved code pointers outside of heap
(C frames), stopping at the native frame immediately preceding the glue
frame which contains the method ID of the native method (this is necessary
to allow retrieving the return address of the glue frame).
|
static Address |
unwindNativeStackFrameForGC(Address currfp)
The current frame is expected to be one of the JNI functions
called from C,
below which is one or more native stack frames.
|
private static final boolean traceAthrow
public static final int TRAP_UNKNOWN
public static final int TRAP_NULL_POINTER
public static final int TRAP_ARRAY_BOUNDS
public static final int TRAP_DIVIDE_BY_ZERO
public static final int TRAP_STACK_OVERFLOW
public static final int TRAP_CHECKCAST
public static final int TRAP_REGENERATE
public static final int TRAP_JNI_STACK
public static final int TRAP_MUST_IMPLEMENT
public static final int TRAP_STORE_CHECK
public static final int TRAP_STACK_OVERFLOW_FATAL
public static final int TRAP_UNREACHABLE_BYTECODE
private static final String UNREACHABLE_BC_MESSAGE
static int allocationCountDownToGC
static int jniCountDownToGC
public RuntimeEntrypoints()
static boolean instanceOf(Object object, int targetID) throws NoClassDefFoundError
object
- object to be testedtargetID
- type reference id corresponding to target
class/array/interfaceNoClassDefFoundError
static void checkcast(Object object, int id) throws ClassCastException, NoClassDefFoundError
object
- object to be testedid
- of type reference corresponding to target class/array/interfaceClassCastException
NoClassDefFoundError
static void aastore(Object[] arrayRef, int index, Object value) throws ArrayStoreException, ArrayIndexOutOfBoundsException
static void aastoreUninterruptible(Object[] arrayRef, int index, Object value)
static void checkstore(Object array, Object arrayElement) throws ArrayStoreException
ArrayStoreException
public static boolean isAssignableWith(RVMType lhs, RVMType rhs)
lhs
- type of variablerhs
- type of valuestatic Object unresolvedNewScalar(int id, int site) throws NoClassDefFoundError, OutOfMemoryError
id
- id of type reference of class to createsite
- the site id of the calling allocation siteNoClassDefFoundError
OutOfMemoryError
public static Object resolvedNewScalar(RVMClass cls)
cls
- RVMClass of array to createpublic static Object resolvedNewScalar(int size, TIB tib, boolean hasFinalizer, int allocator, int align, int offset, int site) throws OutOfMemoryError
size
- size of object (including header), in bytestib
- type information block for objecthasFinalizer
- does this type have a finalizer?allocator
- int that encodes which allocator should be usedalign
- the alignment requested; must be a power of 2.offset
- the offset at which the alignment is desired.site
- the site id of the calling allocation siteOutOfMemoryError
public static Object unresolvedNewArray(int numElements, int id, int site) throws NoClassDefFoundError, OutOfMemoryError, NegativeArraySizeException
numElements
- number of array elementsid
- id of type reference of array to create.site
- the site id of the calling allocation siteNoClassDefFoundError
OutOfMemoryError
NegativeArraySizeException
public static Object resolvedNewArray(int numElements, RVMArray array) throws OutOfMemoryError, NegativeArraySizeException
numElements
- number of array elementsarray
- RVMArray of array to createOutOfMemoryError
NegativeArraySizeException
public static Object resolvedNewArray(int numElements, RVMArray array, int site) throws OutOfMemoryError, NegativeArraySizeException
public static Object resolvedNewArray(int numElements, int logElementSize, int headerSize, TIB tib, int allocator, int align, int offset, int site) throws OutOfMemoryError, NegativeArraySizeException
numElements
- number of array elementslogElementSize
- size in bytes of an array element, log base 2.headerSize
- size in bytes of array headertib
- type information block for array objectallocator
- int that encodes which allocator should be usedalign
- the alignment requested; must be a power of 2.offset
- the offset at which the alignment is desired.site
- the site id of the calling allocation siteOutOfMemoryError
NegativeArraySizeException
public static Object clone(Object obj) throws OutOfMemoryError, CloneNotSupportedException
For simplicity, we just code this more or less in Java using internal reflective operations and some magic. This is inefficient for large scalar objects, but until that is proven to be a performance problem, we won't worry about it. By keeping this in Java instead of dropping into Memory.copy, we avoid having to add special case code to deal with write barriers, and other such things.
This method calls specific cloning routines based on type to help guide the inliner (which won't inline a single large method).
obj
- the object to cloneCloneNotSupportedException
- when the object does not support cloningOutOfMemoryError
private static Object cloneArray(Object obj, RVMType type) throws OutOfMemoryError
obj
- the array to clonetype
- the type information for the arrayOutOfMemoryError
private static Object cloneClass(Object obj, RVMType type) throws OutOfMemoryError, CloneNotSupportedException
obj
- the object to clonetype
- the type information for the classCloneNotSupportedException
- when the object does not support cloningOutOfMemoryError
private static Object cloneClass2(Object obj, RVMType type) throws OutOfMemoryError
obj
- the object to clonetype
- the type information for the classOutOfMemoryError
private static void raiseNegativeArraySizeException() throws NegativeArraySizeException
NegativeArraySizeException
public static int getObjectHashCode(Object object)
object
- the object to hashObject.hashCode()
public static void initializeClassForDynamicLink(RVMClass cls)
cls
- the class to prepare for dynamic linkMemberReference.needsDynamicLink(org.jikesrvm.classloader.RVMMethod)
static void unexpectedInterfaceMethodCall()
static void unexpectedAbstractMethodCall()
public static void athrow(Throwable exceptionObject)
exceptionObject
- exception object to deliver
(null --> deliver NullPointerException).
does not return
(stack is unwound and execution resumes in a catch block)
This method is public so that it can be invoked by java.lang.VMClass.static void deliverHardwareException(int trapCode, Word trapInfo)
Does not return. (stack is unwound, starting at trap site, and execution resumes in a catch block somewhere up the stack) /or/ execution resumes at instruction following trap (for TRAP_STACK_OVERFLOW)
Note: Control reaches here by the actions of an external "C" signal handler which saves the register state of the trap site into the "exceptionRegisters" field of the current Thread object. The signal handler also inserts a <hardware trap> frame onto the stack immediately above this frame, for use by HardwareTrapGCMapIterator during garbage collection.
trapCode
- code indicating kind of exception that was trapped
(see TRAP_xxx, above)trapInfo
- array subscript (for array bounds trap, only), marker
(for stack overflow traps on PPC) orstatic void unlockAndThrow(Object objToUnlock, Throwable objToThrow)
Does not return (stack is unwound and execution resumes in a catch block).
objToUnlock
- object to unlockobjToThrow
- exception object to deliver
(null
--> deliver NullPointerException).static void raiseArrayIndexOutOfBoundsException(int index)
index
- the failing indexstatic void raiseArrayIndexOutOfBoundsException()
public static void raiseNullPointerException()
public static void raiseArrayStoreException()
static void raiseArithmeticException()
static void raiseAbstractMethodError()
static void raiseIllegalAccessError()
public static void init()
public static Object buildMultiDimensionalArray(int methodId, int[] numElements, RVMArray arrayType)
methodId
- TODO document menumElements
- number of elements to allocate for each dimensionarrayType
- type of array that will resultpublic static Object buildTwoDimensionalArray(int methodId, int dim0, int dim1, RVMArray arrayType)
methodId
- TODO document medim0
- the arraylength for arrays in dimension 0dim1
- the arraylength for arrays in dimension 1arrayType
- type of array that will resultpublic static Object buildMDAHelper(RVMMethod method, int[] numElements, int dimIndex, RVMArray arrayType)
method
- Apparently unused (!)numElements
- Number of elements to allocate for each dimensiondimIndex
- Current dimension to buildarrayType
- type of array that will resultprivate static void deliverException(Throwable exceptionObject, AbstractRegisters exceptionRegisters)
Does not return:
exceptionObject
- exception object to deliverexceptionRegisters
- register state corresponding to exception siteprivate static void handleUncaughtException(Throwable exceptionObject)
public static Address unwindNativeStackFrame(Address currfp)
currfp
- The current frame is expected to be one of the JNI functions
called from C, below which is one or more native stack framespublic static Address unwindNativeStackFrameForGC(Address currfp)
currfp
- the frame pointer of the current frameprivate static void unwindInvisibleStackFrame(AbstractRegisters registers)
!!TODO: Could be a reflective method invoker frame. Does it clobber any non-volatiles? If so, how do we restore them? (I don't think our current implementations of reflective method invokers save/restore any nonvolatiles, so we're probably ok. --dave 6/29/01
registers
- exception registerspublic static void checkJNICountDownToGC()
private static void checkAllocationCountDownToGC()
private static boolean canForceGC()
true
if we are stress testing garbage collector and the
system is in state where we can force a garbage collection.