Search in sources :

Example 56 with BasicBlock

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

the class GenerationContextTest method assertThatEnclosingHandlersContainRethrow.

private void assertThatEnclosingHandlersContainRethrow(ExceptionHandlerBasicBlock rethrow, ExceptionHandlerBasicBlockBag ehbbb) {
    boolean rethrowFound = false;
    Enumeration<BasicBlock> exceptionHandlerBasicBlocks = ehbbb.enumerator();
    while (exceptionHandlerBasicBlocks.hasMoreElements()) {
        BasicBlock nextElement = exceptionHandlerBasicBlocks.nextElement();
        if (nextElement == rethrow) {
            rethrowFound = true;
        }
    }
    assertTrue(rethrowFound);
}
Also used : BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock)

Example 57 with BasicBlock

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

the class GenerationContextTest method methodsWithReturnValueHaveReturnInstructionInEpilogue.

@Test
public void methodsWithReturnValueHaveReturnInstructionInEpilogue() throws Exception {
    NormalMethod nm = getNormalMethodForTest("staticMethodReturningLongMaxValue");
    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);
    assertThatBlockOnlyHasOneRealInstruction(prologue);
    BasicBlock epilogue = gc.getEpilogue();
    assertThatEpilogueBlockIsSetupCorrectly(gc, inlineSequence, epilogue);
    assertThatLastInstructionInEpilogueIsReturn(gc, epilogue);
    RegisterOperand returnValue = Return.getVal(epilogue.lastRealInstruction()).asRegister();
    assertThat(returnValue.getType(), is(TypeReference.Long));
    assertThatExitBlockIsSetCorrectly(gc);
    assertThatDataIsSavedCorrectly(nm, cm, io, gc);
    assertThat(gc.getResultReg().isLong(), is(true));
    assertThatGCHasNoExceptionHandlers(gc);
    assertThatRegisterPoolExists(gc);
    assertThatChecksWontBeSkipped(gc);
}
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) 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) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Test(org.junit.Test)

Example 58 with BasicBlock

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

the class GenerationContextTest method assertThatUnlockAndRethrowBlockIsCorrectForInlinedMethod.

private void assertThatUnlockAndRethrowBlockIsCorrectForInlinedMethod(GenerationContext parentContext, GenerationContext childContext, InlineSequence inlineSequence, BasicBlock prologue, Operand lockObject, BasicBlock epilogue) {
    ExceptionHandlerBasicBlockBag ehbb = childContext.getEnclosingHandlers();
    Enumeration<BasicBlock> enumerator = ehbb.enumerator();
    assertThat(childContext.getUnlockAndRethrow().exceptionHandlers(), is(parentContext.getEnclosingHandlers()));
    ExceptionHandlerBasicBlock rethrow = (ExceptionHandlerBasicBlock) enumerator.nextElement();
    assertSame(rethrow, childContext.getUnlockAndRethrow());
    assertThatRethrowBlockIsCorrect(inlineSequence, lockObject, rethrow);
    checkCodeOrderForRethrowBlock(childContext, prologue, epilogue, rethrow);
    ExceptionHandlerBasicBlockBag parentHandlers = parentContext.getEnclosingHandlers();
    Enumeration<BasicBlock> parentHandlerBBEnum = parentHandlers.enumerator();
    HashSet<BasicBlock> parentHandlerBBs = new HashSet<BasicBlock>();
    while (parentHandlerBBEnum.hasMoreElements()) {
        parentHandlerBBs.add(parentHandlerBBEnum.nextElement());
    }
    BasicBlock childRethrow = childContext.getUnlockAndRethrow();
    OutEdgeEnumeration outEdges = childRethrow.outEdges();
    boolean linkedToAllBlocksFromParentHandler = true;
    while (outEdges.hasMoreElements()) {
        BasicBlock target = (BasicBlock) outEdges.nextElement().to();
        if (!parentHandlerBBs.contains(target) && target != childContext.getExit()) {
            linkedToAllBlocksFromParentHandler = false;
            break;
        }
    }
    assertTrue(linkedToAllBlocksFromParentHandler);
    ExceptionHandlerBasicBlockBag ehbbb = childContext.getEnclosingHandlers();
    assertSame(parentContext.getEnclosingHandlers(), ehbbb.getCaller());
    assertThatEnclosingHandlersContainRethrow(rethrow, ehbbb);
}
Also used : OutEdgeEnumeration(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode.OutEdgeEnumeration) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) ExceptionHandlerBasicBlockBag(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag) HashSet(java.util.HashSet)

Example 59 with BasicBlock

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

the class GenerationContextTest method constructorCreatesOperandsForInstanceMethods.

@Test
public void constructorCreatesOperandsForInstanceMethods() 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);
    InlineSequence inlineSequence = new InlineSequence(nm);
    assertThatInlineSequenceWasSetCorrectly(gc, inlineSequence);
    assertThatNumberOfParametersIs(gc, 5);
    RegisterOperand thisOperand = getThisOperand(gc);
    assertThatRegOpHoldsClassType(thisOperand);
    assertThatRegOpHasDeclaredType(thisOperand);
    RegisterOperand objectRegOp = gc.getArguments()[1].asRegister();
    assertThatRegOpHoldsClassType(objectRegOp);
    assertThatRegOpHasDeclaredType(objectRegOp);
    RegisterOperand doubleRegOp = gc.getArguments()[2].asRegister();
    assertThat(doubleRegOp.isDouble(), is(true));
    assertThatRegOpHasDeclaredType(doubleRegOp);
    RegisterOperand intRegOp = gc.getArguments()[3].asRegister();
    assertThat(intRegOp.isInt(), is(true));
    assertThatRegOpHasDeclaredType(intRegOp);
    RegisterOperand longRegOp = gc.getArguments()[4].asRegister();
    assertThat(longRegOp.isLong(), is(true));
    assertThatRegOpHasDeclaredType(longRegOp);
    Register thisLocalReg = gc.localReg(0, nm.getDeclaringClass().getTypeRef());
    assertThatRegOpIsLocalRegOfRegister(thisOperand, thisLocalReg);
    Register objectReg = gc.localReg(1, TypeReference.JavaLangObject);
    assertThatRegOpIsLocalRegOfRegister(objectRegOp, objectReg);
    Register doubleReg = gc.localReg(2, TypeReference.Double);
    assertThatRegOpIsLocalRegOfRegister(doubleRegOp, doubleReg);
    Register intReg = gc.localReg(4, TypeReference.Int);
    assertThatRegOpIsLocalRegOfRegister(intRegOp, intReg);
    Register longReg = gc.localReg(5, TypeReference.Long);
    assertThatRegOpIsLocalRegOfRegister(longRegOp, longReg);
    BasicBlock prologue = gc.getPrologue();
    assertThatPrologueBlockIsSetupCorrectly(gc, inlineSequence, prologue);
    assertThatFirstInstructionInPrologueIsPrologue(inlineSequence, prologue);
    Instruction lastPrologueInstruction = prologue.lastRealInstruction();
    assertThatInstructionIsGuardMoveForPrologue(lastPrologueInstruction, thisOperand, gc);
    assertThatPrologueOperandIsRegOpFromLocalNr(prologue, thisOperand, 0);
    assertThatPrologueOperandIsRegOpFromLocalNr(prologue, objectRegOp, 1);
    assertThatPrologueOperandIsRegOpFromLocalNr(prologue, doubleRegOp, 2);
    assertThatPrologueOperandIsRegOpFromLocalNr(prologue, intRegOp, 3);
    assertThatPrologueOperandIsRegOpFromLocalNr(prologue, longRegOp, 4);
    assertThatEpilogueIsForVoidReturnMethod(gc, inlineSequence);
    assertThatExitBlockIsSetCorrectly(gc);
    assertThatDataIsSavedCorrectly(nm, cm, io, gc);
    assertThatReturnValueIsVoid(gc);
    assertThatGCHasNoExceptionHandlers(gc);
    assertThatRegisterPoolExists(gc);
    assertThatChecksWontBeSkipped(gc);
    assertThatNoRethrowBlockExists(gc);
}
Also used : OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineOracle(org.jikesrvm.compilers.opt.inlining.InlineOracle) 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) Register(org.jikesrvm.compilers.opt.ir.Register) NormalMethod(org.jikesrvm.classloader.NormalMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineSequence(org.jikesrvm.compilers.opt.inlining.InlineSequence) Test(org.junit.Test)

Example 60 with BasicBlock

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

the class GenerationContextTest method inliningInstanceMethodWithNarrowingOfReferenceParam.

@Test
public void inliningInstanceMethodWithNarrowingOfReferenceParam() 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 = { MethodsForTests.class };
    NormalMethod callee = getNormalMethodForTest("emptyStaticMethodWithReferenceParam", argumentTypes);
    MethodOperand methOp = MethodOperand.VIRTUAL(callee.getMemberRef().asMethodReference(), callee);
    Instruction callInstr = Call.create(CALL, null, null, methOp, 1);
    RegisterOperand objectParam = createMockRegisterOperand(TypeReference.JavaLangObject);
    assertFalse(objectParam.isPreciseType());
    assertFalse(objectParam.isDeclaredType());
    objectParam.setPreciseType();
    Call.setParam(callInstr, 0, objectParam);
    RegisterOperand objectParamCopy = objectParam.copy().asRegister();
    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);
    RegisterOperand objectParamArg = child.getArguments()[0].asRegister();
    TypeReference calleeClass = callee.getDeclaringClass().getTypeRef();
    assertThatRegOpWasNarrowedToCalleeClass(objectParamArg, calleeClass);
    RegisterOperand expectedLocalForObjectParam = child.makeLocal(0, objectParamArg);
    assertTrue(objectParamArg.sameRegisterPropertiesAs(expectedLocalForObjectParam));
    InlineSequence expectedInlineSequence = new InlineSequence(callee, callInstr.position(), callInstr);
    assertEquals(expectedInlineSequence, child.getInlineSequence());
    assertThatPrologueAndEpilogueAreWiredCorrectlyForChildContext(ebag, nodeNumber, child);
    Enumeration<Instruction> prologueRealInstr = child.getPrologue().forwardRealInstrEnumerator();
    Instruction objectMove = prologueRealInstr.nextElement();
    narrowRegOpToCalleeClass(objectParamCopy, calleeClass);
    assertMoveOperationIsCorrect(callInstr, REF_MOVE, expectedLocalForObjectParam, objectParamCopy, objectMove);
    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) 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) NormalMethod(org.jikesrvm.classloader.NormalMethod) DefaultInlineOracle(org.jikesrvm.compilers.opt.inlining.DefaultInlineOracle) InlineSequence(org.jikesrvm.compilers.opt.inlining.InlineSequence) TypeReference(org.jikesrvm.classloader.TypeReference) Test(org.junit.Test)

Aggregations

BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)219 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)117 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)93 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)66 ExceptionHandlerBasicBlock (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock)52 Register (org.jikesrvm.compilers.opt.ir.Register)50 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)48 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)37 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)33 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)27 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)24 HeapOperand (org.jikesrvm.compilers.opt.ir.operand.HeapOperand)21 BasicBlockOperand (org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand)20 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)19 TypeReference (org.jikesrvm.classloader.TypeReference)18 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)18 Test (org.junit.Test)17 BranchOperand (org.jikesrvm.compilers.opt.ir.operand.BranchOperand)16 InlineSequence (org.jikesrvm.compilers.opt.inlining.InlineSequence)14 MemoryOperand (org.jikesrvm.compilers.opt.ir.operand.MemoryOperand)14