mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
support graal-js in nashorn compat mode
This commit is contained in:
parent
9d0403a59f
commit
52501f40fc
@ -249,7 +249,12 @@ public class NBCLI {
|
||||
|
||||
ScenariosExecutor executor = new ScenariosExecutor("executor-" + sessionName, 1);
|
||||
|
||||
Scenario scenario = new Scenario(sessionName, options.getScriptingEngine(), options.getProgressSpec());
|
||||
Scenario scenario = new Scenario(
|
||||
sessionName,
|
||||
options.getScriptingEngine(),
|
||||
options.getProgressSpec(),
|
||||
options.wantsGraaljsCompatMode()
|
||||
);
|
||||
ScriptBuffer buffer = new BasicScriptBuffer(
|
||||
options.getLogsDirectory()+ FileSystems.getDefault().getSeparator()+ "_scenario."+ scenario.getName() +".js"
|
||||
).add(options.getCommands().toArray(new Cmd[0]));
|
||||
|
@ -75,8 +75,9 @@ public class NBCLIOptions {
|
||||
private final static String ENABLE_CHART = "--enable-chart";
|
||||
private final static String DOCKER_METRICS = "--docker-metrics";
|
||||
|
||||
private static final String GRAALVM_ENGINE = "--graalvm";
|
||||
private static final String GRAALJS_ENGINE = "--graaljs";
|
||||
private static final String NASHORN_ENGINE = "--nashorn";
|
||||
private static final String GRAALJS_COMPAT = "--graaljs-compat";
|
||||
|
||||
|
||||
public static final Set<String> RESERVED_WORDS = new HashSet<>() {{
|
||||
@ -125,6 +126,7 @@ public class NBCLIOptions {
|
||||
private boolean wantsWorkloadsList = false;
|
||||
private final List<String> wantsToIncludePaths = new ArrayList<>();
|
||||
private Scenario.Engine engine = Scenario.Engine.Graalvm;
|
||||
private boolean graaljs_compat = false;
|
||||
|
||||
|
||||
public NBCLIOptions(String[] args) {
|
||||
@ -181,7 +183,11 @@ public class NBCLIOptions {
|
||||
}
|
||||
|
||||
switch (word) {
|
||||
case GRAALVM_ENGINE:
|
||||
case GRAALJS_COMPAT:
|
||||
graaljs_compat = true;
|
||||
arglist.removeFirst();
|
||||
break;
|
||||
case GRAALJS_ENGINE:
|
||||
engine = Scenario.Engine.Graalvm;
|
||||
arglist.removeFirst();
|
||||
break;
|
||||
@ -399,6 +405,10 @@ public class NBCLIOptions {
|
||||
return engine;
|
||||
}
|
||||
|
||||
public boolean wantsGraaljsCompatMode() {
|
||||
return graaljs_compat;
|
||||
}
|
||||
|
||||
public List<LoggerConfig> getHistoLoggerConfigs() {
|
||||
List<LoggerConfig> configs = histoLoggerConfigs.stream().map(LoggerConfig::new).collect(Collectors.toList());
|
||||
checkLoggerConfigs(configs, LOG_HISTOGRAMS);
|
||||
|
@ -24,6 +24,7 @@ import io.nosqlbench.engine.api.extensions.ScriptingPluginInfo;
|
||||
import io.nosqlbench.engine.api.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.engine.core.metrics.NashornMetricRegistryBindings;
|
||||
import io.nosqlbench.engine.api.scripting.ScriptEnvBuffer;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.graalvm.polyglot.EnvironmentAccess;
|
||||
import org.graalvm.polyglot.HostAccess;
|
||||
@ -54,6 +55,7 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
private ScenarioController scenarioController;
|
||||
private ProgressIndicator progressIndicator;
|
||||
private String progressInterval = "console:1m";
|
||||
private boolean wantsGraaljsCompatMode;
|
||||
private ScenarioContext scriptEnv;
|
||||
private String name;
|
||||
private ScenarioLogger scenarioLogger;
|
||||
@ -65,10 +67,11 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
Graalvm
|
||||
}
|
||||
|
||||
public Scenario(String name, Engine engine, String progressInterval) {
|
||||
public Scenario(String name, Engine engine, String progressInterval, boolean wantsGraaljsCompatMode) {
|
||||
this.name = name;
|
||||
this.engine = engine;
|
||||
this.progressInterval = progressInterval;
|
||||
this.wantsGraaljsCompatMode = wantsGraaljsCompatMode;
|
||||
}
|
||||
|
||||
public Scenario(String name, Engine engine) {
|
||||
@ -107,7 +110,11 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
|
||||
switch (engine) {
|
||||
case Nashorn:
|
||||
scriptEngine = engineManager.getEngineByName("nashorn");
|
||||
NashornScriptEngineFactory f = new NashornScriptEngineFactory();
|
||||
this.scriptEngine = f.getScriptEngine("--language=es6");
|
||||
|
||||
// engineManager.getEngineByName("nashorn");
|
||||
// TODO: Figure out how to do this in engine bindings: --language=es-6
|
||||
break;
|
||||
case Graalvm:
|
||||
Context.Builder contextSettings = Context.newBuilder("js")
|
||||
@ -124,14 +131,14 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
.option("js.ecmascript-version", "2020")
|
||||
.option("js.nashorn-compat", "true");
|
||||
|
||||
scriptEngine = GraalJSScriptEngine.create(null, contextSettings);
|
||||
this.scriptEngine = GraalJSScriptEngine.create(null, contextSettings);
|
||||
|
||||
try {
|
||||
scriptEngine.put("javaObj", new Object());
|
||||
scriptEngine.eval("(javaObj instanceof Java.type('java.lang.Object'));");
|
||||
} catch (ScriptException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// try {
|
||||
// this.scriptEngine.put("javaObj", new Object());
|
||||
// this.scriptEngine.eval("(javaObj instanceof Java.type('java.lang.Object'));");
|
||||
// } catch (ScriptException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
|
||||
break;
|
||||
}
|
||||
@ -147,9 +154,15 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
scriptEngine.put("params", scenarioScriptParams);
|
||||
|
||||
if (engine == Engine.Graalvm) {
|
||||
scriptEngine.put("scenario", new PolyglotScenarioController(scenarioController));
|
||||
scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
||||
scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
|
||||
if (wantsGraaljsCompatMode) {
|
||||
scriptEngine.put("scenario", scenarioController);
|
||||
scriptEngine.put("metrics", new NashornMetricRegistryBindings(metricRegistry));
|
||||
scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
|
||||
} else {
|
||||
scriptEngine.put("scenario", new PolyglotScenarioController(scenarioController));
|
||||
scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
||||
scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
|
||||
}
|
||||
} else if (engine == Engine.Nashorn) {
|
||||
scriptEngine.put("scenario", scenarioController);
|
||||
scriptEngine.put("metrics", new NashornMetricRegistryBindings(metricRegistry));
|
||||
|
Loading…
Reference in New Issue
Block a user