News for hackers. Stuff that matters.
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?
Re:Project Valhalla: A look inside Java's epic refactor by quantumwoke on Sunday December 03, 2023 @02:20AM (#38505472)
Yes, you can read more about the JVM changes in this blog post: https://openjdk.org/projects/valhalla/design-notes/state-of-...
Re:Project Valhalla: A look inside Java's epic refactor by brundolf on Sunday December 03, 2023 @02:28AM (#38505502)
Nice. So for example, it looks like Kotlin already has a nearly identical feature at the language level, which will be optimizable when Valhalla ships: https://github.com/Kotlin/KEEP/blob/master/notes/value-class...

> 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 pjmlp on Sunday December 03, 2023 @03:37AM (#38505724)
Except it will mean that the semantics will be observable between JVM, ART, and all remaining Kotlin targets.
Re:Project Valhalla: A look inside Java's epic refactor by tarasglek on Sunday December 03, 2023 @02:08AM (#38505432)
as long as they dont have real first class functions, still behind modern languages
Re:Project Valhalla: A look inside Java's epic refactor by kaba0 on Sunday December 03, 2023 @03:06AM (#38505642)
It has had those for a decade now.
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 kaba0 on Sunday December 03, 2023 @11:12AM (#38508103)
To mark it as non-first class, you have to provide something it doesn’t support.
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 brundolf on Sunday December 03, 2023 @02:29AM (#38505503)
Yeah that looked like a typo (the exact opposite of what they meant to say)
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 mrkeen on Sunday December 03, 2023 @10:54AM (#38507962)
> Arguably, equality has no default, meaningful implementation.

> Object identity is a good default

Re:Project Valhalla: A look inside Java's epic refactor by kaba0 on Sunday December 03, 2023 @11:11AM (#38508090)
Is a good fallback, might have been better wording on my part.
Re:Project Valhalla: A look inside Java's epic refactor by The_Colonel on Sunday December 03, 2023 @09:55AM (#38507476)
The default implementation in Object class tests for identity.
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 neonsunset on Sunday December 03, 2023 @07:38AM (#38506638)
Look what they need to mimic even a fraction of C#'s power :)
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 @05:21AM (#38515624)
It takes some degree of ignorance to claim that Java can be used in scenarios which require proper structs and object interior pointers.

JNI is an abomination and a cautionary tale for everyone implementing interop facilities into their language.

Re:Project Valhalla: A look inside Java's epic refactor by pjmlp on Monday December 04, 2023 @05:33AM (#38515708)
My ignorance takes me to places you can only wonder about.

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.

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 pjmlp on Monday December 04, 2023 @06:37AM (#38516050)
At which point better use Swift, a language designed as C, C++ and Objective-C replacement from the ground up.
Re:Project Valhalla: A look inside Java's epic refactor by neonsunset on Monday December 04, 2023 @06:43AM (#38516094)
Not until its performance improves (why yes, I too was surprised to find it being slower than C# in many situations).
Re:Project Valhalla: A look inside Java's epic refactor by pjmlp on Monday December 04, 2023 @06:45AM (#38516103)
As if calling into iOS APIs, some of which written in Swift, via an additional layer would be faster.

By the way, MAUI folks had to rewrite plenty of stuff in Java/Kotlin and Swift, to improve MAUI performance.

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 pjmlp on Monday December 04, 2023 @08:44AM (#38517093)
You missed the "and Swift".
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...

[1] https://openjdk.org/projects/panama/

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:

    [UnmanagedCallersOnly(EntryPoint = "receive_c_string")]
    public unsafe static void ReceiveCString(byte* ptr) { /* impl.. */ }
(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

Re:Project Valhalla: A look inside Java's epic refactor by Dudester230602 on Sunday December 03, 2023 @10:35AM (#38507787)
Why not abandon the entire thing?
Re:Project Valhalla: A look inside Java's epic refactor by Koshkin on Sunday December 03, 2023 @11:01AM (#38508022)
On the contrary - looking at the Java ecosystem I sometimes think, one must be insane not to use Java.
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.
Re:Project Valhalla: A look inside Java's epic refactor by pjmlp on Monday December 04, 2023 @04:40AM (#38515379)
The only real alternative is .NET, hence why I use both platforms, :)
Re:Project Valhalla: A look inside Java's epic refactor by sillywalk on Sunday December 03, 2023 @03:06PM (#38510268)
For second I thought this was OpenBSD's OpenSSL Valhalla Rampage

https://opensslrampage.org/