Search in sources :

Example 1 with HostedOptionValues

use of com.oracle.svm.core.option.HostedOptionValues in project graal by oracle.

the class NativeImageGenerator method run.

/**
 * Executes the image build. Only one image can be built with this generator.
 */
public void run(Map<Method, CEntryPointData> entryPoints, Method mainEntryPoint, JavaMainSupport javaMainSupport, String imageName, AbstractBootImage.NativeImageKind k, SubstitutionProcessor harnessSubstitutions, ForkJoinPool compilationExecutor, ForkJoinPool analysisExecutor, EconomicSet<String> allOptionNames) {
    try {
        if (!buildStarted.compareAndSet(false, true)) {
            throw UserError.abort("An image build has already been performed with this generator.");
        }
        int maxConcurrentThreads = NativeImageOptions.getMaximumNumberOfConcurrentThreads(new OptionValues(optionProvider.getHostedValues()));
        this.imageBuildPool = createForkJoinPool(maxConcurrentThreads);
        imageBuildPool.submit(() -> {
            try {
                ImageSingletons.add(HostedOptionValues.class, new HostedOptionValues(optionProvider.getHostedValues()));
                ImageSingletons.add(RuntimeOptionValues.class, new RuntimeOptionValues(optionProvider.getRuntimeValues(), allOptionNames));
                doRun(entryPoints, mainEntryPoint, javaMainSupport, imageName, k, harnessSubstitutions, compilationExecutor, analysisExecutor);
            } finally {
                try {
                    /*
                         * Make sure we clean up after ourselves even in the case of an exception.
                         */
                    if (deleteTempDirectory) {
                        deleteAll(tempDirectory());
                    }
                    featureHandler.forEachFeature(Feature::cleanup);
                } catch (Throwable e) {
                /*
                         * Suppress subsequent errors so that we unwind the original error brought
                         * us here.
                         */
                }
            }
        }).get();
    } catch (InterruptedException | CancellationException e) {
        System.out.println("Interrupted!");
        throw new InterruptImageBuilding();
    } catch (ExecutionException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        } else if (e.getCause() instanceof Error) {
            throw (Error) e.getCause();
        }
    } finally {
        shutdownPoolSafe();
    }
}
Also used : HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) RuntimeOptionValues(com.oracle.svm.core.option.RuntimeOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) CancellationException(java.util.concurrent.CancellationException) RuntimeOptionValues(com.oracle.svm.core.option.RuntimeOptionValues) InterruptImageBuilding(com.oracle.svm.core.util.InterruptImageBuilding) UserError(com.oracle.svm.core.util.UserError) VMError(com.oracle.svm.core.util.VMError) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) ExecutionException(java.util.concurrent.ExecutionException) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Aggregations

HostedOptionValues (com.oracle.svm.core.option.HostedOptionValues)1 RuntimeOptionValues (com.oracle.svm.core.option.RuntimeOptionValues)1 InterruptImageBuilding (com.oracle.svm.core.util.InterruptImageBuilding)1 UserError (com.oracle.svm.core.util.UserError)1 VMError (com.oracle.svm.core.util.VMError)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1