Search in sources :

Example 31 with MethodOperand

use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand in project JikesRVM by JikesRVM.

the class GenerationContextTest method childContextsSaveOSRBarrierInformationInOutermostParent.

@Test
public void childContextsSaveOSRBarrierInformationInOutermostParent() throws Exception {
    NormalMethod nm = getNormalMethodForTest("methodForInliningTests");
    CompiledMethod cm = new OptCompiledMethod(-1, nm);
    OptOptions opts = new OptOptions();
    InlineOracle io = new DefaultInlineOracle();
    GenerationContext outermost = new GenerationContext(nm, null, cm, opts, io);
    Class<?>[] classArgs = { Object.class };
    NormalMethod callee = getNormalMethodForTest("emptyStaticMethodWithObjectParamAndReturnValue", classArgs);
    MethodOperand methOp = MethodOperand.STATIC(callee);
    RegisterOperand result = createMockRegisterOperand(TypeReference.JavaLangObject);
    Instruction callInstr = Call.create(CALL, result, null, methOp, 1);
    RegisterOperand objectParam = createMockRegisterOperand(TypeReference.JavaLangObject);
    Call.setParam(callInstr, 0, objectParam);
    callInstr.setPosition(new InlineSequence(nm));
    ExceptionHandlerBasicBlockBag ebag = getMockEbag();
    GenerationContext child = outermost.createChildContext(ebag, callee, callInstr);
    Instruction osrBarrier = createMockOSRBarrier();
    Instruction call = createMockCall();
    child.saveOSRBarrierForInst(osrBarrier, call);
    assertThat(outermost.getOSRBarrierFromInst(call), is(osrBarrier));
    GenerationContext child2 = child.createChildContext(ebag, callee, callInstr);
    Instruction osrBarrier2 = createMockOSRBarrier();
    Instruction call2 = createMockCall();
    child2.saveOSRBarrierForInst(osrBarrier2, call2);
    assertThat(outermost.getOSRBarrierFromInst(call2), is(osrBarrier2));
}
Also used : OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineOracle(org.jikesrvm.compilers.opt.inlining.InlineOracle) 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) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) ExceptionHandlerBasicBlockBag(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag) 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 32 with MethodOperand

use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand in project JikesRVM by JikesRVM.

the class GenerationContextTest method buildCallInstructionForStaticMethodWithoutReturn.

private Instruction buildCallInstructionForStaticMethodWithoutReturn(NormalMethod callee, NormalMethod caller) {
    MethodOperand methOp = MethodOperand.STATIC(callee);
    Instruction callInstr = Call.create(CALL, null, null, methOp, 0);
    callInstr.setPosition(new InlineSequence(caller));
    return callInstr;
}
Also used : InlineSequence(org.jikesrvm.compilers.opt.inlining.InlineSequence) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand)

Example 33 with MethodOperand

use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand in project JikesRVM by JikesRVM.

the class GenerationContextTest method inliningMethodWithConstantReceiver.

@Test
public void inliningMethodWithConstantReceiver() throws Exception {
    NormalMethod nm = getNormalMethodForTest("methodForInliningTests");
    CompiledMethod cm = new OptCompiledMethod(-1, nm);
    OptOptions opts = new OptOptions();
    InlineOracle io = new DefaultInlineOracle();
    GenerationContext gc = new GenerationContext(nm, null, cm, opts, io);
    Class<?>[] argumentTypes = { Object.class, double.class, int.class, long.class };
    NormalMethod callee = getNormalMethodForTest("emptyInstanceMethodWithParams", argumentTypes);
    MethodOperand methOp = MethodOperand.VIRTUAL(callee.getMemberRef().asMethodReference(), callee);
    Instruction callInstr = Call.create(CALL, null, null, methOp, 5);
    ObjectConstantOperand receiver = new ObjectConstantOperand(new MethodsForTests(), null);
    Call.setParam(callInstr, 0, receiver);
    RegisterOperand objectParam = prepareCallWithObjectParam(callInstr);
    RegisterOperand doubleParam = prepareCallWithDoubleParam(callInstr);
    RegisterOperand intParam = prepareCallWithIntParam(callInstr);
    RegisterOperand longParam = prepareCallWithLongParam(callInstr);
    callInstr.setPosition(new InlineSequence(nm));
    ExceptionHandlerBasicBlockBag ebag = getMockEbag();
    int nodeNumber = 12345;
    gc.getCfg().setNumberOfNodes(nodeNumber);
    GenerationContext child = gc.createChildContext(ebag, callee, callInstr);
    assertThatStateIsCopiedFromParentToChild(gc, callee, child, ebag);
    assertThatReturnValueIsVoid(child);
    Operand thisArg = child.getArguments()[0];
    RegisterOperand expectedLocalForReceiverParam = child.makeLocal(0, thisArg.getType());
    expectedLocalForReceiverParam.setPreciseType();
    RegisterOperand expectedNullCheckGuard = child.makeNullCheckGuard(expectedLocalForReceiverParam.getRegister());
    BC2IR.setGuardForRegOp(expectedLocalForReceiverParam, expectedNullCheckGuard);
    assertNotNull(expectedNullCheckGuard);
    RegisterOperand firstArg = child.getArguments()[1].asRegister();
    RegisterOperand expectedLocalForObjectParam = child.makeLocal(1, firstArg);
    assertTrue(firstArg.sameRegisterPropertiesAs(expectedLocalForObjectParam));
    RegisterOperand secondArg = child.getArguments()[2].asRegister();
    RegisterOperand expectedLocalForDoubleParam = child.makeLocal(2, secondArg);
    assertTrue(secondArg.sameRegisterPropertiesAs(expectedLocalForDoubleParam));
    RegisterOperand thirdArg = child.getArguments()[3].asRegister();
    RegisterOperand expectedLocalForIntParam = child.makeLocal(4, thirdArg);
    assertTrue(thirdArg.sameRegisterPropertiesAs(expectedLocalForIntParam));
    RegisterOperand fourthArg = child.getArguments()[4].asRegister();
    RegisterOperand expectedLocalForLongParam = child.makeLocal(5, fourthArg);
    assertTrue(fourthArg.sameRegisterPropertiesAs(expectedLocalForLongParam));
    InlineSequence expectedInlineSequence = new InlineSequence(callee, callInstr.position(), callInstr);
    assertEquals(expectedInlineSequence, child.getInlineSequence());
    assertThatPrologueAndEpilogueAreWiredCorrectlyForChildContext(ebag, nodeNumber, child);
    Enumeration<Instruction> prologueRealInstr = child.getPrologue().forwardRealInstrEnumerator();
    Instruction guardMove = prologueRealInstr.nextElement();
    assertThat(guardMove.operator(), is(GUARD_MOVE));
    assertThat(guardMove.getBytecodeIndex(), is(UNKNOWN_BCI));
    RegisterOperand guardMoveResult = Move.getResult(guardMove);
    assertTrue(guardMoveResult.sameRegisterPropertiesAs(expectedNullCheckGuard));
    Operand moveValue = Move.getVal(guardMove);
    assertTrue(moveValue.isTrueGuard());
    assertNull(guardMove.position());
    Instruction receiverMove = prologueRealInstr.nextElement();
    Operand expectedReceiver = receiver.copy();
    // TODO definite non-nullness of constant operand is not being verified
    assertSame(callInstr.position(), receiverMove.position());
    assertThat(receiverMove.operator(), is(REF_MOVE));
    assertThat(receiverMove.getBytecodeIndex(), is(PROLOGUE_BCI));
    RegisterOperand receiverMoveResult = Move.getResult(receiverMove);
    assertTrue(receiverMoveResult.sameRegisterPropertiesAsExceptForGuardWhichIsSimilar(expectedLocalForReceiverParam));
    Operand receiverMoveValue = Move.getVal(receiverMove);
    assertTrue(receiverMoveValue.similar(expectedReceiver));
    Instruction objectMove = prologueRealInstr.nextElement();
    RegisterOperand objectParamCopy = objectParam.copy().asRegister();
    assertMoveOperationIsCorrect(callInstr, REF_MOVE, expectedLocalForObjectParam, objectParamCopy, objectMove);
    Instruction doubleMove = prologueRealInstr.nextElement();
    RegisterOperand doubleParamCopy = doubleParam.copy().asRegister();
    assertMoveOperationIsCorrect(callInstr, DOUBLE_MOVE, expectedLocalForDoubleParam, doubleParamCopy, doubleMove);
    Instruction intMove = prologueRealInstr.nextElement();
    RegisterOperand intParamCopy = intParam.copy().asRegister();
    assertMoveOperationIsCorrect(callInstr, INT_MOVE, expectedLocalForIntParam, intParamCopy, intMove);
    Instruction longMove = prologueRealInstr.nextElement();
    RegisterOperand longParamCopy = longParam.copy().asRegister();
    assertMoveOperationIsCorrect(callInstr, LONG_MOVE, expectedLocalForLongParam, longParamCopy, longMove);
    assertThatNoMoreInstructionsExist(prologueRealInstr);
    BasicBlock epilogue = child.getEpilogue();
    assertThatEpilogueLabelIsCorrectForInlinedMethod(child, expectedInlineSequence, epilogue);
    assertThatEpilogueIsEmpty(epilogue);
    assertThatNoRethrowBlockExists(child);
    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) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) ExceptionHandlerBasicBlockBag(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) MethodsForTests(org.jikesrvm.tests.util.MethodsForTests) NormalMethod(org.jikesrvm.classloader.NormalMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) InlineSequence(org.jikesrvm.compilers.opt.inlining.InlineSequence) Test(org.junit.Test)

Example 34 with MethodOperand

use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand in project JikesRVM by JikesRVM.

the class TailRecursionEliminationTest method unannotatedCallsAreSubjectToOptimization.

@Test
public void unannotatedCallsAreSubjectToOptimization() throws Exception {
    Class<?>[] types = {};
    RVMMethod m = TestingTools.getNormalMethod(MethodsForTests.class, "emptyStaticMethodWithoutAnnotations", types);
    MethodOperand methOp = MethodOperand.STATIC(m);
    Instruction call = Call.create(CALL, null, null, methOp, 0);
    assertTrue(tailRecursionElimination.allowedToOptimize(call));
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) Test(org.junit.Test)

Aggregations

MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)34 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)26 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)26 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)17 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)12 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)11 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)11 NormalMethod (org.jikesrvm.classloader.NormalMethod)10 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)10 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)10 Test (org.junit.Test)10 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)9 InlineSequence (org.jikesrvm.compilers.opt.inlining.InlineSequence)9 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)9 ExceptionHandlerBasicBlockBag (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag)9 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)9 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)9 RVMMethod (org.jikesrvm.classloader.RVMMethod)8 TypeReference (org.jikesrvm.classloader.TypeReference)8 OptOptions (org.jikesrvm.compilers.opt.OptOptions)8