/** * Pre-initializes a polyglot engine instance. * * @since 0.31 */ @Override public void preInitializeEngine() { ensureInitialized(); final PolyglotEngineImpl preInitializedEngine = PolyglotEngineImpl.preInitialize( this, INSTRUMENT.createDispatchOutput(System.out), INSTRUMENT.createDispatchOutput(System.err), System.in, TruffleOptions.AOT ? null : Thread.currentThread().getContextClassLoader()); preInitializedEngineRef.set(preInitializedEngine); }
/** * Pre-initializes a polyglot engine instance. */ @Override public void preInitializeEngine() { final Handler logHandler = PolyglotLogHandler.createStreamHandler(System.err, false, true); try { final PolyglotEngineImpl preInitializedEngine = PolyglotEngineImpl.preInitialize( this, INSTRUMENT.createDispatchOutput(System.out), INSTRUMENT.createDispatchOutput(System.err), System.in, TruffleOptions.AOT ? null : Thread.currentThread().getContextClassLoader(), logHandler); preInitializedEngineRef.set(preInitializedEngine); } finally { logHandler.flush(); } }
/** * Internal method do not use. * * @since 0.27 */ @Override public Engine buildEngine(OutputStream out, OutputStream err, InputStream in, Map<String, String> arguments, long timeout, TimeUnit timeoutUnit, boolean sandbox, long maximumAllowedAllocationBytes, boolean useSystemProperties, boolean boundEngine) { ensureInitialized(); OutputStream resolvedOut = out == null ? System.out : out; OutputStream resolvedErr = err == null ? System.err : err; InputStream resolvedIn = in == null ? System.in : in; DispatchOutputStream dispatchOut = INSTRUMENT.createDispatchOutput(resolvedOut); DispatchOutputStream dispatchErr = INSTRUMENT.createDispatchOutput(resolvedErr); ClassLoader contextClassLoader = TruffleOptions.AOT ? null : Thread.currentThread().getContextClassLoader(); PolyglotEngineImpl impl = preInitializedEngineRef.getAndSet(null); if (impl != null) { if (!impl.patch(dispatchOut, dispatchErr, resolvedIn, arguments, timeout, timeoutUnit, sandbox, useSystemProperties, contextClassLoader, boundEngine)) { impl.ensureClosed(false, true); impl = null; } } if (impl == null) { impl = new PolyglotEngineImpl(this, dispatchOut, dispatchErr, resolvedIn, arguments, timeout, timeoutUnit, sandbox, useSystemProperties, contextClassLoader, boundEngine); } Engine engine = getAPIAccess().newEngine(impl); impl.api = engine; return engine; }
realOut = realRuntime.out; } else { realOut = INSTRUMENT.createDispatchOutput(out); engine().attachOutputConsumer(realOut, realRuntime.out); realErr = realRuntime.err; } else { realErr = INSTRUMENT.createDispatchOutput(err); engine().attachOutputConsumer(realErr, realRuntime.err);
Handler logHandler = PolyglotLogHandler.asHandler(logHandlerOrStream); DispatchOutputStream dispatchOut = INSTRUMENT.createDispatchOutput(resolvedOut); DispatchOutputStream dispatchErr = INSTRUMENT.createDispatchOutput(resolvedErr); ClassLoader contextClassLoader = TruffleOptions.AOT ? null : Thread.currentThread().getContextClassLoader();
/** * Creates new instance of a runtime. Uses data stored in this builder to configure it. Once * the instance is obtained, pass it to * {@link PolyglotEngine.Builder#runtime(com.oracle.truffle.api.vm.PolyglotRuntime)} method. * * @return new instances of the {@link PolyglotRuntime} * @since 0.25 */ public PolyglotRuntime build() { DispatchOutputStream realOut = INSTRUMENT.createDispatchOutput(out == null ? System.out : out); DispatchOutputStream realErr = INSTRUMENT.createDispatchOutput(err == null ? System.err : err); InputStream realIn = in == null ? System.in : in; return new PolyglotRuntime(realOut, realErr, realIn, false); }
PolyglotRuntime build(boolean autoDispose) { DispatchOutputStream realOut = INSTRUMENT.createDispatchOutput(out == null ? System.out : out); DispatchOutputStream realErr = INSTRUMENT.createDispatchOutput(err == null ? System.err : err); InputStream realIn = in == null ? System.in : in; return new PolyglotRuntime(realOut, realErr, realIn, autoDispose); } }