Top Description Inners Fields Constructors Methods
org.aspectj.weaver.loadtime

public Class Aj

extends Object
implements ClassPreProcessor
Class Inheritance
All Implemented Interfaces
org.aspectj.weaver.loadtime.ClassPreProcessor
Imports
java.lang.ref.Reference, .ReferenceQueue, .WeakReference, java.security.ProtectionDomain, java.util.ArrayList, .Collections, .HashMap, .List, .Map, .Set, .StringTokenizer, org.aspectj.bridge.context.CompilationAndWeavingContext, org.aspectj.weaver.Dump, org.aspectj.weaver.tools.Trace, .TraceFactory, .WeavingAdaptor, org.aspectj.weaver.tools.cache.SimpleCache, .SimpleCacheFactory

Adapter between the generic class pre processor interface and the AspectJ weaver Load time weaving consistency relies on Bcel.setRepository
Author
Alexandre Vasseur (alex AT gnilux DOT com)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Aj.AdaptorKey

An AdaptorKey is a WeakReference wrapping a classloader reference that will enqueue to a specified queue when the classloader is GC'd.

pack-priv static class
pack-priv static class
Aj.WeaverContainer

Cache of weaver There is one weaver per classloader

Field Summary

Modifier and TypeField and Description
private static ReferenceQueue<ClassLoader>
adaptorQueue

References are added to this queue when their associated classloader is removed, and once on here that indicates that we should tidy up the adaptor map and remove the adaptor (weaver) from the map we are maintaining from adaptorkey > adaptor (weaver)

private static final String
private static final String
public static SimpleCache
public static List<String>
private static Trace
private IWeavingContext

Constructor Summary

AccessConstructor and Description
public
Aj()

public

Method Summary

Modifier and TypeMethod and Description
public static void
checkQ()

Process the reference queue that contains stale AdaptorKeys - the keys are put on the queue when their classloader referent is garbage collected and so the associated adaptor (weaver) should be removed from the map

public void
public boolean

Returns:

true if classes have been generated.
generatedClassesExist
(ClassLoader
the class cloder
loader
)

Check to see if any classes have been generated for a particular classes loader.

public static int

Returns:

the number of entries still in the weavingAdaptors map
getActiveAdaptorCount
()

public String
getNamespace(ClassLoader loader)

Returns a namespace based on the contest of the aspects available

public void
public void
public byte[]
preProcess(String className, byte[] bytes, ClassLoader loader, ProtectionDomain protectionDomain)

Implements org.aspectj.weaver.loadtime.ClassPreProcessor.preProcess.

public static int

Returns:

number of stale weavers removed
removeStaleAdaptors
(boolean
produce System.err info on the tidying up process
displayProgress
)

The reference queue is only processed when a request is made for a weaver adaptor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

adaptorQueueback to summary
private static ReferenceQueue<ClassLoader> adaptorQueue

References are added to this queue when their associated classloader is removed, and once on here that indicates that we should tidy up the adaptor map and remove the adaptor (weaver) from the map we are maintaining from adaptorkey > adaptor (weaver)

deleLoaderback to summary
private static final String deleLoader
deleLoader2back to summary
private static final String deleLoader2
laCacheback to summary
public static SimpleCache laCache
loadersToSkipback to summary
public static List<String> loadersToSkip
traceback to summary
private static Trace trace
weavingContextback to summary
private IWeavingContext weavingContext

Constructor Detail

Ajback to summary
public Aj()
Ajback to summary
public Aj(IWeavingContext context)

Method Detail

checkQback to summary
public static void checkQ()

Process the reference queue that contains stale AdaptorKeys - the keys are put on the queue when their classloader referent is garbage collected and so the associated adaptor (weaver) should be removed from the map

flushGeneratedClassesback to summary
public void flushGeneratedClasses(ClassLoader loader)
generatedClassesExistback to summary
public boolean generatedClassesExist(ClassLoader loader)

Check to see if any classes have been generated for a particular classes loader. Calls ClassLoaderWeavingAdaptor.generatedClassesExist()

Parameters
loader:ClassLoader

the class cloder

Returns:boolean

true if classes have been generated.

getActiveAdaptorCountback to summary
public static int getActiveAdaptorCount()
Returns:int

the number of entries still in the weavingAdaptors map

getNamespaceback to summary
public String getNamespace(ClassLoader loader)

Returns a namespace based on the contest of the aspects available

initializeback to summary
public void initialize()

Implements org.aspectj.weaver.loadtime.ClassPreProcessor.initialize.

Initialization

Annotations
@Override
prepareForRedefinitionback to summary
public void prepareForRedefinition(ClassLoader loader, String className)

Implements org.aspectj.weaver.loadtime.ClassPreProcessor.prepareForRedefinition.

Annotations
@Override
preProcessback to summary
public byte[] preProcess(String className, byte[] bytes, ClassLoader loader, ProtectionDomain protectionDomain)

Implements org.aspectj.weaver.loadtime.ClassPreProcessor.preProcess.

Annotations
@Override
removeStaleAdaptorsback to summary
public static int removeStaleAdaptors(boolean displayProgress)

The reference queue is only processed when a request is made for a weaver adaptor. This means there can be one or two stale weavers left around. If the user knows they have finished all their weaving, they might wish to call removeStaleAdaptors which will process anything left on the reference queue containing adaptorKeys for garbage collected classloaders.

Parameters
displayProgress:boolean

produce System.err info on the tidying up process

Returns:int

number of stale weavers removed

org.aspectj.weaver.loadtime back to summary

private Class Aj.AdaptorKey

extends WeakReference
Class Inheritance

An AdaptorKey is a WeakReference wrapping a classloader reference that will enqueue to a specified queue when the classloader is GC'd. Since the AdaptorKey is used as a key into a hashmap we need to give it a non-varying hashcode/equals implementation, and we need that hashcode not to vary even when the internal referent has been GC'd. The hashcode is calculated on creation of the AdaptorKey based on the loader instance that it is wrapping. This means even when the referent is gone we can still use the AdaptorKey and it will 'point' to the same place as it always did.

Field Summary

Modifier and TypeField and Description
private final int
private final String
private final int
private final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public ClassLoader
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.

Field Detail

hashValueback to summary
private final int hashValue
loaderClassback to summary
private final String loaderClass
loaderHashCodeback to summary
private final int loaderHashCode
sysHashCodeback to summary
private final int sysHashCode

Constructor Detail

AdaptorKeyback to summary
public AdaptorKey(ClassLoader loader)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getClassLoaderback to summary
public ClassLoader getClassLoader()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
org.aspectj.weaver.loadtime back to summary

pack-priv Class Aj.ExplicitlyInitializedClassLoaderWeavingAdaptor

extends Object
Class Inheritance
  • java.lang.Object
  • org.aspectj.weaver.loadtime.Aj.ExplicitlyInitializedClassLoaderWeavingAdaptor

Field Summary

Modifier and TypeField and Description
private boolean
private final ClassLoaderWeavingAdaptor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ClassLoaderWeavingAdaptor
private void
initialize(ClassLoader loader, IWeavingContext weavingContext)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

isInitializedback to summary
private boolean isInitialized
weavingAdaptorback to summary
private final ClassLoaderWeavingAdaptor weavingAdaptor

Constructor Detail

ExplicitlyInitializedClassLoaderWeavingAdaptorback to summary
public ExplicitlyInitializedClassLoaderWeavingAdaptor(ClassLoaderWeavingAdaptor weavingAdaptor)

Method Detail

getWeavingAdaptorback to summary
public ClassLoaderWeavingAdaptor getWeavingAdaptor(ClassLoader loader, IWeavingContext weavingContext)
initializeback to summary
private void initialize(ClassLoader loader, IWeavingContext weavingContext)
org.aspectj.weaver.loadtime back to summary

pack-priv Class Aj.WeaverContainer

extends Object
Class Inheritance

Cache of weaver There is one weaver per classloader

Field Summary

Modifier and TypeField and Description
private static final ClassLoader
private static Aj.ExplicitlyInitializedClassLoaderWeavingAdaptor
pack-priv static final Map<Aj.AdaptorKey, Aj.ExplicitlyInitializedClassLoaderWeavingAdaptor>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static WeavingAdaptor
getWeaver(ClassLoader loader, IWeavingContext weavingContext)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

myClassLoaderback to summary
private static final ClassLoader myClassLoader
myClassLoaderAdaptorback to summary
private static Aj.ExplicitlyInitializedClassLoaderWeavingAdaptor myClassLoaderAdaptor
weavingAdaptorsback to summary
pack-priv static final Map<Aj.AdaptorKey, Aj.ExplicitlyInitializedClassLoaderWeavingAdaptor> weavingAdaptors

Constructor Detail

WeaverContainerback to summary
pack-priv WeaverContainer()

Method Detail

getWeaverback to summary
pack-priv static WeavingAdaptor getWeaver(ClassLoader loader, IWeavingContext weavingContext)