13

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.

  • 1
    Note: many of these methods are intrinsics and thus the native methods are not actually called, instead the JVM knows to inline machine code instructions which do the same thing. – Peter Lawrey Jul 17 '15 at 17:08

1 Answers1

14

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").

wero
  • 32,544
  • 3
  • 59
  • 84
  • 1
    I think that's just the JNI implementations, which might be used by the interpreter. Most `Unsafe` methods have [intrinsics](http://stackoverflow.com/a/29721720/1362755) used by the C1/C2 compilers. – the8472 Jul 16 '15 at 08:38