--- old/src/share/classes/sun/applet/AppletImageRef.java 2014-01-21 10:09:06.000000000 -0800 +++ new/src/share/classes/sun/applet/AppletImageRef.java 2014-01-21 10:09:05.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2014, 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 @@ -27,27 +27,71 @@ import java.awt.Toolkit; import java.awt.Image; +import java.lang.ref.SoftReference; import sun.awt.image.URLImageSource; import java.net.URL; -class AppletImageRef extends sun.misc.Ref { +class AppletImageRef { + private SoftReference soft = null; + URL url; /** + * Returns a pointer to the object referenced by this Ref. If the object + * has been thrown away by the garbage collector, it will be + * reconstituted. This method does everything necessary to ensure that the garbage + * collector throws things away in Least Recently Used(LRU) order. Applications should + * never override this method. The get() method effectively caches calls to + * reconstitute(). + */ + public synchronized Image get() { + Image t = check(); + if (t == null) { + t = reconstitute(); + setThing(t); + } + return t; + } + + /** * Create the Ref */ AppletImageRef(URL url) { this.url = url; } - public void flush() { - super.flush(); + /** + * Flushes the cached object. Forces the next invocation of get() to + * invoke reconstitute(). + */ + public synchronized void flush() { + SoftReference s = soft; + if (s != null) s.clear(); + soft = null; + } + + /** + * Sets the thing to the specified object. + * @param thing the specified object + */ + public synchronized void setThing(Object thing) { + flush(); + soft = new SoftReference(thing); + } + + /** + * Checks to see what object is being pointed at by this Ref and returns it. + */ + public synchronized Image check() { + SoftReference s = soft; + if (s == null) return null; + return s.get(); } /** * Reconsitute the image. Only called when the ref has been flushed. */ - public Object reconstitute() { + public Image reconstitute() { Image img = Toolkit.getDefaultToolkit().createImage(new URLImageSource(url)); return img; } --- old/src/share/classes/sun/applet/AppletResourceLoader.java 2014-01-21 10:09:06.000000000 -0800 +++ new/src/share/classes/sun/applet/AppletResourceLoader.java 2014-01-21 10:09:06.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2014, 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 @@ -27,21 +27,17 @@ import java.net.URL; import java.awt.Image; -import sun.misc.Ref; /** * Part of this class still remains only to support legacy, 100%-impure * applications such as HotJava 1.0.1. */ +@Deprecated public class AppletResourceLoader { public static Image getImage(URL url) { return AppletViewer.getCachedImage(url); } - public static Ref getImageRef(URL url) { - return AppletViewer.getCachedImageRef(url); - } - public static void flushImages() { AppletViewer.flushImageCache(); } --- old/src/share/classes/sun/applet/AppletViewer.java 2014-01-21 10:09:07.000000000 -0800 +++ new/src/share/classes/sun/applet/AppletViewer.java 2014-01-21 10:09:07.000000000 -0800 @@ -35,7 +35,6 @@ import java.net.URL; import java.net.MalformedURLException; import java.net.SocketPermission; -import sun.misc.Ref; import java.security.AccessController; import java.security.PrivilegedAction; import java.lang.reflect.InvocationTargetException; @@ -390,22 +389,18 @@ return getCachedImage(url); } - static Image getCachedImage(URL url) { - // System.getSecurityManager().checkConnection(url.getHost(), url.getPort()); - return (Image)getCachedImageRef(url).get(); - } - /** - * Get an image ref. + * Get an image. */ - static Ref getCachedImageRef(URL url) { + static Image getCachedImage(URL url) { + // System.getSecurityManager().checkConnection(url.getHost(), url.getPort()); synchronized (imageRefs) { AppletImageRef ref = (AppletImageRef)imageRefs.get(url); if (ref == null) { ref = new AppletImageRef(url); imageRefs.put(url, ref); } - return ref; + return ref.get(); } } --- old/src/share/classes/sun/misc/Cache.java 2014-01-21 10:09:07.000000000 -0800 +++ new/src/share/classes/sun/misc/Cache.java 2014-01-21 10:09:07.000000000 -0800 @@ -25,6 +25,7 @@ package sun.misc; +import java.lang.ref.SoftReference; import java.util.Dictionary; import java.util.Enumeration; import java.util.NoSuchElementException; @@ -32,12 +33,26 @@ /** * Caches the collision list. */ -class CacheEntry extends Ref { +class CacheEntry { int hash; Object key; CacheEntry next; - public Object reconstitute() { - return null; + SoftReference value; + + public CacheEntry() { + value = null; + } + + public CacheEntry(Object o) { + value = new SoftReference<>(o); + } + + public Object get() { + return value.get(); + } + + public void setThing(Object thing) { + value = new SoftReference<>(thing); } } @@ -192,7 +207,7 @@ int index = (hash & 0x7FFFFFFF) % tab.length; for (CacheEntry e = tab[index]; e != null; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { - return e.check(); + return e.get(); } } return null; @@ -220,7 +235,7 @@ for (CacheEntry old = oldTable[i]; old != null;) { CacheEntry e = old; old = old.next; - if (e.check() != null) { + if (e.get() != null) { int index = (e.hash & 0x7FFFFFFF) % newCapacity; e.next = newTable[index]; newTable[index] = e; @@ -253,10 +268,10 @@ CacheEntry ne = null; for (CacheEntry e = tab[index]; e != null; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { - Object old = e.check(); + Object old = e.get(); e.setThing(value); return old; - } else if (e.check() == null) + } else if (e.get() == null) ne = e; /* reuse old flushed value */ } @@ -296,7 +311,7 @@ tab[index] = e.next; } count--; - return e.check(); + return e.get(); } } return null; @@ -322,7 +337,7 @@ public boolean hasMoreElements() { while (index >= 0) { while (entry != null) - if (entry.check() != null) + if (entry.get() != null) return true; else entry = entry.next; @@ -338,8 +353,8 @@ if (entry != null) { CacheEntry e = entry; entry = e.next; - if (e.check() != null) - return keys ? e.key : e.check(); + if (e.get() != null) + return keys ? e.key : e.get(); } } throw new NoSuchElementException("CacheEnumerator"); --- old/src/share/classes/sun/misc/Ref.java 2014-01-21 10:09:08.000000000 -0800 +++ /dev/null 2014-01-15 22:56:25.558256776 -0800 @@ -1,122 +0,0 @@ -/* - * Copyright (c) 1995, 2004, 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.misc; -import java.lang.ref.SoftReference; - - -/** - * A "Ref" is an indirect reference to an object that the garbage collector - * knows about. An application should override the reconstitute() method with one - * that will construct the object based on information in the Ref, often by - * reading from a file. The get() method retains a cache of the result of the last call to - * reconstitute() in the Ref. When space gets tight, the garbage collector - * will clear old Ref cache entries when there are no other pointers to the - * object. In normal usage, Ref will always be subclassed. The subclass will add the - * instance variables necessary for the reconstitute() method to work. It will also add a - * constructor to set them up, and write a version of reconstitute(). - * - * @deprecated This class has been replaced by - * java.util.SoftReference. - * - * @see java.util.SoftReference - * - */ -@Deprecated - -public abstract class Ref { - - private SoftReference soft = null; - - /** - * Returns a pointer to the object referenced by this Ref. If the object - * has been thrown away by the garbage collector, it will be - * reconstituted. This method does everything necessary to ensure that the garbage - * collector throws things away in Least Recently Used(LRU) order. Applications should - * never override this method. The get() method effectively caches calls to - * reconstitute(). - */ - public synchronized Object get() { - Object t = check(); - if (t == null) { - t = reconstitute(); - setThing(t); - } - return t; - } - - /** - * Returns a pointer to the object referenced by this Ref by - * reconstituting it from some external source (such as a file). This method should not - * bother with caching since the method get() will deal with that. - *

- * In normal usage, Ref will always be subclassed. The subclass will add - * the instance variables necessary for reconstitute() to work. It will - * also add a constructor to set them up, and write a version of - * reconstitute(). - */ - public abstract Object reconstitute(); - - /** - * Flushes the cached object. Forces the next invocation of get() to - * invoke reconstitute(). - */ - public synchronized void flush() { - SoftReference s = soft; - if (s != null) s.clear(); - soft = null; - } - - /** - * Sets the thing to the specified object. - * @param thing the specified object - */ - public synchronized void setThing(Object thing) { - flush(); - soft = new SoftReference(thing); - } - - /** - * Checks to see what object is being pointed at by this Ref and returns it. - */ - public synchronized Object check() { - SoftReference s = soft; - if (s == null) return null; - return s.get(); - } - - /** - * Constructs a new Ref. - */ - public Ref() { } - - /** - * Constructs a new Ref that initially points to thing. - */ - public Ref(Object thing) { - setThing(thing); - } - -}