4

I came across the sum.misc.Unsafe class when reading the implementation of ForkJoinPool. But no source code or api docs were found in the JDK.

Where can I find the source code or api docs for the sun.misc.*

Evans Y.
  • 4,209
  • 6
  • 35
  • 43

2 Answers2

8

For Java source code, I usually go to GrepCode

MByD
  • 135,866
  • 28
  • 264
  • 277
2

While such code is available (see Binyamin's post) it is generally a very bad idea to write anything that needs such code.

First, you are not generally assured that any JVM has such a class available (only JVMs descending from SUN's codebase would contain non-published, non-standard, SUN specific libraries). Also, since these are not standard libraries, you can't really depend on them being present or unchanged in subsequent releases of the SUN JVM.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • +1 While I make use of these libraries in some of my libraries I a) make sure to also implement a version which doesn't require Unsafe b) can then check whether it really make a difference. c) use it as little as possible. It worth noting there is an intention to remove/change it significantly in future versions. e.g. Java 8+. Whether this actually happens is another question. ;) – Peter Lawrey May 04 '12 at 06:50
  • 2
    While it is "best practice" not to use such libraries, it has not stopped the more determined from actually making good use of them - and usually for profit. So attempting to deter the determined will only exacerbate their curiosity, so +1 for saying you shouldn't go there ;-) If you're touching deep internals of any system, you always carry the risk that these implementations go away. However, Unsafe is so intrinsic to many APIs and many JVMs, I very much doubt it will go away easily. – KRK Owner Apr 16 '14 at 21:59