Within the definition of thread state kvm


enum {
THREAD_JUST_BORN =. 1, / * Not start * /
THREAD_ACTIVE = 2, / * currently running, or in a queue waiting to run in * /
THREAD_SUSPENDED =. 4, / * wait for monitor or Alarm * /
THREAD_DEAD =. 8, / * thread exit * /
THREAD_MONITOR_WAIT = 16, // wait for a lock
THREAD_CONVAR_WAIT = 32, // waiting for wakeup
THREAD_DBG_SUSPENDED = 64 // debug using
} state; // thread state defined
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
herein introduces THREAD_JUST_BORN THREAD_JUST_BORN. BuildThread is set in the process:

newThread-> State = THREAD_JUST_BORN;
. 1
and on the process start kvm -006 process in detail.

The call site BuildThread are two:

In InitializeThreading method call, this process starts at -006 kvm have introduced.

In getVMthread call, which code is as follows:

THREAD getVMthread(JAVATHREAD_HANDLE javaThreadH)
{
/* Create the VM-level thread structure if necessary */
THREAD VMthread = unhand(javaThreadH)->VMthread;
if (!VMthread) {
VMthread = BuildThread(javaThreadH);
}
return VMthread;
}
1
2
3
4
5
6
7
8
9
而关于 getVMthread方法的调用点有三处:

Java_java_lang_Thread_start (ie Thread.start () method)
Java_java_lang_Thread_setPriority0 (ie Thread.setPriority () method)
Java_java_lang_Thread_interrupt0 (ie Thread.interrupt () method)
, then, which is the first call getVMthread approach it?

The answer is Java_java_lang_Thread_setPriority0, because the method is called in the thread method as follows:

public Thread() {
init(null, "Thread-" + nextThreadNum());
}

private void init(Runnable target, String name) {
Thread parent = currentThread();
this.target = target;
this.name = name.toCharArray();
this.priority = parent.getPriority();
setPriority0(priority);
}

Native void setPriority0 Private (int newPriority);
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
thus the final call Java_java_lang_Thread_setPriority0 method in the method, the code is as follows:

void Java_java_lang_Thread_setPriority0(void)
{
int priority = popStack();
THREAD VMthread;


START_TEMPORARY_ROOTS
DECLARE_TEMPORARY_ROOT (JAVATHREAD, javaThread,
popStackAsType (JAVATHREAD)); // get the current thread object
// set the priority
javaThread-> = priority (priority> MAX_PRIORITY MAX_PRIORITY:?
;: (Priority <MIN_PRIORITY MIN_PRIORITY priority)?)
VMthread = getVMthread (& javaThread); // get vm thread
VMthread-> timeslice = javaThread-> priority * TIMESLICEFACTOR; // allocate time slices
END_TEMPORARY_ROOTS
}
---------------

Guess you like

Origin www.cnblogs.com/liyanyan665/p/11414337.html