use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.
the class SpecialCompiler method baselineCompile.
/**
* Compiles the method with the baseline compiler.
* <ol>
* <li>generate prologue (PSEUDO_bytecode) from the state.
* <li>make up new byte code with prologue.
* <li>set method's bytecode to the specilizaed byte code.
* <li>call BaselineCompilerImpl.compile,
* the 'compile' method is customized to process pseudo instructions,
* and it will reset the byte code to the original one, and adjust
* the map from bytecode to the generated machine code. then the
* reference map can be generated corrected relying on the original
* bytecode.
* </ol>
* <p>
* NOTE: this is different from optCompile which resets the
* bytecode after compilation. I believe this minimizes the
* work to change both compilers.
* @param state the execution state for the compilation
* @return the compiled method produced by the baseline compiler
*/
public static CompiledMethod baselineCompile(ExecutionState state) {
NormalMethod method = state.getMethod();
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("BASE : starts compiling " + method);
}
/* generate prologue bytes */
byte[] prologue = state.generatePrologue();
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("prologue length " + prologue.length);
}
// the compiler will call setForOsrSpecialization after generating the reference map
/* set a flag for specialization, compiler will see it, and
* know how to do it properly.
*/
method.setForOsrSpecialization(prologue, state.getMaxStackHeight());
/* for baseline compilation, we do not adjust the exception table and line table
* because the compiler will generate maps after compilation.
* Any necessary adjustment should be made during the compilation
*/
CompiledMethod newCompiledMethod;
if (VM.BuildForIA32) {
newCompiledMethod = org.jikesrvm.compilers.baseline.ia32.BaselineCompilerImpl.compile(method);
} else {
if (VM.VerifyAssertions)
VM._assert(VM.BuildForPowerPC);
newCompiledMethod = org.jikesrvm.compilers.baseline.ppc.BaselineCompilerImpl.compile(method);
}
// compiled method was already set by BaselineCompilerImpl.compile
// the call here does nothing
// method.finalizeOsrSpecialization();
// mark the method is a specialized one
newCompiledMethod.setSpecialForOSR();
if (VM.TraceOnStackReplacement) {
// ((BaselineCompiledMethod)newCompiledMethod).printCodeMapEntries();
VM.sysWriteln("BASE : done, CMID 0x" + Integer.toHexString(newCompiledMethod.getId()) + "(" + newCompiledMethod.getId() + ") JTOC offset " + Services.addressAsHexString(newCompiledMethod.getOsrJTOCoffset().toWord().toAddress()));
}
return newCompiledMethod;
}
use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.
the class SpecialCompiler method recompileState.
/**
* recompile an execution state
* @param state a list of execution states
* @param invalidate Is this an invalidation?
* @return the compiled method for the root state
*/
public static CompiledMethod recompileState(ExecutionState state, boolean invalidate) {
// compile from callee to caller
CompiledMethod newCM = null;
do {
if (!invalidate) {
newCM = optCompile(state);
} else {
newCM = baselineCompile(state);
}
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("new CMID 0x" + Integer.toHexString(newCM.getId()) + "(" + newCM.getId() + ") for " + newCM.getMethod());
}
if (state.callerState == null)
break;
state = state.callerState;
// set callee_cmid of the caller
state.callee_cmid = newCM.getId();
} while (true);
return newCM;
}
use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.
the class ExecutionStateExtractor method printStackTraces.
public static void printStackTraces(int[] stack, Offset osrFPoff) {
VM.disableGC();
Address fp = Magic.objectAsAddress(stack).plus(osrFPoff);
Address ip = Magic.getReturnAddressUnchecked(fp);
fp = Magic.getCallerFramePointer(fp);
while (Magic.getCallerFramePointer(fp).NE(StackFrameLayout.getStackFrameSentinelFP())) {
int cmid = Magic.getCompiledMethodID(fp);
if (cmid == StackFrameLayout.getInvisibleMethodID()) {
VM.sysWriteln(" invisible method ");
} else {
CompiledMethod cm = CompiledMethods.getCompiledMethod(cmid);
Offset instrOff = cm.getInstructionOffset(ip);
cm.printStackTrace(instrOff, PrintContainer.get(System.out));
if (cm.getMethod().getDeclaringClass().hasBridgeFromNativeAnnotation()) {
fp = RuntimeEntrypoints.unwindNativeStackFrame(fp);
}
}
ip = Magic.getReturnAddressUnchecked(fp);
fp = Magic.getCallerFramePointer(fp);
}
VM.enableGC();
}
use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.
the class GenerationContextTest method prologueAndEpilogueForSynchronizedInstanceMethodHaveMonitorEnterAndExit.
@Test
public void prologueAndEpilogueForSynchronizedInstanceMethodHaveMonitorEnterAndExit() throws Exception {
NormalMethod nm = getNormalMethodForTest("emptySynchronizedInstanceMethod");
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);
assertThatLocalsForInstanceMethodWithoutParametersAreCorrect(nm, gc);
RegisterOperand thisOperand = getThisOperand(gc);
BasicBlock prologue = gc.getPrologue();
assertThatPrologueBlockIsSetupCorrectly(gc, inlineSequence, prologue);
assertThatFirstInstructionInPrologueIsPrologue(inlineSequence, prologue);
Enumeration<Instruction> prologueInstructions = prologue.forwardRealInstrEnumerator();
prologueInstructions.nextElement();
Instruction secondInstruction = prologueInstructions.nextElement();
assertThatInstructionIsGuardMoveForPrologue(secondInstruction, thisOperand, gc);
Instruction lastInstruction = prologueInstructions.nextElement();
assertInstructionIsMonitorEnterInPrologue(lastInstruction, inlineSequence);
assertThatGuardIsCorrectForMonitorEnter(lastInstruction);
Operand lockObject = MonitorOp.getRef(lastInstruction);
Operand expectedLockObject = buildLockObjectForInstanceMethod(nm, thisOperand, gc);
assertTrue(expectedLockObject.similar(lockObject));
assertThatNumberOfRealInstructionsMatches(prologue, 3);
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);
}
use of org.jikesrvm.compilers.common.CompiledMethod in project JikesRVM by JikesRVM.
the class GenerationContextTest method isLocalReturnsTrueForRegistersCreatedViaMakeLocal.
@Test
public void isLocalReturnsTrueForRegistersCreatedViaMakeLocal() 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);
int thisLocalNumber = 0;
TypeReference localType = nm.getDeclaringClass().getTypeRef();
RegisterOperand thisRegOp = gc.makeLocal(thisLocalNumber, localType);
assertTrue(gc.isLocal(thisRegOp, thisLocalNumber, localType));
}
Aggregations