Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find the native implementations of these functions?

Tags:

java

openjdk

I found these in open JDK (System.c file)

static JNINativeMethod methods[] = {
    {"currentTimeMillis", "()J",              (void *)&JVM_CurrentTimeMillis},
    {"nanoTime",          "()J",              (void *)&JVM_NanoTime},
    {"arraycopy",     "(" OBJ "I" OBJ "II)V", (void *)&JVM_ArrayCopy},
};

#undef OBJ

JNIEXPORT void JNICALL
Java_java_lang_System_registerNatives(JNIEnv *env, jclass cls)
{
    (*env)->RegisterNatives(env, cls,
                            methods, sizeof(methods)/sizeof(methods[0]));
}

but I was not able to find the native implemetations of these functions currentTimeMillis nanoTime arraycopy

Form where can I get the native implementations of these functions ? Is that available in open JDK?

like image 781
Tom Avatar asked Aug 23 '11 16:08

Tom


People also ask

What is native implementation?

Native methods are implemented mostly in C and compiled to native code which runs directly on the machine. This is in contrast to normal methods, which are implemented in Java and compiled to Java byte code, which is executed by the Java Virtual Machine (JVM).

What are native functions 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 method library?

Native Method Libraries are libraries that are written in other programming languages, such as C, C++, and assembly. These libraries can be loaded through JNI. So, the picture you posted is saying that JNI allows access to Native Method Libraries.


1 Answers

if found it in

jdk7/hotspot/src/share/vm/prims/jvm.cpp:229

JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored))
 JVMWrapper("JVM_CurrentTimeMillis");
 return os::javaTimeMillis();
JVM_END

the real implementation (for linux) is in

/jdk7/hotspot/src/os/linux/vm/os_linux.cpp

the other methods are just below it

like image 104
user271275 Avatar answered Oct 23 '22 04:10

user271275