Search in sources :

Example 76 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class TransferToInterpreterTest method test.

@Test
public void test() {
    RootNode rootNode = new TestRootNode();
    GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime();
    OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(rootNode);
    target.call(0);
    Assert.assertFalse(target.isValid());
    OptionValues options = TruffleCompilerOptions.getOptions();
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    final OptimizedCallTarget compilable = target;
    TruffleCompilerImpl compiler = (TruffleCompilerImpl) runtime.newTruffleCompiler();
    CompilationIdentifier compilationId = compiler.getCompilationIdentifier(compilable);
    TruffleInliningPlan inliningPlan = new TruffleInlining(compilable, new DefaultInliningPolicy());
    compiler.compileAST(debug, compilable, inliningPlan, compilationId, null, null);
    Assert.assertTrue(target.isValid());
    target.call(0);
    Assert.assertTrue(target.isValid());
    target.call(1);
    Assert.assertFalse(target.isValid());
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleInliningPlan(org.graalvm.compiler.truffle.common.TruffleInliningPlan) CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) OptionValues(org.graalvm.compiler.options.OptionValues) TruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl) GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) DefaultInliningPolicy(org.graalvm.compiler.truffle.runtime.DefaultInliningPolicy) TruffleInlining(org.graalvm.compiler.truffle.runtime.TruffleInlining) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) DebugContext(org.graalvm.compiler.debug.DebugContext) Test(org.junit.Test)

Example 77 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class ReadEliminationClosure method processKilledLoopLocations.

@Override
protected void processKilledLoopLocations(Loop<Block> loop, ReadEliminationBlockState initialState, ReadEliminationBlockState mergedStates) {
    assert initialState != null;
    assert mergedStates != null;
    if (initialState.readCache.size() > 0) {
        LoopKillCache loopKilledLocations = loopLocationKillCache.get(loop);
        // it is visited
        if (loopKilledLocations == null) {
            loopKilledLocations = new LoopKillCache(1);
            loopLocationKillCache.put(loop, loopKilledLocations);
        } else {
            OptionValues options = loop.getHeader().getBeginNode().getOptions();
            if (loopKilledLocations.visits() > ReadEliminationMaxLoopVisits.getValue(options)) {
                // we have processed the loop too many times, kill all locations so the inner
                // loop will never be processed more than once again on visit
                loopKilledLocations.setKillsAll();
            } else {
                // we have fully processed this loop >1 times, update the killed locations
                EconomicSet<LocationIdentity> forwardEndLiveLocations = EconomicSet.create(Equivalence.DEFAULT);
                for (CacheEntry<?> entry : initialState.readCache.getKeys()) {
                    forwardEndLiveLocations.add(entry.getIdentity());
                }
                for (CacheEntry<?> entry : mergedStates.readCache.getKeys()) {
                    forwardEndLiveLocations.remove(entry.getIdentity());
                }
                // loop
                for (LocationIdentity location : forwardEndLiveLocations) {
                    loopKilledLocations.rememberLoopKilledLocation(location);
                }
                if (debug.isLogEnabled() && loopKilledLocations != null) {
                    debug.log("[Early Read Elimination] Setting loop killed locations of loop at node %s with %s", loop.getHeader().getBeginNode(), forwardEndLiveLocations);
                }
            }
            // remember the loop visit
            loopKilledLocations.visited();
        }
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity)

Example 78 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class TruffleToTruffleCallExceptionHandlerTest method partialEval.

@SuppressWarnings("try")
private static StructuredGraph partialEval(OptimizedCallTarget compilable, Object[] arguments, AllowAssumptions allowAssumptions) {
    compilable.call(arguments);
    compilable.call(arguments);
    compilable.call(arguments);
    OptionValues options = TruffleCompilerOptions.getOptions();
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    try (DebugContext.Scope s = debug.scope("TruffleCompilation", new TruffleDebugJavaMethod(compilable))) {
        TruffleInlining inliningDecision = new TruffleInlining(compilable, new DefaultInliningPolicy());
        SpeculationLog speculationLog = compilable.getSpeculationLog();
        return truffleCompiler.getPartialEvaluator().createGraph(debug, compilable, inliningDecision, allowAssumptions, INVALID_COMPILATION_ID, speculationLog, null);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : SpeculationLog(jdk.vm.ci.meta.SpeculationLog) OptionValues(org.graalvm.compiler.options.OptionValues) DefaultInliningPolicy(org.graalvm.compiler.truffle.runtime.DefaultInliningPolicy) TruffleInlining(org.graalvm.compiler.truffle.runtime.TruffleInlining) TruffleDebugJavaMethod(org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 79 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class AheadOfTimeCompilationTest method compile.

@SuppressWarnings("try")
private StructuredGraph compile(String test, boolean compileAOT) {
    OptionValues options = new OptionValues(getInitialOptions(), ImmutableCode, compileAOT);
    StructuredGraph graph = parseEager(test, AllowAssumptions.YES, options);
    compile(graph.method(), graph);
    return graph;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Example 80 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class CompileTheWorld method compile.

/**
 * Compiles all methods in all classes in a given class path.
 *
 * @param classPath class path denoting classes to compile
 * @throws IOException
 */
@SuppressWarnings("try")
private void compile(String classPath) throws IOException {
    final String[] entries = classPath.split(File.pathSeparator);
    long start = System.currentTimeMillis();
    Map<Thread, StackTraceElement[]> initialThreads = Thread.getAllStackTraces();
    try {
        // compile dummy method to get compiler initialized outside of the
        // config debug override.
        HotSpotResolvedJavaMethod dummyMethod = (HotSpotResolvedJavaMethod) JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod(CompileTheWorld.class.getDeclaredMethod("dummy"));
        int entryBCI = JVMCICompiler.INVOCATION_ENTRY_BCI;
        boolean useProfilingInfo = false;
        boolean installAsDefault = false;
        CompilationTask task = new CompilationTask(jvmciRuntime, compiler, new HotSpotCompilationRequest(dummyMethod, entryBCI, 0L), useProfilingInfo, installAsDefault, currentOptions);
        task.runCompilation();
    } catch (NoSuchMethodException | SecurityException e1) {
        printStackTrace(e1);
    }
    /*
         * Always use a thread pool, even for single threaded mode since it simplifies the use of
         * DebugValueThreadFilter to filter on the thread names.
         */
    int threadCount = 1;
    if (Options.MultiThreaded.getValue(currentOptions)) {
        threadCount = Options.Threads.getValue(currentOptions);
        if (threadCount == 0) {
            threadCount = Runtime.getRuntime().availableProcessors();
        }
    } else {
        running = true;
    }
    OptionValues savedOptions = currentOptions;
    currentOptions = new OptionValues(compilationOptions);
    threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new CompilerThreadFactory("CompileTheWorld"));
    try {
        for (int i = 0; i < entries.length; i++) {
            final String entry = entries[i];
            ClassPathEntry cpe;
            if (entry.endsWith(".zip") || entry.endsWith(".jar")) {
                cpe = new JarClassPathEntry(entry);
            } else if (entry.equals(JRT_CLASS_PATH_ENTRY)) {
                cpe = new JRTClassPathEntry(entry, Options.LimitModules.getValue(currentOptions));
            } else {
                if (!new File(entry).isDirectory()) {
                    println("CompileTheWorld : Skipped classes in " + entry);
                    println();
                    continue;
                }
                cpe = new DirClassPathEntry(entry);
            }
            if (methodFilters == null || methodFilters.length == 0) {
                println("CompileTheWorld : Compiling all classes in " + entry);
            } else {
                String include = Arrays.asList(methodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", "));
                println("CompileTheWorld : Compiling all methods in " + entry + " matching one of the following filters: " + include);
            }
            if (excludeMethodFilters != null && excludeMethodFilters.length > 0) {
                String exclude = Arrays.asList(excludeMethodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", "));
                println("CompileTheWorld : Excluding all methods matching one of the following filters: " + exclude);
            }
            println();
            ClassLoader loader = cpe.createClassLoader();
            for (String className : cpe.getClassNames()) {
                // Are we done?
                if (classFileCounter >= stopAt) {
                    break;
                }
                classFileCounter++;
                if (className.startsWith("jdk.management.") || className.startsWith("jdk.internal.cmm.*") || // These threads tend to cause deadlock at VM exit
                className.startsWith("sun.tools.jconsole.")) {
                    continue;
                }
                if (!isClassIncluded(className)) {
                    continue;
                }
                try {
                    // Load and initialize class
                    Class<?> javaClass = Class.forName(className, true, loader);
                    // Pre-load all classes in the constant pool.
                    try {
                        HotSpotResolvedObjectType objectType = HotSpotResolvedObjectType.fromObjectClass(javaClass);
                        ConstantPool constantPool = objectType.getConstantPool();
                        for (int cpi = 1; cpi < constantPool.length(); cpi++) {
                            constantPool.loadReferencedType(cpi, Bytecodes.LDC);
                        }
                    } catch (Throwable t) {
                        // If something went wrong during pre-loading we just ignore it.
                        if (isClassIncluded(className)) {
                            println("Preloading failed for (%d) %s: %s", classFileCounter, className, t);
                        }
                        continue;
                    }
                    // Are we compiling this class?
                    MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
                    if (classFileCounter >= startAt) {
                        println("CompileTheWorld (%d) : %s", classFileCounter, className);
                        // Compile each constructor/method in the class.
                        for (Constructor<?> constructor : javaClass.getDeclaredConstructors()) {
                            HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(constructor);
                            if (canBeCompiled(javaMethod, constructor.getModifiers())) {
                                compileMethod(javaMethod);
                            }
                        }
                        for (Method method : javaClass.getDeclaredMethods()) {
                            HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method);
                            if (canBeCompiled(javaMethod, method.getModifiers())) {
                                compileMethod(javaMethod);
                            }
                        }
                        // Also compile the class initializer if it exists
                        HotSpotResolvedJavaMethod clinit = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaType(javaClass).getClassInitializer();
                        if (clinit != null && canBeCompiled(clinit, clinit.getModifiers())) {
                            compileMethod(clinit);
                        }
                    }
                } catch (Throwable t) {
                    if (isClassIncluded(className)) {
                        println("CompileTheWorld (%d) : Skipping %s %s", classFileCounter, className, t.toString());
                        printStackTrace(t);
                    }
                }
            }
            cpe.close();
        }
    } finally {
        currentOptions = savedOptions;
    }
    if (!running) {
        startThreads();
    }
    int wakeups = 0;
    while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) {
        if (wakeups % 15 == 0) {
            TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles");
        }
        try {
            threadPool.awaitTermination(1, TimeUnit.SECONDS);
            wakeups++;
        } catch (InterruptedException e) {
        }
    }
    threadPool = null;
    long elapsedTime = System.currentTimeMillis() - start;
    println();
    if (Options.MultiThreaded.getValue(currentOptions)) {
        TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms elapsed, %d ms compile time, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), elapsedTime, compileTime.get(), memoryUsed.get());
    } else {
        TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), compileTime.get(), memoryUsed.get());
    }
    // Apart from the main thread, there should be only be daemon threads
    // alive now. If not, then a class initializer has probably started
    // a thread that could cause a deadlock while trying to exit the VM.
    // One known example of this is sun.tools.jconsole.OutputViewer which
    // spawns threads to redirect sysout and syserr. To help debug such
    // scenarios, the stacks of potentially problematic threads are dumped.
    Map<Thread, StackTraceElement[]> suspiciousThreads = new HashMap<>();
    for (Map.Entry<Thread, StackTraceElement[]> e : Thread.getAllStackTraces().entrySet()) {
        Thread thread = e.getKey();
        if (thread != Thread.currentThread() && !initialThreads.containsKey(thread) && !thread.isDaemon() && thread.isAlive()) {
            suspiciousThreads.put(thread, e.getValue());
        }
    }
    if (!suspiciousThreads.isEmpty()) {
        TTY.println("--- Non-daemon threads started during CTW ---");
        for (Map.Entry<Thread, StackTraceElement[]> e : suspiciousThreads.entrySet()) {
            Thread thread = e.getKey();
            if (thread.isAlive()) {
                TTY.println(thread.toString() + " " + thread.getState());
                for (StackTraceElement ste : e.getValue()) {
                    TTY.println("\tat " + ste);
                }
            }
        }
        TTY.println("---------------------------------------------");
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HashMap(java.util.HashMap) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) URLClassLoader(java.net.URLClassLoader) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) Method(java.lang.reflect.Method) HotSpotCompilationRequest(jdk.vm.ci.hotspot.HotSpotCompilationRequest) Print(org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.Print) CompilationTask(org.graalvm.compiler.hotspot.CompilationTask) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) ConstantPool(jdk.vm.ci.meta.ConstantPool) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) JarFile(java.util.jar.JarFile) File(java.io.File) EconomicMap(org.graalvm.collections.EconomicMap) Map(java.util.Map) HashMap(java.util.HashMap) UnmodifiableEconomicMap(org.graalvm.collections.UnmodifiableEconomicMap) CompilerThreadFactory(org.graalvm.compiler.core.CompilerThreadFactory) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Aggregations

OptionValues (org.graalvm.compiler.options.OptionValues)158 Test (org.junit.Test)65 DebugContext (org.graalvm.compiler.debug.DebugContext)50 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)36 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)30 Graph (org.graalvm.compiler.graph.Graph)22 OptionKey (org.graalvm.compiler.options.OptionKey)16 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)13 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)11 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)10 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)10 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)10 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)9 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)9 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)9 Providers (org.graalvm.compiler.phases.util.Providers)9 IOException (java.io.IOException)8 Method (java.lang.reflect.Method)8 CompilationResult (org.graalvm.compiler.code.CompilationResult)7 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)7