[icedtea-web] RFC: Fix for PR852: Classloader not being flushed after close
Deepak Bhole
dbhole at redhat.com
Thu Jan 26 10:18:42 PST 2012
Hi,
This patch fixes PR852. I would like to put it in 1.2 in addition to
HEAD.
ChangeLog:
2012-01-26 Deepak Bhole <dbhole at redhat.com>
PR852: Classloader not being flushed after last applet from a site is closed
* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Added variable
to count usage for a given ClassLoader instance.
(getInstance): Decrement use count for a loader after it is merged with
another. Increment loader use count before returning.
(incrementLoaderCount): New method. Increments loader use count.
(decrementLoaderCount): New method. Decrements loader use count.
* java/sun/applet/PluginAppletViewer.java (appletClose): Decrement loader
use count when applet is closed.
Okay for both?
Cheers,
Deepak
-------------- next part --------------
diff -r 41f03d932cdf NEWS
--- a/NEWS Mon Jan 09 18:45:31 2012 -0500
+++ b/NEWS Thu Jan 26 13:15:59 2012 -0500
@@ -22,6 +22,7 @@
- PR749: sun.applet.PluginStreamHandler#handleMessage(String) really slow
- PR782: Support building against npapi-sdk as well
- PR838: IcedTea plugin crashes with chrome browser when javascript is executed
+ - PR852: Classloader not being flushed after last applet from a site is closed
- RH586194: Unable to connect to connect with Juniper VPN client
- RH718693: MindTerm SSH Applet doesn't work
Common
diff -r 41f03d932cdf netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Mon Jan 09 18:45:31 2012 -0500
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Thu Jan 26 13:15:59 2012 -0500
@@ -173,6 +173,11 @@
private boolean foundMainJar= false;
/**
+ * Variable to track how many times this loader is in use
+ */
+ private Integer useCount = 0;
+
+ /**
* Create a new JNLPClassLoader from the specified file.
*
* @param file the JNLP file
@@ -321,6 +326,7 @@
throw new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LSignedAppJarUsingUnsignedJar"), R("LSignedAppJarUsingUnsignedJarInfo"));
loader.merge(extLoader);
+ decrementLoaderCount(extLoader); // loader urls have been merged, ext loader is no longer used
}
// loader is now current + ext. But we also need to think of
@@ -347,7 +353,11 @@
// loaders are mapped to a unique key. Only extensions and parent
// share a key, so it is safe to always share based on it
- urlToLoader.put(uniqueKey, loader);
+
+ incrementLoaderCount(loader);
+ synchronized(urlToLoader) {
+ urlToLoader.put(uniqueKey, loader);
+ }
return loader;
}
@@ -1762,6 +1772,46 @@
}
return result;
}
+
+ /**
+ * Increments loader use count by 1
+ *
+ * @throws SecurityException if caller is not trusted
+ */
+ public static void incrementLoaderCount(JNLPClassLoader loader) {
+
+ // For use by trusted code only
+ if (System.getSecurityManager() != null)
+ System.getSecurityManager().checkPermission(new AllPermission());
+
+ synchronized(loader.useCount) {
+ loader.useCount++;
+ }
+ }
+
+ /**
+ * Decrements loader use count by 1
+ *
+ * If count reaches 0, loader is removed from list of available loaders
+ *
+ * @throws SecurityException if caller is not trusted
+ */
+ public static void decrementLoaderCount(JNLPClassLoader loader) {
+
+ // For use by trusted code only
+ if (System.getSecurityManager() != null)
+ System.getSecurityManager().checkPermission(new AllPermission());
+
+ synchronized(loader.useCount) {
+ loader.useCount--;
+
+ if (loader.useCount <= 0) {
+ synchronized(urlToLoader) {
+ urlToLoader.remove(loader.file.getUniqueKey());
+ }
+ }
+ }
+ }
/*
* Helper class to expose protected URLClassLoader methods.
diff -r 41f03d932cdf plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
--- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java Mon Jan 09 18:45:31 2012 -0500
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java Thu Jan 26 13:15:59 2012 -0500
@@ -1625,6 +1625,9 @@
appletShutdown(p);
appletPanels.removeElement(p);
+
+ // Mark classloader unusable
+ JNLPClassLoader.decrementLoaderCount((JNLPClassLoader) cl);
try {
SwingUtilities.invokeAndWait(new Runnable() {
More information about the distro-pkg-dev
mailing list