Search in sources :

Example 81 with CompiledMethod

use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.

the class SpecialCompiler method baselineCompile.

/**
 * Compiles the method with the baseline compiler.
 * <ol>
 *   <li>generate  prologue (PSEUDO_bytecode) from the state.
 *   <li>make up new byte code with prologue.
 *   <li>set method's bytecode to the specilizaed byte code.
 *   <li>call BaselineCompilerImpl.compile,
 *    the 'compile' method is customized to process pseudo instructions,
 *    and it will reset the byte code to the original one, and adjust
 *    the map from bytecode to the generated machine code. then the
 *    reference map can be generated corrected relying on the original
 *    bytecode.
 * </ol>
 * <p>
 * NOTE: this is different from optCompile which resets the
 *    bytecode after compilation. I believe this minimizes the
 *    work to change both compilers.
 * @param state the execution state for the compilation
 * @return the compiled method produced by the baseline compiler
 */
public static CompiledMethod baselineCompile(ExecutionState state) {
    NormalMethod method = state.getMethod();
    if (VM.TraceOnStackReplacement) {
        VM.sysWriteln("BASE : starts compiling " + method);
    }
    /* generate prologue bytes */
    byte[] prologue = state.generatePrologue();
    if (VM.TraceOnStackReplacement) {
        VM.sysWriteln("prologue length " + prologue.length);
    }
    // the compiler will call setForOsrSpecialization after generating the reference map
    /* set a flag for specialization, compiler will see it, and
     * know how to do it properly.
     */
    method.setForOsrSpecialization(prologue, state.getMaxStackHeight());
    /* for baseline compilation, we do not adjust the exception table and line table
    * because the compiler will generate maps after compilation.
    * Any necessary adjustment should be made during the compilation
    */
    CompiledMethod newCompiledMethod;
    if (VM.BuildForIA32) {
        newCompiledMethod = org.jikesrvm.compilers.baseline.ia32.BaselineCompilerImpl.compile(method);
    } else {
        if (VM.VerifyAssertions)
            VM._assert(VM.BuildForPowerPC);
        newCompiledMethod = org.jikesrvm.compilers.baseline.ppc.BaselineCompilerImpl.compile(method);
    }
    // compiled method was already set by BaselineCompilerImpl.compile
    // the call here does nothing
    // method.finalizeOsrSpecialization();
    // mark the method is a specialized one
    newCompiledMethod.setSpecialForOSR();
    if (VM.TraceOnStackReplacement) {
        // ((BaselineCompiledMethod)newCompiledMethod).printCodeMapEntries();
        VM.sysWriteln("BASE : done, CMID 0x" + Integer.toHexString(newCompiledMethod.getId()) + "(" + newCompiledMethod.getId() + ") JTOC offset " + Services.addressAsHexString(newCompiledMethod.getOsrJTOCoffset().toWord().toAddress()));
    }
    return newCompiledMethod;
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod)

Example 82 with CompiledMethod

use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.

the class SpecialCompiler method recompileState.

/**
 * recompile an execution state
 * @param state a list of execution states
 * @param invalidate Is this an invalidation?
 * @return the compiled method for the root state
 */
public static CompiledMethod recompileState(ExecutionState state, boolean invalidate) {
    // compile from callee to caller
    CompiledMethod newCM = null;
    do {
        if (!invalidate) {
            newCM = optCompile(state);
        } else {
            newCM = baselineCompile(state);
        }
        if (VM.TraceOnStackReplacement) {
            VM.sysWriteln("new CMID 0x" + Integer.toHexString(newCM.getId()) + "(" + newCM.getId() + ") for " + newCM.getMethod());
        }
        if (state.callerState == null)
            break;
        state = state.callerState;
        // set callee_cmid of the caller
        state.callee_cmid = newCM.getId();
    } while (true);
    return newCM;
}
Also used : CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod)

Example 83 with CompiledMethod

use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.

the class ExecutionStateExtractor method printStackTraces.

public static void printStackTraces(int[] stack, Offset osrFPoff) {
    VM.disableGC();
    Address fp = Magic.objectAsAddress(stack).plus(osrFPoff);
    Address ip = Magic.getReturnAddressUnchecked(fp);
    fp = Magic.getCallerFramePointer(fp);
    while (Magic.getCallerFramePointer(fp).NE(StackFrameLayout.getStackFrameSentinelFP())) {
        int cmid = Magic.getCompiledMethodID(fp);
        if (cmid == StackFrameLayout.getInvisibleMethodID()) {
            VM.sysWriteln(" invisible method ");
        } else {
            CompiledMethod cm = CompiledMethods.getCompiledMethod(cmid);
            Offset instrOff = cm.getInstructionOffset(ip);
            cm.printStackTrace(instrOff, PrintContainer.get(System.out));
            if (cm.getMethod().getDeclaringClass().hasBridgeFromNativeAnnotation()) {
                fp = RuntimeEntrypoints.unwindNativeStackFrame(fp);
            }
        }
        ip = Magic.getReturnAddressUnchecked(fp);
        fp = Magic.getCallerFramePointer(fp);
    }
    VM.enableGC();
}
Also used : Address(org.vmmagic.unboxed.Address) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Offset(org.vmmagic.unboxed.Offset)

Example 84 with CompiledMethod

use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.

the class GenerationContextTest method prologueAndEpilogueForSynchronizedInstanceMethodHaveMonitorEnterAndExit.

@Test
public void prologueAndEpilogueForSynchronizedInstanceMethodHaveMonitorEnterAndExit() throws Exception {
    NormalMethod nm = getNormalMethodForTest("emptySynchronizedInstanceMethod");
    CompiledMethod cm = new OptCompiledMethod(-1, nm);
    OptOptions opts = new OptOptions();
    InlineOracle io = new DefaultInlineOracle();
    GenerationContext gc = new GenerationContext(nm, null, cm, opts, io);
    InlineSequence inlineSequence = new InlineSequence(nm);
    assertThatInlineSequenceWasSetCorrectly(gc, inlineSequence);
    assertThatLocalsForInstanceMethodWithoutParametersAreCorrect(nm, gc);
    RegisterOperand thisOperand = getThisOperand(gc);
    BasicBlock prologue = gc.getPrologue();
    assertThatPrologueBlockIsSetupCorrectly(gc, inlineSequence, prologue);
    assertThatFirstInstructionInPrologueIsPrologue(inlineSequence, prologue);
    Enumeration<Instruction> prologueInstructions = prologue.forwardRealInstrEnumerator();
    prologueInstructions.nextElement();
    Instruction secondInstruction = prologueInstructions.nextElement();
    assertThatInstructionIsGuardMoveForPrologue(secondInstruction, thisOperand, gc);
    Instruction lastInstruction = prologueInstructions.nextElement();
    assertInstructionIsMonitorEnterInPrologue(lastInstruction, inlineSequence);
    assertThatGuardIsCorrectForMonitorEnter(lastInstruction);
    Operand lockObject = MonitorOp.getRef(lastInstruction);
    Operand expectedLockObject = buildLockObjectForInstanceMethod(nm, thisOperand, gc);
    assertTrue(expectedLockObject.similar(lockObject));
    assertThatNumberOfRealInstructionsMatches(prologue, 3);
    BasicBlock epilogue = gc.getEpilogue();
    assertThatEpilogueBlockIsSetupCorrectly(gc, inlineSequence, epilogue);
    assertThatFirstInstructionEpilogueIsMonitorExit(inlineSequence, epilogue);
    assertThatLastInstructionInEpilogueIsReturn(gc, epilogue);
    assertThatReturnInstructionReturnsVoid(epilogue);
    assertThatNumberOfRealInstructionsMatches(epilogue, 2);
    assertThatExitBlockIsSetCorrectly(gc);
    assertThatRegisterPoolExists(gc);
    assertThatDataIsSavedCorrectly(nm, cm, io, gc);
    assertThatReturnValueIsVoid(gc);
    assertThatExceptionHandlersWereGenerated(gc);
    assertThatUnlockAndRethrowBlockIsCorrect(gc, inlineSequence, prologue, expectedLockObject, epilogue);
    assertThatChecksWontBeSkipped(gc);
}
Also used : OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineOracle(org.jikesrvm.compilers.opt.inlining.InlineOracle) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) ClassConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) OptOptions(org.jikesrvm.compilers.opt.OptOptions) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) NormalMethod(org.jikesrvm.classloader.NormalMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineSequence(org.jikesrvm.compilers.opt.inlining.InlineSequence) Test(org.junit.Test)

Example 85 with CompiledMethod

use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.

the class GenerationContextTest method isLocalReturnsTrueForRegistersCreatedViaMakeLocal.

@Test
public void isLocalReturnsTrueForRegistersCreatedViaMakeLocal() throws Exception {
    Class<?>[] argumentTypes = { Object.class, double.class, int.class, long.class };
    NormalMethod nm = getNormalMethodForTest("emptyInstanceMethodWithParams", argumentTypes);
    CompiledMethod cm = new OptCompiledMethod(-1, nm);
    OptOptions opts = new OptOptions();
    InlineOracle io = new DefaultInlineOracle();
    GenerationContext gc = new GenerationContext(nm, null, cm, opts, io);
    int thisLocalNumber = 0;
    TypeReference localType = nm.getDeclaringClass().getTypeRef();
    RegisterOperand thisRegOp = gc.makeLocal(thisLocalNumber, localType);
    assertTrue(gc.isLocal(thisRegOp, thisLocalNumber, localType));
}
Also used : OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineOracle(org.jikesrvm.compilers.opt.inlining.InlineOracle) NormalMethod(org.jikesrvm.classloader.NormalMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) OptOptions(org.jikesrvm.compilers.opt.OptOptions) TypeReference(org.jikesrvm.classloader.TypeReference) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Test(org.junit.Test)

Aggregations

CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)97 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)56 NormalMethod (org.jikesrvm.classloader.NormalMethod)41 Test (org.junit.Test)33 OptOptions (org.jikesrvm.compilers.opt.OptOptions)32 Address (org.vmmagic.unboxed.Address)30 DefaultInlineOracle (org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle)28 InlineOracle (org.jikesrvm.compilers.opt.inlining.InlineOracle)28 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)20 Offset (org.vmmagic.unboxed.Offset)20 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)19 InlineSequence (org.jikesrvm.compilers.opt.inlining.InlineSequence)17 RVMMethod (org.jikesrvm.classloader.RVMMethod)14 ExceptionHandlerBasicBlockBag (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag)14 TypeReference (org.jikesrvm.classloader.TypeReference)13 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)13 ExceptionHandlerBasicBlock (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock)13 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)13 BaselineCompiledMethod (org.jikesrvm.compilers.baseline.BaselineCompiledMethod)10 RVMClass (org.jikesrvm.classloader.RVMClass)7