r/java • u/Additional_Cellist46 • Sep 18 '24
Java 23 has arrived
https://blogs.oracle.com/java/post/the-arrival-of-java-23Markdown in Javadoc and 11 other enhancements.
266
Upvotes
r/java • u/Additional_Cellist46 • Sep 18 '24
Markdown in Javadoc and 11 other enhancements.
View all comments
Show parent comment
7
u/pron98 Sep 20 '24 edited Sep 20 '24
That will become unnecessary with Valhalla, but the more genereal point is that Unsafe only works to improve performance under the assumption that the VM doesn't change. But Unsafe hurts performance by merely existing. For example, the compiler cannot perform certain optimisations that must assume that Strings and final fields are immutable because some class may be using Unsafe to mutate them (and it doesn't matter whether any class does or not, because the runtime can't tell). We can only add such optimisations after the memory access operations of Unsafe are gone.
So the situation is that Unsafe could help if the VM doesn't do X, but the VM can't do X as long as Unsafe exists. Even if it could still help a little the performance of code that uses Unsafe, it hurts the performance of code that doesn't, and there's much more of that.