Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading of the native code library for start0() native method in Thread class [duplicate]

Tags:

java

I am looking for some in-depth explanation How Thread.start() internally invokes run() method. I know that its my JVM which internally calls run() via start() method and when I started checking the source code of Thread class, I found these below code:

    public synchronized void start()
    {
        if(threadStatus != 0)
            throw new IllegalThreadStateException();
        group.add(this);
        start0();
        if(stopBeforeStart)
            stop0(throwableFromStop);
    }

    private native void start0(); 

Now as I can see that the start() is calling the native method start0() but I can not see any code related to the loading of native code library.

Please help me understanding the complete call flow.

Thanks, Sandip

like image 335
Sandy Avatar asked Jun 13 '13 12:06

Sandy


2 Answers

Java is open source.. A small research can bring you the source code of the native code also. See, you can see yourself the flow. See Where to find source code for java.lang native methods?.

According to: Java native method source code use jdk7 source

JDK 7's Thread.c: http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/00cd9dc3c2b5/src/share/native/java/lang/Thread.c

Per my knowledge, looking up that native code to see what happens is not as fun as looking up java code you have seen till.

Because, though they encourage us not to use native code, they use it because jdk is differently released for different platforms. In most of the jdk sources we can see some native method declarations.

like image 107
pinkpanther Avatar answered Oct 31 '22 08:10

pinkpanther


Look at OpenJDK JVM sources: Thread.c and jvm.cpp (JVM_StartThread)

like image 34
gma Avatar answered Oct 31 '22 10:10

gma