use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.
the class MultianewarrayHelper method newArrayArray.
/**
* Allocate something like {@code new Foo[cnt0][cnt1]...[cntN-1]},
* or {@code new int[cnt0][cnt1]...[cntN-1]}.
* @param methodId method id of caller
* @param numDimensions number of array dimensions
* @param typeId type id of type reference for array
* @param argOffset position of word *above* `cnt0' argument within
* caller's frame This is used to access the number of elements to
* be allocated for each dimension.
*
* See also: bytecode 0xc5 ("multianewarray") in BaselineCompilerImpl
*
* @return newly allocated multidimensional array
*/
@Entrypoint
static Object newArrayArray(int methodId, int numDimensions, int typeId, int argOffset) throws NoClassDefFoundError, NegativeArraySizeException, OutOfMemoryError {
if (numDimensions == 2) {
int dim0, dim1;
// fetch number of elements to be allocated for each array dimension
VM.disableGC();
Address argp = Magic.getFramePointer().plus(argOffset);
argp = argp.minus(BYTES_IN_WORD);
dim0 = argp.loadInt();
argp = argp.minus(BYTES_IN_WORD);
dim1 = argp.loadInt();
VM.enableGC();
// validate arguments
if ((dim0 < 0) || (dim1 < 0))
throw new NegativeArraySizeException();
// create array
TypeReference tRef = TypeReference.getTypeRef(typeId);
RVMArray array = tRef.resolve().asArray();
return RuntimeEntrypoints.buildTwoDimensionalArray(methodId, dim0, dim1, array);
} else {
// fetch number of elements to be allocated for each array dimension
int[] numElements = new int[numDimensions];
VM.disableGC();
Address argp = Magic.getFramePointer().plus(argOffset);
for (int i = 0; i < numDimensions; ++i) {
argp = argp.minus(BYTES_IN_WORD);
numElements[i] = argp.loadInt();
}
VM.enableGC();
// validate arguments
for (int elements : numElements) {
if (elements < 0)
throw new NegativeArraySizeException();
}
// create array
TypeReference tRef = TypeReference.getTypeRef(typeId);
RVMArray array = tRef.resolve().asArray();
return RuntimeEntrypoints.buildMultiDimensionalArray(methodId, numElements, array);
}
}
use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.
the class RuntimeEntrypoints method checkstore.
@Entrypoint
@Inline
static void checkstore(Object array, Object arrayElement) throws ArrayStoreException {
if (arrayElement == null) {
// null may be assigned to any type
return;
}
RVMType lhsType = Magic.getObjectType(array);
RVMType elmType = lhsType.asArray().getElementType();
if (elmType == RVMType.JavaLangObjectType) {
// array of Object can receive anything
return;
}
RVMType rhsType = Magic.getObjectType(arrayElement);
if (elmType == rhsType) {
// exact type match
return;
}
if (isAssignableWith(elmType, rhsType)) {
return;
}
throw new ArrayStoreException();
}
use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.
the class RuntimeEntrypoints method instanceOf.
// ---------------------------------------------------------------//
// Type Checking. //
// ---------------------------------------------------------------//
/**
* Test if object is instance of target class/array or
* implements target interface.
* @param object object to be tested
* @param targetID type reference id corresponding to target
* class/array/interface
* @return true iff is object instance of target type?
*/
@Entrypoint
static boolean instanceOf(Object object, int targetID) throws NoClassDefFoundError {
/* Here, LHS and RHS refer to the way we would treat these if they were
arguments to an assignment operator and we were testing for
assignment-compatibility. In Java, "rhs instanceof lhs" means that
the operation "lhs = rhs" would succeed. This of course is backwards
if one is looking at it from the point of view of the "instanceof"
operator. */
TypeReference tRef = TypeReference.getTypeRef(targetID);
RVMType lhsType = tRef.peekType();
if (lhsType == null) {
lhsType = tRef.resolve();
}
if (!lhsType.isResolved()) {
// forces loading/resolution of super class/interfaces
lhsType.resolve();
}
/* Test for null only AFTER we have resolved the type of targetID. */
if (object == null) {
// null is not an instance of any type
return false;
}
RVMType rhsType = ObjectModel.getObjectType(object);
/* RHS must already be resolved, since we have a non-null object that is
an instance of RHS */
if (VM.VerifyAssertions)
VM._assert(rhsType.isResolved());
if (VM.VerifyAssertions)
VM._assert(lhsType.isResolved());
return lhsType == rhsType || DynamicTypeCheck.instanceOfResolved(lhsType, rhsType);
}
use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.
the class RuntimeEntrypoints method aastore.
@Entrypoint
static void aastore(Object[] arrayRef, int index, Object value) throws ArrayStoreException, ArrayIndexOutOfBoundsException {
checkstore(arrayRef, value);
int nelts = ObjectModel.getArrayLength(arrayRef);
if (index >= 0 && index < nelts) {
Services.setArrayUninterruptible(arrayRef, index, value);
} else {
throw new ArrayIndexOutOfBoundsException(index);
}
}
use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.
the class RuntimeEntrypoints method aastoreUninterruptible.
@Entrypoint
@Uninterruptible
static void aastoreUninterruptible(Object[] arrayRef, int index, Object value) {
if (VM.VerifyAssertions) {
int nelts = ObjectModel.getArrayLength(arrayRef);
VM._assert(index >= 0 && index < nelts);
}
Services.setArrayUninterruptible(arrayRef, index, value);
}
Aggregations