Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8273101: Eliminate the usage of threadgroup sandboxing in the java.util.logging #5326

wants to merge 4 commits into from
Changes from all commits
File filter

Filter by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

@@ -51,7 +51,6 @@ interface and provides the ability to call package-private methods
for this purpose, namely the loss of compile-time checking. */

public class SharedSecrets {
private static JavaAWTAccess javaAWTAccess;
private static JavaAWTFontAccess javaAWTFontAccess;
private static JavaBeansAccess javaBeansAccess;
private static JavaLangAccess javaLangAccess;
@@ -295,16 +294,6 @@ public static void setJavaUtilZipFileAccess(JavaUtilZipFileAccess access) {
javaUtilZipFileAccess = access;

public static void setJavaAWTAccess(JavaAWTAccess jaa) {
javaAWTAccess = jaa;

public static JavaAWTAccess getJavaAWTAccess() {
// this may return null in which case calling code needs to
// provision for.
return javaAWTAccess;

public static void setJavaAWTFontAccess(JavaAWTFontAccess jafa) {
javaAWTFontAccess = jafa;
@@ -44,8 +44,6 @@
import java.beans.PropertyChangeListener;
import java.lang.ref.SoftReference;

import jdk.internal.access.JavaAWTAccess;
import jdk.internal.access.SharedSecrets;
import sun.util.logging.PlatformLogger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
@@ -821,73 +819,6 @@ public synchronized PropertyChangeListener[] getPropertyChangeListeners(
return changeSupport.getPropertyChangeListeners(propertyName);

// Set up JavaAWTAccess in SharedSecrets
static {
SharedSecrets.setJavaAWTAccess(new JavaAWTAccess() {
private boolean hasRootThreadGroup(final AppContext ecx) {
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
return ecx.threadGroup.getParent() == null;

* Returns the AppContext used for applet logging isolation, or null if
* the default global context can be used.
* If there's no applet, or if the caller is a stand alone application,
* or running in the main app context, returns null.
* Otherwise, returns the AppContext of the calling applet.
* @return null if the global default context can be used,
* an AppContext otherwise.
public Object getAppletContext() {
// There's no AppContext: return null.
// No need to call getAppContext() if numAppContext == 0:
// it means that no AppContext has been created yet, and
// we don't want to trigger the creation of a main app
// context since we don't need it.
if (numAppContexts.get() == 0) return null;

AppContext ecx = null;

// Not sure we really need to re-check numAppContexts here.
// If all applets have gone away then we could have a
// numAppContexts coming back to 0. So we recheck
// it here because we don't want to trigger the
// creation of a main AppContext in that case.
// This is probably not 100% MT-safe but should reduce
// the window of opportunity in which that issue could
// happen.
if (numAppContexts.get() > 0) {
// Defaults to thread group caching.
// This is probably not required as we only really need
// isolation in a deployed applet environment, in which
// case ecx will not be null when we reach here
// However it helps emulate the deployed environment,
// in tests for instance.
ecx = ecx != null ? ecx : getAppContext();

// getAppletContext() may be called when initializing the main
// app context - in which case mainAppContext will still be
// null. To work around this issue we simply use
// AppContext.threadGroup.getParent() == null instead, since
// mainAppContext is the only AppContext which should have
// the root TG as its thread group.
// See: JDK-8023258
final boolean isMainAppContext = ecx == null
|| mainAppContext == ecx
|| mainAppContext == null && hasRootThreadGroup(ecx);

return isMainAppContext ? null : ecx;


public static <T> T getSoftReferenceValue(Object key,
Supplier<T> supplier) {

@@ -39,8 +39,7 @@
import java.util.function.Predicate;
import jdk.internal.access.JavaAWTAccess;
import jdk.internal.access.SharedSecrets;

import sun.util.logging.internal.LoggingProviderImpl;
import static jdk.internal.logger.DefaultLoggerFinder.isSystem;

@@ -454,38 +453,9 @@ private void readPrimordialConfiguration() { // must be called while holding con

// LoggerContext maps from AppContext
private WeakHashMap<Object, LoggerContext> contextsMap = null;

// Returns the LoggerContext for the user code (i.e. application or AppContext).
// Loggers are isolated from each AppContext.
// The user context.
private LoggerContext getUserContext() {
LoggerContext context = null;

SecurityManager sm = System.getSecurityManager();
JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
if (sm != null && javaAwtAccess != null) {
// for each applet, it has its own LoggerContext isolated from others
final Object ecx = javaAwtAccess.getAppletContext();
if (ecx != null) {
synchronized (javaAwtAccess) {
// find the AppContext of the applet code
// will be null if we are in the main app context.
if (contextsMap == null) {
contextsMap = new WeakHashMap<>();
context = contextsMap.get(ecx);
if (context == null) {
// Create a new LoggerContext for the applet.
context = new LoggerContext();
contextsMap.put(ecx, context);
// for standalone app, return userContext
return context != null ? context : userContext;
return userContext;

// The system context.