Search in sources :

Example 16 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class TruffleSafepointTest method before.

@Before
public void before() throws ExecutionException, InterruptedException {
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
            return true;
        }
    });
    boolean handshakesSupported = true;
    Future<Void> future = null;
    try (Context c = createTestContext()) {
        c.enter();
        try {
            c.initialize(ProxyLanguage.ID);
            Env env = LanguageContext.get(null).getEnv();
            try {
                future = env.submitThreadLocal(null, new ThreadLocalAction(false, false) {

                    @Override
                    protected void perform(Access access) {
                    }
                });
            } catch (UnsupportedOperationException e) {
                if ("Thread local handshakes are not supported on this platform. A possible reason may be that the underlying JVMCI version is too old.".equals(e.getMessage())) {
                    handshakesSupported = false;
                } else {
                    throw e;
                }
            }
        } finally {
            c.leave();
        }
    }
    if (future != null) {
        future.get();
    }
    Assume.assumeTrue(handshakesSupported);
    if (VERBOSE) {
        System.out.println();
        System.out.print(name.getMethodName() + ":");
        testStarted = System.currentTimeMillis();
    }
}
Also used : LanguageContext(com.oracle.truffle.api.test.polyglot.ProxyLanguage.LanguageContext) Context(org.graalvm.polyglot.Context) TruffleContext(com.oracle.truffle.api.TruffleContext) Env(com.oracle.truffle.api.TruffleLanguage.Env) ThreadLocalAction(com.oracle.truffle.api.ThreadLocalAction) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Before(org.junit.Before)

Example 17 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class JavaStringCoercionTest method before.

@Before
public void before() {
    HostAccess access = TargetMappings.enableStringCoercions(HostAccess.newBuilder().allowPublicAccess(true)).build();
    setupEnv(Context.newBuilder().allowHostAccess(access).allowAllAccess(true).build(), ProxyLanguage.setDelegate(new ProxyLanguage() {
    }));
}
Also used : HostAccess(org.graalvm.polyglot.HostAccess) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Before(org.junit.Before)

Example 18 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class LegacyTruffleExceptionTest method testLegacyExceptionCustomGuestObject.

@Test
public void testLegacyExceptionCustomGuestObject() {
    setupEnv(createContext(verifyingHandler), new ProxyLanguage() {

        @Override
        protected CallTarget parse(TruffleLanguage.ParsingRequest request) throws Exception {
            return createAST(LegacyTruffleExceptionTest.class, languageInstance, (n) -> {
                LegacyCatchableException exception = new LegacyCatchableException("Test exception", n);
                LangObject exceptionObject = new LangObject(exception);
                exception.setExceptionObject(exceptionObject);
                return exceptionObject;
            }, true);
        }
    });
    verifyingHandler.expect(BlockNode.Kind.TRY, BlockNode.Kind.CATCH, BlockNode.Kind.FINALLY);
    context.eval(ProxyLanguage.ID, "Test");
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Node(com.oracle.truffle.api.nodes.Node) BeforeClass(org.junit.BeforeClass) ExportLibrary(com.oracle.truffle.api.library.ExportLibrary) PolyglotException(org.graalvm.polyglot.PolyglotException) ThrowNode(com.oracle.truffle.api.test.TruffleExceptionTest.ThrowNode) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) Test(org.junit.Test) CallTarget(com.oracle.truffle.api.CallTarget) BlockNode(com.oracle.truffle.api.test.TruffleExceptionTest.BlockNode) AbstractPolyglotTest(com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest) TestRootNode(com.oracle.truffle.api.test.TruffleExceptionTest.TestRootNode) ExceptionType(com.oracle.truffle.api.interop.ExceptionType) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) ExportMessage(com.oracle.truffle.api.library.ExportMessage) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleExceptionTest.createContext(com.oracle.truffle.api.test.TruffleExceptionTest.createContext) Context(org.graalvm.polyglot.Context) Assert(org.junit.Assert) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) TruffleTestAssumptions(com.oracle.truffle.tck.tests.TruffleTestAssumptions) TruffleExceptionTest.createAST(com.oracle.truffle.api.test.TruffleExceptionTest.createAST) Before(org.junit.Before) CallTarget(com.oracle.truffle.api.CallTarget) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) PolyglotException(org.graalvm.polyglot.PolyglotException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test) AbstractPolyglotTest(com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest)

Example 19 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class GR36225 method testSharedGuestToHostCodeCache.

@Test
public void testSharedGuestToHostCodeCache() throws Exception {
    Counter counter = new Counter();
    ExecutorService executorService = Executors.newFixedThreadPool(10);
    try (Engine engine = Engine.newBuilder().build()) {
        ProxyLanguage.setDelegate(new ProxyLanguage() {

            @Override
            protected CallTarget parse(ParsingRequest request) throws Exception {
                return RootNode.createConstantNode(new InvokeMember()).getCallTarget();
            }
        });
        List<Future<String>> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(executorService.submit(() -> {
                try (Context context = Context.newBuilder().engine(engine).build()) {
                    Source source = Source.create(ProxyLanguage.ID, "");
                    Value fn = context.eval(source);
                    fn.execute(counter, "increment");
                }
                return "x";
            }));
        }
        for (Future<String> future : futures) {
            future.get();
        }
    } finally {
        ProxyLanguage.setDelegate(new ProxyLanguage());
    }
    Assert.assertEquals(10, counter.counter.get());
}
Also used : Context(org.graalvm.polyglot.Context) CallTarget(com.oracle.truffle.api.CallTarget) ArrayList(java.util.ArrayList) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) ArityException(com.oracle.truffle.api.interop.ArityException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) Source(org.graalvm.polyglot.Source) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) ExecutorService(java.util.concurrent.ExecutorService) Value(org.graalvm.polyglot.Value) Future(java.util.concurrent.Future) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Example 20 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class AsCollectionsTest method enterContext.

@Before
public void enterContext() {
    context = Context.newBuilder().allowHostAccess(HostAccess.ALL).build();
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected LanguageContext createContext(Env contextEnv) {
            env = contextEnv;
            return super.createContext(contextEnv);
        }
    });
    context.initialize(ProxyLanguage.ID);
    context.enter();
}
Also used : Env(com.oracle.truffle.api.TruffleLanguage.Env) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Before(org.junit.Before)

Aggregations

ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)64 Test (org.junit.Test)47 CallTarget (com.oracle.truffle.api.CallTarget)32 AbstractPolyglotTest (com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest)28 PolyglotException (org.graalvm.polyglot.PolyglotException)26 RootNode (com.oracle.truffle.api.nodes.RootNode)21 Source (org.graalvm.polyglot.Source)21 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)20 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)20 Context (org.graalvm.polyglot.Context)17 TruffleContext (com.oracle.truffle.api.TruffleContext)16 Before (org.junit.Before)16 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)14 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)13 CountDownLatch (java.util.concurrent.CountDownLatch)11 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)10 ArrayList (java.util.ArrayList)10 ExecutionException (java.util.concurrent.ExecutionException)10 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)9 ExecutorService (java.util.concurrent.ExecutorService)9