You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BcelWeakClassLoaderReference.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* *******************************************************************
  2. * Copyright (c) 2008 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Andy Clement initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import org.aspectj.apache.bcel.util.ClassLoaderReference;
  14. import org.aspectj.weaver.WeakClassLoaderReference;
  15. /**
  16. * Wraps a reference to a classloader inside a WeakReference. This should be used where we do not want the existence of a
  17. * classloader reference to prevent garbage collection of that classloader (and possibly an associated weaver instance in the case
  18. * of load time weaving).
  19. * <p>
  20. * In more detail:<br>
  21. * When load time weaving, the class Aj maintains a WeakHashMap from the classloader instance to a weaver instance. The aim is that
  22. * the weaver is around as long as the classloader is and should the classloader be dereferenced then the weaver can also be garbage
  23. * collected. The problem is that if there are many references to the classloader from within the weaver, these are considered hard
  24. * references and cause the classloader to be long lived - even if the user of the classloader has dereferenced it in their code.
  25. * The solution is that the weaver should use instances of WeakClassLoaderReference objects - so that when the users hard reference
  26. * to the classloader goes, nothing in the weaver will cause it to hang around. There is a big assertion here that the
  27. * WeakClassLoaderReference instances will not 'lose' their ClassLoader references until the top level ClassLoader reference is
  28. * null'd. This means there is no need to check for the null case on get() in this WeakReference logic below, because we shouldn't
  29. * be using this weaver if its associated ClassLoader has been collected. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=210470
  30. *
  31. *
  32. * @author Andy Clement
  33. */
  34. public class BcelWeakClassLoaderReference extends WeakClassLoaderReference implements ClassLoaderReference {
  35. public BcelWeakClassLoaderReference(ClassLoader loader) {
  36. super(loader);
  37. }
  38. public boolean equals(Object obj) {
  39. if (!(obj instanceof BcelWeakClassLoaderReference))
  40. return false;
  41. BcelWeakClassLoaderReference other = (BcelWeakClassLoaderReference) obj;
  42. return (other.hashcode == hashcode);
  43. }
  44. }