use of org.jikesrvm.adaptive.util.CompilerAdviceAttribute in project JikesRVM by JikesRVM.
the class BulkCompile method compileAllMethods.
/**
* Compile all methods nominated in the compiler advice,
* which should have been provided in a .ca advice file.<p>
*
* This method will be called at boot time (via notifyStartup())
* if ENABLE_PRECOMPILE is true. For replay compilation, this
* method needs to be called explicitly from within the application
* or benchmark harness. Typical usage in a benchmarking context
* would be to call this method at the end of the first iteration
* of the benchmark so that all/most classes were loaded, and
* compilation could occur prior to the second iteration.
*/
public static void compileAllMethods() {
if (!(Controller.options.ENABLE_BULK_COMPILE || Controller.options.ENABLE_PRECOMPILE)) {
/* should not be here */
VM.sysFail("Attempt to perform bulk compilation without setting either -X:aos:enable_bulk_compile=true or -X:aos:enable_precompile=true");
}
EdgeCounts.loadCountsFromFileIfAvailable(VM.EdgeCounterFile);
CompilerAdvice.readCompilerAdvice();
if (Controller.options.BULK_COMPILATION_VERBOSITY >= 1)
VM.sysWriteln(Controller.options.ENABLE_PRECOMPILE ? "Start precompile" : "Start bulk compile");
for (CompilerAdviceAttribute value : CompilerAdviceAttribute.values()) {
if (value.getOptLevel() == -1) {
if (Controller.options.BULK_COMPILATION_VERBOSITY > 1) {
VM.sysWriteln("Skipping base method: ", value.toString());
} else if (Controller.options.BULK_COMPILATION_VERBOSITY == 1) {
VM.sysWrite(".");
}
continue;
}
ClassLoader cl = RVMClassLoader.findWorkableClassloader(value.getClassName());
if (cl == null)
continue;
TypeReference tRef = TypeReference.findOrCreate(cl, value.getClassName());
RVMClass cls = (RVMClass) tRef.peekType();
if (cls != null) {
// Ensure the class is properly loaded
if (!cls.isInstantiated()) {
if (!cls.isResolved()) {
if (Controller.options.BULK_COMPILATION_VERBOSITY > 1) {
VM.sysWriteln("Resolving class: ", cls.toString());
} else if (Controller.options.BULK_COMPILATION_VERBOSITY == 1) {
VM.sysWrite("R");
}
cls.resolve();
}
if (Controller.options.BULK_COMPILATION_VERBOSITY > 1) {
VM.sysWriteln("Instantiating class: ", cls.toString());
} else if (Controller.options.BULK_COMPILATION_VERBOSITY == 1) {
VM.sysWrite("I");
}
cls.instantiate();
}
// Find the method
RVMMethod method = cls.findDeclaredMethod(value.getMethodName(), value.getMethodSig());
// If found, compile it
if ((method != null) && !method.hasNoOptCompileAnnotation() && (method instanceof org.jikesrvm.classloader.NormalMethod)) {
// if user's requirement is higher than advice
if (value.getOptLevel() > Controller.options.DERIVED_MAX_OPT_LEVEL) {
if (Controller.options.BULK_COMPILATION_VERBOSITY > 1) {
VM.sysWrite("Replay advice overriden by default opt levels. Wanted ");
VM.sysWrite(value.getOptLevel());
VM.sysWrite(", but Controller.options.DERIVED_MAX_OPT_LEVEL: ");
VM.sysWrite(Controller.options.DERIVED_MAX_OPT_LEVEL);
VM.sysWrite(" ");
VM.sysWriteln(value.toString());
} else if (Controller.options.BULK_COMPILATION_VERBOSITY == 1) {
VM.sysWrite(value.getOptLevel(), "!");
}
method.compile();
} else {
CompilationPlan compPlan;
if (Controller.options.counters()) {
// for invocation counter, we only use one optimization level
compPlan = InvocationCounts.createCompilationPlan((NormalMethod) method);
AOSLogging.logger.recompilationStarted(compPlan);
if (Controller.options.BULK_COMPILATION_VERBOSITY > 1) {
VM.sysWrite("Bulk compiling for counters ");
VM.sysWriteln(value.toString());
}
RuntimeCompiler.recompileWithOpt(compPlan);
AOSLogging.logger.recompilationCompleted(compPlan);
} else if (Controller.options.sampling()) {
// Create our set of standard optimization plans.
compPlan = Controller.recompilationStrategy.createCompilationPlan((NormalMethod) method, value.getOptLevel(), null);
if (Controller.options.BULK_COMPILATION_VERBOSITY > 1) {
VM.sysWrite("Bulk compiling for sampling ");
VM.sysWriteln(value.toString());
}
if (Controller.options.BULK_COMPILATION_VERBOSITY == 1) {
VM.sysWrite(value.getOptLevel());
}
AOSLogging.logger.recompilationStarted(compPlan);
RuntimeCompiler.recompileWithOpt(compPlan);
AOSLogging.logger.recompilationCompleted(compPlan);
} else {
if (Controller.options.BULK_COMPILATION_VERBOSITY > 1) {
VM.sysWrite("Compiler advice file overridden ");
VM.sysWriteln(value.toString());
}
method.compile();
}
}
} else {
if (Controller.options.BULK_COMPILATION_VERBOSITY > 1) {
VM.sysWrite("Replay failed for ");
VM.sysWrite(value.toString());
VM.sysWrite(" ");
VM.sysWriteln(cl.toString());
} else if (Controller.options.BULK_COMPILATION_VERBOSITY == 1) {
VM.sysWrite("*");
}
}
}
}
AOSLogging.logger.compileAllMethodsCompleted();
if (Controller.options.BULK_COMPILATION_VERBOSITY >= 1)
VM.sysWriteln();
if (Controller.options.BULK_COMPILATION_VERBOSITY >= 1)
VM.sysWriteln("Recompilation complete");
}
use of org.jikesrvm.adaptive.util.CompilerAdviceAttribute 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.adaptive.util.CompilerAdviceAttribute in project JikesRVM by JikesRVM.
the class OSRProfiler method invalidateState.
// invalidate an execution state
private static synchronized void invalidateState(ExecutionState state) {
// step 1: invalidate the compiled method with this OSR assumption
// how does this affect the performance?
CompiledMethod mostRecentlyCompiledMethod = CompiledMethods.getCompiledMethod(state.cmid);
if (VM.VerifyAssertions) {
VM._assert(mostRecentlyCompiledMethod.getMethod() == state.meth);
}
// be invalidated in more than one thread at the same time
if (mostRecentlyCompiledMethod != state.meth.getCurrentCompiledMethod()) {
return;
}
// make sure the compiled method is an opt one
if (!(mostRecentlyCompiledMethod instanceof OptCompiledMethod)) {
return;
}
// reset the compiled method to null first, if other thread invokes
// this method before following opt recompilation, it can avoid OSR
state.meth.invalidateCompiledMethod(mostRecentlyCompiledMethod);
// a list of state from callee -> caller
if (VM.TraceOnStackReplacement) {
VM.sysWriteln("OSR " + OSRProfiler.invalidations + " : " + state.bcIndex + "@" + state.meth);
}
// simply reset the compiled method to null is not good
// for long run loops, because invalidate may cause
// the method falls back to the baseline again...
// NOW, we look for the previous compilation plan, and reuse
// the compilation plan.
boolean recmplsucc = false;
if (Controller.enabled) {
CompilationPlan cmplplan = null;
if (Controller.options.ENABLE_PRECOMPILE && CompilerAdviceAttribute.hasAdvice()) {
CompilerAdviceAttribute attr = CompilerAdviceAttribute.getCompilerAdviceInfo(state.meth);
if (VM.VerifyAssertions) {
VM._assert(attr.getCompiler() == CompiledMethod.OPT);
}
if (Controller.options.counters()) {
// for invocation counter, we only use one optimization level
cmplplan = InvocationCounts.createCompilationPlan(state.meth);
} else {
// for now there is not two options for sampling, so
// we don't have to use: if (Controller.options.sampling())
cmplplan = Controller.recompilationStrategy.createCompilationPlan(state.meth, attr.getOptLevel(), null);
}
} else {
ControllerPlan ctrlplan = ControllerMemory.findMatchingPlan(mostRecentlyCompiledMethod);
if (ctrlplan != null) {
cmplplan = ctrlplan.getCompPlan();
}
}
if (cmplplan != null) {
if (VM.VerifyAssertions) {
VM._assert(cmplplan.getMethod() == state.meth);
}
// for invalidated method, we do not perform OSR guarded inlining anymore.
// the Options object may be shared by several methods,
// we have to reset it back
boolean savedOsr = cmplplan.options.OSR_GUARDED_INLINING;
cmplplan.options.OSR_GUARDED_INLINING = false;
int newcmid = RuntimeCompiler.recompileWithOpt(cmplplan);
cmplplan.options.OSR_GUARDED_INLINING = savedOsr;
if (newcmid != -1) {
AOSLogging.logger.debug("recompiling state with opt succeeded " + state.cmid);
AOSLogging.logger.debug("new cmid " + newcmid);
// transfer hotness to the new cmid
double oldSamples = Controller.methodSamples.getData(state.cmid);
Controller.methodSamples.reset(state.cmid);
Controller.methodSamples.augmentData(newcmid, oldSamples);
recmplsucc = true;
if (VM.TraceOnStackReplacement) {
VM.sysWriteln(" recompile " + state.meth + " at -O" + cmplplan.options.getOptLevel());
}
}
}
}
if (!recmplsucc) {
int newcmid = RuntimeCompiler.recompileWithOpt(state.meth);
if (newcmid == -1) {
if (VM.TraceOnStackReplacement) {
VM.sysWriteln(" opt recompilation failed!");
}
state.meth.invalidateCompiledMethod(mostRecentlyCompiledMethod);
}
}
if (VM.TraceOnStackReplacement) {
VM.sysWriteln(" opt recompilation done!");
}
}
Aggregations