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();
}
}
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() {
}));
}
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");
}
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());
}
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();
}
Aggregations