Search in sources :

Example 1 with CompilationPlan

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

use of org.jikesrvm.compilers.opt.driver.CompilationPlan 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");
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) NormalMethod(org.jikesrvm.classloader.NormalMethod) RVMClassLoader(org.jikesrvm.classloader.RVMClassLoader) CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan) TypeReference(org.jikesrvm.classloader.TypeReference) CompilerAdviceAttribute(org.jikesrvm.adaptive.util.CompilerAdviceAttribute) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 3 with CompilationPlan

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

the class OptTestHarness method processOptionString.

private void processOptionString(String[] args) {
    for (int i = 0, n = args.length; i < n; i++) {
        try {
            String arg = args[i];
            if (arg.startsWith("-oc:") && options.processAsOption("-X:irc:", arg.substring(4))) {
            // handled in processAsOption
            } else if ("-useBootOptions".equals(arg)) {
                OptimizingCompiler.setBootOptions(options);
            } else if ("-longcommandline".equals(arg)) {
                // the -longcommandline option reads options from a file.
                String fileName = args[++i];
                String[] optionString = fileAccess.readOptionStringFromFile(fileName);
                processOptionString(optionString);
            } else if ("+baseline".equals(arg)) {
                useBaselineCompiler = true;
            } else if ("-baseline".equals(arg)) {
                useBaselineCompiler = false;
            } else if ("-load".equals(arg)) {
                loadClass(args[++i]);
            } else if ("-class".equals(arg)) {
                RVMClass klass = loadClass(args[++i]);
                processClass(klass, options);
                duplicateOptions();
            } else if ("-method".equals(arg) || "-methodOpt".equals(arg) || "-methodBase".equals(arg)) {
                // Default for this method is determined by BASELINE var
                boolean isBaseline = useBaselineCompiler;
                // Unless specified by these options
                if ("-methodOpt".equals(arg)) {
                    isBaseline = false;
                }
                if ("-methodBase".equals(arg)) {
                    isBaseline = true;
                }
                RVMClass klass = null;
                try {
                    klass = loadClass(args[++i]);
                } catch (Exception e) {
                    output.sysErrPrintln("WARNING: Skipping method from " + args[i]);
                }
                if (klass == null)
                    continue;
                String name = args[++i];
                String desc = args[++i];
                RVMMethod method = findDeclaredOrFirstMethod(klass, name, desc);
                if (method == null || method.isAbstract() || method.isNative()) {
                    output.sysErrPrintln("WARNING: Skipping method " + args[i - 2] + "." + name);
                } else {
                    processMethod(method, options, isBaseline);
                }
                duplicateOptions();
            } else if ("-performance".equals(arg)) {
                perf = new Performance(output);
            } else if ("-disableClassLoading".equals(arg)) {
                disableClassloading = true;
            } else if ("-er".equals(arg)) {
                executeWithReflection = true;
                RVMClass klass = loadClass(args[++i]);
                String name = args[++i];
                String desc = args[++i];
                NormalMethod method = (NormalMethod) findDeclaredOrFirstMethod(klass, name, desc);
                CompiledMethod cm = null;
                if (method == null) {
                    output.sysErrPrintln("Canceling further option processing to prevent assertion failures.");
                    return;
                }
                if (useBaselineCompiler) {
                    cm = BaselineCompiler.compile(method);
                } else {
                    CompilationPlan cp = new CompilationPlan(method, OptimizationPlanner.createOptimizationPlan(options), null, options);
                    try {
                        cm = OptimizingCompiler.compile(cp);
                    } catch (Throwable e) {
                        output.sysErrPrintln("SKIPPING method:" + method + "Due to exception: " + e);
                    }
                }
                if (cm != null) {
                    method.replaceCompiledMethod(cm);
                    if (printCodeAddress) {
                        output.sysOutPrintln(compiledMethodMessage(method));
                    }
                }
                TypeReference[] argDesc = method.getDescriptor().parseForParameterTypes(klass.getClassLoader());
                Object[] reflectMethodArgs = new Object[argDesc.length];
                i = parseMethodArgs(argDesc, args, i, reflectMethodArgs);
                java.lang.reflect.Method reflectoid = java.lang.reflect.JikesRVMSupport.createMethod(method);
                reflectoidVector.add(reflectoid);
                reflectMethodVector.add(method);
                reflectMethodArgsVector.add(reflectMethodArgs);
                duplicateOptions();
            } else if ("-main".equals(arg)) {
                executeMainMethod = true;
                i++;
                mainClass = loadClass(args[i]);
                i++;
                mainArgs = new String[args.length - i];
                for (int j = 0, z = mainArgs.length; j < z; j++) {
                    mainArgs[j] = args[i + j];
                }
                break;
            } else {
                output.sysErrPrintln("Unrecognized argument: " + arg + " - ignored");
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            output.sysErrPrintln("Uncaught ArrayIndexOutOfBoundsException, possibly" + " not enough command-line arguments - aborting");
            printFormatString();
            e.printStackTrace(output.getSystemErr());
            break;
        } catch (Exception e) {
            output.sysErrPrintln(e.toString());
            e.printStackTrace(output.getSystemErr());
            break;
        }
    }
}
Also used : CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan) InvocationTargetException(java.lang.reflect.InvocationTargetException) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) RVMClass(org.jikesrvm.classloader.RVMClass) RVMMethod(org.jikesrvm.classloader.RVMMethod) NormalMethod(org.jikesrvm.classloader.NormalMethod) TypeReference(org.jikesrvm.classloader.TypeReference) Method(java.lang.reflect.Method)

Example 4 with CompilationPlan

use of org.jikesrvm.compilers.opt.driver.CompilationPlan 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 5 with CompilationPlan

use of org.jikesrvm.compilers.opt.driver.CompilationPlan 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 &amp; 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)

Aggregations

CompilationPlan (org.jikesrvm.compilers.opt.driver.CompilationPlan)12 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)7 NormalMethod (org.jikesrvm.classloader.NormalMethod)6 ControllerPlan (org.jikesrvm.adaptive.controller.ControllerPlan)5 OptimizationPlanElement (org.jikesrvm.compilers.opt.driver.OptimizationPlanElement)5 OptOptions (org.jikesrvm.compilers.opt.OptOptions)4 CompilerAdviceAttribute (org.jikesrvm.adaptive.util.CompilerAdviceAttribute)3 RVMClass (org.jikesrvm.classloader.RVMClass)2 RVMMethod (org.jikesrvm.classloader.RVMMethod)2 TypeReference (org.jikesrvm.classloader.TypeReference)2 OptimizingCompilerException (org.jikesrvm.compilers.opt.OptimizingCompilerException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 AOSInstrumentationPlan (org.jikesrvm.adaptive.recompilation.instrumentation.AOSInstrumentationPlan)1 ExceptionHandlerMap (org.jikesrvm.classloader.ExceptionHandlerMap)1 RVMClassLoader (org.jikesrvm.classloader.RVMClassLoader)1 MagicNotImplementedException (org.jikesrvm.compilers.opt.MagicNotImplementedException)1 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)1 Entrypoint (org.vmmagic.pragma.Entrypoint)1