Search in sources :

Example 1 with BaselineCompiledMethod

use of org.jikesrvm.compilers.baseline.BaselineCompiledMethod 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 2 with BaselineCompiledMethod

use of org.jikesrvm.compilers.baseline.BaselineCompiledMethod in project JikesRVM by JikesRVM.

the class TraceInterface method skipOwnFramesAndDump.

@Override
@NoInline
// This can't be uninterruptible --- it is an IO routine
@Interruptible
public Address skipOwnFramesAndDump(ObjectReference typeRef) {
    TIB tib = Magic.addressAsTIB(typeRef.toAddress());
    RVMMethod m = null;
    int bci = -1;
    int compiledMethodID = 0;
    Offset ipOffset = Offset.zero();
    Address fp = Magic.getFramePointer();
    Address ip = Magic.getReturnAddressUnchecked(fp);
    fp = Magic.getCallerFramePointer(fp);
    // This code borrows heavily from RVMThread.dumpStack
    final Address STACKFRAME_SENTINEL_FP = StackFrameLayout.getStackFrameSentinelFP();
    final int INVISIBLE_METHOD_ID = StackFrameLayout.getInvisibleMethodID();
    while (Magic.getCallerFramePointer(fp).NE(STACKFRAME_SENTINEL_FP)) {
        compiledMethodID = Magic.getCompiledMethodID(fp);
        if (compiledMethodID != INVISIBLE_METHOD_ID) {
            // normal java frame(s)
            CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(compiledMethodID);
            if (compiledMethod.getCompilerType() != CompiledMethod.TRAP) {
                ipOffset = compiledMethod.getInstructionOffset(ip);
                m = compiledMethod.getMethod();
                if (VM.BuildForOptCompiler && compiledMethod.getCompilerType() == CompiledMethod.OPT) {
                    OptCompiledMethod optInfo = (OptCompiledMethod) compiledMethod;
                    /* Opt stack frames may contain multiple inlined methods. */
                    OptMachineCodeMap map = optInfo.getMCMap();
                    int iei = map.getInlineEncodingForMCOffset(ipOffset);
                    if (iei >= 0) {
                        int[] inlineEncoding = map.inlineEncoding;
                        boolean allocCall = true;
                        bci = map.getBytecodeIndexForMCOffset(ipOffset);
                        for (int j = iei; j >= 0 && allocCall; j = OptEncodedCallSiteTree.getParent(j, inlineEncoding)) {
                            int mid = OptEncodedCallSiteTree.getMethodID(j, inlineEncoding);
                            m = MemberReference.getMethodRef(mid).getResolvedMember();
                            if (!isAllocCall(m.getName().getBytes()))
                                allocCall = false;
                            if (j > 0)
                                bci = OptEncodedCallSiteTree.getByteCodeOffset(j, inlineEncoding);
                        }
                        if (!allocCall)
                            break;
                    }
                } else {
                    if (!isAllocCall(m.getName().getBytes())) {
                        BaselineCompiledMethod baseInfo = (BaselineCompiledMethod) compiledMethod;
                        final int INSTRUCTION_WIDTH = ArchConstants.getInstructionWidth();
                        bci = baseInfo.findBytecodeIndexForInstruction(ipOffset.toWord().lsh(INSTRUCTION_WIDTH).toOffset());
                        break;
                    }
                }
            }
        }
        ip = Magic.getReturnAddressUnchecked(fp);
        fp = Magic.getCallerFramePointer(fp);
    }
    if (m != null) {
        int allocid = (((compiledMethodID & 0x0000ffff) << 15) ^ ((compiledMethodID & 0xffff0000) >> 16) ^ ipOffset.toInt()) & ~0x80000000;
        /* Now print the location string. */
        VM.sysWrite('\n');
        VM.writeHex(allocid);
        VM.sysWrite('-');
        VM.sysWrite('>');
        VM.sysWrite('[');
        VM.writeHex(compiledMethodID);
        VM.sysWrite(']');
        m.getDeclaringClass().getDescriptor().sysWrite();
        VM.sysWrite(':');
        m.getName().sysWrite();
        m.getDescriptor().sysWrite();
        VM.sysWrite(':');
        VM.writeHex(bci);
        VM.sysWrite('\t');
        RVMType type = tib.getType();
        type.getDescriptor().sysWrite();
        VM.sysWrite('\n');
    }
    return fp;
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) OptMachineCodeMap(org.jikesrvm.compilers.opt.runtimesupport.OptMachineCodeMap) Address(org.vmmagic.unboxed.Address) RVMType(org.jikesrvm.classloader.RVMType) BaselineCompiledMethod(org.jikesrvm.compilers.baseline.BaselineCompiledMethod) TIB(org.jikesrvm.objectmodel.TIB) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) BaselineCompiledMethod(org.jikesrvm.compilers.baseline.BaselineCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Offset(org.vmmagic.unboxed.Offset) Interruptible(org.vmmagic.pragma.Interruptible) NoInline(org.vmmagic.pragma.NoInline)

Aggregations

RVMMethod (org.jikesrvm.classloader.RVMMethod)2 BaselineCompiledMethod (org.jikesrvm.compilers.baseline.BaselineCompiledMethod)2 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)2 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)2 OptMachineCodeMap (org.jikesrvm.compilers.opt.runtimesupport.OptMachineCodeMap)2 Offset (org.vmmagic.unboxed.Offset)2 RVMType (org.jikesrvm.classloader.RVMType)1 OptimizingCompilerException (org.jikesrvm.compilers.opt.OptimizingCompilerException)1 TIB (org.jikesrvm.objectmodel.TIB)1 Interruptible (org.vmmagic.pragma.Interruptible)1 NoInline (org.vmmagic.pragma.NoInline)1 Address (org.vmmagic.unboxed.Address)1