changeset 54974:9bb638b282bc

8216592: Removal of the class sun.awt.AWTSecurityManager Reviewed-by: prr
author serb
date Tue, 05 Feb 2019 14:54:06 -0800
parents 0c339d151cdc
children c2b366b9c360
files src/java.desktop/share/classes/java/awt/Font.java src/java.desktop/share/classes/sun/awt/AWTSecurityManager.java src/java.desktop/share/classes/sun/awt/AppContext.java src/java.desktop/share/classes/sun/font/FontDesignMetrics.java src/java.desktop/share/classes/sun/font/FontManager.java src/java.desktop/share/classes/sun/font/SunFontManager.java
diffstat 6 files changed, 40 insertions(+), 297 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/java/awt/Font.java	Mon Feb 04 11:01:04 2019 +0530
+++ b/src/java.desktop/share/classes/java/awt/Font.java	Tue Feb 05 14:54:06 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -495,13 +495,7 @@
 
     private Font2D getFont2D() {
         FontManager fm = FontManagerFactory.getInstance();
-        if (fm.usingPerAppContextComposites() &&
-            font2DHandle != null &&
-            font2DHandle.font2D instanceof CompositeFont &&
-            ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
-            return fm.findFont2D(name, style,
-                                          FontManager.LOGICAL_FALLBACK);
-        } else if (font2DHandle == null) {
+        if (font2DHandle == null) {
             font2DHandle =
                 fm.findFont2D(name, style,
                               FontManager.LOGICAL_FALLBACK).handle;
--- a/src/java.desktop/share/classes/sun/awt/AWTSecurityManager.java	Mon Feb 04 11:01:04 2019 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.awt;
-
-/**
-  * The AWTSecurityManager class provides the ability to secondarily
-  * index AppContext objects through SecurityManager extensions.
-  * As noted in AppContext.java, AppContexts are primarily indexed by
-  * ThreadGroup.  In the case where the ThreadGroup doesn't provide
-  * enough information to determine AppContext (e.g. system threads),
-  * if a SecurityManager is installed which derives from
-  * AWTSecurityManager, the AWTSecurityManager's getAppContext()
-  * method is called to determine the AppContext.
-  *
-  * A typical example of the use of this class is where an applet
-  * is called by a system thread, yet the system AppContext is
-  * inappropriate, because applet code is currently executing.
-  * In this case, the getAppContext() method can walk the call stack
-  * to determine the applet code being executed and return the applet's
-  * AppContext object.
-  *
-  * @author  Fred Ecks
-  */
-public class AWTSecurityManager extends SecurityManager {
-
-    /**
-      * Get the AppContext corresponding to the current context.
-      * The default implementation returns null, but this method
-      * may be overridden by various SecurityManagers
-      * (e.g. AppletSecurity) to index AppContext objects by the
-      * calling context.
-      *
-      * @return  the AppContext corresponding to the current context.
-      * @see     sun.awt.AppContext
-      * @see     java.lang.SecurityManager
-      * @since   1.2.1
-      */
-    public AppContext getAppContext() {
-        return null; // Default implementation returns null
-    }
-
-} /* class AWTSecurityManager */
--- a/src/java.desktop/share/classes/sun/awt/AppContext.java	Mon Feb 04 11:01:04 2019 +0530
+++ b/src/java.desktop/share/classes/sun/awt/AppContext.java	Tue Feb 05 14:54:06 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -123,17 +123,6 @@
  * therefore safely invoke any of its methods without worry of being
  * blocked.
  *
- * Note: If a SecurityManager is installed which derives from
- * sun.awt.AWTSecurityManager, it may override the
- * AWTSecurityManager.getAppContext() method to return the proper
- * AppContext based on the execution context, in the case where
- * the default ThreadGroup-based AppContext indexing would return
- * the main "system" AppContext.  For example, in an applet situation,
- * if a system thread calls into an applet, rather than returning the
- * main "system" AppContext (the one corresponding to the system thread),
- * an installed AWTSecurityManager may return the applet's AppContext
- * based on the execution context.
- *
  * @author  Thomas Ball
  * @author  Fred Ecks
  */
@@ -287,10 +276,7 @@
 
     /**
      * Returns the appropriate AppContext for the caller,
-     * as determined by its ThreadGroup.  If the main "system" AppContext
-     * would be returned and there's an AWTSecurityManager installed, it
-     * is called to get the proper AppContext based on the execution
-     * context.
+     * as determined by its ThreadGroup.
      *
      * @return  the AppContext for the caller.
      * @see     java.lang.ThreadGroup
@@ -384,18 +370,6 @@
         return (ctx != null && ctx == mainAppContext);
     }
 
-    private static AppContext getExecutionAppContext() {
-        SecurityManager securityManager = System.getSecurityManager();
-        if ((securityManager != null) &&
-            (securityManager instanceof AWTSecurityManager))
-        {
-            AWTSecurityManager awtSecMgr = (AWTSecurityManager) securityManager;
-            AppContext secAppContext = awtSecMgr.getAppContext();
-            return secAppContext; // Return what we're told
-        }
-        return null;
-    }
-
     private long DISPOSAL_TIMEOUT = 5000;  // Default to 5-second timeout
                                            // for disposal of all Frames
                                            // (we wait for this time twice,
@@ -872,8 +846,7 @@
                 // context since we don't need it.
                 if (numAppContexts.get() == 0) return null;
 
-                // Get the context from the security manager
-                AppContext ecx = getExecutionAppContext();
+                AppContext ecx = null;
 
                 // Not sure we really need to re-check numAppContexts here.
                 // If all applets have gone away then we could have a
--- a/src/java.desktop/share/classes/sun/font/FontDesignMetrics.java	Mon Feb 04 11:01:04 2019 +0530
+++ b/src/java.desktop/share/classes/sun/font/FontDesignMetrics.java	Tue Feb 05 14:54:06 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,22 +25,18 @@
 
 package sun.font;
 
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.SoftReference;
-
+import java.awt.Font;
 import java.awt.FontMetrics;
-import java.awt.Font;
 import java.awt.GraphicsEnvironment;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.NoninvertibleTransformException;
-import java.awt.geom.Rectangle2D;
 import java.awt.font.FontRenderContext;
 import java.awt.font.TextLayout;
-
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
 import java.util.concurrent.ConcurrentHashMap;
 
 import sun.java2d.Disposer;
@@ -263,7 +259,7 @@
          * by this code as they use the metrics of the physical anyway.
          */
         SunFontManager fm = SunFontManager.getInstance();
-        if (fm.maybeUsingAlternateCompositeFonts() &&
+        if (fm.usingAlternateCompositeFonts() &&
             FontUtilities.getFont2D(font) instanceof CompositeFont) {
             return new FontDesignMetrics(font, frc);
         }
--- a/src/java.desktop/share/classes/sun/font/FontManager.java	Mon Feb 04 11:01:04 2019 +0530
+++ b/src/java.desktop/share/classes/sun/font/FontManager.java	Tue Feb 05 14:54:06 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,16 +22,12 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 package sun.font;
 
 import java.awt.Font;
 import java.awt.FontFormatException;
 import java.io.File;
-import java.util.Locale;
-import java.util.TreeMap;
-
-import javax.swing.plaf.FontUIResource;
-
 
 /**
  * Interface between Java Fonts (java.awt.Font) and the underlying
@@ -93,13 +89,6 @@
         throws FontFormatException;
 
     /**
-     * If usingPerAppContextComposites is true, we are in "applet"
-     * (eg browser) environment and at least one context has selected
-     * an alternate composite font behaviour.
-     */
-    public boolean usingPerAppContextComposites();
-
-    /**
      * Creates a derived composite font from the specified font (handle).
      *
      * @param family the font family of the derived font
--- a/src/java.desktop/share/classes/sun/font/SunFontManager.java	Mon Feb 04 11:01:04 2019 +0530
+++ b/src/java.desktop/share/classes/sun/font/SunFontManager.java	Tue Feb 05 14:54:06 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,7 +50,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.swing.plaf.FontUIResource;
-import sun.awt.AppContext;
+
 import sun.awt.FontConfiguration;
 import sun.awt.SunToolkit;
 import sun.awt.util.ThreadGroupUtils;
@@ -256,11 +256,6 @@
         return t1Filter;
     }
 
-    @Override
-    public boolean usingPerAppContextComposites() {
-        return _usingPerAppContextComposites;
-    }
-
     static {
 
         java.security.AccessController.doPrivileged(
@@ -1936,7 +1931,6 @@
     public Font2D findFont2D(String name, int style, int fallback) {
         String lowerCaseName = name.toLowerCase(Locale.ENGLISH);
         String mapName = lowerCaseName + dotStyleStr(style);
-        Font2D font;
 
         /* If preferLocaleFonts() or preferProportionalFonts() has been
          * called we may be using an alternate set of composite fonts in this
@@ -1944,19 +1938,7 @@
          * this is so, and gives access to the alternate composite for the
          * name.
          */
-        if (_usingPerAppContextComposites) {
-            @SuppressWarnings("unchecked")
-            ConcurrentHashMap<String, Font2D> altNameCache =
-                (ConcurrentHashMap<String, Font2D>)
-                AppContext.getAppContext().get(CompositeFont.class);
-            if (altNameCache != null) {
-                font = altNameCache.get(mapName);
-            } else {
-                font = null;
-            }
-        } else {
-            font = fontNameCache.get(mapName);
-        }
+        Font2D font = fontNameCache.get(mapName);
         if (font != null) {
             return font;
         }
@@ -2161,25 +2143,9 @@
          * cache for these.
          */
 
-        if (fontsAreRegistered || fontsAreRegisteredPerAppContext) {
-            Hashtable<String, FontFamily> familyTable = null;
-            Hashtable<String, Font2D> nameTable;
-
-            if (fontsAreRegistered) {
-                familyTable = createdByFamilyName;
-                nameTable = createdByFullName;
-            } else {
-                AppContext appContext = AppContext.getAppContext();
-                @SuppressWarnings("unchecked")
-                Hashtable<String,FontFamily> tmp1 =
-                    (Hashtable<String,FontFamily>)appContext.get(regFamilyKey);
-                familyTable = tmp1;
-
-                @SuppressWarnings("unchecked")
-                Hashtable<String, Font2D> tmp2 =
-                    (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
-                nameTable = tmp2;
-            }
+        if (fontsAreRegistered) {
+            Hashtable<String, FontFamily> familyTable = createdByFamilyName;
+            Hashtable<String, Font2D> nameTable = createdByFullName;
 
             family = familyTable.get(lowerCaseName);
             if (family != null) {
@@ -2684,9 +2650,6 @@
      * Calling the methods below is "heavyweight" but it is expected that
      * these methods will be called very rarely.
      *
-     * If _usingPerAppContextComposites is true, we are in "applet"
-     * (eg browser) environment and at least one context has selected
-     * an alternate composite font behaviour.
      * If _usingAlternateComposites is true, we are not in an "applet"
      * environment and the (single) application has selected
      * an alternate composite font behaviour.
@@ -2698,21 +2661,13 @@
      * but that may have to wait. The results should be correct, just not
      * optimal.
      */
-    private static final Object altJAFontKey       = new Object();
-    private static final Object localeFontKey       = new Object();
-    private static final Object proportionalFontKey = new Object();
-    private boolean _usingPerAppContextComposites = false;
     private boolean _usingAlternateComposites = false;
 
-    /* These values are used only if we are running as a standalone
-     * application, as determined by maybeMultiAppContext();
-     */
     private static boolean gAltJAFont = false;
     private boolean gLocalePref = false;
     private boolean gPropPref = false;
 
-    /* This method doesn't check if alternates are selected in this app
-     * context. Its used by the FontMetrics caching code which in such
+    /* Its used by the FontMetrics caching code which in such
      * a case cannot retrieve a cached metrics solely on the basis of
      * the Font.equals() method since it needs to also check if the Font2D
      * is the same.
@@ -2724,26 +2679,8 @@
      * logical font definitions we may need to revisit this if GTK reports
      * combined metrics instead. For now though this test can be simple.
      */
-    public boolean maybeUsingAlternateCompositeFonts() {
-       return _usingAlternateComposites || _usingPerAppContextComposites;
-    }
-
     public boolean usingAlternateCompositeFonts() {
-        return (_usingAlternateComposites ||
-                (_usingPerAppContextComposites &&
-                AppContext.getAppContext().get(CompositeFont.class) != null));
-    }
-
-    private static boolean maybeMultiAppContext() {
-        Boolean appletSM = (Boolean)
-            java.security.AccessController.doPrivileged(
-                new java.security.PrivilegedAction<Object>() {
-                        public Object run() {
-                            SecurityManager sm = System.getSecurityManager();
-                            return sm instanceof sun.awt.AWTSecurityManager;
-                        }
-                    });
-        return appletSM.booleanValue();
+        return _usingAlternateComposites;
     }
 
     /* Modifies the behaviour of a subsequent call to preferLocaleFonts()
@@ -2758,22 +2695,11 @@
         if (!FontUtilities.isWindows) {
             return;
         }
-
-        if (!maybeMultiAppContext()) {
-            gAltJAFont = true;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            appContext.put(altJAFontKey, altJAFontKey);
-        }
+        gAltJAFont = true;
     }
 
     public boolean usingAlternateFontforJALocales() {
-        if (!maybeMultiAppContext()) {
-            return gAltJAFont;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            return appContext.get(altJAFontKey) == altJAFontKey;
-        }
+        return gAltJAFont;
     }
 
     public synchronized void preferLocaleFonts() {
@@ -2784,29 +2710,12 @@
         if (!FontConfiguration.willReorderForStartupLocale()) {
             return;
         }
-
-        if (!maybeMultiAppContext()) {
-            if (gLocalePref == true) {
-                return;
-            }
-            gLocalePref = true;
-            createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
-            _usingAlternateComposites = true;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            if (appContext.get(localeFontKey) == localeFontKey) {
-                return;
-            }
-            appContext.put(localeFontKey, localeFontKey);
-            boolean acPropPref =
-                appContext.get(proportionalFontKey) == proportionalFontKey;
-            ConcurrentHashMap<String, Font2D>
-                altNameCache = new ConcurrentHashMap<String, Font2D> ();
-            /* If there is an existing hashtable, we can drop it. */
-            appContext.put(CompositeFont.class, altNameCache);
-            _usingPerAppContextComposites = true;
-            createCompositeFonts(altNameCache, true, acPropPref);
+        if (gLocalePref == true) {
+            return;
         }
+        gLocalePref = true;
+        createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
+        _usingAlternateComposites = true;
     }
 
     public synchronized void preferProportionalFonts() {
@@ -2820,29 +2729,12 @@
         if (!FontConfiguration.hasMonoToPropMap()) {
             return;
         }
-
-        if (!maybeMultiAppContext()) {
-            if (gPropPref == true) {
-                return;
-            }
-            gPropPref = true;
-            createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
-            _usingAlternateComposites = true;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            if (appContext.get(proportionalFontKey) == proportionalFontKey) {
-                return;
-            }
-            appContext.put(proportionalFontKey, proportionalFontKey);
-            boolean acLocalePref =
-                appContext.get(localeFontKey) == localeFontKey;
-            ConcurrentHashMap<String, Font2D>
-                altNameCache = new ConcurrentHashMap<String, Font2D> ();
-            /* If there is an existing hashtable, we can drop it. */
-            appContext.put(CompositeFont.class, altNameCache);
-            _usingPerAppContextComposites = true;
-            createCompositeFonts(altNameCache, acLocalePref, true);
+        if (gPropPref == true) {
+            return;
         }
+        gPropPref = true;
+        createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
+        _usingAlternateComposites = true;
     }
 
     private static HashSet<String> installedNames = null;
@@ -2865,13 +2757,10 @@
         return installedNames;
     }
 
-    /* Keys are used to lookup per-AppContext Hashtables */
-    private static final Object regFamilyKey  = new Object();
-    private static final Object regFullNameKey = new Object();
+    private static final Object regFamilyLock  = new Object();
     private Hashtable<String,FontFamily> createdByFamilyName;
     private Hashtable<String,Font2D>     createdByFullName;
     private boolean fontsAreRegistered = false;
-    private boolean fontsAreRegisteredPerAppContext = false;
 
     public boolean registerFont(Font font) {
         /* This method should not be called with "null".
@@ -2882,7 +2771,7 @@
         }
 
         /* Initialise these objects only once we start to use this API */
-        synchronized (regFamilyKey) {
+        synchronized (regFamilyLock) {
             if (createdByFamilyName == null) {
                 createdByFamilyName = new Hashtable<String,FontFamily>();
                 createdByFullName = new Hashtable<String,Font2D>();
@@ -2919,31 +2808,10 @@
         }
 
         /* Checks passed, now register the font */
-        Hashtable<String,FontFamily> familyTable;
-        Hashtable<String,Font2D> fullNameTable;
-        if (!maybeMultiAppContext()) {
-            familyTable = createdByFamilyName;
-            fullNameTable = createdByFullName;
-            fontsAreRegistered = true;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            @SuppressWarnings("unchecked")
-            Hashtable<String,FontFamily> tmp1 =
-                (Hashtable<String,FontFamily>)appContext.get(regFamilyKey);
-            familyTable = tmp1;
-            @SuppressWarnings("unchecked")
-            Hashtable<String,Font2D> tmp2 =
-                (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
-            fullNameTable = tmp2;
-
-            if (familyTable == null) {
-                familyTable = new Hashtable<String,FontFamily>();
-                fullNameTable = new Hashtable<String,Font2D>();
-                appContext.put(regFamilyKey, familyTable);
-                appContext.put(regFullNameKey, fullNameTable);
-            }
-            fontsAreRegisteredPerAppContext = true;
-        }
+        Hashtable<String, FontFamily> familyTable = createdByFamilyName;
+        Hashtable<String, Font2D> fullNameTable = createdByFullName;
+        fontsAreRegistered = true;
+
         /* Create the FontFamily and add font to the tables */
         Font2D font2D = FontUtilities.getFont2D(font);
         int style = font2D.getStyle();
@@ -2989,12 +2857,6 @@
         Hashtable<String,FontFamily> familyTable;
         if (fontsAreRegistered) {
             familyTable = createdByFamilyName;
-        } else if (fontsAreRegisteredPerAppContext) {
-            AppContext appContext = AppContext.getAppContext();
-            @SuppressWarnings("unchecked")
-            Hashtable<String,FontFamily> tmp =
-                (Hashtable<String,FontFamily>)appContext.get(regFamilyKey);
-            familyTable = tmp;
         } else {
             return null;
         }
@@ -3019,12 +2881,6 @@
         Hashtable<String,Font2D> nameTable;
         if (fontsAreRegistered) {
             nameTable = createdByFullName;
-        } else if (fontsAreRegisteredPerAppContext) {
-            AppContext appContext = AppContext.getAppContext();
-            @SuppressWarnings("unchecked")
-            Hashtable<String,Font2D> tmp =
-                (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
-            nameTable = tmp;
         } else {
             return null;
         }