Mercurial > hg > truffle
diff truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java @ 22141:46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 14 Sep 2015 11:02:52 +0200 |
parents | 1957c49a979d |
children | dc83cc1f94f2 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java Thu Sep 10 16:26:31 2015 +0200 +++ b/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java Mon Sep 14 11:02:52 2015 +0200 @@ -34,6 +34,8 @@ import com.oracle.truffle.api.interop.java.JavaInterop; import com.oracle.truffle.api.source.*; import java.io.*; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; import java.net.*; import java.nio.file.*; import java.util.*; @@ -586,7 +588,8 @@ if (representation.isInstance(obj)) { return representation.cast(obj); } - return JavaInterop.asJavaObject(representation, (TruffleObject) obj); + T wrapper = JavaInterop.asJavaObject(representation, (TruffleObject) obj); + return JavaWrapper.create(representation, wrapper, this); } /** @@ -618,6 +621,32 @@ } @SuppressWarnings("try") + final Symbol invokeProxy(final InvocationHandler chain, final Object wrapper, final Method method, final Object[] args) throws IOException { + final Debugger[] fillIn = {debugger}; + final CountDownLatch done = new CountDownLatch(1); + final Object[] res = {null, null}; + executor.execute(new Runnable() { + @Override + public void run() { + try (final Closeable c = SPI.executionStart(TruffleVM.this, fillIn, null)) { + if (debugger == null) { + debugger = fillIn[0]; + } + res[0] = chain.invoke(wrapper, method, args); + } catch (IOException ex) { + res[1] = ex; + } catch (Throwable ex) { + res[1] = ex; + } finally { + done.countDown(); + } + } + }); + exceptionCheck(res); + return new Symbol(language, res, done); + } + + @SuppressWarnings("try") private void invokeImpl(Debugger[] fillIn, Object thiz, Object[] args, Object[] res, CountDownLatch done) { try (final Closeable c = SPI.executionStart(TruffleVM.this, fillIn, null)) { if (debugger == null) {