Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.oracle.truffle.polyglot;
import static com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere;
import static com.oracle.truffle.api.source.Source.CONTENT_NONE;
import static com.oracle.truffle.polyglot.EngineAccessor.INSTRUMENT;
import static com.oracle.truffle.polyglot.EngineAccessor.LANGUAGE;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.logging.Level;
import org.graalvm.options.OptionDescriptors;
import org.graalvm.polyglot.HostAccess.TargetMappingPrecedence;
import org.graalvm.polyglot.SandboxPolicy;
import org.graalvm.polyglot.impl.AbstractPolyglotImpl;
import org.graalvm.polyglot.impl.ModuleToUnnamedBridge;
import org.graalvm.polyglot.io.FileSystem;
import org.graalvm.polyglot.io.MessageTransport;
import org.graalvm.polyglot.io.ProcessHandler;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleFile;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleOptions;
import com.oracle.truffle.api.impl.DefaultTruffleRuntime;
import com.oracle.truffle.api.impl.DispatchOutputStream;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.strings.TruffleString;
import com.oracle.truffle.polyglot.EngineAccessor.AbstractClassLoaderSupplier;
import com.oracle.truffle.polyglot.PolyglotEngineImpl.LogConfig;
import com.oracle.truffle.polyglot.PolyglotLoggers.EngineLoggerProvider;
/*
* This class is exported to the GraalVM SDK. Keep that in mind when changing its class or package name.
*/
/**
* Internal service implementation of the polyglot API.
*/
public final class PolyglotImpl extends AbstractPolyglotImpl {
/*
* Used to prevent implementations of accessible API classes.
*/
static final Object SECRET = new Object();
static final Object[] EMPTY_ARGS = new Object[0];
private final PolyglotSourceDispatch sourceDispatch = new PolyglotSourceDispatch(this);
private final PolyglotSourceSectionDispatch sourceSectionDispatch = new PolyglotSourceSectionDispatch(this);
private final PolyglotExecutionListenerDispatch executionListenerDispatch = new PolyglotExecutionListenerDispatch(this);
private final PolyglotExecutionEventDispatch executionEventDispatch = new PolyglotExecutionEventDispatch(this);
final PolyglotEngineDispatch engineDispatch = new PolyglotEngineDispatch(this);
final PolyglotContextDispatch contextDispatch = new PolyglotContextDispatch(this);
private final PolyglotExceptionDispatch exceptionDispatch = new PolyglotExceptionDispatch(this);
final PolyglotInstrumentDispatch instrumentDispatch = new PolyglotInstrumentDispatch(this);
final PolyglotLanguageDispatch languageDispatch = new PolyglotLanguageDispatch(this);
private final AtomicReference preInitializedEngineRef = new AtomicReference<>();
private final Map, PolyglotValueDispatch> primitiveValues = new HashMap<>();
Object hostNull; // effectively final
private PolyglotValueDispatch disconnectedHostValue;
private PolyglotValueDispatch disconnectedBigIntegerHostValue;
private volatile Object defaultFileSystemContext;
private static volatile AbstractPolyglotImpl isolatePolyglot;
/**
* Internal method do not use.
*/
public PolyglotImpl() {
}
@Override
public int getPriority() {
return 0; // default priority
}
private static AbstractPolyglotImpl findImpl() {
try {
Method f = org.graalvm.polyglot.Engine.class.getDeclaredMethod("getImpl");
f.setAccessible(true);
return (AbstractPolyglotImpl) f.invoke(null);
} catch (Exception e) {
throw new InternalError(e);
}
}
/*
* Note: do not call this unless you know what you are doing. Always use the polyglot impl that
* you get passed. The only valid use-cases for this are for creating a fallback engine.
*/
static PolyglotImpl findInstance() {
AbstractPolyglotImpl polyglot = findImpl();
while (polyglot != null && !(polyglot instanceof PolyglotImpl)) {
polyglot = polyglot.getNext();
}
if (polyglot == null) {
throw new AssertionError(String.format("%s not found or installed but required.", PolyglotImpl.class.getSimpleName()));
}
return (PolyglotImpl) polyglot;
}
static AbstractPolyglotImpl findIsolatePolyglot() {
return isolatePolyglot;
}
static void setIsolatePolyglot(AbstractPolyglotImpl instance) {
assert instance != null;
assert isolatePolyglot == null;
isolatePolyglot = instance;
}
PolyglotEngineImpl getPreinitializedEngine() {
return preInitializedEngineRef.get();
}
@Override
public void initialize() {
super.initialize();
this.hostNull = getAPIAccess().newValue(PolyglotValueDispatch.createHostNull(this), null, EngineAccessor.HOST.getHostNull());
this.disconnectedHostValue = new PolyglotValueDispatch.HostValue(this);
this.disconnectedBigIntegerHostValue = new PolyglotValueDispatch.BigIntegerHostValue(this);
PolyglotValueDispatch.createDefaultValues(this, null, primitiveValues);
}
@Override
public Object initializeModuleToUnnamedAccess(Lookup unnamedLookup, Object unnamedAccess, Object unnamedAPIAccess, Object unnamedIOAccess, Object unnamedManagementAccess) {
ModuleToUnnamedBridge bridge = ModuleToUnnamedBridge.create(unnamedLookup, unnamedAccess, unnamedAPIAccess, unnamedIOAccess, unnamedManagementAccess);
AbstractPolyglotImpl impl = getRootImpl();
while (impl != null) {
initializeModuleToUnnamedBridge(impl, bridge);
impl = impl.getNextOrNull();
}
return bridge.getModuleAccess();
}
private static void initializeModuleToUnnamedBridge(AbstractPolyglotImpl impl, ModuleToUnnamedBridge bridge) {
impl.setConstructors(Objects.requireNonNull(bridge.getAPIAccess()));
impl.setIO(Objects.requireNonNull(bridge.getIOAccess()));
impl.setMonitoring(Objects.requireNonNull(bridge.getManagementAccess()));
impl.initialize();
}
@Override
public Object buildLimits(long statementLimit, Predicate