use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand in project JikesRVM by JikesRVM.
the class GenerationContextTest method assertThatRethrowBlockIsCorrect.
private void assertThatRethrowBlockIsCorrect(InlineSequence inlineSequence, Operand lockObject, ExceptionHandlerBasicBlock rethrow) {
Enumeration<TypeOperand> exceptionTypes = rethrow.getExceptionTypes();
TypeOperand firstHandledException = exceptionTypes.nextElement();
assertThat(exceptionTypes.hasMoreElements(), is(false));
assertTrue(firstHandledException.similar(new TypeOperand(RVMType.JavaLangThrowableType)));
Enumeration<Instruction> rethrowInstructions = rethrow.forwardRealInstrEnumerator();
Instruction firstInstructionInRethrow = rethrowInstructions.nextElement();
assertThat(firstInstructionInRethrow.operator(), is(GET_CAUGHT_EXCEPTION));
assertThat(firstInstructionInRethrow.getBytecodeIndex(), is(SYNTH_CATCH_BCI));
assertTrue(firstInstructionInRethrow.position().equals(inlineSequence));
RegisterOperand catchExceptionObject = Nullary.getResult(firstInstructionInRethrow);
assertThat(catchExceptionObject.getType(), is(TypeReference.JavaLangThrowable));
Instruction secondInstructionInRethrow = rethrowInstructions.nextElement();
assertThatNoMoreInstructionsExist(rethrowInstructions);
assertThat(secondInstructionInRethrow.operator(), is(CALL));
MethodOperand methodOp = Call.getMethod(secondInstructionInRethrow);
assertTrue(methodOp.getTarget().equals(Entrypoints.unlockAndThrowMethod));
assertTrue(methodOp.isNonReturningCall());
Operand callAddress = Call.getAddress(secondInstructionInRethrow);
Address actualAddress = callAddress.asAddressConstant().value;
Address expectedAddress = Entrypoints.unlockAndThrowMethod.getOffset().toWord().toAddress();
assertTrue(actualAddress.EQ(expectedAddress));
Operand lockObjectFromRethrow = Call.getParam(secondInstructionInRethrow, 0);
assertTrue(lockObjectFromRethrow.similar(lockObject));
RegisterOperand catchOperand = Call.getParam(secondInstructionInRethrow, 1).asRegister();
assertTrue(catchOperand.sameRegisterPropertiesAs(catchExceptionObject));
assertTrue(rethrow.mayThrowUncaughtException());
assertTrue(rethrow.canThrowExceptions());
}
use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand in project JikesRVM by JikesRVM.
the class GenerationContextTest method invalidReceiverCausesException.
@Test(expected = OptimizingCompilerException.class)
public void invalidReceiverCausesException() 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);
NormalMethod callee = getNormalMethodForTest("emptyInstanceMethodWithoutAnnotations");
MethodOperand methOp = MethodOperand.VIRTUAL(callee.getMemberRef().asMethodReference(), callee);
Instruction callInstr = Call.create(CALL, null, null, methOp, 1);
Operand receiver = new InvalidReceiverOperand();
Call.setParam(callInstr, 0, receiver);
callInstr.setPosition(new InlineSequence(nm));
ExceptionHandlerBasicBlockBag ebag = getMockEbag();
gc.createChildContext(ebag, callee, callInstr);
}
use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand 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);
}
use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand in project JikesRVM by JikesRVM.
the class GenerationContextTest method inliningInstanceMethodWithRegisterReceiverNoNarrowing.
@Test
public void inliningInstanceMethodWithRegisterReceiverNoNarrowing() 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);
RegisterOperand receiver = createMockRegisterOperand(callee.getDeclaringClass().getTypeRef());
assertFalse(receiver.isPreciseType());
assertFalse(receiver.isDeclaredType());
receiver.setPreciseType();
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);
RegisterOperand thisArg = child.getArguments()[0].asRegister();
TypeReference calleeClass = callee.getDeclaringClass().getTypeRef();
assertSame(thisArg.getType(), calleeClass);
RegisterOperand expectedLocalForReceiverParam = child.makeLocal(0, thisArg);
assertTrue(thisArg.sameRegisterPropertiesAs(expectedLocalForReceiverParam));
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 receiverMove = prologueRealInstr.nextElement();
RegisterOperand expectedReceiver = receiver.copy().asRegister();
assertMoveOperationIsCorrect(callInstr, REF_MOVE, expectedLocalForReceiverParam, expectedReceiver, receiverMove);
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);
}
use of org.jikesrvm.compilers.opt.ir.operand.MethodOperand in project JikesRVM by JikesRVM.
the class TailRecursionEliminationTest method callsWithNoTailCallEliminationAnnotationArentSubjectToOptimization.
@Test
public void callsWithNoTailCallEliminationAnnotationArentSubjectToOptimization() throws Exception {
Class<?>[] types = {};
RVMMethod m = TestingTools.getNormalMethod(MethodsForTests.class, "emptyStaticMethodWithNoTailCallEliminationAnnotation", types);
MethodOperand methOp = MethodOperand.STATIC(m);
Instruction call = Call.create(CALL, null, null, methOp, 0);
assertFalse(tailRecursionElimination.allowedToOptimize(call));
}
Aggregations