Re:Project Valhalla: A look inside Java's epic refactor
by brundolf on Sunday December 03, 2023 @02:06AM
(#38505424)
To what degree do these features translate to JVM changes, vs just Java language changes (I know the two are fairly tightly coupled)? Eg will this mean new bytecode/optimizations that could be used to optimize other JVM languages which already have similar features?
> In the future, in a Valhalla-capable JVM, JVM primitive classes will enable efficient representation of Kotlin value classes with an arbitrary number of underlying fields on JVM.
Re:Project Valhalla: A look inside Java's epic refactor
by fulafel on Sunday December 03, 2023 @11:03AM
(#38508034)
The Java 8 additions are sugar for OO interfaces that help doing things similarly as if you had first class functions. But like before, only primitive types and objects are actually first class things.
Re:Project Valhalla: A look inside Java's epic refactor
by vasvir on Sunday December 03, 2023 @02:22AM
(#38505475)
> Objects, by contrast, are resistant to this kind of optimization because they have an identity distinct from their value. This is what .equals() tests for: the object’s location in memory.
AFAIK equals() test for equality not identity in Java.
Re:Project Valhalla: A look inside Java's epic refactor
by mrkeen on Sunday December 03, 2023 @03:37AM
(#38505729)
> AFAIK equals() test for equality not identity in Java.
In an ideal world, == would test for equality. In a worse world, equals() would test for equality. But we live in a Java world: Equals() is predefined as an identity check on Objects, and it's up invididual implementations to override that check with something better.
Re:Project Valhalla: A look inside Java's epic refactor
by kaba0 on Sunday December 03, 2023 @10:01AM
(#38507514)
Arguably, equality has no default, meaningful implementation. Object identity is a good default, while data-like objects=records should have the trivial equality in place. But a connection is not equal to any other, even if their internal state is equivalent.
Re:Project Valhalla: A look inside Java's epic refactor
by grandinj on Sunday December 03, 2023 @03:37AM
(#38505726)
Hmmm, int[] now being a subtype of Object[] is going to cause some odd bugs in code that does lots of reflection - eg. some of the frameworks that doing Rails style magic in Java.
Re:Project Valhalla: A look inside Java's epic refactor
by bhouston on Sunday December 03, 2023 @07:33AM
(#38506608)
Is this mostly adopted what C# has had single the early 2000s? C# always out performed Java for specifically this reason. It is why Unity standardized on C#.
Re:Project Valhalla: A look inside Java's epic refactor
by pjmlp on Monday December 04, 2023 @04:39AM
(#38515375)
C#'s power can always be worked around with JNI, for those that don't have issues with polyglot codebases.
Also lets not forget that Java (even if in a different flavour), powers 80% of mobile phone market, that power alone wasn't enough to keep Windows Phone going, mostly written in C++ anyway (COM/WinRT).
Or the real time Java implementations used by the military, like PTC.
Re:Project Valhalla: A look inside Java's epic refactor
by neonsunset on Monday December 04, 2023 @06:08AM
(#38515895)
That's a rather damning prospect, that the mobile OS market has.
Luckily, it's not all Android and I will be happily calling Swift directly out of .NET with upcoming interop changes and never have to touch this embarrassment of an API again that is JNI.
Re:Project Valhalla: A look inside Java's epic refactor
by neonsunset on Monday December 04, 2023 @07:29AM
(#38516459)
The reason why parts of the code had to be rewritten in Java was to work around inherent inadequacy of JNI. This is a sad reality all non-JVM languages have to deal with when targeting Android.
Re:Project Valhalla: A look inside Java's epic refactor
by neonsunset on Monday December 04, 2023 @09:23AM
(#38517587)
If you're mentioning it, I would expect you to know that motivation behind writing Swift helpers was entirely different. Not that it matters in the long run because there will be even better way to do it.
If you don't, then the comment is speculative, pointless and driven by bias.
Re:Project Valhalla: A look inside Java's epic refactor
by pjmlp on Monday December 04, 2023 @09:38AM
(#38517802)
Regardless, it was done, turns out C# can't do everything on a foreign platform.
The better way is to write Swift, or eventually Objective-C, when iOS is anyway the only OS being targeted, instead of adding complexity layers, just because one fancies C#.
Re:Project Valhalla: A look inside Java's epic refactor
by Alupis on Monday December 04, 2023 @02:05PM
(#38521572)
If one were to look under the hood of C#/CLR/dotnet and see just how it does native access, it would be as much of an "abomination" as JNI. The only difference is the tooling provided to C# users is higher level than JNI.
However, unlike the dotnet world, the JVM ecosystem provides numerous ways to do native access, if raw JNI isn't your thing. JNA has been around forever, then there's JNR as well, numerous less-used libraries, and finally Project Panama[1]. Pick the one you like... we get choices.
The dotnet people usually only ever get one option, and believe (falsely) that it's the greatest. A lot like Stockholm Syndrome...
Re:Project Valhalla: A look inside Java's epic refactor
by neonsunset on Monday December 04, 2023 @02:47PM
(#38522169)
Declaring and calling a C method in C# is as trivial as
[LibraryImport("my_library", EntryPoint = "pass_numbers")]
partial static void PassNumbers(int a, int b, int c);
For AOT compilation, you can even completely statically link[0] it into the binary and annotate with [SuppressGCTransition] - it will be as cheap as a direct call from C++ (although GC transition is just a helper stub call that is barely noticeable on microbenchmarks - 1-2ns difference at throughput).
In fact, you can also do the reverse and AOT-compile C# projects to regular dll/libs which can be called from C, C++, Rust, etc. land with ease:
(there are other aspects that make this a powerful combo like being able to wrap pointers into new Span<byte>(ptr, length)'s and transparently inter-operating with most of the standard library without ever allocating)
Panama may offer better UX but not the one that can match C# and only marginally improves performance over JNI[1] (which is still slow).
Re:Project Valhalla: A look inside Java's epic refactor
by projectileboy on Sunday December 03, 2023 @09:15PM
(#38512983)
Agree. At this point the JVM ecosystem is pretty mature. Complaining about it is a bit like complaining about Unix. The question isn't whether or not it's good compared to an ideal; the question is whether or not it's good compared to existing alternatives.
> In the future, in a Valhalla-capable JVM, JVM primitive classes will enable efficient representation of Kotlin value classes with an arbitrary number of underlying fields on JVM.
AFAIK equals() test for equality not identity in Java.
In an ideal world, == would test for equality. In a worse world, equals() would test for equality. But we live in a Java world: Equals() is predefined as an identity check on Objects, and it's up invididual implementations to override that check with something better.
> Object identity is a good default
Also lets not forget that Java (even if in a different flavour), powers 80% of mobile phone market, that power alone wasn't enough to keep Windows Phone going, mostly written in C++ anyway (COM/WinRT).
Or the real time Java implementations used by the military, like PTC.
JNI is an abomination and a cautionary tale for everyone implementing interop facilities into their language.
https://www.ptc.com/en/products/developer-tools/perc
https://www.aicas.com/wp/products-services/jamaicavm/
https://www.microej.com/
And to 80% market share in mobile OS market, full of JNI all over the place.
Luckily, it's not all Android and I will be happily calling Swift directly out of .NET with upcoming interop changes and never have to touch this embarrassment of an API again that is JNI.
By the way, MAUI folks had to rewrite plenty of stuff in Java/Kotlin and Swift, to improve MAUI performance.
If you don't, then the comment is speculative, pointless and driven by bias.
The better way is to write Swift, or eventually Objective-C, when iOS is anyway the only OS being targeted, instead of adding complexity layers, just because one fancies C#.
However, unlike the dotnet world, the JVM ecosystem provides numerous ways to do native access, if raw JNI isn't your thing. JNA has been around forever, then there's JNR as well, numerous less-used libraries, and finally Project Panama[1]. Pick the one you like... we get choices.
The dotnet people usually only ever get one option, and believe (falsely) that it's the greatest. A lot like Stockholm Syndrome...
[1] https://openjdk.org/projects/panama/
In fact, you can also do the reverse and AOT-compile C# projects to regular dll/libs which can be called from C, C++, Rust, etc. land with ease:
(there are other aspects that make this a powerful combo like being able to wrap pointers into new Span<byte>(ptr, length)'s and transparently inter-operating with most of the standard library without ever allocating)Panama may offer better UX but not the one that can match C# and only marginally improves performance over JNI[1] (which is still slow).
[0] https://learn.microsoft.com/en-us/dotnet/core/deploying/nati...
[1] https://github.com/Glavo/java-ffi-benchmark
https://opensslrampage.org/