home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / plugin.jar / sun / plugin / ClassLoaderInfo.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  6.5 KB  |  354 lines

  1. package sun.plugin;
  2.  
  3. import java.io.PrintStream;
  4. import java.lang.ref.ReferenceQueue;
  5. import java.net.URL;
  6. import java.security.AccessController;
  7. import java.util.ArrayList;
  8. import java.util.Collection;
  9. import java.util.HashMap;
  10. import java.util.Iterator;
  11. import sun.applet.AppletClassLoader;
  12. import sun.applet.AppletPanel;
  13. import sun.plugin.security.PluginClassLoader;
  14. import sun.plugin.util.Trace;
  15. import sun.security.action.GetIntegerAction;
  16. import sun.security.action.GetPropertyAction;
  17.  
  18. public class ClassLoaderInfo {
  19.    private URL codebase;
  20.    private String key;
  21.    private int references = 0;
  22.    private HashMap jars;
  23.    private boolean locked;
  24.    private boolean isCachable = true;
  25.    private static boolean initialized;
  26.    private static HashMap infos = new HashMap();
  27.    private static int zombieLimit = 0;
  28.    private static ArrayList zombies = new ArrayList();
  29.    private LoaderReference loaderRef = null;
  30.    private static ReferenceQueue refQueue = new ReferenceQueue();
  31.    private boolean localJarsLoaded = false;
  32.  
  33.    private static synchronized void initialize() {
  34.       if (!initialized) {
  35.          initialized = true;
  36.          reset();
  37.       }
  38.    }
  39.  
  40.    public static synchronized void reset() {
  41.       initialized = true;
  42.       zombieLimit = 0;
  43.       String var0 = (String)AccessController.doPrivileged(new GetPropertyAction("javaplugin.classloader.cache.enabled"));
  44.       if (var0 == null || var0.equals("true")) {
  45.          zombieLimit = (Integer)AccessController.doPrivileged(new GetIntegerAction("javaplugin.classloader.cache.sizes", 4));
  46.       }
  47.  
  48.       if (zombieLimit > 4) {
  49.          zombieLimit = 4;
  50.       }
  51.  
  52.    }
  53.  
  54.    public static synchronized void clearClassLoaderCache() {
  55.       for(ClassLoaderInfo var1 : zombies) {
  56.          if (var1 != null) {
  57.             infos.remove(var1.key);
  58.             var1.clearLoaderRef();
  59.          }
  60.       }
  61.  
  62.       zombies.clear();
  63.       Collection var6 = infos.values();
  64.       if (var6 != null) {
  65.          Iterator var5 = var6.iterator();
  66.  
  67.          while(var5.hasNext()) {
  68.             Object var2 = null;
  69.             ArrayList var3 = (ArrayList)var5.next();
  70.             if (var3 != null) {
  71.                for(ClassLoaderInfo var7 : var3) {
  72.                   if (var7 != null) {
  73.                      var7.isCachable = false;
  74.                   }
  75.                }
  76.             }
  77.          }
  78.       }
  79.  
  80.       AppletPanel.flushClassLoaders();
  81.    }
  82.  
  83.    public static synchronized void dumpClassLoaderCache(PrintStream var0) {
  84.       StringBuffer var1 = new StringBuffer();
  85.       var1.append("Dump classloader list ...\n");
  86.       Collection var2 = infos.values();
  87.       if (var2 != null) {
  88.          for(ArrayList var5 : var2) {
  89.             if (var5 != null) {
  90.                for(ClassLoaderInfo var4 : var5) {
  91.                   if (var4 != null && var4.loaderRef != null && var4.loaderRef.get() != null) {
  92.                      boolean var7 = zombies.contains(var4);
  93.                      var1.append("    codebase=" + var4.codebase);
  94.                      var1.append(", key=" + var4.key);
  95.                      var1.append(", zombie=" + var7);
  96.                      var1.append(", cache=" + var4.isCachable);
  97.                      var1.append(", refcount=" + var4.references);
  98.                      var1.append(", info=" + var4);
  99.                      var1.append("\n");
  100.                   }
  101.                }
  102.             }
  103.          }
  104.       }
  105.  
  106.       var1.append("Done.");
  107.       var0.println(var1.toString());
  108.    }
  109.  
  110.    public static synchronized void markNotCachable(URL var0, String var1) {
  111.       assert checkListsValidity();
  112.  
  113.       ClassLoaderInfo var2 = getUsableClassLoaderInfo(var1);
  114.       if (var2 != null) {
  115.          var2.isCachable = false;
  116.          if (zombies.remove(var2)) {
  117.             removeClassLoaderInfo(var2);
  118.          }
  119.  
  120.          AppletPanel.flushClassLoader(var1);
  121.       }
  122.  
  123.       assert checkListsValidity();
  124.  
  125.    }
  126.  
  127.    private static synchronized void removeClassLoaderInfo(ClassLoaderInfo var0) {
  128.       ArrayList var1 = (ArrayList)infos.get(var0.key);
  129.       if (var1 != null) {
  130.          var1.remove(var0);
  131.          if (var1.size() == 0) {
  132.             infos.remove(var0.key);
  133.          }
  134.       }
  135.  
  136.       var0.clearLoaderRef();
  137.    }
  138.  
  139.    private static synchronized void addClassLoaderInfo(ClassLoaderInfo var0) {
  140.       ArrayList var1 = (ArrayList)infos.get(var0.key);
  141.       if (var1 == null) {
  142.          var1 = new ArrayList();
  143.          var1.add(var0);
  144.          infos.put(var0.key, var1);
  145.       } else {
  146.          var1.add(var0);
  147.       }
  148.  
  149.    }
  150.  
  151.    private static synchronized ClassLoaderInfo getUsableClassLoaderInfo(String var0) {
  152.       ArrayList var1 = (ArrayList)infos.get(var0);
  153.       if (var1 != null) {
  154.          Iterator var2 = var1.iterator();
  155.          ClassLoaderInfo var3 = null;
  156.  
  157.          while(var2.hasNext()) {
  158.             var3 = (ClassLoaderInfo)var2.next();
  159.             if (var3.isCachable) {
  160.                return var3;
  161.             }
  162.          }
  163.       }
  164.  
  165.       return null;
  166.    }
  167.  
  168.    public static synchronized ClassLoaderInfo find(URL var0, String var1) {
  169.       assert checkListsValidity();
  170.  
  171.       initialize();
  172.       if (var0 == null) {
  173.          return null;
  174.       } else {
  175.          ClassLoaderInfo var2 = getUsableClassLoaderInfo(var1);
  176.          if (var2 != null) {
  177.             zombies.remove(var2);
  178.          } else {
  179.             var2 = new ClassLoaderInfo(var0, var1);
  180.             addClassLoaderInfo(var2);
  181.          }
  182.  
  183.          assert checkListsValidity();
  184.  
  185.          return var2;
  186.       }
  187.    }
  188.  
  189.    synchronized void addReference() {
  190.       ++this.references;
  191.       Trace.msgPrintln("classloaderinfo.referencing", new Object[]{this, String.valueOf(this.references)});
  192.    }
  193.  
  194.    synchronized void removeReference() {
  195.       --this.references;
  196.       Trace.msgPrintln("classloaderinfo.releasing", new Object[]{this, String.valueOf(this.references)});
  197.       if (this.references < 0) {
  198.          throw new Error("negative ref count???");
  199.       } else {
  200.          if (this.references == 0) {
  201.             addZombie(this);
  202.          }
  203.  
  204.       }
  205.    }
  206.  
  207.    private static synchronized void addZombie(ClassLoaderInfo var0) {
  208.       assert checkListsValidity();
  209.  
  210.       AppletPanel.flushClassLoader(var0.key);
  211.       if (zombieLimit != 0 && var0.isCachable) {
  212.          Trace.msgPrintln("classloaderinfo.caching", new Object[]{var0});
  213.          AppletClassLoader var1 = (AppletClassLoader)var0.loaderRef.get();
  214.          if (var1 != null && var1.getExceptionStatus()) {
  215.             var0.clearLoaderRef();
  216.          }
  217.  
  218.          zombies.add(var0);
  219.          cleanupZombies();
  220.          Trace.msgPrintln("classloaderinfo.cachesize", new Object[]{new Integer(zombies.size())});
  221.          if (zombies.size() > zombieLimit) {
  222.             ClassLoaderInfo var2 = (ClassLoaderInfo)zombies.get(0);
  223.             Trace.msgPrintln("classloaderinfo.num", new Object[]{String.valueOf(zombieLimit), var2});
  224.             zombies.remove(0);
  225.             removeClassLoaderInfo(var2);
  226.             var2.clearLoaderRef();
  227.          }
  228.       } else {
  229.          removeClassLoaderInfo(var0);
  230.       }
  231.  
  232.       assert checkListsValidity();
  233.  
  234.    }
  235.  
  236.    synchronized AppletClassLoader getLoader() {
  237.       Object var1 = null;
  238.       if (this.loaderRef != null) {
  239.          var1 = (AppletClassLoader)this.loaderRef.get();
  240.       }
  241.  
  242.       if (var1 == null) {
  243.          var1 = (PluginClassLoader)AccessController.doPrivileged(new 1(this));
  244.          this.loaderRef = new LoaderReference(this, (ClassLoader)var1);
  245.          this.jars.clear();
  246.          this.localJarsLoaded = false;
  247.       }
  248.  
  249.       return (AppletClassLoader)var1;
  250.    }
  251.  
  252.    private synchronized void clearLoaderRef() {
  253.       if (this.loaderRef != null) {
  254.          this.loaderRef.clear();
  255.          this.loaderRef = null;
  256.       }
  257.  
  258.    }
  259.  
  260.    private static synchronized void cleanupZombies() {
  261.       for(LoaderReference var0 = (LoaderReference)refQueue.poll(); var0 != null; var0 = (LoaderReference)refQueue.poll()) {
  262.          String var1 = var0.getKey();
  263.          ArrayList var2 = (ArrayList)infos.get(var1);
  264.          if (var2 != null) {
  265.             for(ClassLoaderInfo var5 : (ArrayList)var2.clone()) {
  266.                if (var5.loaderRef == var0 && zombies.contains(var5)) {
  267.                   var2.remove(var5);
  268.                   zombies.remove(var5);
  269.                }
  270.             }
  271.          }
  272.       }
  273.  
  274.    }
  275.  
  276.    private ClassLoaderInfo(URL var1, String var2) {
  277.       this.codebase = var1;
  278.       this.key = var2;
  279.       this.jars = new HashMap();
  280.    }
  281.  
  282.    synchronized void addJar(String var1) {
  283.       this.jars.put(var1, var1);
  284.    }
  285.  
  286.    synchronized boolean hasJar(String var1) {
  287.       return this.jars.get(var1) != null;
  288.    }
  289.  
  290.    public boolean getLocalJarsLoaded() {
  291.       return this.localJarsLoaded;
  292.    }
  293.  
  294.    public void setLocalJarsLoaded(boolean var1) {
  295.       this.localJarsLoaded = var1;
  296.    }
  297.  
  298.    public final synchronized void lock() throws InterruptedException {
  299.       while(this.locked) {
  300.          this.wait();
  301.       }
  302.  
  303.       this.locked = true;
  304.    }
  305.  
  306.    public final synchronized void unlock() {
  307.       this.locked = false;
  308.       this.notifyAll();
  309.    }
  310.  
  311.    public static synchronized boolean checkListsValidity() {
  312.       Object var0 = null;
  313.  
  314.       for(ArrayList var3 : infos.values()) {
  315.          if (var3 != null) {
  316.             int var4 = 0;
  317.  
  318.             for(ClassLoaderInfo var6 : var3) {
  319.                if (var6 != null && var6.isCachable) {
  320.                   ++var4;
  321.                }
  322.             }
  323.  
  324.             if (var4 > 1) {
  325.                return false;
  326.             }
  327.          }
  328.       }
  329.  
  330.       for(ClassLoaderInfo var7 : zombies) {
  331.          if (var7 != null && !var7.isCachable) {
  332.             return false;
  333.          }
  334.       }
  335.  
  336.       return true;
  337.    }
  338.  
  339.    // $FF: synthetic method
  340.    static URL access$000(ClassLoaderInfo var0) {
  341.       return var0.codebase;
  342.    }
  343.  
  344.    // $FF: synthetic method
  345.    static ReferenceQueue access$100() {
  346.       return refQueue;
  347.    }
  348.  
  349.    // $FF: synthetic method
  350.    static String access$200(ClassLoaderInfo var0) {
  351.       return var0.key;
  352.    }
  353. }
  354.