Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find the source code for `native` methods in Java library?

In the sun.misc package, I saw these methods under Unsafe class.

public final native boolean compareAndSwapObject(Object var1, long var2, Object var4, Object var5);

public final native boolean compareAndSwapInt(Object var1, long var2, int var4, int var5);

public final native boolean compareAndSwapLong(Object var1, long var2, long var4, long var6);

It seems that these methods are atomic and are written in C, but I can't find the source code for these method on Github.. Does anyone have any ideas about this? How can I find an open-source implementation for these methods easily?

like image 734
Hanfei Sun Avatar asked May 15 '15 03:05

Hanfei Sun


People also ask

How do I find my native code?

All of the native code for an app is stored in the libs/ directory in the root of the apk. It's compiled ARM or x86 code, or both. You can find it in libs/architecture_type/lib_name.so. You can dissemble the code with objdump or gdb.

What is native method library in Java?

Native methods are Java™ methods that start in a language other than Java. Native methods can access system-specific functions and APIs that are not available directly in Java. The use of native methods limits the portability of an application, because it involves system-specific code.

What is native code in JVM?

The Java Native Interface (JNI) establishes a well-defined and platform-independent interface between the two. Native code can be used together with Java in two distinct ways: as "native methods" in a running JVM and as the code that creates a JVM using the "Invocation API".


1 Answers

You can check out the OpenJDK code here: http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/tip/src/share/vm/prims/unsafe.cpp

like image 52
Buddy Avatar answered Oct 13 '22 22:10

Buddy