Search in sources :

Example 6 with AbstractRegisters

use of org.jikesrvm.architecture.AbstractRegisters in project JikesRVM by JikesRVM.

the class StackTrace method recordFramesUninterruptible.

/**
 * Walk the stack recording the stack frames encountered
 * The stack being walked is our stack, so code is Uninterrupible to stop the
 * stack moving.
 *
 * @param stackTraceThread the thread whose stack is walked
 */
@Uninterruptible
@NoInline
private void recordFramesUninterruptible(RVMThread stackTraceThread) {
    int stackFrameCount = 0;
    Address fp;
    Address ip;
    /* Stack trace for the thread */
    if (stackTraceThread == RVMThread.getCurrentThread()) {
        fp = Magic.getFramePointer();
    } else {
        AbstractRegisters contextRegisters = stackTraceThread.getContextRegisters();
        fp = contextRegisters.getInnermostFramePointer();
    }
    ip = Magic.getReturnAddress(fp);
    fp = Magic.getCallerFramePointer(fp);
    while (Magic.getCallerFramePointer(fp).NE(StackFrameLayout.getStackFrameSentinelFP())) {
        // VM.sysWriteln("at stackFrameCount = ",stackFrameCount);
        int compiledMethodId = Magic.getCompiledMethodID(fp);
        compiledMethods[stackFrameCount] = compiledMethodId;
        if (compiledMethodId != StackFrameLayout.getInvisibleMethodID()) {
            CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(compiledMethodId);
            if (compiledMethod.getCompilerType() != CompiledMethod.TRAP) {
                instructionOffsets[stackFrameCount] = compiledMethod.getInstructionOffset(ip).toInt();
                if (compiledMethod.hasBridgeFromNativeAnnotation()) {
                    // VM.sysWriteln("native!");
                    // skip native frames, stopping at last native frame preceeding the
                    // Java To C transition frame
                    fp = RuntimeEntrypoints.unwindNativeStackFrame(fp);
                }
            } else {
            // VM.sysWriteln("trap!");
            }
        } else {
        // VM.sysWriteln("invisible method!");
        }
        stackFrameCount++;
        ip = Magic.getReturnAddress(fp, stackTraceThread);
        fp = Magic.getCallerFramePointer(fp);
    }
}
Also used : Address(org.vmmagic.unboxed.Address) AbstractRegisters(org.jikesrvm.architecture.AbstractRegisters) BaselineCompiledMethod(org.jikesrvm.compilers.baseline.BaselineCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) Uninterruptible(org.vmmagic.pragma.Uninterruptible) NoInline(org.vmmagic.pragma.NoInline)

Example 7 with AbstractRegisters

use of org.jikesrvm.architecture.AbstractRegisters in project JikesRVM by JikesRVM.

the class BaselineExecutionStateExtractor method extractState.

@Override
public ExecutionState extractState(RVMThread thread, Offset tsFromFPoff, Offset methFPoff, int cmid) {
    if (VM.TraceOnStackReplacement) {
        VM.sysWriteln("BASE execStateExtractor starting ...");
    }
    AbstractRegisters contextRegisters = thread.getContextRegisters();
    byte[] stack = thread.getStack();
    if (VM.VerifyAssertions) {
        int fooCmid = Magic.getIntAtOffset(stack, methFPoff.plus(STACKFRAME_METHOD_ID_OFFSET));
        VM._assert(fooCmid == cmid);
    }
    ArchBaselineCompiledMethod fooCM = (ArchBaselineCompiledMethod) CompiledMethods.getCompiledMethod(cmid);
    NormalMethod fooM = (NormalMethod) fooCM.getMethod();
    // get the next bc index
    VM.disableGC();
    Address rowIP = Magic.objectAsAddress(stack).loadAddress(methFPoff.plus(STACKFRAME_RETURN_ADDRESS_OFFSET));
    Offset ipOffset = fooCM.getInstructionOffset(rowIP);
    VM.enableGC();
    // CAUTION: IP Offset should point to next instruction
    int bcIndex = fooCM.findBytecodeIndexForInstruction(ipOffset.plus(INSTRUCTION_WIDTH));
    // assertions
    if (VM.VerifyAssertions)
        VM._assert(bcIndex != -1);
    // create execution state object
    ExecutionState state = new ExecutionState(thread, methFPoff, cmid, bcIndex, tsFromFPoff);
    /* extract values for local and stack, but first of all
     * we need to get type information for current PC.
     */
    BytecodeTraverser typer = new BytecodeTraverser();
    typer.computeLocalStackTypes(fooM, bcIndex);
    byte[] localTypes = typer.getLocalTypes();
    byte[] stackTypes = typer.getStackTypes();
    // type. We should remove non-reference type
    for (int i = 0, n = localTypes.length; i < n; i++) {
        // if typer reports a local is reference type, but the GC map says no
        // then set the localType to uninitialized, see VM spec, bytecode verifier
        // CAUTION: gc map uses mc offset in bytes!!!
        boolean gcref = fooCM.referenceMaps.isLocalRefType(fooM, ipOffset.plus(INSTRUCTION_WIDTH), i);
        if (!gcref && (localTypes[i] == ClassTypeCode)) {
            // use gc map as reference
            localTypes[i] = VoidTypeCode;
            if (VM.TraceOnStackReplacement) {
                VM.sysWriteln("GC maps disgrees with type matcher at " + i + "th local");
                VM.sysWriteln();
            }
        }
    }
    if (VM.TraceOnStackReplacement) {
        Offset ipIndex = ipOffset.toWord().rsha(LG_INSTRUCTION_WIDTH).toOffset();
        VM.sysWriteln("BC Index : " + bcIndex);
        VM.sysWriteln("IP Index : ", ipIndex.plus(1));
        VM.sysWriteln("MC Offset : ", ipOffset.plus(INSTRUCTION_WIDTH));
        VM.sysWrite("Local Types :");
        for (byte localType : localTypes) {
            VM.sysWrite(" " + (char) localType);
        }
        VM.sysWriteln();
        VM.sysWrite("Stack Types :");
        for (byte stackType : stackTypes) {
            VM.sysWrite(" " + (char) stackType);
        }
        VM.sysWriteln();
    }
    // go through the stack frame and extract values
    // In the variable value list, we keep the order as follows:
    // L0, L1, ..., S0, S1, ....
    // adjust local offset and stack offset
    // NOTE: donot call BaselineCompilerImpl.getFirstLocalOffset(method)
    int bufCMID = Magic.getIntAtOffset(stack, tsFromFPoff.plus(STACKFRAME_METHOD_ID_OFFSET));
    CompiledMethod bufCM = CompiledMethods.getCompiledMethod(bufCMID);
    int cType = bufCM.getCompilerType();
    // restore non-volatile registers that could contain locals; saved by yieldpointfrom methods
    // for the moment disabled OPT compilation of yieldpointfrom, because here we assume baselinecompilation !! TODO
    TempRegisters registers = new TempRegisters(contextRegisters);
    WordArray gprs = registers.gprs;
    double[] fprs = registers.fprs;
    Object[] objs = registers.objs;
    VM.disableGC();
    // the threadswitchfrom... method on the other hand can be baseline or opt!
    if (cType == CompiledMethod.BASELINE) {
        if (VM.VerifyAssertions) {
            VM._assert(bufCM.getMethod().hasBaselineSaveLSRegistersAnnotation());
            VM._assert(methFPoff.EQ(tsFromFPoff.plus(((ArchBaselineCompiledMethod) bufCM).getFrameSize())));
        }
        Offset currentRegisterLocation = tsFromFPoff.plus(((ArchBaselineCompiledMethod) bufCM).getFrameSize());
        for (int i = LAST_FLOAT_STACK_REGISTER.value(); i >= FIRST_FLOAT_LOCAL_REGISTER.value(); --i) {
            currentRegisterLocation = currentRegisterLocation.minus(BYTES_IN_DOUBLE);
            long lbits = Magic.getLongAtOffset(stack, currentRegisterLocation);
            fprs[i] = Magic.longBitsAsDouble(lbits);
        }
        for (int i = LAST_FIXED_STACK_REGISTER.value(); i >= FIRST_FIXED_LOCAL_REGISTER.value(); --i) {
            currentRegisterLocation = currentRegisterLocation.minus(BYTES_IN_ADDRESS);
            Word w = Magic.objectAsAddress(stack).loadWord(currentRegisterLocation);
            gprs.set(i, w);
        }
    } else {
        // (cType == CompiledMethod.OPT)
        // KV: this code needs to be modified. We need the tsFrom methods to save all NON-VOLATILES in their prolog (as is the case for baseline)
        // This is because we don't know at compile time which registers might be in use and wich not by the caller method at runtime!!
        // For now we disallow tsFrom methods to be opt compiled when the caller is baseline compiled
        // todo: fix this together with the SaveVolatile rewrite
        OptCompiledMethod fooOpt = (OptCompiledMethod) bufCM;
        // foo definitely not save volatile.
        if (VM.VerifyAssertions) {
            boolean saveVolatile = fooOpt.isSaveVolatile();
            VM._assert(!saveVolatile);
        }
        Offset offset = tsFromFPoff.plus(fooOpt.getUnsignedNonVolatileOffset());
        // recover nonvolatile GPRs
        int firstGPR = fooOpt.getFirstNonVolatileGPR();
        if (firstGPR != -1) {
            for (int i = firstGPR; i <= LAST_NONVOLATILE_GPR.value(); i++) {
                Word w = Magic.objectAsAddress(stack).loadWord(offset);
                gprs.set(i, w);
                offset = offset.plus(BYTES_IN_ADDRESS);
            }
        }
        // recover nonvolatile FPRs
        int firstFPR = fooOpt.getFirstNonVolatileFPR();
        if (firstFPR != -1) {
            for (int i = firstFPR; i <= LAST_NONVOLATILE_FPR.value(); i++) {
                long lbits = Magic.getLongAtOffset(stack, offset);
                fprs[i] = Magic.longBitsAsDouble(lbits);
                offset = offset.plus(BYTES_IN_DOUBLE);
            }
        }
    }
    // save objects in registers in register object array
    int size = localTypes.length;
    for (int i = 0; i < size; i++) {
        if ((localTypes[i] == ClassTypeCode) || (localTypes[i] == ArrayTypeCode)) {
            short loc = fooCM.getGeneralLocalLocation(i);
            if (BaselineCompilerImpl.isRegister(loc)) {
                objs[loc] = Magic.addressAsObject(gprs.get(loc).toAddress());
            }
        }
    }
    VM.enableGC();
    // for locals
    getVariableValueFromLocations(stack, methFPoff, localTypes, fooCM, LOCAL, registers, state);
    // for stacks
    Offset stackOffset = methFPoff.plus(fooCM.getEmptyStackOffset());
    getVariableValue(stack, stackOffset, stackTypes, fooCM, STACK, state);
    if (VM.TraceOnStackReplacement) {
        state.printState();
    }
    if (VM.TraceOnStackReplacement) {
        VM.sysWriteln("BASE executionStateExtractor done ");
    }
    return state;
}
Also used : ExecutionState(org.jikesrvm.osr.ExecutionState) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) Word(org.vmmagic.unboxed.Word) Address(org.vmmagic.unboxed.Address) BytecodeTraverser(org.jikesrvm.osr.BytecodeTraverser) AbstractRegisters(org.jikesrvm.architecture.AbstractRegisters) ArchBaselineCompiledMethod(org.jikesrvm.compilers.baseline.ppc.ArchBaselineCompiledMethod) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Offset(org.vmmagic.unboxed.Offset) ArchBaselineCompiledMethod(org.jikesrvm.compilers.baseline.ppc.ArchBaselineCompiledMethod) NormalMethod(org.jikesrvm.classloader.NormalMethod) WordArray(org.vmmagic.unboxed.WordArray)

Aggregations

AbstractRegisters (org.jikesrvm.architecture.AbstractRegisters)7 Address (org.vmmagic.unboxed.Address)6 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)5 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)3 NoInline (org.vmmagic.pragma.NoInline)3 BaselineCompiledMethod (org.jikesrvm.compilers.baseline.BaselineCompiledMethod)2 RVMThread (org.jikesrvm.scheduler.RVMThread)2 Entrypoint (org.vmmagic.pragma.Entrypoint)2 Uninterruptible (org.vmmagic.pragma.Uninterruptible)2 Offset (org.vmmagic.unboxed.Offset)2 NormalMethod (org.jikesrvm.classloader.NormalMethod)1 ArchBaselineCompiledMethod (org.jikesrvm.compilers.baseline.ppc.ArchBaselineCompiledMethod)1 BytecodeTraverser (org.jikesrvm.osr.BytecodeTraverser)1 ExecutionState (org.jikesrvm.osr.ExecutionState)1 Unpreemptible (org.vmmagic.pragma.Unpreemptible)1 UnpreemptibleNoWarn (org.vmmagic.pragma.UnpreemptibleNoWarn)1 ObjectReference (org.vmmagic.unboxed.ObjectReference)1 Word (org.vmmagic.unboxed.Word)1 WordArray (org.vmmagic.unboxed.WordArray)1