Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Christian Humer
    @chumer
    @kommen So you already use GraalVM? Feel free to report any issues, we are happy to investigate / optimize your use-case. Also note that libgraal[1] works only on GraalVM, which significantly reduces the warmup time you are seeing.
    [1] https://medium.com/graalvm/libgraal-graalvm-compiler-as-a-precompiled-graalvm-native-image-26e354bee5c
    Dieter Komendera
    @kommen
    so that post itself is served by a clojure app running on graalvm and the initial html served is generated server side via a react/clojurescript app in graaljs :)
    Luca Burgazzoli
    @lburgazzoli
    is there a way to give some hint to the polyglot context about how to resolve overloaded methods when accessing host objects ?

    to give more context, I'm allowing a js code to access some object from a 3th party library for which I do not have much control and one of the method I want to access has some overloaded implementation like:

    process(Consumer<String> ...)
    process(Supplier<Consumer<String>> ...)

    I can eventually wrap it using one of the Proxy class but wondeing if there is a way to do it without
    Paulo Lopes
    @pmlopes
    @lburgazzoli this isn't possible yet graalvm/graaljs#37
    Luca Burgazzoli
    @lburgazzoli
    @pmlopes thx
    Daniil Mikhaylov
    @mdsina

    https://gitter.im/graalvm/graaljs?at=5d57eaba9507182477f5ae3b

    What kind of memory leaks? Can you share a heap dump?

    @chumer
    Sorry for long reply.
    Heap dump: https://drive.google.com/file/d/1pGQBM8pEFar1bXK7-3SIbOVXiCMCKgV-/view?usp=sharing

    Daniil Mikhaylov
    @mdsina
    It is possible to use async\await in graal.js with polyglot?
    Matteo Bertozzi
    @matteobertozzi

    Is there a way to get the current source location (SourceSection) from java?

    e.g. a js script executed via context.eval() calls a java method, the java method logs the current js script name+line

    PolyglotException has a getSourceLocation() that provide this information. also stack traces from polyglot seems to contains information about the source location e.g. at :program(Unnamed:2:23-53)

    Paulo Lopes
    @pmlopes
    @chumer I've noticed that the docs say that graaljs support java map iteration possible using the js notation but the provided example seems to show that it isn't working as expected: graalvm/graaljs#203
    Paulo Lopes
    @pmlopes
    Hi all I've a question regarding graal polyglot proxies. Say that I would like to have a java object to behave like a js array which interface should I use? The ProxyArray doesn't seem to allow adding elements to the array, while the ProxyObject uses string for keys...
    Paul Driver
    @frodwith
    ProxyArray has set(long index, Value value)
    Paulo Lopes
    @pmlopes
    That's correct but in JavaScript how will this be translated to the proxy API: [].push(1)?
    Daniil Mikhaylov
    @mdsina
    ProxyArray will work as JS Array only if experimental option js.experimental-foreign-object-prototype is set. https://github.com/graalvm/graaljs/blob/master/CHANGELOG.md
    Paulo Lopes
    @pmlopes
    @mdsina :+1: for the info.
    Quinton Hoole
    @quinton-hoole
    I'm hoping that there's a quick and simple answer to this question. Just let me know if this is the wrong forum. I have a unit test that uses Value.newInstance() from Java to create an instance of a javascript object. It worked fine in earlier versions of GraalVM (at least up to RC 14, as I recall. But now it throws com.oracle.truffle.polyglot.PolyglotUnsupportedException. I'm using Context.allowAll(). Anyone know what changed, and what the new way to do this is? I'll post the code here shortly...
    I've dug through the docs and i don't seem to be doing anything obviously wrong.

    String JS_Code =
    "class Student {"

                    + "constructor() {"
                    + "this.id = 0;"
                    + "this.name = \"\";"
                    + "this.buddies = [];"
                    + "this.birthDate = new Date();"
                    + "}"
                    + "setId(id) {"
                    + "this.id = id;"
                    + "}"
                    + "getId() {"
                    + "return this.id;"
                    + "}"
                    + "setName(name) {"
                    + "this.name = name;"
                    + "}"
                    + "getName() {"
                    + "return this.name;"
                    + "}"
                    + "addBuddy(buddy) {"
                    + "this.buddies.push(buddy);"
                    + "}"
                    + "getBuddies() {"
                    + "return this.buddies;"
                    + "}"
                    + "}";

    ...

        Context polyglotCtx = Context.newBuilder(new String[] {"js"}).allowAllAccess(true).build();

    ...

        Value Student = polyglotCtx.eval("js", JS_Code);
        Value student = Student.newInstance();
    The last line throws com.oracle.truffle.polyglot.PolyglotUnsupportedException.
    This is against:
    $ java -version
    openjdk version "1.8.0_222"
    OpenJDK Runtime Environment (build 1.8.0_222-20190711112007.graal.jdk8u-src-tar-gz-b08)
    OpenJDK 64-Bit GraalVM CE 19.2.0 (build 25.222-b08-jvmci-19.2-b02, mixed mode)
    i.e. the latest version as of today.
    Quinton Hoole
    @quinton-hoole

    I've pared this down to a minimal example, which illustrates a potential Graal bug. Value.canInstantiate() returns true, but Value.newInstance() throws java.lang.UnsupportedOperationException. What I'm not sure about is why an undefined type is reported in the exception. Here's the code:

        try (Context context = Context.create()) {
        String JS_Code = "class Student { constructor() { } }";
        Value Student = context.eval("js", JS_Code);
        assert Student.hasMembers();
        assert Student.canInstantiate();
        Value student = Student.newInstance();
    }

    And here's the exception:

    $ java HelloPolyglot
    Exception in thread "main" java.lang.UnsupportedOperationException: Unsupported operation Value.newInstance(Object...) for 'undefined'(language: JavaScript, type: undefined). You can ensure that the operation is supported using Value.canInstantiate().
    at com.oracle.truffle.polyglot.PolyglotValue.unsupported(PolyglotValue.java:448)
    at com.oracle.truffle.polyglot.PolyglotValue.newInstanceUnsupported(PolyglotValue.java:222)
    at com.oracle.truffle.polyglot.PolyglotValue$InteropCodeCache$NewInstanceNode.doCached(PolyglotValue.java:1830)

    Nathan Ringo
    @remexre
    not sure if this is the right room to ask, but is there a way to read a pointer from sulong/llvm from the JS side?
    Christian Humer
    @chumer
    @quinton-hoole You have a small problem in your code. The Student class literal does return undefined and not the Student class itself. This is something specified by the ECMA script specification.
    Here is a suggestion for a fix:
        public static void main(String[] args) {
            try (Context context = Context.create()) {
                String JS_Code = "class Student { constructor() { } }";
                context.eval("js", JS_Code);
                Value Student = context.eval("js", "Student");
                assert Student.hasMembers();
                assert Student.canInstantiate();
                Value student = Student.newInstance();
            }
        }
    Roland Schatz
    @rschatz
    @remexre only if the type of the pointer is known... see https://www.graalvm.org/docs/reference-manual/languages/llvm/#interoperability for examples
    Nathan Ringo
    @remexre
    That only works for non-primitive types though, correct?
    Roland Schatz
    @rschatz
    yes, but if it's a pointer to a primitive, you can just treat it as an array of length 1 (e.g. polyglot_from_i32_array(..., 1))
    Nathan Ringo
    @remexre
    I'd need to make a wrapper function that calls polyglot_from_i32_array to expose it to js though, right?
    Roland Schatz
    @rschatz
    yes
    alternatively, you can write a C function to do the reading, and expose that to JS
    Nathan Ringo
    @remexre
    Hm, ok
    Roland Schatz
    @rschatz
    you have to communicate the type somehow
    Nathan Ringo
    @remexre
    I mean ideally the helpers would be exposed for me on the Polyglot object :p
    Or the pointer values would store the LLVM type internally
    Roland Schatz
    @rschatz
    the problem is the array length, we don't see that in the type, and we don't want to expose potentially dangerous operations to JS by default
    Nathan Ringo
    @remexre
    I mean, free is exposed by default :p
    And a double free doesn't get bubbled up to a Java exception, it just aborts
    Roland Schatz
    @rschatz
    ah, you mean the polyglot_from_i32_array function? right, we currently don't expose builtins from sulong... we should probably, the question is where? they are not actually defined in any bitcode file
    Nathan Ringo
    @remexre
    Polyglot.sulong.from_i32_array, then?
    Not sure where Java-side, but probably as statics on some class one has to import
    Roland Schatz
    @rschatz
    i was thinking more along the lines of Polyglot.eval("llvm", "polyglot_from_i32_array")
    Nathan Ringo
    @remexre
    /shrug either way
    Roland Schatz
    @rschatz
    because Polyglot.something is a JS construct... the Polyglot.eval variant has the advantage that it works with all languages, without anything to do on the language side
    Nathan Ringo
    @remexre
    Yeah, good point
    (bbl, gotta sleep)
    Quinton Hoole
    @quinton-hoole
    Thanks @chumer ! You're a star!
    Nathan Ringo
    @remexre
    @rschatz how much work do you think that'd be to add "properly"? For now probably just gonna create my_polyglotfrom...() wrappers around the polglotfrom...() functions as a temporary hack, but I'd be interested in contributing a small patch :)