JEP 419: Foreign Function and Memory API
openjdk.java.net
openjdk.java.net
The new upcoming (or even already in preview) language and platform features also support each other very well. I think they are heading in a clear direction with the different projects.
Span, safe stackalloc, readonly structs, bittlable structs, native delegates,....
Microsoft "fixed" things by saying "All your 2.0 net code is broken in 3.0".
no code was ever broken with .net 2.0, .net 3.0, .net 3.5, etc. .net was just mostly binary compatible, most often source compatible, but basic syntax never broke, the api/runtime often broke, but that is a different matter.
i.e. why .net core broke a lot of stuff was not syntax it was most often that libraries changed/were missing.
java's runtime was mostly source/binary compatible compared to .net, but thats why a ton of stuff was never used, like http client/serve lul..
A programming language is composed by grammar, semantics and standard library, it doesn't matter at what level it breaks, if the code or binaries cannot be brought forward without changes.
Since Oracle decided to actually remove parts of Java, they certainly heard from people using that ton of stuff that no one uses.
The model for Java was Smalltalk, but in Smalltalk everything was an object => difficult to optimize. Primitive types were introduced in Java to optimize computation with those basic datatypes.
The state of things was fine, until Generics were introduced. Generics preserved backwards compatibility, but widened the division between object and primitive types.
This division was fine, until it started to matter that Java can't be used for high-performance applications. For enterprise application, this gap has never really mattered.
(Ya, ya, ya Java wasn't the first. But somehow Java 1.0 got mindshare. And this time Java's got a massive installed base and ecosystem, greatly increasing the likelihood for Project Loom's adoption.)
Where can I read more about the version freeze?
:(
https://developer.android.com/studio/releases/gradle-plugin#...
... which up until a few months ago was the last LTS. So they're fairly up to date by now.
I agree with your sentiment though. Nothing is perfect, but I do appreciate what they've been doing with GraalVM, new JEPs, and advancing the language (other than the var keyword ;)
I'm not sure why you are inferring that. They aren't replacing openjdk vm intrinsics using this immediately, but that's hardly surprising for a brand new feature.
The motivation is simple: applications should become the arbiters that decide which modules get to invoke native code. Libraries don't get to nilly-willy call non-Java code anymore. If, say, a dependency upgrade introduces changes that involve a new native call, it will be very noticeable.
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).
P/Invoke does not parse C headers, but neither does this proposal.
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.
/** @dll.import("USER32", entrypoint="GetSysColor") */
static native int getSysColor(int nIndex);
versus [DllImport("USER32", EntryPoint = "GetSysColor")]
static extern int GetSysColor(int nIndex);Can I use it to call any WinAPI without C glue?
JNA => "I write java code & load libsomething at runtime, asking for FuncName(int, int) which java can then call into native code."
You want JNA for your use case.
This feature is basically JNA, but more efficient and built into the JVM itself.
I am guessing this is for more sophisticated things than just sending data to Microsoft Excel application?
JNI is somewhat harder to use, because you need custom glue on both sides of the border: Some custom classes in Java and some custom code on the C (and C++) side.
This proposal would remove the need for the glue on the C side and would allow a pure java solution.
Something like this has existed in third-party form for a while as JNA (https://github.com/java-native-access/jna), but now it's going to be built into the JRE itself (if the proposal passes through review)
Having worked with JNI in the past, I find the FF concept convenient but still somewhat verbose. In any case, my experience is 3 years old. A lot may have changed since then.
1 - https://dev.to/petarov/java-and-native-code-in-openjdk-13-18...