Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the source code of native methods available?

At first I want to let you know that this question is not related with What is native implementation in Java. I got many useful information from that thread.

I want to know that are the codes of the native implementations available? I have jdk source code but I can not find the native codes for System.currentTimeMillis or Runtime.getRuntime().availableProcessors() or other native method.

like image 517
Tapas Bose Avatar asked Jun 28 '11 05:06

Tapas Bose


2 Answers

Yes, see os::javaTimeMillis in /src/os/solaris/vm/os_solaris.cpp to see the Solaris implementation for instance.

There are a few layers of wrappers to get there though, see JVM_CurrentTimeMillis in /src/share/vm/prims/jvm.cpp

like image 100
Henrik Gustafsson Avatar answered Nov 08 '22 10:11

Henrik Gustafsson


Because the underlying methods are intrinsic to the OS you are running Java on, you will not find their source code in the JDK documentation. I suppose you'd need to find out exactly which procedures are called on your platform, and if source code is available for those (which strongly depends on your OS).

like image 23
Michael Avatar answered Nov 08 '22 10:11

Michael