Package net.bytebuddy.dynamic
Class NexusAccessor
- java.lang.Object
-
- net.bytebuddy.dynamic.NexusAccessor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceNexusAccessor.DispatcherA dispatcher for registering type initializers in theNexus.static classNexusAccessor.InitializationAppenderAn initialization appender that looks up a loaded type initializer from Byte Buddy'sNexus.
-
Field Summary
Fields Modifier and Type Field Description private static NexusAccessor.DispatcherDISPATCHERThe dispatcher to use.private java.lang.ref.ReferenceQueue<? super java.lang.ClassLoader>referenceQueueThe reference queue that is notified upon a GC eligibleNexusentry ornullif no such queue should be notified.
-
Constructor Summary
Constructors Constructor Description NexusAccessor()Creates a new accessor for theNexuswithout any active management of stale references within a nexus.NexusAccessor(java.lang.ref.ReferenceQueue<? super java.lang.ClassLoader> referenceQueue)Creates a new accessor for aNexuswhere any GC eligible are enqueued to the supplied reference queue.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidclean(java.lang.ref.Reference<? extends java.lang.ClassLoader> reference)Removes a stale entries that are registered in theNexus.private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.static booleanisAlive()Checks if thisNexusAccessoris capable of registering loaded type initializers.voidregister(java.lang.String name, java.lang.ClassLoader classLoader, int identification, LoadedTypeInitializer loadedTypeInitializer)Registers a loaded type initializer in Byte Buddy'sNexuswhich is injected into the system class loader.
-
-
-
Field Detail
-
DISPATCHER
private static final NexusAccessor.Dispatcher DISPATCHER
The dispatcher to use.
-
referenceQueue
@MaybeNull @ValueHandling(REVERSE_NULLABILITY) private final java.lang.ref.ReferenceQueue<? super java.lang.ClassLoader> referenceQueue
The reference queue that is notified upon a GC eligibleNexusentry ornullif no such queue should be notified.
-
-
Constructor Detail
-
NexusAccessor
public NexusAccessor()
Creates a new accessor for theNexuswithout any active management of stale references within a nexus.
-
NexusAccessor
public NexusAccessor(@MaybeNull java.lang.ref.ReferenceQueue<? super java.lang.ClassLoader> referenceQueue)
Creates a new accessor for aNexuswhere any GC eligible are enqueued to the supplied reference queue. Any such enqueued reference can be explicitly removed from the nexus via theclean(Reference)method. Nexus entries can become stale if a class loader is garbage collected after a class was loaded but before a class was initialized.- Parameters:
referenceQueue- The reference queue onto which stale references should be enqueued ornullif no reference queue should be notified.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.- Type Parameters:
T- The type of the action's resolved value.- Parameters:
action- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
isAlive
public static boolean isAlive()
Checks if thisNexusAccessoris capable of registering loaded type initializers.- Returns:
trueif this accessor is alive.
-
clean
public static void clean(java.lang.ref.Reference<? extends java.lang.ClassLoader> reference)
Removes a stale entries that are registered in theNexus. Entries can become stale if a class is loaded but never initialized prior to its garbage collection. As all class loaders within a nexus are only referenced weakly, such class loaders are always garbage collected. However, the initialization data stored by Byte Buddy does not become eligible which is why it needs to be cleaned explicitly.- Parameters:
reference- The reference to remove. References are collected via a reference queue that is supplied to theNexusAccessor.
-
register
public void register(java.lang.String name, @MaybeNull java.lang.ClassLoader classLoader, int identification, LoadedTypeInitializer loadedTypeInitializer)Registers a loaded type initializer in Byte Buddy'sNexuswhich is injected into the system class loader.
-
-