Live data from Hacker News

Removal of Unsafe in Java 9 – A disaster in the making

blog.dripstat.com

81–90 of 142 posts

Re: Removal of Unsafe in Java 9 – A disaster in the making

#81

Earlier quoted context omitted.

Why those concurrent intrinsics are not available with "safe" code? They are not compatible with Java Memory Model? They are not implemented at some platforms? What's so unsafe about concurrent primitives? There is API in java.util.concurrent.atomic, for example. I understand that Unsafe is used for direct access to memory, but why this direct access is needed? May be there are other ways to solve those problems.

AFAIK there aren't other ways to get the performance required to be competitive in the financial space. People that are using these libraries don't want to use undocumented, Unsafe code. However, their hands are forced given the races they are competing in. They could switch to C++ but that's not really a great option for firms that have java code bases going back 10+ years. Plus, personally, and for a lot of others,…

Exactly. Though I'd add that its not just the financial space that is doing this for performance. Lots of people that are trying to scale high throughput systems use unsafe for similar reasons:

Akka for instance uses it: https://github.com/akka/akka/blob/0de9f0ff40fc5e43540df58718...

Re: Removal of Unsafe in Java 9 – A disaster in the making

#82

Earlier quoted context omitted.

The issues is 2 fold for people. 1) People use Apache Storm and Cassandra daily. These need Unsafe to function at current performance changing its functionality may change these tools. This can be considered existiential threat to their job. 2) The one big selling point of the JVM is that JVM 1.0 code will run in JVM 8.0 without issue, and often much faster. With this change that isn't necessarily true, and potiental…

About #2: there are many internal changes even between minor releases and if you relying on those internals, your code is NOT portable.

sun.misc.Unsafe effectively became a non-internal API a long time ago. Yeah, it's flagged internal, but it doesn't get broken without a damned good reason (I can't remember the last time it meaningfully broke, even).

Re: Removal of Unsafe in Java 9 – A disaster in the making

#83
post #69

There's a lot of backlash here against the author with comments like: "You used a sun.* package? You deserve to die in a fire as well!" These comments look like they are coming from people who have never used Unsafe. First, Unsafe provides some immensely useful features to the Java ecosystem. Second, there is no alternative to Unsafe on the JVM. That includes JNI (native code integrated within the JVM). So far, Oracl…

That link is a very useful contribution to this discussion (and possibly the first really useful comment in this thread), thanks. Everyone's entitled to their opinion, informed or not, but if you want an informed opinion, the question needs to be what the current uses of Unsafe are, why they're used, and whether there are plans for a migration path.

It sort of seems like the major use case (judging from those numbers) is reading and writing raw byte buffers, possibly mapped from other objects/files, with native performance. Is there a potential sensible design for a bounds-checked raw data API ("unsafe but only within these pages") that maintains the JVM's usual safety guarantees for all other data, and can be implemented in a performant way?

Re: Removal of Unsafe in Java 9 – A disaster in the making

#84
post #44

What about shipping sun.misc.Unsafe as 3rd party package? Is there anything in it that can't be done as through JNI?

It'd be unusably slow. "sun.misc.Unsafe" compiles in the instruction stream. JNI implementation would need to go through a complicated calling mechanism. I think it'd be up to 100x slower.

At least in OpenJDK it is in fact implemented as a JNI package, so it is already going through the JNI calling convention: http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/s...

Re: Removal of Unsafe in Java 9 – A disaster in the making

#85
post #3

Earlier quoted context omitted.

In addition, it's in the sun.misc package, if it's not in java.* or javax.* it is ripe for pruning, you'd think people would have learned by now to stop using internal classes since pretty much every JRE/JDK release known to mankind has changed them or removed them.

The problem with that, is unlike most of the other internal classes, there is zero other way to do the things people are doing with unsafe without it. It's not a matter of expedience, it's a matter of necessity.

Yes, removing Unsafe would make things like PowerMock and Robolectric impossible to (re)implement. So what? Those libraries never should have been possible, and we can live without them.

Languages need to be selective about what features they support, and Java was never intended to support things like mocking static methods, or creating instances without invoking any constructors.

Re: Removal of Unsafe in Java 9 – A disaster in the making

#86
post #34

I just read an article that says in order to even use Unsafe, you have to use reflection to unwind the stack and go searching for a reference to the Unsafe instance, because the Java authors worked so hard to make it private. So it seems to me that they'd be well within their rights to remove the class. Normally when you go to that level of epic hackery, you can't expect for official support or backwards compatibilit…

Could you provide a link to the article? I'm not saying you're wrong (I'm not a Java guy) but that sounds convoluted.

Re: Removal of Unsafe in Java 9 – A disaster in the making

#87

Earlier quoted context omitted.

The problem with that, is unlike most of the other internal classes, there is zero other way to do the things people are doing with unsafe without it. It's not a matter of expedience, it's a matter of necessity.

Yes, removing Unsafe would make things like PowerMock and Robolectric impossible to (re)implement. So what? Those libraries never should have been possible, and we can live without them. Languages need to be selective about what features they support, and Java was never intended to support things like mocking static methods, or creating instances without invoking any constructors.

Without the current unsafe package most performance sensitive applications (whether throughput, latency, or pause sensitive) will have no recourse to meet their current performance levels.

That will leave people to choose between staying on Java 8, worse (and often unacceptable) performance, and migrating to a different language.

At this point, there is a very good chance if your library/application is known for performance and exists on the JVM it uses unsafe and without a migration plan all of us who care about performance will likely have to move off the language.

Re: Removal of Unsafe in Java 9 – A disaster in the making

#88

This is related and unrelated and maybe even meta to some degree: There are a couple of companies that are guilty of using their free software update mechanism to try and trick people into installing crap they don't want (and might even mess-up their systems): Sun and Adobe. I almost happened to me last night as I updated Flash on a test system and some bullshit anti-virus crap-ware was going to be installed because…

You understand of course that Sun has been out of business for a very long time right?

Re: Removal of Unsafe in Java 9 – A disaster in the making

#89

Earlier quoted context omitted.

The problem with that, is unlike most of the other internal classes, there is zero other way to do the things people are doing with unsafe without it. It's not a matter of expedience, it's a matter of necessity.

Yes, removing Unsafe would make things like PowerMock and Robolectric impossible to (re)implement. So what? Those libraries never should have been possible, and we can live without them. Languages need to be selective about what features they support, and Java was never intended to support things like mocking static methods, or creating instances without invoking any constructors.

We can live without Robolectric? How do we write tests for Android code without it?

Re: Removal of Unsafe in Java 9 – A disaster in the making

#90

This is related and unrelated and maybe even meta to some degree: There are a couple of companies that are guilty of using their free software update mechanism to try and trick people into installing crap they don't want (and might even mess-up their systems): Sun and Adobe. I almost happened to me last night as I updated Flash on a test system and some bullshit anti-virus crap-ware was going to be installed because…

java hasnt been bundled with crapware since oracle bought it
Post reply on HN