Top Description Inners Fields Constructors Methods
net.bytebuddy.dynamic

public Class NexusAccessor

extends Object
Class Inheritance
Annotations
@Enhance
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, net.bytebuddy.build.AccessControllerPlugin, .HashCodeAndEqualsPlugin, net.bytebuddy.description.method.MethodDescription, net.bytebuddy.description.type.TypeDescription, net.bytebuddy.dynamic.loading.ClassInjector, .ClassLoadingStrategy, net.bytebuddy.implementation.Implementation, .LoadedTypeInitializer, net.bytebuddy.implementation.bytecode.ByteCodeAppender, .Removal, .StackManipulation, net.bytebuddy.implementation.bytecode.collection.ArrayFactory, net.bytebuddy.implementation.bytecode.constant.ClassConstant, .IntegerConstant, .NullConstant, .TextConstant, net.bytebuddy.implementation.bytecode.member.MethodInvocation, net.bytebuddy.utility.JavaModule, net.bytebuddy.utility.nullability.MaybeNull, net.bytebuddy.jar.asm.MethodVisitor, java.lang.ref.Reference, .ReferenceQueue, java.lang.reflect.InvocationTargetException, .Method, java.security.PrivilegedAction, java.util.Arrays, .Collections

The Nexus accessor is creating a VM-global singleton Nexus such that it can be seen by all class loaders of a virtual machine. Furthermore, it provides an API to access this global instance.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static interface
NexusAccessor.Dispatcher

A dispatcher for registering type initializers in the Nexus.

public static class
NexusAccessor.InitializationAppender

An initialization appender that looks up a loaded type initializer from Byte Buddy's Nexus.

Field Summary

Modifier and TypeField and Description
private static final NexusAccessor.Dispatcher
DISPATCHER

The dispatcher to use.

private final ReferenceQueue<? super ClassLoader>
referenceQueue

The reference queue that is notified upon a GC eligible Nexus entry or null if no such queue should be notified.

Constructor Summary

AccessConstructor and Description
public
NexusAccessor()

Creates a new accessor for the Nexus without any active management of stale references within a nexus.

public
NexusAccessor(ReferenceQueue<? super ClassLoader>
The reference queue onto which stale references should be enqueued or null if no reference queue should be notified.
referenceQueue
)

Creates a new accessor for a Nexus where any GC eligible are enqueued to the supplied reference queue.

Method Summary

Modifier and TypeMethod and Description
public static void
clean(Reference<? extends ClassLoader>
The reference to remove. References are collected via a reference queue that is supplied to the NexusAccessor.
reference
)

Removes a stale entries that are registered in the Nexus.

private static <
The type of the action's resolved value.
T
>
T

Returns:

The action's resolved value.
doPrivileged
(PrivilegedAction<T>
The action to execute from a privileged context.
action
)

A proxy for java.security.AccessController#doPrivileged that is activated if available.

public static boolean

Returns:

true if this accessor is alive.
isAlive
()

Checks if this NexusAccessor is capable of registering loaded type initializers.

public void
register(String
The binary name of the class.
name
,
ClassLoader
The class's class loader.
classLoader
,
int
The id used for identifying the loaded type initializer that was added to the Nexus.
identification
,
LoadedTypeInitializer
The loaded type initializer to make available via the Nexus.
loadedTypeInitializer
)

Registers a loaded type initializer in Byte Buddy's Nexus which is injected into the system class loader.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DISPATCHERback to summary
private static final NexusAccessor.Dispatcher DISPATCHER

The dispatcher to use.

referenceQueueback to summary
private final ReferenceQueue<? super ClassLoader> referenceQueue

The reference queue that is notified upon a GC eligible Nexus entry or null if no such queue should be notified.

Annotations
@MaybeNull
@ValueHandling:REVERSE_NULLABILITY

Constructor Detail

NexusAccessorback to summary
public NexusAccessor()

Creates a new accessor for the Nexus without any active management of stale references within a nexus.

NexusAccessorback to summary
public NexusAccessor(ReferenceQueue<? super ClassLoader> referenceQueue)

Creates a new accessor for a Nexus where any GC eligible are enqueued to the supplied reference queue. Any such enqueued reference can be explicitly removed from the nexus via the NexusAccessor#clean(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:ReferenceQueue<? super ClassLoader>

The reference queue onto which stale references should be enqueued or null if no reference queue should be notified.

Method Detail

cleanback to summary
public static void clean(Reference<? extends ClassLoader> reference)

Removes a stale entries that are registered in the Nexus. 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:Reference<? extends ClassLoader>

The reference to remove. References are collected via a reference queue that is supplied to the NexusAccessor.

doPrivilegedback to summary
private static <T> T doPrivileged(PrivilegedAction<T> action)

A proxy for java.security.AccessController#doPrivileged that is activated if available.

Parameters
<T>
The type of the action's resolved value.
action:PrivilegedAction<T>

The action to execute from a privileged context.

Returns:T

The action's resolved value.

Annotations
@Enhance
isAliveback to summary
public static boolean isAlive()

Checks if this NexusAccessor is capable of registering loaded type initializers.

Returns:boolean

true if this accessor is alive.

registerback to summary
public void register(String name, ClassLoader classLoader, int identification, LoadedTypeInitializer loadedTypeInitializer)

Registers a loaded type initializer in Byte Buddy's Nexus which is injected into the system class loader.

Parameters
name:String

The binary name of the class.

classLoader:ClassLoader

The class's class loader.

identification:int

The id used for identifying the loaded type initializer that was added to the Nexus.

loadedTypeInitializer:LoadedTypeInitializer

The loaded type initializer to make available via the Nexus.

net.bytebuddy.dynamic back to summary

protected Interface NexusAccessor.Dispatcher

Known Direct Implementers
net.bytebuddy.dynamic.NexusAccessor.Dispatcher.Available, net.bytebuddy.dynamic.NexusAccessor.Dispatcher.Unavailable

A dispatcher for registering type initializers in the Nexus.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
NexusAccessor.Dispatcher.Available

An enabled dispatcher for registering a type initializer in a Nexus.

public static enum
NexusAccessor.Dispatcher.CreationAction

Creates a new dispatcher for accessing a Nexus.

public static class
NexusAccessor.Dispatcher.Unavailable

A disabled dispatcher where a Nexus is not available.

Method Summary

Modifier and TypeMethod and Description
public void
clean(Reference<? extends ClassLoader>
The reference to remove.
reference
)

Cleans any dead entries of the system class loader's Nexus.

public boolean

Returns:

true if this dispatcher is alive.
isAlive
()

Returns true if this dispatcher is alive.

public void
register(String
The name of a type for which a loaded type initializer is registered.
name
,
ClassLoader
The class loader for which a loaded type initializer is registered.
classLoader
,
ReferenceQueue<? super ClassLoader>
A reference queue to notify about stale nexus entries or null if no queue should be referenced.
referenceQueue
,
int
An identification for the initializer to run.
identification
,
LoadedTypeInitializer
The loaded type initializer to be registered.
loadedTypeInitializer
)

Registers a type initializer with the system class loader's nexus.

Method Detail

cleanback to summary
public void clean(Reference<? extends ClassLoader> reference)

Cleans any dead entries of the system class loader's Nexus.

Parameters
reference:Reference<? extends ClassLoader>

The reference to remove.

isAliveback to summary
public boolean isAlive()

Returns true if this dispatcher is alive.

Returns:boolean

true if this dispatcher is alive.

registerback to summary
public void register(String name, ClassLoader classLoader, ReferenceQueue<? super ClassLoader> referenceQueue, int identification, LoadedTypeInitializer loadedTypeInitializer)

Registers a type initializer with the system class loader's nexus.

Parameters
name:String

The name of a type for which a loaded type initializer is registered.

classLoader:ClassLoader

The class loader for which a loaded type initializer is registered.

referenceQueue:ReferenceQueue<? super ClassLoader>

A reference queue to notify about stale nexus entries or null if no queue should be referenced.

identification:int

An identification for the initializer to run.

loadedTypeInitializer:LoadedTypeInitializer

The loaded type initializer to be registered.

net.bytebuddy.dynamic back to summary

public Class NexusAccessor.Dispatcher.Available

extends Object
implements Dispatcher
Class Inheritance
All Implemented Interfaces
net.bytebuddy.dynamic.NexusAccessor.Dispatcher
Annotations
@Enhance

An enabled dispatcher for registering a type initializer in a Nexus.

Field Summary

Modifier and TypeField and Description
private final Method
private final Method

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
clean(Reference<? extends ClassLoader>
The reference to remove.
reference
)

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.clean.

Cleans any dead entries of the system class loader's Nexus.
public boolean
isAlive()

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.isAlive.

Returns true if this dispatcher is alive.
public void
register(String
The name of a type for which a loaded type initializer is registered.
name
,
ClassLoader
The class loader for which a loaded type initializer is registered.
classLoader
,
ReferenceQueue<? super ClassLoader>
A reference queue to notify about stale nexus entries or null if no queue should be referenced.
referenceQueue
,
int
An identification for the initializer to run.
identification
,
LoadedTypeInitializer
The loaded type initializer to be registered.
loadedTypeInitializer
)

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.register.

Registers a type initializer with the system class loader's nexus.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cleanback to summary
private final Method clean

The Nexus#clean(Reference) method.

registerback to summary
private final Method register

The Nexus#register(String, ClassLoader, ReferenceQueue, int, Object) method.

Constructor Detail

Availableback to summary
protected Available(Method register, Method clean)

Creates a new dispatcher.

Parameters
register:Method

The Nexus#register(String, ClassLoader, ReferenceQueue, int, Object) method.

clean:Method

The Nexus#clean(Reference) method.

Method Detail

cleanback to summary
public void clean(Reference<? extends ClassLoader> reference)

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.clean.

Doc from net.bytebuddy.dynamic.NexusAccessor.Dispatcher.clean.

Cleans any dead entries of the system class loader's Nexus.

Parameters
reference:Reference<? extends ClassLoader>

The reference to remove.

isAliveback to summary
public boolean isAlive()

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.isAlive.

Doc from net.bytebuddy.dynamic.NexusAccessor.Dispatcher.isAlive.

Returns true if this dispatcher is alive.

Returns:boolean

true if this dispatcher is alive.

registerback to summary
public void register(String name, ClassLoader classLoader, ReferenceQueue<? super ClassLoader> referenceQueue, int identification, LoadedTypeInitializer loadedTypeInitializer)

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.register.

Doc from net.bytebuddy.dynamic.NexusAccessor.Dispatcher.register.

Registers a type initializer with the system class loader's nexus.

Parameters
name:String

The name of a type for which a loaded type initializer is registered.

classLoader:ClassLoader

The class loader for which a loaded type initializer is registered.

referenceQueue:ReferenceQueue<? super ClassLoader>

A reference queue to notify about stale nexus entries or null if no queue should be referenced.

identification:int

An identification for the initializer to run.

loadedTypeInitializer:LoadedTypeInitializer

The loaded type initializer to be registered.

net.bytebuddy.dynamic back to summary

public final Enum NexusAccessor.Dispatcher.CreationAction

extends Enum<NexusAccessor.Dispatcher.CreationAction>
implements PrivilegedAction<NexusAccessor.Dispatcher>
Class Inheritance
All Implemented Interfaces
java.security.PrivilegedAction

Creates a new dispatcher for accessing a Nexus.

Field Summary

Modifier and TypeField and Description
public static final NexusAccessor.Dispatcher.CreationAction
INSTANCE

The singleton instance.

Constructor Summary

AccessConstructor and Description
private

Field Detail

INSTANCEback to summary
public static final NexusAccessor.Dispatcher.CreationAction INSTANCE

The singleton instance.

Constructor Detail

CreationActionback to summary
private CreationAction()

Method Detail

runback to summary
public NexusAccessor.Dispatcher run()

Implements java.security.PrivilegedAction.run.

Doc from java.security.PrivilegedAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:NexusAccessor.Dispatcher

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedAction should document what (if anything) this value represents.

Annotations
@SuppressFBWarnings:REC_CATCH_EXCEPTION
justification:Exception should not be rethrown but trigger a fallback.
valueOfback to summary
public static NexusAccessor.Dispatcher.CreationAction valueOf(String name)
valuesback to summary
public static NexusAccessor.Dispatcher.CreationAction[] values()
net.bytebuddy.dynamic back to summary

public Class NexusAccessor.Dispatcher.Unavailable

extends Object
implements Dispatcher
Class Inheritance
All Implemented Interfaces
net.bytebuddy.dynamic.NexusAccessor.Dispatcher
Annotations
@Enhance

A disabled dispatcher where a Nexus is not available.

Field Summary

Modifier and TypeField and Description
private final String
message

The reason for the dispatcher being unavailable.

Constructor Summary

AccessConstructor and Description
protected
Unavailable(String
The reason for the dispatcher being unavailable.
message
)

Creates a new unavailable dispatcher.

Method Summary

Modifier and TypeMethod and Description
public void
clean(Reference<? extends ClassLoader>
The reference to remove.
reference
)

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.clean.

Cleans any dead entries of the system class loader's Nexus.
public boolean
isAlive()

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.isAlive.

Returns true if this dispatcher is alive.
public void
register(String
The name of a type for which a loaded type initializer is registered.
name
,
ClassLoader
The class loader for which a loaded type initializer is registered.
classLoader
,
ReferenceQueue<? super ClassLoader>
A reference queue to notify about stale nexus entries or null if no queue should be referenced.
referenceQueue
,
int
An identification for the initializer to run.
identification
,
LoadedTypeInitializer
The loaded type initializer to be registered.
loadedTypeInitializer
)

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.register.

Registers a type initializer with the system class loader's nexus.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

messageback to summary
private final String message

The reason for the dispatcher being unavailable.

Constructor Detail

Unavailableback to summary
protected Unavailable(String message)

Creates a new unavailable dispatcher.

Parameters
message:String

The reason for the dispatcher being unavailable.

Method Detail

cleanback to summary
public void clean(Reference<? extends ClassLoader> reference)

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.clean.

Doc from net.bytebuddy.dynamic.NexusAccessor.Dispatcher.clean.

Cleans any dead entries of the system class loader's Nexus.

Parameters
reference:Reference<? extends ClassLoader>

The reference to remove.

isAliveback to summary
public boolean isAlive()

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.isAlive.

Doc from net.bytebuddy.dynamic.NexusAccessor.Dispatcher.isAlive.

Returns true if this dispatcher is alive.

Returns:boolean

true if this dispatcher is alive.

registerback to summary
public void register(String name, ClassLoader classLoader, ReferenceQueue<? super ClassLoader> referenceQueue, int identification, LoadedTypeInitializer loadedTypeInitializer)

Implements net.bytebuddy.dynamic.NexusAccessor.Dispatcher.register.

Doc from net.bytebuddy.dynamic.NexusAccessor.Dispatcher.register.

Registers a type initializer with the system class loader's nexus.

Parameters
name:String

The name of a type for which a loaded type initializer is registered.

classLoader:ClassLoader

The class loader for which a loaded type initializer is registered.

referenceQueue:ReferenceQueue<? super ClassLoader>

A reference queue to notify about stale nexus entries or null if no queue should be referenced.

identification:int

An identification for the initializer to run.

loadedTypeInitializer:LoadedTypeInitializer

The loaded type initializer to be registered.

net.bytebuddy.dynamic back to summary

public Class NexusAccessor.InitializationAppender

extends Object
implements ByteCodeAppender
Class Inheritance
All Implemented Interfaces
net.bytebuddy.implementation.bytecode.ByteCodeAppender
Annotations
@Enhance

An initialization appender that looks up a loaded type initializer from Byte Buddy's Nexus.

Field Summary

Modifier and TypeField and Description
private final int
identification

The id used for identifying the loaded type initializer that was added to the Nexus.

Constructor Summary

AccessConstructor and Description
public
InitializationAppender(int
The id used for identifying the loaded type initializer that was added to the Nexus.
identification
)

Creates a new initialization appender.

Method Summary

Modifier and TypeMethod and Description
public ByteCodeAppender.Size
apply(MethodVisitor
The method visitor to which the byte code appender writes its code to.
methodVisitor
,
Implementation.Context
The implementation context of the current type creation process.
implementationContext
,
MethodDescription
The method that is the target of the instrumentation.
instrumentedMethod
)

Implements net.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Applies this byte code appender to a type creation process.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

identificationback to summary
private final int identification

The id used for identifying the loaded type initializer that was added to the Nexus.

Constructor Detail

InitializationAppenderback to summary
public InitializationAppender(int identification)

Creates a new initialization appender.

Parameters
identification:int

The id used for identifying the loaded type initializer that was added to the Nexus.

Method Detail

applyback to summary
public ByteCodeAppender.Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod)

Implements net.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Doc from net.bytebuddy.implementation.bytecode.ByteCodeAppender.apply.

Applies this byte code appender to a type creation process.

Parameters
methodVisitor:MethodVisitor

The method visitor to which the byte code appender writes its code to.

implementationContext:Implementation.Context

The implementation context of the current type creation process.

instrumentedMethod:MethodDescription

The method that is the target of the instrumentation.

Returns:ByteCodeAppender.Size

The required size for the applied byte code to run.