<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hi Dmitry!<br>
      <br>
      Thanks for your interest in GraalVM. Answers are inline below.<br>
      <br>
      <br>
    </div>
    <style>body{font-family:Helvetica,Arial;font-size:16px}</style>
    <div id="bloop_customfont"
      style="font-family:Helvetica,Arial;font-size:16px; color:
      rgba(0,0,0,1.0); margin: 0px; line-height: auto;">On 3 May 2018 at
      15:40:08, Dmitry Timofeev (<a
        href="mailto:dmytro.tymofeev@bitfury.com" moz-do-not-send="true">dmytro.tymofeev@bitfury.com</a>)
      wrote:</div>
    <blockquote type="cite" class="clean_bq"><span>
        <div text="#000000" bgcolor="#FFFFFF">
          <div>
            <title></title>
            <p>Hi,</p>
            <p>Iā€™m working on making a framework in a native language
              (Rust)
              extensible in other languages (Java, Python). We currently
              use JNI,
              which is low-level and error-prone. I consider if GraalVM
              would
              make some things easier or make the integration more
              efficient.
              Would anyone please help with these questions?</p>
            <p>1. Is it a good use-case for GraalVM? It seems so from
              the docs,
              as GraalVM aims to eliminate the costs associated with
              calling code
              running on a VM from the native code and vice-versa.<br>
            </p>
          </div>
        </div>
      </span></blockquote>
    Yes, this is a perfect use-case for GraalVM.<br>
    <br>
    Since Rust compiles to LLVM bitcode, you should be able to run your
    Rust code using the LLVM support in GraalVM. But be aware that Rust
    support is still experimental. We do most of our testing with C/C++,
    only very basic testing is done for Rust, so you'll likely run into
    a few bugs, but we're happy to help if you run into problems.<br>
    <br>
    <blockquote type="cite"
      cite="mid:etPan.5af2b61a.1ba62c08.6d5@oracle.com"><span>
        <div text="#000000" bgcolor="#FFFFFF">
          <div>
            <p>
              2. The reference documentation says C --&gt; Java is not
              supported
              yet, but coming soon.</p>
          </div>
        </div>
      </span><br>
      <span></span></blockquote>
    Support for C-&gt;Java interop (actually LLVM-&gt;Java interop) just
    landed in master (see
<a class="moz-txt-link-freetext" href="https://github.com/graalvm/sulong/commit/a8ec4a7e8cb4488c7f8b774bbc7b1342efd92c71">https://github.com/graalvm/sulong/commit/a8ec4a7e8cb4488c7f8b774bbc7b1342efd92c71</a>
    ), and will be included in RC2.<br>
    <br>
    <blockquote type="cite"
      cite="mid:etPan.5af2b61a.1ba62c08.6d5@oracle.com"><span>
        <div text="#000000" bgcolor="#FFFFFF">
          <div>
            <p> Does it mean that developers will be able to
              use Java from C with <i>no</i> JNI (= pass arbitrary
              structs, call
              any Java method from any native thread)? Is it going to be
              a viable
              full-featured replacement for any JNI use-case?</p>
          </div>
        </div>
      </span><br>
      <span></span></blockquote>
    Note that our LLVM-&gt;Java interface is different from usual native
    interfaces, since running LLVM code in GraalVM is not actually
    running native code, it is running the LLVM code inside the managed
    VM (but still accessing native memory). Because of that, it's not
    directly comparable to JNI. With JNI, you're basically "leaving" the
    VM when you call a native method. With LLVM on GraalVM, you're
    running your C/C++/Rust code inside the VM.<br>
    <br>
    The LLVM-&gt;Java interface is very similar to all other LLVM-&gt;*
    interop interfaces we have in GraalVM (see
<a class="moz-txt-link-freetext" href="http://www.graalvm.org/docs/reference-manual/languages/llvm/#interoperability">http://www.graalvm.org/docs/reference-manual/languages/llvm/#interoperability</a>
    and <a class="moz-txt-link-freetext" href="http://www.graalvm.org/docs/reference-manual/polyglot/">http://www.graalvm.org/docs/reference-manual/polyglot/</a>).<br>
    You can just load Java classes and use them using the regular
    polyglot builtin functions. You can pass native structs and access
    them from Java directly, and you can "cast" Java objects to native
    structs and access them as if they were real native memory. All of
    this works without any data copying. This is one of the main
    advantages of our polyglot execution model. And all of that works
    not just with Java objects, but also with all other languages that
    run on GraalVM (e.g. Javascript). As such, this is much more
    flexible than JNI.<br>
    <br>
    <blockquote type="cite"
      cite="mid:etPan.5af2b61a.1ba62c08.6d5@oracle.com"><span>
        <div text="#000000" bgcolor="#FFFFFF">
          <div>
            <p>
              3. If I do such integration of a native language with Java
              the old
              way ā€” using JNI, native methods and libraries ā€” but run on
              GraalVM,
              will this application enjoy any inter-language
              optimizations?</p>
          </div>
        </div>
      </span><br>
      <span></span></blockquote>
    No, the compiler can not optimize across JNI calls. You will of
    course still get all optimizations between the individual GraalVM
    languages when they call each other and exchange data, but every
    transition from/to native code will be an optimization boundary for
    the compiler.<br>
    <br>
    <br>
    I hope this answers your questions. Your project sounds very
    interesting, I encourage you to play around with that, and report
    any problems you encounter.<br>
    <br>
    - Roland<br>
    <br>
    <blockquote type="cite" class="clean_bq"><span>
        <div text="#000000" bgcolor="#FFFFFF">
          <div>
            <p>Thanks!<br>
            </p>
            <pre class="moz-signature" cols="72">--
Dmitry  
</pre>
            <br>
            -- THIS COMMUNICATION AND ANY ATTACHMENTS MAY CONTAIN
            CONFIDENTIAL
            INFORMATION OF THE SENDER. ALL UNAUTHORIZED USE, DISCLOSURE
            OR
            DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED
            RECIPIENT,
            PLEASE NOTIFY THE SENDER IMMEDIATELY AND DESTROY ALL COPIES
            OF THIS
            COMMUNICATION. THANK YOU.<br>
            _______________________________________________
            <br>
            GraalVM-Users mailing list
            <br>
            <a class="moz-txt-link-abbreviated" href="mailto:GraalVM-Users@oss.oracle.com">GraalVM-Users@oss.oracle.com</a>
            <br>
            <a class="moz-txt-link-freetext" href="https://oss.oracle.com/mailman/listinfo/graalvm-users">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></div>
        </div>
      </span></blockquote>
    <p><br>
    </p>
  </body>
</html>