Search in sources :

Example 1 with OptimizationPlanElement

use of org.jikesrvm.compilers.opt.driver.OptimizationPlanElement in project JikesRVM by JikesRVM.

the class OnStackReplacementEvent method process.

/**
 * This function will generate a controller plan and
 * inserted in the recompilation queue.
 */
@Override
public void process() {
    CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(CMID);
    NormalMethod todoMethod = (NormalMethod) compiledMethod.getMethod();
    double priority;
    OptOptions options;
    OptimizationPlanElement[] optimizationPlan;
    ControllerPlan oldPlan = ControllerMemory.findLatestPlan(todoMethod);
    if (oldPlan != null) {
        CompilationPlan oldCompPlan = oldPlan.getCompPlan();
        priority = oldPlan.getPriority();
        options = oldCompPlan.options;
        optimizationPlan = oldCompPlan.optimizationPlan;
    } else {
        priority = 5.0;
        options = (OptOptions) RuntimeCompiler.options;
        optimizationPlan = (OptimizationPlanElement[]) RuntimeCompiler.optimizationPlan;
    }
    CompilationPlan compPlan = new CompilationPlan(todoMethod, optimizationPlan, null, options);
    OnStackReplacementPlan plan = new OnStackReplacementPlan(this.suspendedThread, compPlan, this.CMID, this.whereFrom, this.tsFromFPoff, this.ypTakenFPoff, priority);
    Controller.compilationQueue.insert(priority, plan);
    AOSLogging.logger.logOsrEvent("OSR inserts compilation plan successfully!");
    // do not hold the reference anymore.
    suspendedThread = null;
    CMID = 0;
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod) OptimizationPlanElement(org.jikesrvm.compilers.opt.driver.OptimizationPlanElement) CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan) OptOptions(org.jikesrvm.compilers.opt.OptOptions) ControllerPlan(org.jikesrvm.adaptive.controller.ControllerPlan) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod)

Example 2 with OptimizationPlanElement

use of org.jikesrvm.compilers.opt.driver.OptimizationPlanElement in project JikesRVM by JikesRVM.

the class RuntimeCompiler method recompileWithOpt.

/**
 * A wrapper method for those callers that don't want to make
 * optimization plans and need a given opt level
 * @param method the method to recompile
 * @param optLevel the opt level to use
 * @return a compiled method id or -1 when the compilation failed
 */
public static int recompileWithOpt(NormalMethod method, int optLevel) {
    if (VM.BuildForOptCompiler) {
        OptOptions optOptions = (OptOptions) options;
        OptOptions newOptions = optOptions.dup();
        newOptions.setOptLevel(optLevel);
        CompilationPlan plan = new CompilationPlan(method, (OptimizationPlanElement[]) optimizationPlan, null, newOptions);
        return recompileWithOpt(plan);
    } else {
        if (VM.VerifyAssertions)
            VM._assert(VM.NOT_REACHED);
        return -1;
    }
}
Also used : OptimizationPlanElement(org.jikesrvm.compilers.opt.driver.OptimizationPlanElement) CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan) OptOptions(org.jikesrvm.compilers.opt.OptOptions)

Example 3 with OptimizationPlanElement

use of org.jikesrvm.compilers.opt.driver.OptimizationPlanElement in project JikesRVM by JikesRVM.

the class RuntimeCompiler method optCompileWithFallBack.

// These methods are safe to invoke from RuntimeCompiler.compile
/**
 * This method tries to compile the passed method with the Compiler,
 * using the default compilation plan.  If
 * this fails we will use the quicker compiler (baseline for now)
 * The following is carefully crafted to avoid (infinte) recursive opt
 * compilation for all combinations of bootimages & lazy/eager compilation.
 * Be absolutely sure you know what you're doing before changing it !!!
 * @param method the method to compile
 * @return a compiled method (opt when possible, baseline when the opt compiler
 *  busy)
 */
public static synchronized CompiledMethod optCompileWithFallBack(NormalMethod method) {
    if (VM.BuildForOptCompiler) {
        if (compilationInProgress) {
            return fallback(method);
        } else {
            try {
                compilationInProgress = true;
                CompilationPlan plan = new CompilationPlan(method, (OptimizationPlanElement[]) optimizationPlan, null, (OptOptions) options);
                return optCompileWithFallBackInternal(method, plan);
            } finally {
                compilationInProgress = false;
            }
        }
    } else {
        if (VM.VerifyAssertions)
            VM._assert(VM.NOT_REACHED);
        return null;
    }
}
Also used : OptimizationPlanElement(org.jikesrvm.compilers.opt.driver.OptimizationPlanElement) CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan)

Example 4 with OptimizationPlanElement

use of org.jikesrvm.compilers.opt.driver.OptimizationPlanElement 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)

Example 5 with OptimizationPlanElement

use of org.jikesrvm.compilers.opt.driver.OptimizationPlanElement in project JikesRVM by JikesRVM.

the class SpecialCompiler method optCompile.

/**
 * <ol>
 *   <li>generate prologue PSEUDO_bytecode from the state.
 *   <li>make new bytecodes with prologue.
 *   <li>set method's bytecode to specialized one.
 *   <li>adjust exception map, line number map.
 *   <li>compile the method.
 *   <li>restore bytecode, exception, linenumber map to the original one.
 * </ol>
 *
 * @param state the execution state for the compilation
 * @return the compiled method produced by the optimizing compiler
 */
public static CompiledMethod optCompile(ExecutionState state) {
    NormalMethod method = state.getMethod();
    if (VM.TraceOnStackReplacement) {
        VM.sysWriteln("OPT : starts compiling " + method);
    }
    ControllerPlan latestPlan = ControllerMemory.findLatestPlan(method);
    OptOptions _options = null;
    if (latestPlan != null) {
        _options = latestPlan.getCompPlan().options.dup();
    } else {
        // no previous compilation plan, a long run loop promoted from baseline.
        // this only happens when testing, not in real code
        _options = new OptOptions();
        _options.setOptLevel(0);
    }
    // disable OSR points in specialized method
    _options.OSR_GUARDED_INLINING = false;
    CompilationPlan compPlan = new CompilationPlan(method, (OptimizationPlanElement[]) RuntimeCompiler.optimizationPlan, null, _options);
    // it is also necessary to recompile the current method
    // without OSR.
    /* generate prologue bytes */
    byte[] prologue = state.generatePrologue();
    int prosize = prologue.length;
    method.setForOsrSpecialization(prologue, state.getMaxStackHeight());
    int[] oldStartPCs = null;
    int[] oldEndPCs = null;
    int[] oldHandlerPCs = null;
    /* adjust exception table. */
    {
        // if (VM.TraceOnStackReplacement) {
        // VM.sysWriteln("OPT adjust exception table.");
        // }
        ExceptionHandlerMap exceptionHandlerMap = method.getExceptionHandlerMap();
        if (exceptionHandlerMap != null) {
            oldStartPCs = exceptionHandlerMap.getStartPC();
            oldEndPCs = exceptionHandlerMap.getEndPC();
            oldHandlerPCs = exceptionHandlerMap.getHandlerPC();
            int n = oldStartPCs.length;
            int[] newStartPCs = new int[n];
            System.arraycopy(oldStartPCs, 0, newStartPCs, 0, n);
            exceptionHandlerMap.setStartPC(newStartPCs);
            int[] newEndPCs = new int[n];
            System.arraycopy(oldEndPCs, 0, newEndPCs, 0, n);
            exceptionHandlerMap.setEndPC(newEndPCs);
            int[] newHandlerPCs = new int[n];
            System.arraycopy(oldHandlerPCs, 0, newHandlerPCs, 0, n);
            exceptionHandlerMap.setHandlerPC(newHandlerPCs);
            for (int i = 0; i < n; i++) {
                newStartPCs[i] += prosize;
                newEndPCs[i] += prosize;
                newHandlerPCs[i] += prosize;
            }
        }
    }
    CompiledMethod newCompiledMethod = RuntimeCompiler.recompileWithOptOnStackSpecialization(compPlan);
    // restore original bytecode, exception table, and line number table
    method.finalizeOsrSpecialization();
    {
        ExceptionHandlerMap exceptionHandlerMap = method.getExceptionHandlerMap();
        if (exceptionHandlerMap != null) {
            exceptionHandlerMap.setStartPC(oldStartPCs);
            exceptionHandlerMap.setEndPC(oldEndPCs);
            exceptionHandlerMap.setHandlerPC(oldHandlerPCs);
        }
    }
    // reverse back to the baseline
    if (newCompiledMethod == null) {
        if (VM.TraceOnStackReplacement) {
            VM.sysWriteln("OPT : fialed, because compilation in progress, " + "fall back to baseline");
        }
        return baselineCompile(state);
    }
    // mark the method is a specialized one
    newCompiledMethod.setSpecialForOSR();
    if (VM.TraceOnStackReplacement) {
        VM.sysWriteln("OPT : done");
        VM.sysWriteln();
    }
    return newCompiledMethod;
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod) OptimizationPlanElement(org.jikesrvm.compilers.opt.driver.OptimizationPlanElement) CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan) ExceptionHandlerMap(org.jikesrvm.classloader.ExceptionHandlerMap) OptOptions(org.jikesrvm.compilers.opt.OptOptions) ControllerPlan(org.jikesrvm.adaptive.controller.ControllerPlan) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod)

Aggregations

CompilationPlan (org.jikesrvm.compilers.opt.driver.CompilationPlan)5 OptimizationPlanElement (org.jikesrvm.compilers.opt.driver.OptimizationPlanElement)5 ControllerPlan (org.jikesrvm.adaptive.controller.ControllerPlan)3 OptOptions (org.jikesrvm.compilers.opt.OptOptions)3 NormalMethod (org.jikesrvm.classloader.NormalMethod)2 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)2 AOSInstrumentationPlan (org.jikesrvm.adaptive.recompilation.instrumentation.AOSInstrumentationPlan)1 CompilerAdviceAttribute (org.jikesrvm.adaptive.util.CompilerAdviceAttribute)1 ExceptionHandlerMap (org.jikesrvm.classloader.ExceptionHandlerMap)1