Search in sources :

Example 1 with AOSInstrumentationPlan

use of org.jikesrvm.adaptive.recompilation.instrumentation.AOSInstrumentationPlan 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);
    }
}
Also used : OptimizationPlanElement(org.jikesrvm.compilers.opt.driver.OptimizationPlanElement) CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan) AOSInstrumentationPlan(org.jikesrvm.adaptive.recompilation.instrumentation.AOSInstrumentationPlan) ControllerPlan(org.jikesrvm.adaptive.controller.ControllerPlan) CompilerAdviceAttribute(org.jikesrvm.adaptive.util.CompilerAdviceAttribute)

Aggregations

ControllerPlan (org.jikesrvm.adaptive.controller.ControllerPlan)1 AOSInstrumentationPlan (org.jikesrvm.adaptive.recompilation.instrumentation.AOSInstrumentationPlan)1 CompilerAdviceAttribute (org.jikesrvm.adaptive.util.CompilerAdviceAttribute)1 CompilationPlan (org.jikesrvm.compilers.opt.driver.CompilationPlan)1 OptimizationPlanElement (org.jikesrvm.compilers.opt.driver.OptimizationPlanElement)1