Search in sources :

Example 1 with Offset

use of org.vmmagic.unboxed.Offset in project JikesRVM by JikesRVM.

the class OSRListener method handleOSRFromOpt.

public static void handleOSRFromOpt(Address yieldpointServiceMethodFP) {
    Address tsFromFP = yieldpointServiceMethodFP;
    Address realFP = Magic.getCallerFramePointer(tsFromFP);
    int ypTakenInCMID = Magic.getCompiledMethodID(realFP);
    Address stackbeg = Magic.objectAsAddress(RVMThread.getCurrentThread().getStack());
    Offset tsFromFPoff = tsFromFP.diff(stackbeg);
    Offset realFPoff = realFP.diff(stackbeg);
    OnStackReplacementTrigger.trigger(ypTakenInCMID, tsFromFPoff, realFPoff, RVMThread.OSROPT);
}
Also used : Address(org.vmmagic.unboxed.Address) Offset(org.vmmagic.unboxed.Offset)

Example 2 with Offset

use of org.vmmagic.unboxed.Offset in project JikesRVM by JikesRVM.

the class DynamicCallGraphOrganizer method thresholdReached.

/**
 * Process contents of buffer:
 *    add call graph edges and increment their weights.
 */
@Override
void thresholdReached() {
    if (DEBUG)
        VM.sysWriteln("DCG_Organizer.thresholdReached()");
    for (int i = 0; i < bufferSize; i = i + 3) {
        int calleeCMID = 0;
        // FIXME: This is necessary but hacky and may not even be correct.
        while (calleeCMID == 0) {
            calleeCMID = buffer[i + 0];
        }
        CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(calleeCMID);
        if (compiledMethod == null)
            continue;
        RVMMethod callee = compiledMethod.getMethod();
        if (callee.isRuntimeServiceMethod()) {
            if (DEBUG)
                VM.sysWrite("Skipping sample with runtime service callee");
            continue;
        }
        int callerCMID = buffer[i + 1];
        compiledMethod = CompiledMethods.getCompiledMethod(callerCMID);
        if (compiledMethod == null)
            continue;
        RVMMethod stackFrameCaller = compiledMethod.getMethod();
        int MCOff = buffer[i + 2];
        Offset MCOffset = Offset.fromIntSignExtend(buffer[i + 2]);
        int bytecodeIndex = -1;
        RVMMethod caller = null;
        switch(compiledMethod.getCompilerType()) {
            case CompiledMethod.TRAP:
            case CompiledMethod.JNI:
                if (DEBUG)
                    VM.sysWrite("Skipping sample with TRAP/JNI caller");
                continue;
            case CompiledMethod.BASELINE:
                {
                    BaselineCompiledMethod baseCompiledMethod = (BaselineCompiledMethod) compiledMethod;
                    // note: the following call expects the offset in INSTRUCTIONS!
                    bytecodeIndex = baseCompiledMethod.findBytecodeIndexForInstruction(MCOffset);
                    caller = stackFrameCaller;
                }
                break;
            case CompiledMethod.OPT:
                {
                    OptCompiledMethod optCompiledMethod = (OptCompiledMethod) compiledMethod;
                    OptMachineCodeMap mc_map = optCompiledMethod.getMCMap();
                    try {
                        bytecodeIndex = mc_map.getBytecodeIndexForMCOffset(MCOffset);
                        if (bytecodeIndex == -1) {
                            // so skip the sample.
                            if (DEBUG) {
                                VM.sysWrite("  *** SKIP SAMPLE ", stackFrameCaller.toString());
                                VM.sysWrite("@", compiledMethod.toString());
                                VM.sysWrite(" at MC offset ", MCOff);
                                VM.sysWrite(" calling ", callee.toString());
                                VM.sysWriteln(" due to invalid bytecodeIndex");
                            }
                            // skip sample.
                            continue;
                        }
                    } catch (java.lang.ArrayIndexOutOfBoundsException e) {
                        VM.sysWrite("  ***ERROR: getBytecodeIndexForMCOffset(", MCOffset);
                        VM.sysWriteln(") ArrayIndexOutOfBounds!");
                        e.printStackTrace();
                        if (VM.ErrorsFatal)
                            VM.sysFail("Exception in AI organizer.");
                        caller = stackFrameCaller;
                        // skip sample
                        continue;
                    } catch (OptimizingCompilerException e) {
                        VM.sysWrite("***Error: SKIP SAMPLE: can't find bytecode index in OPT compiled " + stackFrameCaller + "@" + compiledMethod + " at MC offset ", MCOff);
                        VM.sysWriteln("!");
                        if (VM.ErrorsFatal)
                            VM.sysFail("Exception in AI organizer.");
                        // skip sample
                        continue;
                    }
                    try {
                        caller = mc_map.getMethodForMCOffset(MCOffset);
                    } catch (java.lang.ArrayIndexOutOfBoundsException e) {
                        VM.sysWrite("  ***ERROR: getMethodForMCOffset(", MCOffset);
                        VM.sysWriteln(") ArrayIndexOutOfBounds!");
                        e.printStackTrace();
                        if (VM.ErrorsFatal)
                            VM.sysFail("Exception in AI organizer.");
                        caller = stackFrameCaller;
                        continue;
                    } catch (OptimizingCompilerException e) {
                        VM.sysWrite("***Error: SKIP SAMPLE: can't find caller in OPT compiled " + stackFrameCaller + "@" + compiledMethod + " at MC offset ", MCOff);
                        VM.sysWriteln("!");
                        if (VM.ErrorsFatal)
                            VM.sysFail("Exception in AI organizer.");
                        // skip sample
                        continue;
                    }
                    if (caller == null) {
                        VM.sysWrite("  ***ERROR: getMethodForMCOffset(", MCOffset);
                        VM.sysWriteln(") returned null!");
                        caller = stackFrameCaller;
                        // skip sample
                        continue;
                    }
                }
                break;
        }
        // increment the call graph edge, adding it if needed
        Controller.dcg.incrementEdge(caller, bytecodeIndex, callee);
    }
    if (thresholdReachedCount > 0) {
        thresholdReachedCount--;
    }
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) OptMachineCodeMap(org.jikesrvm.compilers.opt.runtimesupport.OptMachineCodeMap) BaselineCompiledMethod(org.jikesrvm.compilers.baseline.BaselineCompiledMethod) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) BaselineCompiledMethod(org.jikesrvm.compilers.baseline.BaselineCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) Offset(org.vmmagic.unboxed.Offset)

Example 3 with Offset

use of org.vmmagic.unboxed.Offset in project JikesRVM by JikesRVM.

the class BaselineExceptionDeliverer method unwindStackFrame.

/**
 * Unwind a stackframe.
 */
@Override
@Unpreemptible("Unwind stack possibly from unpreemptible code")
public void unwindStackFrame(CompiledMethod compiledMethod, AbstractRegisters registers) {
    NormalMethod method = (NormalMethod) compiledMethod.getMethod();
    ArchBaselineCompiledMethod bcm = (ArchBaselineCompiledMethod) compiledMethod;
    if (method.isSynchronized()) {
        Address ip = registers.getInnermostInstructionAddress();
        Offset instr = compiledMethod.getInstructionOffset(ip);
        Offset lockOffset = bcm.getLockAcquisitionOffset();
        if (instr.sGT(lockOffset)) {
            // we actually have the lock, so must unlock it.
            Object lock;
            if (method.isStatic()) {
                lock = method.getDeclaringClass().getResolvedClassForType();
            } else {
                Address fp = registers.getInnermostFramePointer();
                short location = bcm.getGeneralLocalLocation(0);
                Address addr;
                if (BaselineCompilerImpl.isRegister(location)) {
                    lock = Magic.addressAsObject(registers.getGPRs().get(location).toAddress());
                } else {
                    addr = fp.plus(BaselineCompilerImpl.locationToOffset(location) - // location offsets are positioned on top of their stackslot
                    BYTES_IN_ADDRESS);
                    lock = Magic.addressAsObject(addr.loadAddress());
                }
            }
            if (ObjectModel.holdsLock(lock, RVMThread.getCurrentThread())) {
                ObjectModel.genericUnlock(lock);
            }
        }
    }
    // restore non-volatile registers
    Address fp = registers.getInnermostFramePointer();
    Offset frameOffset = Offset.fromIntSignExtend(bcm.getFrameSize());
    for (int i = bcm.getLastFloatStackRegister(); i >= FIRST_FLOAT_LOCAL_REGISTER.value(); --i) {
        frameOffset = frameOffset.minus(BYTES_IN_DOUBLE);
        long temp = Magic.getLongAtOffset(Magic.addressAsObject(fp), frameOffset);
        registers.getFPRs()[i] = Magic.longBitsAsDouble(temp);
    }
    for (int i = bcm.getLastFixedStackRegister(); i >= FIRST_FIXED_LOCAL_REGISTER.value(); --i) {
        frameOffset = frameOffset.minus(BYTES_IN_ADDRESS);
        registers.getGPRs().set(i, fp.loadWord(frameOffset));
    }
    registers.unwindStackFrame();
}
Also used : Address(org.vmmagic.unboxed.Address) NormalMethod(org.jikesrvm.classloader.NormalMethod) Offset(org.vmmagic.unboxed.Offset) Unpreemptible(org.vmmagic.pragma.Unpreemptible)

Example 4 with Offset

use of org.vmmagic.unboxed.Offset in project JikesRVM by JikesRVM.

the class BaselineGCMapIterator method setupIterator.

/**
 * Set the iterator to scan the map at the machine instruction offset
 * provided. The iterator is positioned to the beginning of the map. NOTE: An
 * iterator may be reused to scan a different method and map.
 *
 * @param compiledMethod
 *          identifies the method and class
 * @param instructionOffset
 *          identifies the map to be scanned.
 * @param fp
 *          identifies a specific occurrance of this method and allows for
 *          processing instance specific information i.e JSR return address
 *          values
 */
@Override
public void setupIterator(CompiledMethod compiledMethod, Offset instructionOffset, Address fp) {
    currentCompiledMethod = (ArchBaselineCompiledMethod) compiledMethod;
    currentMethod = (NormalMethod) compiledMethod.getMethod();
    currentNumLocals = currentMethod.getLocalWords();
    // setup superclass
    // 
    framePtr = fp;
    // setup stackframe mapping
    // 
    mapReader.setMethod(currentMethod, compiledMethod);
    mapReader.locateGCPoint(instructionOffset);
    if (mapReader.currentMapIsForJSR()) {
        mapReader.acquireLockForJSRProcessing();
        int JSRindex = mapReader.setupJSRSubroutineMap();
        while (JSRindex != 0) {
            Address nextCallerAddress;
            short location = convertIndexToLocation(JSRindex);
            if (BaselineCompilerImpl.isRegister(location)) {
                nextCallerAddress = registerLocations.get(location);
            } else {
                nextCallerAddress = framePtr.plus(BaselineCompilerImpl.locationToOffset(location) - // location offsets are positioned on top of stackslot
                BYTES_IN_ADDRESS);
            }
            nextCallerAddress = nextCallerAddress.loadAddress();
            Offset nextMachineCodeOffset = compiledMethod.getInstructionOffset(nextCallerAddress);
            if (VM.TraceStkMaps) {
                traceSetupJSRsubroutineMap(JSRindex, nextCallerAddress, nextMachineCodeOffset);
            }
            JSRindex = mapReader.getNextJSRAddressIndex(nextMachineCodeOffset);
        }
    }
    if (VM.TraceStkMaps || TRACE_ALL) {
        VM.sysWrite("BaselineGCMapIterator setupIterator mapId = ");
        VM.sysWrite(mapReader.getMapId());
        VM.sysWrite(" for ");
        VM.sysWrite(currentMethod);
        VM.sysWriteln(".");
    }
    bridgeData.setupDynamicBridgeMapping(currentMethod, fp);
    reset();
}
Also used : Address(org.vmmagic.unboxed.Address) Offset(org.vmmagic.unboxed.Offset)

Example 5 with Offset

use of org.vmmagic.unboxed.Offset in project JikesRVM by JikesRVM.

the class BaselineCompiledMethod method findBytecodeIndexForInstruction.

/**
 * Find bytecode index corresponding to one of this method's
 * machine instructions.
 *
 * @param instructionOffset instruction offset to map to a bytecode index.<br>
 * Note: This method expects the offset to refer to the machine
 * instruction immediately FOLLOWING the bytecode in question.  just
 * like findLineNumberForInstruction. See CompiledMethod for
 * rationale.<br>
 * NOTE: instructionIndex is in units of instructions, not bytes
 * (different from all the other methods in this interface!!)
 * @return the bytecode index for the machine instruction, -1 if not
 *         available or not found.
 */
@Uninterruptible
public int findBytecodeIndexForInstruction(Offset instructionOffset) {
    Offset instructionIndex = instructionOffset.toWord().rsha(ArchConstants.getLogInstructionWidth()).toOffset();
    int candidateIndex = -1;
    int bcIndex = 0;
    Offset instrIndex = Offset.zero();
    for (int i = 0; i < bytecodeMap.length; ) {
        // unsign-extend
        int b0 = (bytecodeMap[i++]) & 255;
        int deltaBC, deltaIns;
        if (b0 != 255) {
            deltaBC = b0 >> 5;
            deltaIns = b0 & 31;
        } else {
            // unsign-extend
            int b1 = (bytecodeMap[i++]) & 255;
            // unsign-extend
            int b2 = (bytecodeMap[i++]) & 255;
            // unsign-extend
            int b3 = (bytecodeMap[i++]) & 255;
            // unsign-extend
            int b4 = (bytecodeMap[i++]) & 255;
            deltaBC = (b1 << 8) | b2;
            deltaIns = (b3 << 8) | b4;
        }
        bcIndex += deltaBC;
        instrIndex = instrIndex.plus(deltaIns);
        if (instrIndex.sGE(instructionIndex)) {
            break;
        }
        candidateIndex = bcIndex;
    }
    return candidateIndex;
}
Also used : Offset(org.vmmagic.unboxed.Offset) Uninterruptible(org.vmmagic.pragma.Uninterruptible)

Aggregations

Offset (org.vmmagic.unboxed.Offset)215 Address (org.vmmagic.unboxed.Address)48 Inline (org.vmmagic.pragma.Inline)38 Entrypoint (org.vmmagic.pragma.Entrypoint)32 ObjectReference (org.vmmagic.unboxed.ObjectReference)21 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)20 TypeReference (org.jikesrvm.classloader.TypeReference)17 RVMField (org.jikesrvm.classloader.RVMField)14 ForwardReference (org.jikesrvm.compilers.common.assembler.ForwardReference)13 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)13 NoInline (org.vmmagic.pragma.NoInline)13 RVMMethod (org.jikesrvm.classloader.RVMMethod)11 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)10 Word (org.vmmagic.unboxed.Word)10 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)9 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)9 RVMType (org.jikesrvm.classloader.RVMType)8 Register (org.jikesrvm.compilers.opt.ir.Register)8 RVMClass (org.jikesrvm.classloader.RVMClass)7 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)7