Search in sources :

Example 41 with InteropLibrary

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);
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) Frame(com.oracle.truffle.api.frame.Frame) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) SourceSection(com.oracle.truffle.api.source.SourceSection) ArityException(com.oracle.truffle.api.interop.ArityException)

Example 42 with InteropLibrary

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);
    }
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary)

Example 43 with InteropLibrary

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);
        }
    }
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Instrumenter(com.oracle.truffle.api.instrumentation.Instrumenter) InteropException(com.oracle.truffle.api.interop.InteropException) Source(com.oracle.truffle.api.source.Source)

Example 44 with InteropLibrary

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);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 45 with InteropLibrary

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);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary)

Aggregations

InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)158 Test (org.junit.Test)76 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)60 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)51 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)18 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)18 ArityException (com.oracle.truffle.api.interop.ArityException)16 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)15 WasmInstance (org.graalvm.wasm.WasmInstance)15 WebAssembly (org.graalvm.wasm.api.WebAssembly)15 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)12 RootNode (com.oracle.truffle.api.nodes.RootNode)12 InteropException (com.oracle.truffle.api.interop.InteropException)11 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)11 Dictionary (org.graalvm.wasm.api.Dictionary)8 SourceSection (com.oracle.truffle.api.source.SourceSection)6 CallTarget (com.oracle.truffle.api.CallTarget)5 Node (com.oracle.truffle.api.nodes.Node)5 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)5 WasmJsApiException (org.graalvm.wasm.exception.WasmJsApiException)5