Hacker News new | past | comments | ask | show | jobs | submit login

This is the runtime API, that uses the JITs to generate the trampoline codes necessary to go from the Java calling convention to the C calling convention (upcall and downcall), a kind of like libffi for Java.

If you have a typed langages like Scala, Kotlin, Java, you can use jextract [1] which is a more high level API. jextract uses clang to parse C headers files and generates a jar file with all the C function seen as Java methods with all the glue generated for you (the downside is i believe that this jar is OS specific).

This API is more for dynamic languages like Clojure, Groovy, JRuby, where you want to do dynamic runtime calls and still get performance (as far as i understand, the JIT generates the adapter code once per call and you can reuse it).

[1] https://github.com/openjdk/jextract




You could say this is P/Invoke for Java, which .NET had for more than a decade now. Better late than never I guess.


Has P/Invoke been cross-platform for a decade? Additionally, does it parse C headers to create native type wrappers automatically? Last I checked (a long time ago), P/Invoke required you to annotate manually written prototypes?


Yes, P/Invoke has been working cross-platform for a decade with Mono. Have you heard of this thing called Gtk#?

P/Invoke does not parse C headers, but neither does this proposal.


Ah right, Mono. I keep forgetting that was a thing.

This proposal will pave the way for jextract, though. I would argue this series of JEPs is much closer in spirit to something like Rust's cxx than P/Invoke is.


No it isn't. As _old_dude_ pointed out, this is a runtime API that generates JIT wrappers. Rust's cxx does no runtime code generation, while P/Invoke does.


I was not talking about runtime vs compile time, I was talking about how you interact with it as an end user.


Java had it first actually, because P/Invoke was one of the extensions Microsoft added to J++.


Actually, what Java had was J/Direct. P/Invoke was created specifically for C#.


They are the same thing, replace Java annotations with .NET attributes and call it something else due to the lawsuit.

    /** @dll.import("USER32", entrypoint="GetSysColor") */
    static native int getSysColor(int nIndex);
versus

    [DllImport("USER32", EntryPoint = "GetSysColor")]
    static extern int GetSysColor(int nIndex);




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: