TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

92 pointsby pdeva1almost 10 years ago

22 comments

geofftalmost 10 years ago
The quote stops short, and for someone like me who doesn&#x27;t follow Java very much, it feels like it&#x27;s misquoting via omission:<p>&quot;Let me be blunt -- sun.misc.Unsafe must die in a fire. It is -- wait for it -- Unsafe. It must go. Ignore any kind of theoretical rope and start the path to righteousness _<i>&#x2F;now&#x2F;</i>_. It is still years until the end of public updates to JDK 8, so we have &#x2F;<i>years </i>&#x2F;to work this out properly. But sticking our heads in the collective sands and hoping for trivial work arounds to Unsafe is not going to work. If you&#x27;re using Unsafe, this is the year to explain where the API is broken and get it straight....<p>&quot;Please help us kill Unsafe, kill Unsafe dead, kill Unsafe right, and do so as quickly as possible to the ultimate benefit of everyone.&quot;<p>The quoted engineer understands that people use it, claims that there&#x27;s no immediate risk (since Java 8 will stay around), and very very strongly implies that there is <i>a plan</i> to move from Unsafe to something better than Unsafe providing equivalent functionality in a stable way, and asks for help with that. Is this correct?
评论 #9882475 未加载
评论 #9879788 未加载
评论 #9879506 未加载
评论 #9878804 未加载
srequealmost 10 years ago
There&#x27;s a lot of backlash here against the author with comments like:<p>&quot;You used a sun.* package? You deserve to die in a fire as well!&quot;<p>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).<p>So far, Oracle has stated their intent to remove Unsafe from Java 9. To all the users of Unsafe, Oracle is basically saying, &quot;tell us your use cases for Unsafe, and if we decide they are valid we may try to create an alternative for you. If you&#x27;re lucky, we may even ship that alternative in Java 9 or 10! Have a nice day!&quot;<p>Many people, myself included, find this unacceptable. For instance, it looks like several groups are currently collaborating on a document discussing uses cases for Unsafe and whether alternative features satisfying those use cases are expected to appear in Java 9:<p><a href="https:&#x2F;&#x2F;docs.google.com&#x2F;document&#x2F;d&#x2F;1GDm_cAxYInmoHMor-AkStzWvwE9pw6tnz_CebJQxuUE&#x2F;edit?pli=1" rel="nofollow">https:&#x2F;&#x2F;docs.google.com&#x2F;document&#x2F;d&#x2F;1GDm_cAxYInmoHMor-AkStzWv...</a><p>As you can see, the majority of the cells in the column &quot;Expected in Java 9&quot; flat out say &quot;no&quot;. There is a good reason people are up in arms about the removal of this API.<p>Personally, if I had to choose between Oracle keeping Unsafe and Oracle implementing Java 8 Lambdas, I would have picked Unsafe in a heartbeat. At the end of the day, Lambdas are mostly syntactic sugar, especially in their current implementation. Unsafe, on the other hand, actually empowers you to do something more.
评论 #9879974 未加载
评论 #9879950 未加载
评论 #9879562 未加载
ante_annumalmost 10 years ago
So the explanation is:<p><pre><code> Let me be blunt -- sun.misc.Unsafe must die in a fire. It is -- wait for it -- Unsafe. It must go. Ignore any kind of theoretical rope and start the path to righteousness </code></pre> And what the author takes away is:<p><pre><code> This engineer hates the Unsafe class for no reason at all. </code></pre> The reason the engineer hates it is that it&#x27;s unsafe. Disagree with it, sure. But it&#x27;s a reason, and it&#x27;s a good reason (imho). I understand that it&#x27;s commonly used by apps I use, but it&#x27;s hard to keep reading after this kind of knee-jerk.
评论 #9878637 未加载
评论 #9878680 未加载
评论 #9878684 未加载
ZitchDogalmost 10 years ago
Entire companies exist around functionality provided in Unsafe. I don&#x27;t see this going well if they remove it without providing access to the functionality it gives.<p>Java has plenty of problems, but backward compatibility over the years has been simply amazing. This would chip away at one of the few legitimate reasons to use Java in 2015.
评论 #9878728 未加载
评论 #9878719 未加载
评论 #9878685 未加载
评论 #9878729 未加载
carsongrossalmost 10 years ago
Once again, The Platonic Engineer gazes hatefully at the gronky, ugly and awkward things that make things work in real life, rub his hands together and says...<p>&quot;Burn it to the ground.&quot;
评论 #9880704 未加载
评论 #9878786 未加载
jartalmost 10 years ago
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&#x27;d be well within their rights to remove the class.<p>Normally when you go to that level of epic hackery, you can&#x27;t expect for official support or backwards compatibility. So the author of this article using scare tactics to keep that feature seems rather disingenuous.
评论 #9879646 未加载
pronalmost 10 years ago
Chill.<p>There is no disaster in the making. Oracle is very much aware of the issue, and is actually already taking the very same steps suggested by the author. It has assembled a public working group that is coming up with a spec for a public &quot;Unsafe&quot; API[1] (that is safer than Unsafe).<p><i>In the meantime</i>, use of Unsafe in Java 9 will be possible with a command-line flag in order to allow the working group more time to create the new API and for Unsafe consumers to migrate, and of course to allow existing libraries to run on Java 9.<p>[1]: <a href="https:&#x2F;&#x2F;docs.google.com&#x2F;document&#x2F;d&#x2F;1GDm_cAxYInmoHMor-AkStzWvwE9pw6tnz_CebJQxuUE&#x2F;edit" rel="nofollow">https:&#x2F;&#x2F;docs.google.com&#x2F;document&#x2F;d&#x2F;1GDm_cAxYInmoHMor-AkStzWv...</a>
评论 #9878699 未加载
kkmickosalmost 10 years ago
Many people seem to be upset with Oracle, but I think they should be upset with the vendors who ship applications&#x2F;libraries that depend on the &quot;sun.*&quot; packages.<p>Oracle (then Sun) have since _1998_ strongly discouraged the use of them: <a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;19980215011039&#x2F;http:&#x2F;&#x2F;java.sun.com&#x2F;products&#x2F;jdk&#x2F;faq&#x2F;faq-sun-packages.html" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;19980215011039&#x2F;http:&#x2F;&#x2F;java.sun.c...</a>
评论 #9879251 未加载
ihumanalmost 10 years ago
What is &quot;Unsafe?&quot; Is it unsafe, as its name implies? If it is unsafe, why to so many programs use it?
评论 #9878732 未加载
评论 #9878746 未加载
评论 #9878770 未加载
sbovalmost 10 years ago
This seems a bit hyperbolic. Especially the comparison of Python 2 to Python 3. Its not like you could run Python 2 and Python 3 under the same interpreter by passing a flag.
hyperpapealmost 10 years ago
Why on Earth is it a big deal that you need to pass a flag to the JVM at startup?<p>I understand that backwards compatibility is valued, but if I went to my CTO and said &quot;we&#x27;re gonna drop Java 9 in production, and we&#x27;re not gonna test beforehand&quot;...the reaction would not be pretty.
exabrialalmost 10 years ago
Document it, make it public. It&#x27;s very much needed!
jkotalmost 10 years ago
Compression in my library is 3x faster with unsafe. I think it is lesser evil then native code integration.
clamprechtalmost 10 years ago
At least he didn&#x27;t name the article &quot;Unsafe considered harmful.&quot;
xg15almost 10 years ago
&gt; <i>Oracle plans to remove sun.misc.Unsafe in Java 9. This is an absolute disaster in the making and has the potential to completely destroy the entire ecosystem around Java.</i><p>You know your language has a problem if the entire ecosystem threatens to fall apart as soon as you actually try to enforce the language&#x27;s conceptual model and try to make use of the guarantees it provides.
评论 #9878814 未加载
bowyakkaalmost 10 years ago
Ok moving past the rhetoric of don&#x27;t use internal classes, there is a value to sun.misc.Unsafe. It has been well known by Oracle for some time that it has to go away right.<p>Realise that those of us that do use it, are fully aware that it is a hack, and that we should be doing cleaner things. However know that those cleaner things _dont exist_; and that you, Dear application developer might not quite realise some of the shadow puppetry in making your favourite library work, please lay off the bile.<p>As others have said, this blog post stops short, the full quote is part of a very long and ongoing process to rid ourselves of Unsafe, replacing its majors usages with new API&#x27;s.<p>This is a process Oracle started last year after the previous sun.reflect.Reflection.getCalleeClass mess. Yes, it no one should have been using an internal class. This method did not go away; it was made only available to the JVM internals, locked out from end users. The upshot of this was that, with no sane alternative, suddenly logging became between 2x and 100x more expensive where class names become involved. The JDK team somewhat back peddled on this change, and we are stuck here in a strange limbo land.<p>Was it right of Oracle to do this? Absolutely, everyone who goes down the internal package route is fully aware that these are open-state secrets, sure we all know them, but we should not be talking about them. Support for these damn things requires version to version checking, hideous reflection hacks and being prepared to read a lot of JVM source code for when bugs occur.<p>In light of all of this, and being the general level of awesome the JDK folks are they started a very direct community outreach to remove safely Unsafe. Last year they publicly asked people on the mailing list, and privately via email to do a survey (<a href="http:&#x2F;&#x2F;mail.openjdk.java.net&#x2F;pipermail&#x2F;core-libs-dev&#x2F;2014-January&#x2F;024650.html" rel="nofollow">http:&#x2F;&#x2F;mail.openjdk.java.net&#x2F;pipermail&#x2F;core-libs-dev&#x2F;2014-Ja...</a>) on usages of Unsafe. I know this because I got an email from Paul Sandoz asking me to comment on Unsafe abusages. Out of previous thinking from the JDK folks, as well as from the aforementioned survey, we have a bunch of JEP&#x27;s for improving things regarding Unsafe.<p>Where things have gone slightly sideways is that we have, currently no unified working group to deal with these changes. What this document is, is a proposal to make a working group, focused on getting the right changes into the JVM. In the same ways as Project Jigsaw is for modularising the JVM (and is indirectly responsible for removing Unsafe), or the MLVM project handled making the VM better support other languages.<p>Unsafe is dead, long live Unsafe! I fully expect that we will achieve the right changes in during Java 9 to allow those of us that need to break the rules, to do it in a supported fashion. I am _looking_ forward to the day when I can do setMemory or getAndSetInt via a supported API, and not one where I have to know the words Unsafe.theUnsafe. The above is a storm in a teacup, its open-source democracy at work.
karavelovalmost 10 years ago
What about shipping sun.misc.Unsafe as 3rd party package? Is there anything in it that can&#x27;t be done as through JNI?
评论 #9878889 未加载
评论 #9878794 未加载
vbezhenaralmost 10 years ago
Why libraries need Unsafe, after all? What problems does it solve for them?
评论 #9879097 未加载
rebootthesystemalmost 10 years ago
This is related and unrelated and maybe even meta to some degree:<p>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&#x27;t want (and might even mess-up their systems): Sun and Adobe.<p>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 I was moving fast and neglected to un-check the check-box on the site. I was able to stop the install process and start over. No harm done.<p>These companies need public shaming to stop using this bullshit method to make a few more bucks. Are they so hard-up that they need to trick users to install crap to make money? I sure hope not.<p>Sun, Adobe, please STOP trying to trick users into installing crap-ware they were not looking for in the first place.
评论 #9879730 未加载
评论 #9879776 未加载
scubaguyalmost 10 years ago
I read this article yesterday and I really dislike how it is worded. The &quot;this engineer&quot; has a name, Donald Smith, this is what he said:<p>&quot;If you&#x27;re using Unsafe, this is the year to explain where the API is broken and get it straight.... Please help us kill Unsafe, kill Unsafe dead, kill Unsafe right, and do so as quickly as possible to the ultimate benefit of everyone.&quot;<p>It reads like a request to have a discussion on Unsafe, to talk about it and find solutions. Unfortunately, I don&#x27;t see anyone pointing out why Unsafe should be kept around on that thread (<a href="http:&#x2F;&#x2F;mail.openjdk.java.net&#x2F;pipermail&#x2F;openjfx-dev&#x2F;2015-April&#x2F;017028.html" rel="nofollow">http:&#x2F;&#x2F;mail.openjdk.java.net&#x2F;pipermail&#x2F;openjfx-dev&#x2F;2015-Apri...</a>).<p>And this quote from Oracle shows an effort to do things right:<p><a href="http:&#x2F;&#x2F;mail.openjdk.java.net&#x2F;pipermail&#x2F;discuss&#x2F;2013-October&#x2F;003162.html" rel="nofollow">http:&#x2F;&#x2F;mail.openjdk.java.net&#x2F;pipermail&#x2F;discuss&#x2F;2013-October&#x2F;...</a> &quot;This is definitely something we plan to propose for SE 9. I expect to see a JEP from the current maintainers of sun.misc.Unsafe...&quot;<p>This (<a href="http:&#x2F;&#x2F;blog.codefx.org&#x2F;java&#x2F;dev&#x2F;how-java-9-and-project-jigsaw-may-break-your-code&#x2F;" rel="nofollow">http:&#x2F;&#x2F;blog.codefx.org&#x2F;java&#x2F;dev&#x2F;how-java-9-and-project-jigsa...</a>) seems like a more balanced article on the situation.<p>&quot;So far we focused on the problematic aspects of Project Jigsaw. But that should not divert from the exciting and – I think – very positive nature of the planned changes. After reading the documents, I am impressed with the scope and potential of this upcoming Java release. While it is likely not as groundbreaking for individual developers as Java 8, it is even more so for everyone involved in building and deploying – especially of large monolithic projects.&quot; near future. (This is far too small to require a whole JSR.)&quot;
razorsesealmost 10 years ago
Literraly meme language
skrowlalmost 10 years ago
Still using Java in 2015 – A disaster in the making
评论 #9879986 未加载
评论 #9880447 未加载