use of org.jikesrvm.compilers.opt.driver.CompilationPlan in project JikesRVM by JikesRVM.
the class ControllerPlan method doRecompile.
/**
* This method will recompile the method designated by the controller plan
* {@link #getCompPlan}. It also
* <ol>
* <li>credits the samples associated with the old compiled method
* ID to the new method ID and clears the old value.
* <li>clears inlining information
* <li>updates the status of the controller plan
* </ol>
*
* @return {@code null} if the compilation was aborted, the new compiled
* method otherwise
*/
public CompiledMethod doRecompile() {
CompilationPlan cp = getCompPlan();
setTimeInitiated(Controller.controllerClock);
AOSLogging.logger.recompilationStarted(cp);
if (cp.options.PRINT_METHOD) {
VM.sysWriteln("-oc:O" + cp.options.getOptLevel());
}
// Compile the method.
int newCMID = RuntimeCompiler.recompileWithOpt(cp);
int prevCMID = getPrevCMID();
if (Controller.options.sampling()) {
// transfer the samples from the old CMID to the new CMID.
// scale the number of samples down by the expected speedup
// in the newly compiled method.
double expectedSpeedup = getExpectedSpeedup();
double oldNumSamples = Controller.methodSamples.getData(prevCMID);
double newNumSamples = oldNumSamples / expectedSpeedup;
Controller.methodSamples.reset(prevCMID);
if (newCMID > -1) {
Controller.methodSamples.augmentData(newCMID, newNumSamples);
}
}
// set the status of the plan accordingly
if (newCMID != -1) {
setStatus(ControllerPlan.COMPLETED);
} else {
setStatus(ControllerPlan.ABORTED_COMPILATION_ERROR);
}
setCMID(newCMID);
setTimeCompleted(Controller.controllerClock);
CompiledMethod cm = newCMID == -1 ? null : CompiledMethods.getCompiledMethod(newCMID);
if (newCMID == -1) {
AOSLogging.logger.recompilationAborted(cp);
} else {
AOSLogging.logger.recompilationCompleted(cp);
AOSLogging.logger.recordCompileTime(cm, getExpectedCompilationTime());
}
if (Controller.options.ENABLE_ADVICE_GENERATION && (newCMID != -1)) {
AOSGenerator.reCompilationWithOpt(cp);
}
return cm;
}
use of org.jikesrvm.compilers.opt.driver.CompilationPlan in project JikesRVM by JikesRVM.
the class InvocationCounts method counterTripped.
/**
* Called from baseline compiled code when a method's invocation counter
* becomes negative and thus must be handled
*
* @param id the compiled method id
*/
@Entrypoint
static synchronized void counterTripped(int id) {
// set counter to max int to avoid lots of redundant calls.
counts[id] = 0x7fffffff;
if (processed[id])
return;
processed[id] = true;
CompiledMethod cm = CompiledMethods.getCompiledMethod(id);
if (cm == null)
return;
if (VM.VerifyAssertions)
VM._assert(cm.getCompilerType() == CompiledMethod.BASELINE);
NormalMethod m = (NormalMethod) cm.getMethod();
CompilationPlan compPlan = new CompilationPlan(m, _optPlan, null, _options);
ControllerPlan cp = // 2.0 is a bogus number....
new ControllerPlan(compPlan, Controller.controllerClock, id, 2.0, 2.0, 2.0);
cp.execute();
}
use of org.jikesrvm.compilers.opt.driver.CompilationPlan in project JikesRVM by JikesRVM.
the class RuntimeCompiler method compile.
/**
* Compile a Java method when it is first invoked.
* @param method the method to compile
* @return its compiled method.
*/
public static CompiledMethod compile(NormalMethod method) {
if (VM.BuildForAdaptiveSystem) {
CompiledMethod cm;
if (!Controller.enabled) {
// System still early in boot process; compile with baseline compiler
cm = baselineCompile(method);
ControllerMemory.incrementNumBase();
} else {
if (Controller.options.optIRC()) {
if (// will only run once: don't bother optimizing
method.isClassInitializer() || // multiple pending (undelivered) exceptions [--DL]
RVMThread.getCurrentThread().getExceptionRegisters().getInUse()) {
// compile with baseline compiler
cm = baselineCompile(method);
ControllerMemory.incrementNumBase();
} else {
// compile with opt compiler
AOSInstrumentationPlan instrumentationPlan = new AOSInstrumentationPlan(Controller.options, method);
CompilationPlan compPlan = new CompilationPlan(method, (OptimizationPlanElement[]) optimizationPlan, instrumentationPlan, (OptOptions) options);
cm = optCompileWithFallBack(method, compPlan);
}
} else {
if ((Controller.options.BACKGROUND_RECOMPILATION && !Controller.options.ENABLE_PRECOMPILE)) {
// must be an initial compilation: compile with baseline compiler
// or if recompilation with OSR.
cm = baselineCompile(method);
ControllerMemory.incrementNumBase();
} else {
if (CompilerAdviceAttribute.hasAdvice()) {
CompilerAdviceAttribute attr = CompilerAdviceAttribute.getCompilerAdviceInfo(method);
if (attr.getCompiler() != CompiledMethod.OPT) {
cm = fallback(method);
AOSLogging.logger.recordCompileTime(cm, 0.0);
return cm;
}
int newCMID = -2;
CompilationPlan compPlan;
if (Controller.options.counters()) {
// for invocation counter, we only use one optimization level
compPlan = InvocationCounts.createCompilationPlan(method);
} else {
// for now there is not two options for sampling, so
// we don't have to use: if (Controller.options.sampling())
compPlan = Controller.recompilationStrategy.createCompilationPlan(method, attr.getOptLevel(), null);
}
AOSLogging.logger.recompilationStarted(compPlan);
newCMID = recompileWithOpt(compPlan);
cm = newCMID == -1 ? null : CompiledMethods.getCompiledMethod(newCMID);
if (newCMID == -1) {
AOSLogging.logger.recompilationAborted(compPlan);
} else if (newCMID > 0) {
AOSLogging.logger.recompilationCompleted(compPlan);
}
if (cm == null) {
// if recompilation is aborted
cm = baselineCompile(method);
ControllerMemory.incrementNumBase();
}
} else {
// check to see if there is a compilation plan for this method.
ControllerPlan plan = ControllerMemory.findLatestPlan(method);
if (plan == null || plan.getStatus() != ControllerPlan.IN_PROGRESS) {
// initial compilation or some other funny state: compile with baseline compiler
cm = baselineCompile(method);
ControllerMemory.incrementNumBase();
} else {
cm = plan.doRecompile();
if (cm == null) {
// opt compilation aborted for some reason.
cm = baselineCompile(method);
}
}
}
}
}
}
if ((Controller.options.ENABLE_ADVICE_GENERATION) && (cm.getCompilerType() == CompiledMethod.BASELINE) && Controller.enabled) {
AOSGenerator.baseCompilationCompleted(cm);
}
AOSLogging.logger.recordCompileTime(cm, 0.0);
return cm;
} else {
return baselineCompile(method);
}
}
use of org.jikesrvm.compilers.opt.driver.CompilationPlan in project JikesRVM by JikesRVM.
the class OptTestHarness method compileMethodsInVector.
private void compileMethodsInVector() {
// Compile all baseline methods first
int size = baselineMethodVector.size();
output.sysOutPrintln("Compiling " + size + " methods baseline");
// Compile all methods in baseline vector
for (int i = 0; i < size; i++) {
NormalMethod method = (NormalMethod) baselineMethodVector.get(i);
CompiledMethod cm = null;
cm = BaselineCompiler.compile(method);
method.replaceCompiledMethod(cm);
if (printCodeAddress) {
output.sysOutPrintln(compiledMethodMessage(method));
}
}
// Now compile all methods in opt vector
size = optMethodVector.size();
output.sysOutPrintln("Compiling " + size + " methods opt");
for (int i = 0; i < size; i++) {
NormalMethod method = (NormalMethod) optMethodVector.get(i);
OptOptions opts = optOptionsVector.get(i);
try {
CompiledMethod cm = null;
CompilationPlan cp = new CompilationPlan(method, OptimizationPlanner.createOptimizationPlan(opts), null, opts);
cm = OptimizingCompiler.compile(cp);
method.replaceCompiledMethod(cm);
if (printCodeAddress) {
output.sysOutPrintln(compiledMethodMessage(method));
}
} catch (OptimizingCompilerException e) {
if (e.isFatal && VM.ErrorsFatal) {
e.printStackTrace();
VM.sysFail("Internal vm error: " + e);
} else {
output.sysErrPrintln("SKIPPING opt-compilation of " + method + ":\n " + e.getMessage());
if (opts.PRINT_METHOD) {
e.printStackTrace();
}
}
}
}
}
use of org.jikesrvm.compilers.opt.driver.CompilationPlan in project JikesRVM by JikesRVM.
the class SimpleEscape method performSimpleEscapeAnalysis.
private static void performSimpleEscapeAnalysis(RVMMethod m, OptOptions options) {
if (!options.ESCAPE_SIMPLE_IPA) {
return;
}
// do not perform for unloaded methods
MethodSummary summ = SummaryDatabase.findMethodSummary(m);
if (summ != null) {
// do not attempt to perform escape analysis recursively
if (summ.inProgress()) {
return;
}
}
CompilationPlan plan = new CompilationPlan((NormalMethod) m, escapePlan, null, options);
plan.analyzeOnly = true;
try {
OptimizingCompiler.compile(plan);
} catch (MagicNotImplementedException e) {
// summary stays at bottom
summ.setInProgress(false);
}
}
Aggregations