Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the native methods of sun.misc.Unsafe implemented?

I've been reading through the sun.misc.Unsafe class (openjdk6) as I was curious how many native methods it actually referred to. Understandably there are a large number of native methods in the class, however I cannot seem to find where they are implemented.

I've grep'd through the openjdk6 repo and, while I can find implementations of other class's native methods, I cannot find Unsafe's. I'm guessing they are not openjdk code but instead are compiled as part of hotspot?

Am I looking in the wrong place within openjdk or are they indeed implemented in hotspot? References to their location would be greatly appreciated.

like image 977
Benjamin George Roberts Avatar asked Jul 16 '15 08:07

Benjamin George Roberts


People also ask

What is Sun Misc unsafe?

Unsafe. The sun.misc.Unsafe class is intended to be only used by core Java classes which is why its authors made its only constructor private and only added an equally private singleton instance.

Why is Java considered unsafe?

Java lacks null safety. When a function receives an object, this object might be null. That is, if you see 'String s' in your code, you often have no way of knowing whether 's' contains an actually String unless you check at runtime.


1 Answers

The Openjdk versions can be found here:

http://hg.openjdk.java.net/jdk6/jdk6/hotspot/file/4fc084dac61e/src/share/vm/prims/unsafe.cpp

http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/4fc084dac61e/src/share/vm/prims/unsafe.cpp

EDIT:

As pointed out by the8472 these are the native implementations used in interpreter mode. Most of them have intrinsic implementations in hotspot. This header file lists the intrinsic ones (search for "sun_misc_Unsafe").

like image 53
wero Avatar answered Oct 01 '22 19:10

wero