jdk/src/java.desktop/share/classes/sun/awt/AppContext.java
changeset 32874 b563863620ec
parent 32865 f9cb6e427f9e
parent 32834 e1dca5fe4de3
child 33255 110d90e1552f
equal deleted inserted replaced
32873:d445b313f219 32874:b563863620ec
    42 import java.util.HashSet;
    42 import java.util.HashSet;
    43 import java.beans.PropertyChangeSupport;
    43 import java.beans.PropertyChangeSupport;
    44 import java.beans.PropertyChangeListener;
    44 import java.beans.PropertyChangeListener;
    45 import java.lang.ref.SoftReference;
    45 import java.lang.ref.SoftReference;
    46 
    46 
       
    47 import jdk.internal.misc.JavaAWTAccess;
       
    48 import jdk.internal.misc.SharedSecrets;
    47 import sun.misc.ManagedLocalsThread;
    49 import sun.misc.ManagedLocalsThread;
    48 import sun.util.logging.PlatformLogger;
    50 import sun.util.logging.PlatformLogger;
    49 import java.util.concurrent.locks.Condition;
    51 import java.util.concurrent.locks.Condition;
    50 import java.util.concurrent.locks.Lock;
    52 import java.util.concurrent.locks.Lock;
    51 import java.util.concurrent.locks.ReentrantLock;
    53 import java.util.concurrent.locks.ReentrantLock;
   837         return changeSupport.getPropertyChangeListeners(propertyName);
   839         return changeSupport.getPropertyChangeListeners(propertyName);
   838     }
   840     }
   839 
   841 
   840     // Set up JavaAWTAccess in SharedSecrets
   842     // Set up JavaAWTAccess in SharedSecrets
   841     static {
   843     static {
   842         sun.misc.SharedSecrets.setJavaAWTAccess(new sun.misc.JavaAWTAccess() {
   844         SharedSecrets.setJavaAWTAccess(new JavaAWTAccess() {
   843             private boolean hasRootThreadGroup(final AppContext ecx) {
   845             private boolean hasRootThreadGroup(final AppContext ecx) {
   844                 return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
   846                 return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
   845                     @Override
   847                     @Override
   846                     public Boolean run() {
   848                     public Boolean run() {
   847                         return ecx.threadGroup.getParent() == null;
   849                         return ecx.threadGroup.getParent() == null;
   876                 // creation of a main AppContext in that case.
   878                 // creation of a main AppContext in that case.
   877                 // This is probably not 100% MT-safe but should reduce
   879                 // This is probably not 100% MT-safe but should reduce
   878                 // the window of opportunity in which that issue could
   880                 // the window of opportunity in which that issue could
   879                 // happen.
   881                 // happen.
   880                 if (numAppContexts.get() > 0) {
   882                 if (numAppContexts.get() > 0) {
   881                    // Defaults to thread group caching.
   883                     // Defaults to thread group caching.
   882                    // This is probably not required as we only really need
   884                     // This is probably not required as we only really need
   883                    // isolation in a deployed applet environment, in which
   885                     // isolation in a deployed applet environment, in which
   884                    // case ecx will not be null when we reach here
   886                     // case ecx will not be null when we reach here
   885                    // However it helps emulate the deployed environment,
   887                     // However it helps emulate the deployed environment,
   886                    // in tests for instance.
   888                     // in tests for instance.
   887                    ecx = ecx != null ? ecx : getAppContext();
   889                     ecx = ecx != null ? ecx : getAppContext();
   888                 }
   890                 }
   889 
   891 
   890                 // getAppletContext() may be called when initializing the main
   892                 // getAppletContext() may be called when initializing the main
   891                 // app context - in which case mainAppContext will still be
   893                 // app context - in which case mainAppContext will still be
   892                 // null. To work around this issue we simply use
   894                 // null. To work around this issue we simply use
   893                 // AppContext.threadGroup.getParent() == null instead, since
   895                 // AppContext.threadGroup.getParent() == null instead, since
   894                 // mainAppContext is the only AppContext which should have
   896                 // mainAppContext is the only AppContext which should have
   895                 // the root TG as its thread group.
   897                 // the root TG as its thread group.
   896                 // See: JDK-8023258
   898                 // See: JDK-8023258
   897                 final boolean isMainAppContext = ecx == null
   899                 final boolean isMainAppContext = ecx == null
   898                     || mainAppContext == ecx
   900                         || mainAppContext == ecx
   899                     || mainAppContext == null && hasRootThreadGroup(ecx);
   901                         || mainAppContext == null && hasRootThreadGroup(ecx);
   900 
   902 
   901                 return isMainAppContext ? null : ecx;
   903                 return isMainAppContext ? null : ecx;
   902             }
   904             }
   903 
   905 
   904         });
   906         });