From 296a1cadde181cb59c773063e265c28a290929e5 Mon Sep 17 00:00:00 2001 From: Jason Feng Date: Wed, 15 May 2019 15:37:25 -0400 Subject: [PATCH] Add a VMLangAccess method to create threads 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 --- .../classes/com/ibm/oti/vm/VMLangAccess.java | 16 +++++++++++++++- .../share/classes/java/lang/Thread.java | 6 ++++++ .../share/classes/java/lang/VMAccess.java | 6 +++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/jcl/src/java.base/share/classes/com/ibm/oti/vm/VMLangAccess.java b/jcl/src/java.base/share/classes/com/ibm/oti/vm/VMLangAccess.java index 897dcbac254..971718262ad 100644 --- a/jcl/src/java.base/share/classes/com/ibm/oti/vm/VMLangAccess.java +++ b/jcl/src/java.base/share/classes/com/ibm/oti/vm/VMLangAccess.java @@ -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 @@ -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 run 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); } diff --git a/jcl/src/java.base/share/classes/java/lang/Thread.java b/jcl/src/java.base/share/classes/java/lang/Thread.java index b94cc20791b..b38ad6e2256 100644 --- a/jcl/src/java.base/share/classes/java/lang/Thread.java +++ b/jcl/src/java.base/share/classes/java/lang/Thread.java @@ -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 */ diff --git a/jcl/src/java.base/share/classes/java/lang/VMAccess.java b/jcl/src/java.base/share/classes/java/lang/VMAccess.java index 6e5109b219f..c72fd9915b3 100644 --- a/jcl/src/java.base/share/classes/java/lang/VMAccess.java +++ b/jcl/src/java.base/share/classes/java/lang/VMAccess.java @@ -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 @@ -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); + } }