use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class EventContextObject method iterateFrames.
@CompilerDirectives.TruffleBoundary
private static Object iterateFrames(Object[] args, EventContextObject obj) throws ArityException, UnsupportedTypeException {
if (args.length == 0) {
throw ArityException.create(0, 0, args.length);
}
final NodeLibrary lib = NodeLibrary.getUncached();
final InteropLibrary iop = InteropLibrary.getUncached();
final Object callback = args[0];
if (!iop.isExecutable(callback)) {
Object displayCallback = iop.toDisplayString(callback, false);
throw UnsupportedTypeException.create(new Object[] { callback }, "Cannot execute " + displayCallback);
}
Object retValue = Truffle.getRuntime().iterateFrames((frameInstance) -> {
final Node n = frameInstance.getCallNode();
if (n == null || n.getRootNode() == null || n.getRootNode().isInternal()) {
// skip top most record of the instrument and any internal frames
return null;
}
LocationObject location = new LocationObject(n);
final SourceSection ss = location.getInstrumentedSourceSection();
if (ss == null || ss.getSource().isInternal()) {
// skip internal frames
return null;
}
final Frame frame = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
Node instrumentableNode = findInstrumentableParent(n);
if (instrumentableNode != null && lib.hasScope(instrumentableNode, frame)) {
try {
Object frameVars = new CurrentScopeView(lib.getScope(instrumentableNode, frame, false));
Object ret = iop.execute(callback, location, frameVars);
return iop.isNull(ret) ? null : ret;
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException ex) {
throw InsightException.raise(ex);
}
}
return null;
});
return NullObject.nullCheck(retValue);
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InsightSourceFilter method realCheck.
private boolean realCheck(Source src) {
Boolean prev = this.querying.get();
try {
if (Boolean.TRUE.equals(prev)) {
return false;
}
if (key.isClosed()) {
return false;
}
this.querying.set(true);
final InteropLibrary iop = InteropLibrary.getFactory().getUncached();
final int len = key.functionsMaxCount();
InsightPerContext ctx = insight.findCtx();
for (int i = 0; i < len; i++) {
InsightFilter.Data data = (InsightFilter.Data) ctx.functionFor(key, i);
if (data == null || data.sourceFilterFn == null) {
continue;
}
if (checkSource(iop, data, src)) {
return true;
}
}
return false;
} finally {
this.querying.set(prev);
}
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InsightPerSource method onLoad.
@Override
public void onLoad(LoadSourceEvent event) {
InteropLibrary interop = InteropLibrary.getUncached();
Instrumenter instrumenter = instrument.env().getInstrumenter();
int len = sourceBinding.functionsMaxCount();
for (int i = 0; i < len; i++) {
Object fn = instrument.findCtx().functionFor(sourceBinding, i);
if (fn == null) {
continue;
}
final Source source = event.getSource();
try {
interop.execute(fn, new SourceEventObject(source));
} catch (RuntimeException ex) {
if (interop.isException(ex)) {
InsightException.throwWhenExecuted(instrumenter, source, ex);
} else {
throw ex;
}
} catch (InteropException ex) {
InsightException.throwWhenExecuted(instrumenter, source, ex);
}
}
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InteropDefaultsTest method testScopeDefault.
@Test
public void testScopeDefault() {
Object v = new TruffleObject() {
};
InteropLibrary l = createLibrary(InteropLibrary.class, v);
assertFalse(l.isScope(v));
assertFalse(l.hasScopeParent(v));
assertFails(() -> l.getScopeParent(v), UnsupportedMessageException.class);
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class InteropDefaultsTest method assertString.
private void assertString(Object v, String expectedString) throws UnsupportedMessageException, InteropException {
InteropLibrary library = createLibrary(InteropLibrary.class, v);
assertTrue(library.isString(v));
assertEquals(expectedString, library.asString(v));
assertNoBoolean(v);
assertNotNull(v);
assertNoObject(v);
assertNoArray(v);
assertNoBuffer(v);
// assert string
assertNoNumber(v);
assertNoNative(v);
assertNotExecutable(v);
assertNotInstantiable(v);
assertNoMetaObject(v);
assertHasNoMetaObject(v);
assertNoDate(v);
assertNoTime(v);
assertNoTimeZone(v);
assertNoDuration(v);
assertNoSourceLocation(v);
assertNoLanguage(v);
assertNoIdentity(v);
}
Aggregations