8080246: JNLP app cannot be launched due to deadlock
authordtitov
Tue, 09 Jun 2015 11:52:12 -0700
changeset 33284 dd3488738c7a
parent 33283 472c86f25bff
child 33285 5b20fc9010b7
8080246: JNLP app cannot be launched due to deadlock Reviewed-by: serb, vdrozdov
jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java
--- a/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java	Tue May 26 10:39:22 2015 -0700
+++ b/jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java	Tue Jun 09 11:52:12 2015 -0700
@@ -651,16 +651,20 @@
 
 
     @SuppressWarnings("deprecation")
-    static final SoftCache imgCache = new SoftCache();
+    static final SoftCache fileImgCache = new SoftCache();
+
+    @SuppressWarnings("deprecation")
+    static final SoftCache urlImgCache = new SoftCache();
 
     static Image getImageFromHash(Toolkit tk, URL url) {
         checkPermissions(url);
-        synchronized (imgCache) {
-            Image img = (Image)imgCache.get(url);
+        synchronized (urlImgCache) {
+            String key = url.toString();
+            Image img = (Image)urlImgCache.get(key);
             if (img == null) {
                 try {
                     img = tk.createImage(new URLImageSource(url));
-                    imgCache.put(url, img);
+                    urlImgCache.put(key, img);
                 } catch (Exception e) {
                 }
             }
@@ -671,12 +675,12 @@
     static Image getImageFromHash(Toolkit tk,
                                                String filename) {
         checkPermissions(filename);
-        synchronized (imgCache) {
-            Image img = (Image)imgCache.get(filename);
+        synchronized (fileImgCache) {
+            Image img = (Image)fileImgCache.get(filename);
             if (img == null) {
                 try {
                     img = tk.createImage(new FileImageSource(filename));
-                    imgCache.put(filename, img);
+                    fileImgCache.put(filename, img);
                 } catch (Exception e) {
                 }
             }
@@ -696,28 +700,29 @@
 
     protected Image getImageWithResolutionVariant(String fileName,
             String resolutionVariantName) {
-        synchronized (imgCache) {
+        synchronized (fileImgCache) {
             Image image = getImageFromHash(this, fileName);
             if (image instanceof MultiResolutionImage) {
                 return image;
             }
             Image resolutionVariant = getImageFromHash(this, resolutionVariantName);
             image = createImageWithResolutionVariant(image, resolutionVariant);
-            imgCache.put(fileName, image);
+            fileImgCache.put(fileName, image);
             return image;
         }
     }
 
     protected Image getImageWithResolutionVariant(URL url,
             URL resolutionVariantURL) {
-        synchronized (imgCache) {
+        synchronized (urlImgCache) {
             Image image = getImageFromHash(this, url);
             if (image instanceof MultiResolutionImage) {
                 return image;
             }
             Image resolutionVariant = getImageFromHash(this, resolutionVariantURL);
             image = createImageWithResolutionVariant(image, resolutionVariant);
-            imgCache.put(url, image);
+            String key = url.toString();
+            urlImgCache.put(key, image);
             return image;
         }
     }
@@ -828,8 +833,13 @@
         return null;
     }
 
-    protected static boolean imageCached(Object key) {
-        return imgCache.containsKey(key);
+    protected static boolean imageCached(String fileName) {
+        return fileImgCache.containsKey(fileName);
+    }
+
+    protected static boolean imageCached(URL url) {
+        String key = url.toString();
+        return urlImgCache.containsKey(key);
     }
 
     protected static boolean imageExists(String filename) {