Skip to content

Commit

Permalink
Add a VMLangAccess method to create threads
Browse files Browse the repository at this point in the history
Added a package access method java.lang.Thread:Thread(Runnable runnable,
String threadName, boolean isSystemThreadGroup, boolean
inheritThreadLocals, boolean isDaemon, ClassLoader contextClassLoader)
which allows callers outside of java.lang package to create threads with
such options via VMLangAccess interface.
Specifically this supports java.io.ClassCache to create a thread that
belongs to the system thread group, and not inherit ThreadLocals.

Signed-off-by: Jason Feng <[email protected]>
  • Loading branch information
JasonFengJ9 committed May 15, 2019
1 parent abf2e13 commit 296a1ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
16 changes: 15 additions & 1 deletion jcl/src/java.base/share/classes/com/ibm/oti/vm/VMLangAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


/*******************************************************************************
* Copyright (c) 2012, 2018 IBM Corp. and others
* Copyright (c) 2012, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -155,4 +155,18 @@ public interface VMLangAccess {
public void addPackageToList(Class<?> newClass, ClassLoader loader);
/*[ENDIF] Sidecar19-SE */

/**
* Create a thread that it has runnable as its run object, has threadName as its name, has contextClassLoader as its context ClassLoader,
* has an option to be part of system thread group, has an option to inherit ThreadLocals or not, and has an option to set isDaemon.
*
* @param runnable A java.lang.Runnable whose method <code>run</code> will be executed by the new Thread
* @param threadName Name for the Thread being created
* @param isSystemThreadGroup A boolean indicating whether the thread to be created belongs to the system thread group
* @param inheritThreadLocals A boolean indicating whether to inherit initial values for inheritable thread-local variables
* @param isDaemon Indicates whether or not the Thread being created is a daemon thread
* @param contextClassLoader The context ClassLoader
*
* @return A java.lang.Thread created
*/
public Thread createThread(Runnable runnable, String threadName, boolean isSystemThreadGroup, boolean inheritThreadLocals, boolean isDaemon, ClassLoader contextClassLoader);
}
6 changes: 6 additions & 0 deletions jcl/src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ public Thread(ThreadGroup group, Runnable runnable, String threadName) {
this(group, runnable, threadName, null, true);
}

Thread(Runnable runnable, String threadName, boolean isSystemThreadGroup, boolean inheritThreadLocals, boolean isDaemon, ClassLoader contextClassLoader) {
this(isSystemThreadGroup ? systemThreadGroup : null, runnable, threadName, null, inheritThreadLocals);
this.isDaemon = isDaemon;
this.contextClassLoader = contextClassLoader;
}

private Thread(ThreadGroup group, Runnable runnable, String threadName, AccessControlContext acc, boolean inheritThreadLocals) {
super();
/*[PR 1FEVFSU] Re-arrange method so that common code to this constructor and the private one the VM calls can be put in a separate method */
Expand Down
6 changes: 5 additions & 1 deletion jcl/src/java.base/share/classes/java/lang/VMAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package java.lang;

/*******************************************************************************
* Copyright (c) 2012, 2018 IBM Corp. and others
* Copyright (c) 2012, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -216,4 +216,8 @@ public void addPackageToList(java.lang.Class<?> newClass, ClassLoader loader) {
}
/*[ENDIF] Sidecar19-SE */

@Override
public Thread createThread(Runnable runnable, String threadName, boolean isSystemThreadGroup, boolean inheritThreadLocals, boolean isDaemon, ClassLoader contextClassLoader) {
return new Thread(runnable, threadName, isSystemThreadGroup, inheritThreadLocals, isDaemon, contextClassLoader);
}
}

0 comments on commit 296a1ca

Please sign in to comment.