8200123: Replace Thread.init with telescoping constructor

Reviewed-by: dholmes, mchung, plevart
This commit is contained in:
Martin Buchholz 2018-03-29 16:23:35 -07:00
parent 200fb2b35b
commit 1cd649af57
2 changed files with 25 additions and 34 deletions
src/java.base/share/classes/java
lang
util/concurrent/locks

@ -188,7 +188,7 @@ class Thread implements Runnable {
* not specify a stack size. It is up to the VM to do whatever it
* likes with this number; some VMs will ignore it.
*/
private long stackSize;
private final long stackSize;
/*
* JVM-private state that persists after native thread termination.
@ -198,20 +198,20 @@ class Thread implements Runnable {
/*
* Thread ID
*/
private long tid;
private final long tid;
/* For generating thread ID */
private static long threadSeqNumber;
private static synchronized long nextThreadID() {
return ++threadSeqNumber;
}
/*
* Java thread status for tools, default indicates thread 'not yet started'
*/
private volatile int threadStatus;
private static synchronized long nextThreadID() {
return ++threadSeqNumber;
}
/**
* The argument supplied to the current call to
* java.util.concurrent.locks.LockSupport.park.
@ -376,15 +376,6 @@ class Thread implements Runnable {
@HotSpotIntrinsicCandidate
public static void onSpinWait() {}
/**
* Initializes a Thread with the current AccessControlContext.
* @see #init(ThreadGroup,Runnable,String,long,AccessControlContext,boolean)
*/
private void init(ThreadGroup g, Runnable target, String name,
long stackSize) {
init(g, target, name, stackSize, null, true);
}
/**
* Initializes a Thread.
*
@ -398,9 +389,9 @@ class Thread implements Runnable {
* @param inheritThreadLocals if {@code true}, inherit initial values for
* inheritable thread-locals from the constructing thread
*/
private void init(ThreadGroup g, Runnable target, String name,
long stackSize, AccessControlContext acc,
boolean inheritThreadLocals) {
private Thread(ThreadGroup g, Runnable target, String name,
long stackSize, AccessControlContext acc,
boolean inheritThreadLocals) {
if (name == null) {
throw new NullPointerException("name cannot be null");
}
@ -418,8 +409,8 @@ class Thread implements Runnable {
g = security.getThreadGroup();
}
/* If the security doesn't have a strong opinion of the matter
use the parent thread group. */
/* If the security manager doesn't have a strong opinion
on the matter, use the parent thread group. */
if (g == null) {
g = parent.getThreadGroup();
}
@ -458,7 +449,7 @@ class Thread implements Runnable {
this.stackSize = stackSize;
/* Set thread ID */
tid = nextThreadID();
this.tid = nextThreadID();
}
/**
@ -481,7 +472,7 @@ class Thread implements Runnable {
* {@code "Thread-"+}<i>n</i>, where <i>n</i> is an integer.
*/
public Thread() {
init(null, null, "Thread-" + nextThreadNum(), 0);
this(null, null, "Thread-" + nextThreadNum(), 0);
}
/**
@ -497,7 +488,7 @@ class Thread implements Runnable {
* nothing.
*/
public Thread(Runnable target) {
init(null, target, "Thread-" + nextThreadNum(), 0);
this(null, target, "Thread-" + nextThreadNum(), 0);
}
/**
@ -506,7 +497,7 @@ class Thread implements Runnable {
* This is not a public constructor.
*/
Thread(Runnable target, AccessControlContext acc) {
init(null, target, "Thread-" + nextThreadNum(), 0, acc, false);
this(null, target, "Thread-" + nextThreadNum(), 0, acc, false);
}
/**
@ -533,7 +524,7 @@ class Thread implements Runnable {
* thread group
*/
public Thread(ThreadGroup group, Runnable target) {
init(group, target, "Thread-" + nextThreadNum(), 0);
this(group, target, "Thread-" + nextThreadNum(), 0);
}
/**
@ -545,7 +536,7 @@ class Thread implements Runnable {
* the name of the new thread
*/
public Thread(String name) {
init(null, null, name, 0);
this(null, null, name, 0);
}
/**
@ -569,7 +560,7 @@ class Thread implements Runnable {
* thread group
*/
public Thread(ThreadGroup group, String name) {
init(group, null, name, 0);
this(group, null, name, 0);
}
/**
@ -585,7 +576,7 @@ class Thread implements Runnable {
* the name of the new thread
*/
public Thread(Runnable target, String name) {
init(null, target, name, 0);
this(null, target, name, 0);
}
/**
@ -633,7 +624,7 @@ class Thread implements Runnable {
* thread group or cannot override the context class loader methods.
*/
public Thread(ThreadGroup group, Runnable target, String name) {
init(group, target, name, 0);
this(group, target, name, 0);
}
/**
@ -712,7 +703,7 @@ class Thread implements Runnable {
*/
public Thread(ThreadGroup group, Runnable target, String name,
long stackSize) {
init(group, target, name, stackSize);
this(group, target, name, stackSize, null, true);
}
/**
@ -768,7 +759,7 @@ class Thread implements Runnable {
*/
public Thread(ThreadGroup group, Runnable target, String name,
long stackSize, boolean inheritThreadLocals) {
init(group, target, name, stackSize, null, inheritThreadLocals);
this(group, target, name, stackSize, null, inheritThreadLocals);
}
/**

@ -412,11 +412,11 @@ public class LockSupport {
/**
* Returns the thread id for the given thread. We must access
* this directly rather than via method Thread.getId() because
* getId() is not final, and has been known to be overridden in
* ways that do not preserve unique mappings.
* getId() has been known to be overridden in ways that do not
* preserve unique mappings.
*/
static final long getThreadId(Thread thread) {
return U.getLongVolatile(thread, TID);
return U.getLong(thread, TID);
}
// Hotspot implementation via intrinsics API