News for hackers. Stuff that matters.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by iscoelho on Tuesday January 16, 2024 @10:52PM (#39023049)
> "which is already low", "such a small benefit"

This is subjective. In my opinion, even 10%~ is massive. Performance matters and this would be a step backwards.

Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by kaba0 on Wednesday January 17, 2024 @01:37AM (#39024056)
Where it matters, you can just write that part in a low-level language and call out to that.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by yjftsjthsd-h on Wednesday January 17, 2024 @01:48AM (#39024123)
Thus bringing us back to the same unsafety with extra steps and glue required; what did we gain from this?

Edit: Unless you FFI to Rust / Ada / formally verified C, in which case perhaps we can claw back the performance and safety at the cost of a lot more dev work.

Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by kaba0 on Wednesday January 17, 2024 @03:50AM (#39025084)
But more “distance” between the two might be better, like, copying some value-like objects and doing the operation on that and copying back the result is much safer, than passing pointers between the two worlds. And this change might push the balance a bit to this side.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by yjftsjthsd-h on Wednesday January 17, 2024 @03:51PM (#39033273)
Copying is safer but bad performance, so I'm not sure how that helps here?
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by eptcyka on Wednesday January 17, 2024 @02:47AM (#39024591)
FFI boundaries are inherently unsafe regardless of language.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by pron on Wednesday January 17, 2024 @05:33AM (#39025953)
You don't need FFI -- you could reach for JDK internals if you conclude you must; all that requires is a flag. What we gain from this is that the vast majority of programs using Unsafe will gain safety with the new supported APIs and will not lose performance.

Also, FFI to Rust will buy you nothing. Safe Rust performs the same bound checks as Java while unsafe Rust would be just as unsafe as using JDK internals. If you want to prove the safety of unsafe code in some other unsafe language, you might as well do the same for unsafe Java code using JDK internals (it would probably even be easier).

Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by pjmlp on Wednesday January 17, 2024 @02:59AM (#39024685)
Or use C#, Go, Rust instead, which is sadly a loss for Java.

We are no longer in the Sun days, with Java being the answer for everything.

Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by bitcharmer on Wednesday January 17, 2024 @02:58AM (#39024681)
This is incorrect. Native calls whether it's via JNI (even with CriticalJNINatives) or Panama still have a transition cost formerly referred to as gc locker. I'm in a field where performance is number one requirement. Removing unsafe is a terrible idea.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by kaba0 on Wednesday January 17, 2024 @03:51AM (#39025098)
Yes they have, but you can always just go a “scope” higher, and instead of doing a loop that calls out to FFI, you call out to a loop itself.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by bitcharmer on Wednesday January 17, 2024 @04:24AM (#39025391)
You mean expedite whole chunks of logic to a different language, then make your build process much more complicated by having to maintain a completely new ecosystem and compiler infrastructure and make testing more cumbersome?

Sorry, but this is just a bad advice.

Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by kaba0 on Wednesday January 17, 2024 @04:52AM (#39025638)
In the very very rare case you might need it, than I guess, yeah.

But if it turns out to be a real problem, it might still be possible that they will add a way to disable checks with the foreign memory API. It would actually allow for a better user experience, you could do “debug” builds with extensive checking for correctness, which could be disabled via some flag.

Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by needusername on Wednesday January 17, 2024 @05:05AM (#39025731)
You forgot that the deployment also got more complicated.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by andreasmetsala on Wednesday January 17, 2024 @03:24AM (#39024886)
> I'm in a field where performance is number one requirement. Removing unsafe is a terrible idea.

Are you sure you should be using Java if your use-case is performance sensitive?

Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by iscoelho on Wednesday January 17, 2024 @03:45AM (#39025047)
Java today is used and works fine for many high performance applications.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by bitcharmer on Wednesday January 17, 2024 @04:26AM (#39025407)
Yes, I have no doubt about it. You might be stuck in 1990s perception of Java like a good portion of HN commenters who haven't had any real experience with it in the last 10-20 years.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by pron on Wednesday January 17, 2024 @05:18AM (#39025827)
Yes, 10% would be massive, but that's nowhere near the case. The vast majority of Unsafe-using programs would see no or negligible performance degradation and without the unsafety of Unsafe. The 0.01% of Java programs that would see a performance degradation of 10% or more will still be able to get it all back, if they feel it's absolutely needed at the expense of safety, by using JDK internals. That's a win for everyone.
Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by iscoelho on Wednesday January 17, 2024 @05:46PM (#39034666)
Citation needed. You make a lot of claims without evidence.

Dropbox's experience https://dropbox.tech/infrastructure/lossless-compression-wit... shows a >10% performance difference caused by bounds checks in a similar context for a real world application. And before you say it: the Java JIT is not capable of optimizing bounds check elimination more than LLVM at this point in time. The JIT is not magical.

Re:JEP Draft: Deprecate memory-access methods in sun.misc.un... by pron on Sunday January 21, 2024 @02:08PM (#39081730)
I think you misunderstand. There are cases where the performance hit would be significant, but there is absolutely no indication or reason to assume they're widespread. The JDK itself has switched away from Unsafe years ago (mostly except for cases it's not possible, but not due to performance, but technical reasons specific to the JDK alone) and performance overall has largely improved. In the special cases where there might be a performance hit, a single flag can take care of that, but we're concerned with improving the safety and performance of the ecosystem as a whole. If there's something that improves the average but harms some individual cases, we hide it -- as in this case -- behind a flag. Everyone who needs to be convinced that on average the benefit outweighs the cost has been convinced. It is those who think otherwise that would need to make a convincing case that on average Java applications will be harmed rather than helped.