Top Description Inners Fields Constructors Methods
net.bytebuddy.agent

public Class ByteBuddyAgent

extends Object
Class Inheritance
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, net.bytebuddy.agent.utility.nullability.AlwaysNull, .MaybeNull, java.io.*, java.lang.instrument.Instrumentation, java.lang.reflect.InvocationTargetException, .Method, java.net.MalformedURLException, .URISyntaxException, .URL, .URLClassLoader, java.security.CodeSource, .PrivilegedAction, .ProtectionDomain, java.util.*, java.util.jar.*

The Byte Buddy agent provides a JVM java.lang.instrument.Instrumentation in order to allow Byte Buddy the redefinition of already loaded classes. An agent must normally be specified via the command line via the javaagent parameter. As an argument to this parameter, one must specify the location of this agent's jar file such as for example in

java -javaagent:byte-buddy-agent.jar -jar app.jar

Note

The runtime installation of a Java agent is not possible on all JVMs. See the documentation for ByteBuddyAgent#install() for details on JVMs that are supported out of the box.

Important Note

This class's name is known to the Byte Buddy main application and must not be altered.

Note

Byte Buddy does not execute code using an java.security.AccessController. If a security manager is present, the user of this class is responsible for assuring any required privileges. To read an Instrumentation, the net.bytebuddy.agent.getInstrumentation runtime permission is required.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static interface
ByteBuddyAgent.AgentProvider

An agent provider is responsible for handling and providing the jar file of an agent that is being attached.

public static interface
ByteBuddyAgent.AttachmentProvider

An attachment provider is responsible for making the Java attachment API available.

protected static interface
ByteBuddyAgent.AttachmentTypeEvaluator

An attachment evaluator is responsible for deciding if an agent can be attached from the current process.

public static interface
ByteBuddyAgent.ProcessProvider

A process provider is responsible for providing the process id of the current VM.

Field Summary

Modifier and TypeField and Description
private static final String
AGENT_ARGUMENT_SEPARATOR

The character that is used to mark the beginning of the argument to the agent.

private static final String
AGENT_CLASS_PROPERTY

The manifest property specifying the agent class.

private static final String
ATTACHER_FILE_NAME

The naming prefix of all artifacts for an attacher jar.

private static final ByteBuddyAgent.AttachmentTypeEvaluator
ATTACHMENT_TYPE_EVALUATOR

The attachment type evaluator to be used for determining if an attachment requires an external process.

private static final ClassLoader
BOOTSTRAP_CLASS_LOADER

Representation of the bootstrap java.lang.ClassLoader.

private static final int
BUFFER_SIZE

The size of the buffer for copying the agent installer file into another jar.

private static final String
CAN_REDEFINE_CLASSES_PROPERTY

The manifest property specifying the can redefine property.

private static final String
CAN_RETRANSFORM_CLASSES_PROPERTY

The manifest property specifying the can retransform property.

private static final String
CAN_SET_NATIVE_METHOD_PREFIX

The manifest property specifying the can set native method prefix property.

private static final File
CANNOT_SELF_RESOLVE

Represents a failed attempt to self-resolve a jar file location.

private static final String
CLASS_FILE_EXTENSION

The file extension for a class file.

private static final String
CLASS_PATH_ARGUMENT

The class path argument to specify the class path elements.

private static final int
END_OF_FILE

Convenience indices for reading and writing to the buffer to make the code more readable.

private static final String
FILE_PROTOCOL

Represents the file URL protocol.

private static final String
INSTRUMENTATION_METHOD

The name of the method for reading the installer's instrumentation.

private static final String
JAR_FILE_EXTENSION

The file extension for a jar file.

private static final String
JAVA_HOME

The Java property denoting the Java home directory.

public static final String
LATENT_RESOLVE

Indicates that the agent should not resolve its own code location for a self-attachment.

private static final String
MANIFEST_VERSION_VALUE

The manifest property value for the manifest version.

private static final String
OS_NAME

The Java property denoting the operating system name.

private static final int
START_INDEX

Convenience indices for reading and writing to the buffer to make the code more readable.

private static final int
SUCCESSFUL_ATTACH

The status code expected as a result of a successful attachment.

private static final Instrumentation
UNAVAILABLE

An indicator variable to express that no instrumentation is available.

private static final String
WITHOUT_ARGUMENT

Represents a no-op argument for a dynamic agent attachment.

Constructor Summary

AccessConstructor and Description
private
ByteBuddyAgent()

The agent provides only static utility methods and should not be instantiated.

Method Summary

Modifier and TypeMethod and Description
public static void
attach(File
The agent jar file.
agentJar
,
String
The target process id.
processId
)

Attaches the given agent Jar on the target process which must be a virtual machine process.

public static void
attach(File
The agent jar file.
agentJar
,
String
The target process id.
processId
,
String
The argument to provide to the agent.
argument
)

Attaches the given agent Jar on the target process which must be a virtual machine process.

public static void
attach(File
The agent jar file.
agentJar
,
String
The target process id.
processId
,
ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
)

Attaches the given agent Jar on the target process which must be a virtual machine process.

public static void
attach(File
The agent jar file.
agentJar
,
String
The target process id.
processId
,
String
The argument to provide to the agent.
argument
,
ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
)

Attaches the given agent Jar on the target process which must be a virtual machine process.

public static void
attach(File
The agent jar file.
agentJar
,
ByteBuddyAgent.ProcessProvider
A provider of the target process id.
processProvider
)

Attaches the given agent Jar on the target process which must be a virtual machine process.

public static void
attach(File
The agent jar file.
agentJar
,
ByteBuddyAgent.ProcessProvider
A provider of the target process id.
processProvider
,
String
The argument to provide to the agent.
argument
)

Attaches the given agent Jar on the target process which must be a virtual machine process.

public static void
attach(File
The agent jar file.
agentJar
,
ByteBuddyAgent.ProcessProvider
A provider of the target process id.
processProvider
,
ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
)

Attaches the given agent Jar on the target process which must be a virtual machine process.

public static void
attach(File
The agent jar file.
agentJar
,
ByteBuddyAgent.ProcessProvider
A provider of the target process id.
processProvider
,
String
The argument to provide to the agent.
argument
,
ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
)

Attaches the given agent Jar on the target process which must be a virtual machine process.

public static void
attachNative(File
The agent jar file.
agentLibrary
,
String
The target process id.
processId
)

Attaches the given agent library on the target process which must be a virtual machine process.

public static void
attachNative(File
The agent library.
agentLibrary
,
String
The target process id.
processId
,
String
The argument to provide to the agent.
argument
)

Attaches the given agent library on the target process which must be a virtual machine process.

public static void
attachNative(File
The agent library.
agentLibrary
,
String
The target process id.
processId
,
ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
)

Attaches the given agent library on the target process which must be a virtual machine process.

public static void
attachNative(File
The agent library.
agentLibrary
,
String
The target process id.
processId
,
String
The argument to provide to the agent.
argument
,
ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
)

Attaches the given agent library on the target process which must be a virtual machine process.

public static void
attachNative(File
The agent library.
agentLibrary
,
ByteBuddyAgent.ProcessProvider
A provider of the target process id.
processProvider
)

Attaches the given agent library on the target process which must be a virtual machine process.

public static void
attachNative(File
The agent library.
agentLibrary
,
ByteBuddyAgent.ProcessProvider
A provider of the target process id.
processProvider
,
String
The argument to provide to the agent.
argument
)

Attaches the given agent library on the target process which must be a virtual machine process.

public static void
attachNative(File
The agent library.
agentLibrary
,
ByteBuddyAgent.ProcessProvider
A provider of the target process id.
processProvider
,
ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
)

Attaches the given agent library on the target process which must be a virtual machine process.

public static void
attachNative(File
The agent library.
agentLibrary
,
ByteBuddyAgent.ProcessProvider
A provider of the target process id.
processProvider
,
String
The argument to provide to the agent.
argument
,
ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
)

Attaches the given agent library on the target process which must be a virtual machine process.

private static Instrumentation

Returns:

The Byte Buddy agent's java.lang.instrument.Instrumentation instance.
doGetInstrumentation
()

Performs the actual lookup of the java.lang.instrument.Instrumentation from an installed Byte Buddy agent and returns the instance, or returns null if not present.

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 Instrumentation

Returns:

The java.lang.instrument.Instrumentation instance which is provided by an installed Byte Buddy agent.
getInstrumentation
()

Looks up the java.lang.instrument.Instrumentation instance of an installed Byte Buddy agent.

public static Instrumentation

Returns:

An instrumentation instance representing the currently running JVM.
install
()

Installs an agent on the currently running Java virtual machine.

public static Instrumentation

Returns:

An instrumentation instance representing the currently running JVM.
install
(ByteBuddyAgent.AttachmentProvider
The attachment provider to use for the installation.
attachmentProvider
)

Installs an agent on the currently running Java virtual machine using the supplied attachment provider.

public static Instrumentation

Returns:

An instrumentation instance representing the currently running JVM.
install
(ByteBuddyAgent.ProcessProvider
The provider for the current JVM's process id.
processProvider
)

Installs an agent on the Java virtual machine resolved by the process provider.

public static synchronized Instrumentation

Returns:

An instrumentation instance representing the currently running JVM.
install
(ByteBuddyAgent.AttachmentProvider
The attachment provider to use for the installation.
attachmentProvider
,
ByteBuddyAgent.ProcessProvider
The provider for the current JVM's process id.
processProvider
)

Installs an agent on the currently running Java virtual machine using the supplied attachment provider and process provider.

private static void
install(ByteBuddyAgent.AttachmentProvider
The attachment provider to use.
attachmentProvider
,
String
The process id of the target JVM process.
processId
,
String
The argument to provide to the agent.
argument
,
ByteBuddyAgent.AgentProvider
The agent provider for the agent jar or library.
agentProvider
,
boolean
true if the agent is native.
isNative
)

Installs a Java agent on a target VM.

private static void
installExternal(ByteBuddyAgent.AttachmentProvider.Accessor.ExternalAttachment
A description of the external attachment.
externalAttachment
,
String
The process id of the current process.
processId
,
File
The Java agent to install.
agent
,
boolean
true if the agent is native.
isNative
,
String
The argument to provide to the agent or null if no argument should be supplied.
argument
)

Installs a Java agent to the current VM via an external process.

private static File

Returns:

The self-resolved jar file or null if the jar file cannot be located.
trySelfResolve
()

Attempts to resolve the location of the Attacher class for a self-attachment.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait