use of org.jikesrvm.classloader.NormalMethod in project JikesRVM by JikesRVM.
the class GenerationContextTest method resyncDeletesNullCheckGuardsThatMapToUnusedRegisters.
@Test
public void resyncDeletesNullCheckGuardsThatMapToUnusedRegisters() throws Exception {
NormalMethod nm = TestingTools.getNormalMethod(MethodsForTests.class, "emptyInstanceMethodWithoutAnnotations");
OptOptions opts = new OptOptions();
GenerationContext gc = new GenerationContext(nm, null, null, opts, null);
RegisterOperand thisLocal = gc.makeLocal(0, nm.getDeclaringClass().getTypeRef());
Register thisReg = thisLocal.getRegister();
RegisterOperand thisNullCheckGuard = gc.makeNullCheckGuard(thisReg);
assertNotNull(thisNullCheckGuard);
gc.getTemps().removeRegister(thisReg);
gc.resync();
RegisterOperand newNullCheckGuard = gc.makeNullCheckGuard(thisReg);
assertFalse(newNullCheckGuard.sameRegisterPropertiesAs(thisNullCheckGuard));
}
use of org.jikesrvm.classloader.NormalMethod in project JikesRVM by JikesRVM.
the class GenerationContextTest method makeLocalUsesLocalRegToDetermineRegisters.
@Test
public void makeLocalUsesLocalRegToDetermineRegisters() throws Exception {
NormalMethod nm = TestingTools.getNormalMethod(MethodsForTests.class, "emptyInstanceMethodWithoutAnnotations");
OptOptions opts = new OptOptions();
GenerationContext gc = new GenerationContext(nm, null, null, opts, null);
int localNumber = 0;
TypeReference localType = nm.getDeclaringClass().getTypeRef();
Register expectedRegister = gc.localReg(localNumber, localType);
RegisterOperand regOp = gc.makeLocal(localNumber, localType);
assertSame(expectedRegister, regOp.getRegister());
}
use of org.jikesrvm.classloader.NormalMethod 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);
}
use of org.jikesrvm.classloader.NormalMethod 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.classloader.NormalMethod 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);
}
Aggregations