Search in sources :

Example 6 with BailoutException

use of jdk.vm.ci.code.BailoutException in project graal by oracle.

the class CompilerAssertsTest method compilationNonConstantTest.

@Test
public void compilationNonConstantTest() {
    FrameDescriptor descriptor = new FrameDescriptor();
    CompilationConstantTestNode result = new CompilationConstantTestNode(new NonConstantTestNode(5));
    RootTestNode rootNode = new RootTestNode(descriptor, "compilationConstant", result);
    try {
        compileHelper("compilationConstant", rootNode, new Object[0]);
        Assert.fail("Expected bailout exception because expression is not compilation constant");
    } catch (BailoutException e) {
    // Bailout exception expected.
    }
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) NonConstantTestNode(org.graalvm.compiler.truffle.test.nodes.NonConstantTestNode) BailoutException(jdk.vm.ci.code.BailoutException) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 7 with BailoutException

use of jdk.vm.ci.code.BailoutException in project graal by oracle.

the class TruffleCompilerImpl method compileAST.

/**
 * Compiles a Truffle AST. If compilation succeeds, the AST will have compiled code associated
 * with it that can be executed instead of interpreting the AST.
 *
 * @param compilable representation of the AST to be compiled
 * @param inliningPlan
 * @param compilationId identifier to be used for the compilation
 * @param cancellable an object polled during the compilation process to
 *            {@linkplain CancellationBailoutException abort} early if the thread owning the
 *            cancellable requests it
 * @param listener
 */
@SuppressWarnings("try")
public void compileAST(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, CompilationIdentifier compilationId, Cancellable cancellable, TruffleCompilerListener listener) {
    final CompilationPrinter printer = CompilationPrinter.begin(TruffleCompilerOptions.getOptions(), compilationId, new TruffleDebugJavaMethod(compilable), INVOCATION_ENTRY_BCI);
    StructuredGraph graph = null;
    try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(TruffleCompilerOptions.getOptions())) {
        PhaseSuite<HighTierContext> graphBuilderSuite = createGraphBuilderSuite();
        // Failed speculations must be collected before any compilation or
        // partial evaluation is performed.
        SpeculationLog speculationLog = compilable.getSpeculationLog();
        if (speculationLog != null) {
            speculationLog.collectFailedSpeculations();
        }
        try (DebugCloseable a = PartialEvaluationTime.start(debug);
            DebugCloseable c = PartialEvaluationMemUse.start(debug)) {
            graph = partialEvaluator.createGraph(debug, compilable, inliningPlan, AllowAssumptions.YES, compilationId, speculationLog, cancellable);
        }
        // Check if the task has been cancelled
        if (cancellable != null && cancellable.isCancelled()) {
            return;
        }
        if (listener != null) {
            listener.onTruffleTierFinished(compilable, inliningPlan, new GraphInfoImpl(graph));
        }
        CompilationResult compilationResult = compilePEGraph(graph, compilable.toString(), graphBuilderSuite, compilable, asCompilationRequest(compilationId), listener);
        if (listener != null) {
            listener.onSuccess(compilable, inliningPlan, new GraphInfoImpl(graph), new CompilationResultInfoImpl(compilationResult));
        }
        // Partial evaluation and installation are included in
        // compilation time and memory usage reported by printer
        printer.finish(compilationResult);
    } catch (Throwable t) {
        // graph is null
        if (listener != null) {
            BailoutException bailout = t instanceof BailoutException ? (BailoutException) t : null;
            boolean permanentBailout = bailout != null ? bailout.isPermanent() : false;
            listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout);
        }
        throw t;
    }
}
Also used : CompilationAlarm(org.graalvm.compiler.core.common.util.CompilationAlarm) TruffleDebugJavaMethod(org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod) CancellationBailoutException(org.graalvm.compiler.core.common.CancellationBailoutException) BailoutException(jdk.vm.ci.code.BailoutException) RetryableBailoutException(org.graalvm.compiler.core.common.RetryableBailoutException) SpeculationLog(jdk.vm.ci.meta.SpeculationLog) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationPrinter(org.graalvm.compiler.core.CompilationPrinter) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 8 with BailoutException

use of jdk.vm.ci.code.BailoutException in project graal by oracle.

the class TruffleCompilerImpl method notifyListenerOfFailure.

static void notifyListenerOfFailure(final CompilableTruffleAST compilable, TruffleCompilerListener listener, Throwable t) {
    if (listener != null) {
        BailoutException bailout = t instanceof BailoutException ? (BailoutException) t : null;
        boolean permanentBailout = bailout != null ? bailout.isPermanent() : false;
        listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout);
    }
}
Also used : CancellationBailoutException(org.graalvm.compiler.core.common.CancellationBailoutException) BailoutException(jdk.vm.ci.code.BailoutException) RetryableBailoutException(org.graalvm.compiler.core.common.RetryableBailoutException)

Example 9 with BailoutException

use of jdk.vm.ci.code.BailoutException in project graal by oracle.

the class BytecodeParser method bailout.

@Override
public BailoutException bailout(String string) {
    FrameState currentFrameState = createFrameState(bci(), null);
    StackTraceElement[] elements = GraphUtil.approxSourceStackTraceElement(currentFrameState);
    BailoutException bailout = new PermanentBailoutException(string);
    throw GraphUtil.createBailoutException(string, bailout, elements);
}
Also used : PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException) BailoutException(jdk.vm.ci.code.BailoutException) FrameState(org.graalvm.compiler.nodes.FrameState) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException)

Example 10 with BailoutException

use of jdk.vm.ci.code.BailoutException in project graal by oracle.

the class CheckGraalInvariants method runTest.

@SuppressWarnings("try")
public static void runTest(InvariantsTool tool) {
    RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
    Providers providers = rt.getHostBackend().getProviders();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
    Plugins plugins = new Plugins(new InvocationPlugins());
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
    graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
    HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
    Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
    String bootclasspath = tool.getClassPath();
    Assert.assertNotNull("Cannot find boot class path", bootclasspath);
    final List<String> classNames = new ArrayList<>();
    for (String path : bootclasspath.split(File.pathSeparator)) {
        if (tool.shouldProcess(path)) {
            try {
                final ZipFile zipFile = new ZipFile(new File(path));
                for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements(); ) {
                    final ZipEntry zipEntry = entry.nextElement();
                    String name = zipEntry.getName();
                    if (name.endsWith(".class") && !name.startsWith("META-INF/versions/")) {
                        String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
                        if (isInNativeImage(className)) {
                            /*
                                 * Native Image is an external tool and does not need to follow the
                                 * Graal invariants.
                                 */
                            continue;
                        }
                        classNames.add(className);
                    }
                }
            } catch (IOException ex) {
                Assert.fail(ex.toString());
            }
        }
    }
    Assert.assertFalse("Could not find graal jars on boot class path: " + bootclasspath, classNames.isEmpty());
    // Allows a subset of methods to be checked through use of a system property
    String property = System.getProperty(CheckGraalInvariants.class.getName() + ".filters");
    String[] filters = property == null ? null : property.split(",");
    OptionValues options = getInitialOptions();
    CompilerThreadFactory factory = new CompilerThreadFactory("CheckInvariantsThread");
    int availableProcessors = Runtime.getRuntime().availableProcessors();
    ThreadPoolExecutor executor = new ThreadPoolExecutor(availableProcessors, availableProcessors, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory);
    List<String> errors = Collections.synchronizedList(new ArrayList<>());
    for (Method m : BadUsageWithEquals.class.getDeclaredMethods()) {
        ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
        try (DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER)) {
            StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).build();
            try (DebugCloseable s = debug.disableIntercept();
                DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
                graphBuilderSuite.apply(graph, context);
                // update phi stamps
                graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
                checkGraph(context, graph);
                errors.add(String.format("Expected error while checking %s", m));
            } catch (VerificationError e) {
            // expected!
            } catch (Throwable e) {
                errors.add(String.format("Error while checking %s:%n%s", m, printStackTraceToString(e)));
            }
        }
    }
    if (errors.isEmpty()) {
        // Order outer classes before the inner classes
        classNames.sort((String a, String b) -> a.compareTo(b));
        // Initialize classes in single thread to avoid deadlocking issues during initialization
        List<Class<?>> classes = initializeClasses(tool, classNames);
        for (Class<?> c : classes) {
            String className = c.getName();
            executor.execute(() -> {
                try {
                    checkClass(c, metaAccess);
                } catch (Throwable e) {
                    errors.add(String.format("Error while checking %s:%n%s", className, printStackTraceToString(e)));
                }
            });
            for (Method m : c.getDeclaredMethods()) {
                if (Modifier.isNative(m.getModifiers()) || Modifier.isAbstract(m.getModifiers())) {
                // ignore
                } else {
                    String methodName = className + "." + m.getName();
                    if (matches(filters, methodName)) {
                        executor.execute(() -> {
                            try (DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER)) {
                                ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
                                StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
                                try (DebugCloseable s = debug.disableIntercept();
                                    DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
                                    checkMethod(method);
                                    graphBuilderSuite.apply(graph, context);
                                    // update phi stamps
                                    graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
                                    checkGraph(context, graph);
                                } catch (VerificationError e) {
                                    errors.add(e.getMessage());
                                } catch (LinkageError e) {
                                // suppress linkages errors resulting from eager resolution
                                } catch (BailoutException e) {
                                // Graal bail outs on certain patterns in Java bytecode
                                // (e.g.,
                                // unbalanced monitors introduced by jacoco).
                                } catch (Throwable e) {
                                    try {
                                        tool.handleParsingException(e);
                                    } catch (Throwable t) {
                                        errors.add(String.format("Error while checking %s:%n%s", methodName, printStackTraceToString(e)));
                                    }
                                }
                            }
                        });
                    }
                }
            }
        }
        executor.shutdown();
        try {
            executor.awaitTermination(1, TimeUnit.HOURS);
        } catch (InterruptedException e1) {
            throw new RuntimeException(e1);
        }
    }
    if (!errors.isEmpty()) {
        StringBuilder msg = new StringBuilder();
        String nl = String.format("%n");
        for (String e : errors) {
            if (msg.length() != 0) {
                msg.append(nl);
            }
            msg.append(e);
        }
        Assert.fail(msg.toString());
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) VerificationError(org.graalvm.compiler.phases.VerifyPhase.VerificationError) ZipEntry(java.util.zip.ZipEntry) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) ArrayList(java.util.ArrayList) Providers(org.graalvm.compiler.phases.util.Providers) VerifyPhase(org.graalvm.compiler.phases.VerifyPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) PhiNode(org.graalvm.compiler.nodes.PhiNode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) IOException(java.io.IOException) Method(java.lang.reflect.Method) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) BailoutException(jdk.vm.ci.code.BailoutException) ZipFile(java.util.zip.ZipFile) NodeClass(org.graalvm.compiler.graph.NodeClass) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) ZipFile(java.util.zip.ZipFile) File(java.io.File) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) CompilerThreadFactory(org.graalvm.compiler.core.CompilerThreadFactory) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

BailoutException (jdk.vm.ci.code.BailoutException)12 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)5 CancellationBailoutException (org.graalvm.compiler.core.common.CancellationBailoutException)3 RetryableBailoutException (org.graalvm.compiler.core.common.RetryableBailoutException)3 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)3 DebugContext (org.graalvm.compiler.debug.DebugContext)3 OptionValues (org.graalvm.compiler.options.OptionValues)3 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 CompilationResult (org.graalvm.compiler.code.CompilationResult)2 CompilationPrinter (org.graalvm.compiler.core.CompilationPrinter)2 PermanentBailoutException (org.graalvm.compiler.core.common.PermanentBailoutException)2 GraalError (org.graalvm.compiler.debug.GraalError)2 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)2 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)2 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)2 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)2 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1