use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class DebugExprTypeofNode method getLLVMSourceType.
@Specialization
public LLVMSourceType getLLVMSourceType(VirtualFrame frame) {
NodeLibrary nodeLibrary = NodeLibrary.getUncached();
InteropLibrary interopLibrary = InteropLibrary.getUncached();
try {
LLVMDebuggerValue entries = (LLVMDebuggerValue) nodeLibrary.getScope(location, frame, false);
if (interopLibrary.isMemberReadable(entries, name)) {
Object member = interopLibrary.readMember(entries, name);
LLVMDebuggerValue ldv = (LLVMDebuggerValue) member;
Object metaObj = ldv.resolveMetaObject();
return (LLVMSourceType) metaObj;
}
} catch (ClassCastException e) {
// OR metaObj is no primitive type
throw DebugExprException.create(this, "\"%s\" cannot be casted to a LLVMDebuggerValue", name);
} catch (UnsupportedMessageException e) {
// should only happen if hasMembers == false
throw DebugExprException.symbolNotFound(this, name, null);
} catch (UnknownIdentifierException e) {
throw DebugExprException.symbolNotFound(this, e.getUnknownIdentifier(), null);
}
return LLVMSourceType.UNKNOWN;
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class TypeHandler method getMetaObjectString.
static String getMetaObjectString(TruffleInstrument.Env env, final LanguageInfo language, Object argument) {
Object view = env.getLanguageView(language, argument);
InteropLibrary viewLib = InteropLibrary.getFactory().getUncached(view);
String retType = null;
if (viewLib.hasMetaObject(view)) {
try {
retType = INTEROP.asString(INTEROP.getMetaQualifiedName(viewLib.getMetaObject(view)));
} catch (UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreter();
throw new AssertionError(e);
}
}
return retType;
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class ExposeToGuestTest method assertMember.
private static void assertMember(Object object, String member, boolean readable, boolean modifiable) throws InteropException {
InteropLibrary interop = InteropLibrary.getFactory().getUncached();
assertTrue(interop.hasMembers(object));
assertEquals(readable, interop.isMemberReadable(object, member));
assertEquals(modifiable, interop.isMemberModifiable(object, member));
assertFalse(interop.isMemberInsertable(object, member));
assertFalse(interop.isMemberRemovable(object, member));
if (readable) {
assertEquals("42", interop.readMember(object, member));
} else {
try {
interop.readMember(object, member);
fail();
} catch (UnknownIdentifierException e) {
}
}
if (modifiable) {
interop.writeMember(object, member, "42");
} else {
try {
interop.writeMember(object, member, "43");
fail();
} catch (UnknownIdentifierException e) {
}
}
try {
interop.removeMember(object, member);
fail();
} catch (UnsupportedMessageException e) {
}
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class ContextInterruptStandaloneTest method testCancelDuringHostSleep.
@Test
public void testCancelDuringHostSleep() throws ExecutionException, InterruptedException {
CountDownLatch beforeSleep = new CountDownLatch(1);
enterContext = false;
setupEnv(Context.newBuilder(ProxyLanguage.ID).allowHostClassLookup((s) -> true).allowHostAccess(HostAccess.ALL), new ProxyLanguage() {
@Override
protected CallTarget parse(TruffleLanguage.ParsingRequest request) throws Exception {
return new RootNode(languageInstance) {
@Child
InteropLibrary library = InteropLibrary.getFactory().createDispatched(1);
@Override
public Object execute(VirtualFrame frame) {
callHostSleep();
return 0;
}
@CompilerDirectives.TruffleBoundary
private void callHostSleep() {
Object javaThread = LanguageContext.get(this).getEnv().lookupHostSymbol("java.lang.Thread");
beforeSleep.countDown();
try {
library.invokeMember(javaThread, "sleep", 10000);
} catch (UnsupportedMessageException | ArityException | UnknownIdentifierException | UnsupportedTypeException e) {
throw new AssertionError(e);
}
}
}.getCallTarget();
}
@Override
protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
return true;
}
});
ExecutorService executorService = Executors.newFixedThreadPool(1);
try {
Future<?> future = executorService.submit(() -> {
try {
context.eval(ProxyLanguage.ID, "");
Assert.fail();
} catch (PolyglotException pe) {
if (!pe.isCancelled() || pe.isInterrupted()) {
throw pe;
}
}
});
beforeSleep.await();
context.close(true);
future.get();
} finally {
executorService.shutdownNow();
executorService.awaitTermination(100, TimeUnit.SECONDS);
}
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class ContextInterruptStandaloneTest method testCancelFromHostCall.
private void testCancelFromHostCall(boolean nestedContextEntered) {
setupEnv(Context.newBuilder(ProxyLanguage.ID).allowHostClassLookup((s) -> true).allowHostAccess(HostAccess.ALL), new ProxyLanguage() {
@Override
protected CallTarget parse(TruffleLanguage.ParsingRequest request) throws Exception {
return new RootNode(languageInstance) {
@Child
InteropLibrary library = InteropLibrary.getFactory().createDispatched(1);
@Override
public Object execute(VirtualFrame frame) {
Object thisTestClass = ProxyLanguage.LanguageContext.get(this).getEnv().lookupHostSymbol(ContextInterruptStandaloneTest.class.getName());
try {
library.invokeMember(thisTestClass, "callStaticContextCancel", nestedContextEntered);
} catch (UnsupportedMessageException | ArityException | UnknownIdentifierException | UnsupportedTypeException e) {
throw new AssertionError(e);
}
return 0;
}
}.getCallTarget();
}
});
try {
staticContext = context;
context.eval(ProxyLanguage.ID, "");
Assert.fail();
} catch (PolyglotException pe) {
if (!pe.isCancelled()) {
throw pe;
}
} finally {
staticContext = null;
}
}
Aggregations