Search in sources :

Example 6 with OptionDescriptor

use of org.graalvm.options.OptionDescriptor in project graal by oracle.

the class PolyglotEngineOptionsTest method testVisibleOptions.

@Test
public void testVisibleOptions() {
    Engine engine = Engine.create();
    OptionDescriptor compilationThreshold = engine.getOptions().get(COMPILATION_THRESHOLD_OPTION);
    OptionDescriptor queueTimeThreshold = engine.getOptions().get("compiler.QueueTimeThreshold");
    Assert.assertNotNull(compilationThreshold);
    Assert.assertNotNull(queueTimeThreshold);
    engine.close();
}
Also used : OptionDescriptor(org.graalvm.options.OptionDescriptor) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Example 7 with OptionDescriptor

use of org.graalvm.options.OptionDescriptor in project graal by oracle.

the class Launcher method runPolyglotAction.

@SuppressWarnings("fallthrough")
final boolean runPolyglotAction() {
    OptionCategory helpCategory = helpDebug ? OptionCategory.DEBUG : (helpExpert ? OptionCategory.EXPERT : OptionCategory.USER);
    switch(versionAction) {
        case PrintAndContinue:
            printPolyglotVersions();
        // fall through
        case None:
            break;
        case PrintAndExit:
            printPolyglotVersions();
            return true;
    }
    boolean printDefaultHelp = help || ((helpExpert || helpDebug) && !helpTools && !helpLanguages);
    if (printDefaultHelp) {
        printHelp(helpCategory);
        // @formatter:off
        System.out.println();
        System.out.println("Runtime Options:");
        printOption("--polyglot", "Run with all other guest languages accessible.");
        printOption("--native", "Run using the native launcher with limited Java access" + (this.getDefaultVMType() == VMType.Native ? " (default)" : "") + ".");
        printOption("--native.[option]", "Pass options to the native image. To see available options, use '--native.help'.");
        printOption("--jvm", "Run on the Java Virtual Machine with Java access" + (this.getDefaultVMType() == VMType.JVM ? " (default)" : "") + ".");
        printOption("--jvm.[option]", "Pass options to the JVM; for example, '--jvm.classpath=myapp.jar'. To see available options. use '--jvm.help'.");
        printOption("--help", "Print this help message.");
        printOption("--help:languages", "Print options for all installed languages.");
        printOption("--help:tools", "Print options for all installed tools.");
        printOption("--help:expert", "Print additional options for experts.");
        if (helpExpert || helpDebug) {
            printOption("--help:debug", "Print additional options for debugging.");
        }
        printOption("--version:graalvm", "Print GraalVM version information and exit.");
        printOption("--show-version:graalvm", "Print GraalVM version information and continue execution.");
        // @formatter:on
        List<PrintableOption> engineOptions = new ArrayList<>();
        for (OptionDescriptor descriptor : getTempEngine().getOptions()) {
            if (!descriptor.getName().startsWith("engine.") && !descriptor.getName().startsWith("compiler.")) {
                continue;
            }
            if (descriptor.getCategory().ordinal() == helpCategory.ordinal()) {
                engineOptions.add(asPrintableOption(descriptor));
            }
        }
        if (!engineOptions.isEmpty()) {
            printOptions(engineOptions, "Engine options:", 2);
        }
    }
    if (helpLanguages) {
        printLanguageOptions(getTempEngine(), helpCategory);
    }
    if (helpTools) {
        printInstrumentOptions(getTempEngine(), helpCategory);
    }
    if (printDefaultHelp || helpLanguages || helpTools) {
        System.out.println("\nSee http://www.graalvm.org for more information.");
        return true;
    }
    return false;
}
Also used : OptionDescriptor(org.graalvm.options.OptionDescriptor) ArrayList(java.util.ArrayList) OptionCategory(org.graalvm.options.OptionCategory)

Example 8 with OptionDescriptor

use of org.graalvm.options.OptionDescriptor in project graal by oracle.

the class Launcher method parsePolyglotOption.

boolean parsePolyglotOption(String defaultOptionPrefix, Map<String, String> options, String arg) {
    switch(arg) {
        case "--help":
            help = true;
            return true;
        case "--help:debug":
            helpDebug = true;
            return true;
        case "--help:expert":
            helpExpert = true;
            return true;
        case "--help:tools":
            helpTools = true;
            return true;
        case "--help:languages":
            helpLanguages = true;
            return true;
        case "--version:graalvm":
            versionAction = VersionAction.PrintAndExit;
            return true;
        case "--show-version:graalvm":
            versionAction = VersionAction.PrintAndContinue;
            return true;
        case "--polyglot":
            seenPolyglot = true;
            return true;
        default:
            if ((arg.startsWith("--jvm.") && arg.length() > "--jvm.".length()) || arg.equals("--jvm")) {
                if (isAOT()) {
                    throw abort("should not reach here: jvm option failed to switch to JVM");
                }
                return true;
            } else if ((arg.startsWith("--native.") && arg.length() > "--native.".length()) || arg.equals("--native")) {
                if (!isAOT()) {
                    throw abort("native options are not supported on the JVM");
                }
                return true;
            }
            // getLanguageId() or null?
            if (arg.length() <= 2 || !arg.startsWith("--")) {
                return false;
            }
            int eqIdx = arg.indexOf('=');
            String key;
            String value;
            if (eqIdx < 0) {
                key = arg.substring(2);
                value = null;
            } else {
                key = arg.substring(2, eqIdx);
                value = arg.substring(eqIdx + 1);
            }
            if (value == null) {
                value = "true";
            }
            int index = key.indexOf('.');
            String group = key;
            if (index >= 0) {
                group = group.substring(0, index);
            }
            OptionDescriptor descriptor = findPolyglotOptionDescriptor(group, key);
            if (descriptor == null) {
                if (defaultOptionPrefix != null) {
                    descriptor = findPolyglotOptionDescriptor(defaultOptionPrefix, defaultOptionPrefix + "." + key);
                }
                if (descriptor == null) {
                    return false;
                }
            }
            try {
                descriptor.getKey().getType().convert(value);
            } catch (IllegalArgumentException e) {
                throw abort(String.format("Invalid argument %s specified. %s'", arg, e.getMessage()));
            }
            options.put(key, value);
            return true;
    }
}
Also used : OptionDescriptor(org.graalvm.options.OptionDescriptor)

Example 9 with OptionDescriptor

use of org.graalvm.options.OptionDescriptor in project graal by oracle.

the class EvalLauncher method printHelp.

private static void printHelp(OptionCategory maxCategory) {
    Engine engine = Engine.create();
    System.out.println(BASIC_HELP);
    System.out.println("Engine options: ");
    for (OptionDescriptor descriptor : engine.getOptions()) {
        printOption(maxCategory, descriptor);
    }
    System.out.println("Language options: ");
    for (String languageId : engine.getLanguages().keySet()) {
        Language language = engine.getLanguage(languageId);
        for (OptionDescriptor descriptor : language.getOptions()) {
            printOption(maxCategory, descriptor);
        }
    }
    System.out.println("Tool options: ");
    for (String instrumentId : engine.getInstruments().keySet()) {
        Instrument instrument = engine.getInstrument(instrumentId);
        for (OptionDescriptor descriptor : instrument.getOptions()) {
            printOption(maxCategory, descriptor);
        }
    }
}
Also used : Language(org.graalvm.polyglot.Language) OptionDescriptor(org.graalvm.options.OptionDescriptor) Instrument(org.graalvm.polyglot.Instrument) Engine(org.graalvm.polyglot.Engine)

Example 10 with OptionDescriptor

use of org.graalvm.options.OptionDescriptor in project graal by oracle.

the class OptionValuesImpl method put.

public void put(String key, String value) {
    OptionDescriptor descriptor = findDescriptor(key);
    values.put(descriptor.getKey(), descriptor.getKey().getType().convert(value));
}
Also used : OptionDescriptor(org.graalvm.options.OptionDescriptor)

Aggregations

OptionDescriptor (org.graalvm.options.OptionDescriptor)12 Engine (org.graalvm.polyglot.Engine)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 OptionDescriptors (org.graalvm.options.OptionDescriptors)3 Language (org.graalvm.polyglot.Language)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Instrument (org.graalvm.polyglot.Instrument)2 TruffleContext (com.oracle.truffle.api.TruffleContext)1 LanguageContext (com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext)1 Formatter (java.util.Formatter)1 Iterator (java.util.Iterator)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 OptionCategory (org.graalvm.options.OptionCategory)1 OptionKey (org.graalvm.options.OptionKey)1 Context (org.graalvm.polyglot.Context)1