Search in sources :

Example 1 with AbstractPolyglotImpl

use of org.graalvm.polyglot.impl.AbstractPolyglotImpl in project graal by oracle.

the class ContextPreInitializationTest method findImpl.

AbstractPolyglotImpl findImpl() throws ReflectiveOperationException {
    Method getImplMethod = Engine.class.getDeclaredMethod("getImpl");
    getImplMethod.setAccessible(true);
    return (AbstractPolyglotImpl) getImplMethod.invoke(null);
}
Also used : AbstractPolyglotImpl(org.graalvm.polyglot.impl.AbstractPolyglotImpl) Method(java.lang.reflect.Method)

Example 2 with AbstractPolyglotImpl

use of org.graalvm.polyglot.impl.AbstractPolyglotImpl in project graal by oracle.

the class IOHelper method initImpl.

private static AbstractPolyglotImpl initImpl() {
    try {
        Method method = Engine.class.getDeclaredMethod("getImpl");
        method.setAccessible(true);
        AbstractPolyglotImpl polyglotImpl = (AbstractPolyglotImpl) method.invoke(null);
        polyglotImpl.setIO(new IOAccessImpl());
        return polyglotImpl;
    } catch (Exception e) {
        throw new IllegalStateException("Failed to initialize execution listener class.", e);
    }
}
Also used : AbstractPolyglotImpl(org.graalvm.polyglot.impl.AbstractPolyglotImpl) Method(java.lang.reflect.Method) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException)

Example 3 with AbstractPolyglotImpl

use of org.graalvm.polyglot.impl.AbstractPolyglotImpl in project graal by oracle.

the class Management method initImpl.

private static AbstractPolyglotImpl initImpl() {
    try {
        Method method = Engine.class.getDeclaredMethod("getImpl");
        method.setAccessible(true);
        AbstractPolyglotImpl impl = (AbstractPolyglotImpl) method.invoke(null);
        impl.setMonitoring(new ManagementAccessImpl());
        return impl;
    } catch (Exception e) {
        throw new IllegalStateException("Failed to initialize execution listener class.", e);
    }
}
Also used : AbstractPolyglotImpl(org.graalvm.polyglot.impl.AbstractPolyglotImpl) Method(java.lang.reflect.Method)

Example 4 with AbstractPolyglotImpl

use of org.graalvm.polyglot.impl.AbstractPolyglotImpl in project graal by oracle.

the class SourceAPITest method testNoContentSource.

@Test
@SuppressWarnings("rawtypes")
public void testNoContentSource() {
    AbstractPolyglotImpl polyglot = (AbstractPolyglotImpl) ReflectionUtils.invokeStatic(Engine.class, "getImpl");
    com.oracle.truffle.api.source.Source truffleSource = com.oracle.truffle.api.source.Source.newBuilder(ProxyLanguage.ID, "x", "name").content(com.oracle.truffle.api.source.Source.CONTENT_NONE).build();
    Class<?>[] sourceConstructorTypes = new Class[] { AbstractSourceDispatch.class, Object.class };
    Source source = ReflectionUtils.newInstance(Source.class, sourceConstructorTypes, polyglot.getAPIAccess().getDispatch(Source.create(ProxyLanguage.ID, "")), truffleSource);
    assertFalse(source.hasCharacters());
    assertFalse(source.hasBytes());
    try {
        source.getCharacters();
        fail();
    } catch (UnsupportedOperationException ex) {
    // O.K.
    }
    try {
        Context.create().eval(source);
        fail();
    } catch (IllegalArgumentException ex) {
    // O.K.
    }
    com.oracle.truffle.api.source.SourceSection truffleSection = truffleSource.createSection(1, 2, 3, 4);
    Class<?>[] sectionConstructorTypes = new Class[] { Source.class, AbstractSourceSectionDispatch.class, Object.class };
    SourceSection section = ReflectionUtils.newInstance(SourceSection.class, sectionConstructorTypes, source, getSourceSectionDispatch(polyglot), truffleSection);
    assertFalse(section.hasCharIndex());
    assertTrue(section.hasLines());
    assertTrue(section.hasColumns());
    assertEquals("", section.getCharacters());
    assertTrue(truffleSource.getURI().toString().contains("name"));
}
Also used : AbstractPolyglotImpl(org.graalvm.polyglot.impl.AbstractPolyglotImpl) Source(org.graalvm.polyglot.Source) AbstractSourceSectionDispatch(org.graalvm.polyglot.impl.AbstractPolyglotImpl.AbstractSourceSectionDispatch) AbstractSourceDispatch(org.graalvm.polyglot.impl.AbstractPolyglotImpl.AbstractSourceDispatch) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) SourceSection(org.graalvm.polyglot.SourceSection) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Example 5 with AbstractPolyglotImpl

use of org.graalvm.polyglot.impl.AbstractPolyglotImpl in project graal by oracle.

the class PolyglotImpl method getImpl.

private static AbstractPolyglotImpl getImpl() {
    AbstractPolyglotImpl local = abstractImpl;
    if (local == null) {
        try {
            Method f = Engine.class.getDeclaredMethod("getImpl");
            f.setAccessible(true);
            abstractImpl = local = (AbstractPolyglotImpl) f.invoke(null);
            assert local != null : "polyglot impl not found";
        } catch (Exception e) {
            throw new AssertionError(e);
        }
    }
    return local;
}
Also used : AbstractPolyglotImpl(org.graalvm.polyglot.impl.AbstractPolyglotImpl) Method(java.lang.reflect.Method) PolyglotException(org.graalvm.polyglot.PolyglotException) IOException(java.io.IOException)

Aggregations

AbstractPolyglotImpl (org.graalvm.polyglot.impl.AbstractPolyglotImpl)6 Method (java.lang.reflect.Method)4 IOException (java.io.IOException)2 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 Field (java.lang.reflect.Field)1 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Engine (org.graalvm.polyglot.Engine)1 PolyglotException (org.graalvm.polyglot.PolyglotException)1 Source (org.graalvm.polyglot.Source)1 SourceSection (org.graalvm.polyglot.SourceSection)1 AbstractSourceDispatch (org.graalvm.polyglot.impl.AbstractPolyglotImpl.AbstractSourceDispatch)1 AbstractSourceSectionDispatch (org.graalvm.polyglot.impl.AbstractPolyglotImpl.AbstractSourceSectionDispatch)1 Test (org.junit.Test)1