Search in sources :

Example 56 with CompiledMethod

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

the class EdgeListener method update.

/**
 * This method is called when a call stack edge needs to be
 * sampled.  Expect the sfp argument to point to the stack frame that
 * contains the target of the edge to be sampled.
 * <p>
 * NOTE: This method is uninterruptible, therefore we don't need to disable
 *       thread switching during stackframe inspection.
 *
 * @param sfp  a pointer to the stack frame that corresponds to the callee of
 *             the call graph edge that is to be sampled.
 * @param whereFrom Was this a yieldpoint in a PROLOGUE, BACKEDGE, or
 *         EPILOGUE?
 */
@Override
public final void update(Address sfp, int whereFrom) {
    if (DEBUG) {
        VM.sysWrite("EdgeListener.update(", sfp, ",", whereFrom);
        VM.sysWriteln("): enter ", samplesTaken);
    }
    Synchronization.fetchAndAdd(this, AosEntrypoints.edgeListenerUpdateCalledField.getOffset(), 1);
    // don't take a sample for back edge yield points
    if (whereFrom == RVMThread.BACKEDGE)
        return;
    int calleeCMID = 0;
    int callerCMID = 0;
    Address returnAddress = Address.zero();
    if (sfp.loadAddress().EQ(StackFrameLayout.getStackFrameSentinelFP())) {
        if (DEBUG)
            VM.sysWriteln(" Walking off end of stack!");
        return;
    }
    calleeCMID = Magic.getCompiledMethodID(sfp);
    if (calleeCMID == StackFrameLayout.getInvisibleMethodID()) {
        if (DEBUG) {
            VM.sysWrite(" INVISIBLE_METHOD_ID  (assembler code) ");
            VM.sysWrite(calleeCMID);
            VM.sysWriteln();
        }
        return;
    }
    // return address in caller
    returnAddress = Magic.getReturnAddress(sfp);
    // caller's frame pointer
    sfp = Magic.getCallerFramePointer(sfp);
    if (sfp.loadAddress().EQ(StackFrameLayout.getStackFrameSentinelFP())) {
        if (DEBUG)
            VM.sysWriteln(" Walking off end of stack");
        return;
    }
    callerCMID = Magic.getCompiledMethodID(sfp);
    if (callerCMID == StackFrameLayout.getInvisibleMethodID()) {
        if (DEBUG) {
            VM.sysWrite(" INVISIBLE_METHOD_ID  (assembler code) ");
            VM.sysWrite(callerCMID);
            VM.sysWriteln();
        }
        return;
    }
    // store the offset of the return address from the beginning of the
    // instruction
    CompiledMethod callerCM = CompiledMethods.getCompiledMethod(callerCMID);
    if (callerCM.getCompilerType() == CompiledMethod.TRAP) {
        if (DEBUG) {
            VM.sysWriteln(" HARDWARE TRAP FRAME ");
        }
        return;
    }
    Offset callSite = callerCM.getInstructionOffset(returnAddress);
    if (DEBUG) {
        VM.sysWrite("  <");
        VM.sysWrite(calleeCMID);
        VM.sysWrite(",");
        VM.sysWrite(callerCMID);
        VM.sysWrite(",");
        VM.sysWrite(returnAddress);
        VM.sysWriteln(">");
    }
    // Find out what sample we are.
    int sampleNumber = Synchronization.fetchAndAdd(this, AosEntrypoints.edgeListenerSamplesTakenField.getOffset(), 1);
    int idx = 3 * sampleNumber;
    // is in the process of activating our organizer and processing the buffer).
    if (idx < buffer.length) {
        buffer[idx + 1] = callerCMID;
        buffer[idx + 2] = callSite.toInt();
        Magic.fence();
        buffer[idx + 0] = calleeCMID;
        // If we are the last sample, we need to activate the organizer.
        if (sampleNumber + 1 == desiredSamples) {
            activateOrganizer();
        }
    }
}
Also used : Address(org.vmmagic.unboxed.Address) Entrypoint(org.vmmagic.pragma.Entrypoint) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Offset(org.vmmagic.unboxed.Offset)

Example 57 with CompiledMethod

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

the class SpecializedMethodPool method registerCompiledMethod.

static void registerCompiledMethod(SpecializedMethod m) {
    int smid = m.getSpecializedMethodIndex();
    CompiledMethod cm = m.getCompiledMethod();
    storeSpecializedMethod(cm, smid);
}
Also used : Entrypoint(org.vmmagic.pragma.Entrypoint) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod)

Example 58 with CompiledMethod

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

the class BaselineGCMapIteratorTest method getNextReferenceAddressReturnsCorrectReferenceIfReferencesArePresent.

@Test
public void getNextReferenceAddressReturnsCorrectReferenceIfReferencesArePresent() throws Exception {
    NormalMethod nm = TestingTools.getNormalMethod(MethodsForTests.class, "emptyStaticMethodWithObjectParam", Object.class);
    CompiledMethod cm = nm.getCurrentCompiledMethod();
    // Fake a stack frame
    int stackWords = 5;
    WordArray wa = createNonMovableWordArray(stackWords);
    for (int i = 0; i < wa.length(); i++) {
        wa.set(i, Word.fromIntSignExtend(5 * i));
    }
    int targetSlot = wa.length() - 1;
    Address fp = Magic.objectAsAddress(wa).plus(targetSlot * BYTES_IN_WORD);
    // local 0 is reference.
    // +/- 0 words: FP
    // - 1 words: CMID
    // - 2 words: saved GPRs (EDI)
    // - 3 words: saved GPRs (EBX)
    // - 4 words: local0 == reference
    Address targetAddress = fp.minus(4 * BYTES_IN_STACKSLOT);
    Word targetContents = targetAddress.loadWord();
    gcMapIter.setupIterator(cm, Offset.fromIntZeroExtend(cm.getEntryCodeArray().length()), fp);
    Address referenceAddr = gcMapIter.getNextReferenceAddress();
    assertEquals(targetAddress, referenceAddr);
    assertEquals(targetContents, referenceAddr.loadWord());
}
Also used : Word(org.vmmagic.unboxed.Word) Address(org.vmmagic.unboxed.Address) NormalMethod(org.jikesrvm.classloader.NormalMethod) WordArray(org.vmmagic.unboxed.WordArray) TestingTools.createNonMovableWordArray(org.jikesrvm.tests.util.TestingTools.createNonMovableWordArray) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Test(org.junit.Test)

Example 59 with CompiledMethod

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

the class BaselineGCMapIteratorTest method getNextReferenceAddressReturnsZeroIfNoReferencesArePresent.

@Test
public void getNextReferenceAddressReturnsZeroIfNoReferencesArePresent() throws Exception {
    NormalMethod nm = TestingTools.getNormalMethod(MethodsForTests.class, "emptyStaticMethodWithoutAnnotations");
    CompiledMethod cm = nm.getCurrentCompiledMethod();
    gcMapIter.setupIterator(cm, NO_OFFSET, NO_FP);
    Address referenceAddr = gcMapIter.getNextReferenceAddress();
    assertZero(referenceAddr);
}
Also used : Address(org.vmmagic.unboxed.Address) NormalMethod(org.jikesrvm.classloader.NormalMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Test(org.junit.Test)

Example 60 with CompiledMethod

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

the class GenerationContextTest method prologueAndEpilogueForSynchronizedStaticMethodHaveMonitorEnterAndExit.

@Test
public void prologueAndEpilogueForSynchronizedStaticMethodHaveMonitorEnterAndExit() throws Exception {
    NormalMethod nm = getNormalMethodForTest("emptySynchronizedStaticMethod");
    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);
    assertThatNumberOfParametersIs(gc, 0);
    BasicBlock prologue = gc.getPrologue();
    assertThatPrologueBlockIsSetupCorrectly(gc, inlineSequence, prologue);
    assertThatFirstInstructionInPrologueIsPrologue(inlineSequence, prologue);
    Enumeration<Instruction> prologueInstructions = prologue.forwardRealInstrEnumerator();
    prologueInstructions.nextElement();
    Instruction secondInstruction = prologueInstructions.nextElement();
    assertInstructionIsMonitorEnterInPrologue(secondInstruction, inlineSequence);
    assertThatGuardIsCorrectForMonitorEnter(secondInstruction);
    Operand lockObject = MonitorOp.getRef(secondInstruction);
    Operand expectedLockObject = buildLockObjectForStaticMethod(nm);
    assertTrue(expectedLockObject.similar(lockObject));
    assertThatNumberOfRealInstructionsMatches(prologue, 2);
    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) NormalMethod(org.jikesrvm.classloader.NormalMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) InlineSequence(org.jikesrvm.compilers.opt.inlining.InlineSequence) 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) 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