Search in sources :

Example 46 with Entrypoint

use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.

the class RuntimeEntrypoints method unresolvedNewArray.

/**
 * Allocate something like "new Foo[]".
 * @param numElements number of array elements
 * @param id id of type reference of array to create.
 * @param site the site id of the calling allocation site
 * @return array with header installed and all fields set to zero/null
 * See also: bytecode 0xbc ("anewarray")
 */
@Entrypoint
public static Object unresolvedNewArray(int numElements, int id, int site) throws NoClassDefFoundError, OutOfMemoryError, NegativeArraySizeException {
    TypeReference tRef = TypeReference.getTypeRef(id);
    RVMType t = tRef.peekType();
    if (t == null) {
        t = tRef.resolve();
    }
    RVMArray array = t.asArray();
    if (!array.isInitialized()) {
        array.resolve();
        array.instantiate();
    }
    return resolvedNewArray(numElements, array, site);
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) RVMType(org.jikesrvm.classloader.RVMType) TypeReference(org.jikesrvm.classloader.TypeReference) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 47 with Entrypoint

use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.

the class RuntimeEntrypoints method unresolvedNewScalar.

// ---------------------------------------------------------------//
// Object Allocation.                        //
// ---------------------------------------------------------------//
/**
 * Allocate something like "new Foo()".
 * @param id id of type reference of class to create
 * @param site the site id of the calling allocation site
 * @return object with header installed and all fields set to zero/null
 *           (ready for initializer to be run on it)
 * See also: bytecode 0xbb ("new")
 */
@Entrypoint
static Object unresolvedNewScalar(int id, int site) throws NoClassDefFoundError, OutOfMemoryError {
    TypeReference tRef = TypeReference.getTypeRef(id);
    RVMType t = tRef.peekType();
    if (t == null) {
        t = tRef.resolve();
    }
    RVMClass cls = t.asClass();
    if (!cls.isInitialized()) {
        initializeClassForDynamicLink(cls);
    }
    int allocator = MemoryManager.pickAllocator(cls);
    int align = ObjectModel.getAlignment(cls);
    int offset = ObjectModel.getOffsetForAlignment(cls, false);
    return resolvedNewScalar(cls.getInstanceSize(), cls.getTypeInformationBlock(), cls.hasFinalizer(), allocator, align, offset, site);
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) TypeReference(org.jikesrvm.classloader.TypeReference) Entrypoint(org.vmmagic.pragma.Entrypoint) RVMClass(org.jikesrvm.classloader.RVMClass) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 48 with Entrypoint

use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.

the class OutOfLineMachineCode method generateReflectiveMethodInvokerInstructions.

/**
 * Machine code for reflective method invocation.
 * See also: "Compiler.generateMethodInvocation".
 *
 *<pre>
 * Registers taken at runtime:
 *   T0 == address of method entrypoint to be called
 *   T1 == address of gpr registers to be loaded
 *   T2 == address of fpr registers to be loaded
 *   T4 == address of spill area in calling frame
 *
 * Registers returned at runtime:
 *   standard return value conventions used
 *
 * Side effects at runtime:
 *   artificial stackframe created and destroyed
 *   R0, volatile, and scratch registers destroyed
 * </pre>
 */
private static CodeArray generateReflectiveMethodInvokerInstructions() {
    Assembler asm = new Assembler(0);
    // 
    // free registers: 0, S0
    // 
    // save...
    asm.emitMFLR(GPR.R0);
    // ...return address
    asm.emitSTAddr(GPR.R0, STACKFRAME_RETURN_ADDRESS_OFFSET.toInt(), FP);
    // CTR := start of method code
    asm.emitMTCTR(T0);
    // 
    // free registers: 0, S0, T0
    // 
    // create new frame
    // 
    // S0 := old frame pointer
    asm.emitMR(S0, FP);
    // T0 := number of spill words
    asm.emitLIntOffset(T0, T4, ObjectModel.getArrayLengthOffset());
    // T4 -= 4 (predecrement, ie. T4 + 4 is &spill[0] )
    asm.emitADDI(T4, -BYTES_IN_ADDRESS, T4);
    int spillLoopLabel = asm.getMachineCodeIndex();
    // T0 -= 1 (and set CR)
    asm.emitADDICr(T0, T0, -1);
    // if T0 < 0 then break
    ForwardReference fr1 = asm.emitForwardBC(LT);
    // R0 := *(T4 += 4)
    asm.emitLAddrU(GPR.R0, BYTES_IN_ADDRESS, T4);
    // put one word of spill area
    asm.emitSTAddrU(GPR.R0, -BYTES_IN_ADDRESS, FP);
    // goto spillLoop:
    asm.emitB(spillLoopLabel);
    fr1.resolve(asm);
    // allocate frame header and save old fp
    asm.emitSTAddrU(S0, -STACKFRAME_HEADER_SIZE, FP);
    asm.emitLVAL(T0, INVISIBLE_METHOD_ID);
    // set method id
    asm.emitSTWoffset(T0, FP, STACKFRAME_METHOD_ID_OFFSET);
    // 
    // free registers: 0, S0, T0, T4
    // 
    // load up fprs
    // 
    ForwardReference setupFPRLoader = asm.emitForwardBL();
    for (int i = LAST_VOLATILE_FPR.value(); i >= FIRST_VOLATILE_FPR.value(); --i) {
        // FPRi := fprs[i]
        asm.emitLFDU(FPR.lookup(i), BYTES_IN_DOUBLE, T2);
    }
    // 
    // free registers: 0, S0, T0, T2, T4
    // 
    // load up gprs
    // 
    ForwardReference setupGPRLoader = asm.emitForwardBL();
    for (int i = LAST_VOLATILE_GPR.value(); i >= FIRST_VOLATILE_GPR.value(); --i) {
        // GPRi := gprs[i]
        asm.emitLAddrU(GPR.lookup(i), BYTES_IN_ADDRESS, S0);
    }
    // 
    // free registers: 0, S0
    // 
    // invoke method
    // 
    // branch and link to method code
    asm.emitBCCTRL();
    // emit method epilog
    // 
    // restore caller's frame
    asm.emitLAddr(FP, 0, FP);
    // pick up return address
    asm.emitLAddr(S0, STACKFRAME_RETURN_ADDRESS_OFFSET.toInt(), FP);
    // 
    asm.emitMTLR(S0);
    // return to caller
    asm.emitBCLR();
    setupFPRLoader.resolve(asm);
    // T4 := address of first fpr load instruction
    asm.emitMFLR(T4);
    // T0 := number of fprs to be loaded
    asm.emitLIntOffset(T0, T2, ObjectModel.getArrayLengthOffset());
    asm.emitADDI(T4, VOLATILE_FPRS << LG_INSTRUCTION_WIDTH, // T4 := address of first instruction following fpr loads
    T4);
    // T0 := number of bytes of fpr load instructions
    asm.emitSLWI(T0, T0, LG_INSTRUCTION_WIDTH);
    // T4 := address of instruction for highest numbered fpr to be loaded
    asm.emitSUBFC(T4, T0, T4);
    // LR := """
    asm.emitMTLR(T4);
    // predecrement fpr index (to prepare for update instruction)
    asm.emitADDI(T2, -BYTES_IN_DOUBLE, T2);
    // branch to fpr loading instructions
    asm.emitBCLR();
    setupGPRLoader.resolve(asm);
    // T4 := address of first gpr load instruction
    asm.emitMFLR(T4);
    // T0 := number of gprs to be loaded
    asm.emitLIntOffset(T0, T1, ObjectModel.getArrayLengthOffset());
    asm.emitADDI(T4, VOLATILE_GPRS << LG_INSTRUCTION_WIDTH, // T4 := address of first instruction following gpr loads
    T4);
    // T0 := number of bytes of gpr load instructions
    asm.emitSLWI(T0, T0, LG_INSTRUCTION_WIDTH);
    // T4 := address of instruction for highest numbered gpr to be loaded
    asm.emitSUBFC(T4, T0, T4);
    // LR := """
    asm.emitMTLR(T4);
    // predecrement gpr index (to prepare for update instruction)
    asm.emitADDI(S0, -BYTES_IN_ADDRESS, T1);
    // branch to gpr loading instructions
    asm.emitBCLR();
    return asm.getMachineCodes();
}
Also used : ForwardReference(org.jikesrvm.compilers.common.assembler.ForwardReference) Assembler(org.jikesrvm.compilers.common.assembler.ppc.Assembler) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 49 with Entrypoint

use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.

the class DynamicLinker method lazyMethodInvoker.

/**
 * Resolve, compile if necessary, and invoke a method.
 * <pre>
 *  Taken:    nothing (calling context is implicit)
 *  Returned: does not return (method dispatch table is updated and method is executed)
 * </pre>
 */
@Entrypoint
static void lazyMethodInvoker() {
    DynamicLink dl = DL_Helper.resolveDynamicInvocation();
    RVMMethod targMethod = DL_Helper.resolveMethodRef(dl);
    DL_Helper.compileMethod(dl, targMethod);
    CodeArray code = targMethod.getCurrentEntryCodeArray();
    // restore parameters and invoke
    Magic.dynamicBridgeTo(code);
    // does not return here
    if (VM.VerifyAssertions)
        VM._assert(NOT_REACHED);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) CodeArray(org.jikesrvm.compilers.common.CodeArray) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 50 with Entrypoint

use of org.vmmagic.pragma.Entrypoint in project JikesRVM by JikesRVM.

the class DynamicLinker method unimplementedNativeMethod.

/**
 * Report unimplemented native method error.
 * <pre>
 *  Taken:    nothing (calling context is implicit)
 *  Returned: does not return (throws UnsatisfiedLinkError)
 * </pre>
 */
@Entrypoint
static void unimplementedNativeMethod() {
    DynamicLink dl = DL_Helper.resolveDynamicInvocation();
    RVMMethod targMethod = DL_Helper.resolveMethodRef(dl);
    throw new UnsatisfiedLinkError(targMethod.toString());
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) 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