Search in sources :

Example 26 with Entrypoint

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);
    }
}
Also used : Address(org.vmmagic.unboxed.Address) RVMArray(org.jikesrvm.classloader.RVMArray) TypeReference(org.jikesrvm.classloader.TypeReference) Entrypoint(org.vmmagic.pragma.Entrypoint) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 27 with Entrypoint

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();
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) Entrypoint(org.vmmagic.pragma.Entrypoint) Inline(org.vmmagic.pragma.Inline) NoInline(org.vmmagic.pragma.NoInline)

Example 28 with Entrypoint

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);
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) TypeReference(org.jikesrvm.classloader.TypeReference) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 29 with Entrypoint

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);
    }
}
Also used : Entrypoint(org.vmmagic.pragma.Entrypoint) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 30 with Entrypoint

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);
}
Also used : Entrypoint(org.vmmagic.pragma.Entrypoint) Uninterruptible(org.vmmagic.pragma.Uninterruptible) Entrypoint(org.vmmagic.pragma.Entrypoint)

Aggregations

Entrypoint (org.vmmagic.pragma.Entrypoint)69 Inline (org.vmmagic.pragma.Inline)35 ObjectReference (org.vmmagic.unboxed.ObjectReference)33 Offset (org.vmmagic.unboxed.Offset)22 Address (org.vmmagic.unboxed.Address)12 TypeReference (org.jikesrvm.classloader.TypeReference)7 NoInline (org.vmmagic.pragma.NoInline)7 RVMType (org.jikesrvm.classloader.RVMType)6 Unpreemptible (org.vmmagic.pragma.Unpreemptible)6 RVMMethod (org.jikesrvm.classloader.RVMMethod)5 RVMArray (org.jikesrvm.classloader.RVMArray)3 RVMClass (org.jikesrvm.classloader.RVMClass)3 RVMThread (org.jikesrvm.scheduler.RVMThread)3 BaselineSaveLSRegisters (org.vmmagic.pragma.BaselineSaveLSRegisters)3 NoOptCompile (org.vmmagic.pragma.NoOptCompile)3 AbstractRegisters (org.jikesrvm.architecture.AbstractRegisters)2 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)2 ForwardReference (org.jikesrvm.compilers.common.assembler.ForwardReference)2 ITable (org.jikesrvm.objectmodel.ITable)2 TIB (org.jikesrvm.objectmodel.TIB)2