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?
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.
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.
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".
You can check out the OpenJDK code here: http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/tip/src/share/vm/prims/unsafe.cpp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With