| Modifier and Type | Class and Description |
|---|---|
| private static class | InstrumentationImpl.
Holder for StackWalker object. |
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| private final boolean | |
| private volatile boolean | |
| private volatile boolean | |
| private final long | |
| private TransformerManager | |
| private final TransformerManager | |
| private static final boolean | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| private | InstrumentationImpl(long nativeAgent, boolean environmentSupportsRedefineClasses, boolean environmentSupportsNativeMethodPrefix, boolean printWarning)
|
| Modifier and Type | Method and Description |
|---|---|
| public void | addTransformer(ClassFileTransformer transformer)
Implements java. Registers the supplied transformer. |
| public void | addTransformer(ClassFileTransformer transformer, boolean canRetransform)
Implements java. Registers the supplied transformer. |
| public void | appendToBootstrapClassLoaderSearch(JarFile jarfile)
Implements java. Specifies a JAR file with instrumentation classes to be defined by the bootstrap class loader. |
| private native void | |
| public void | appendToSystemClassLoaderSearch(JarFile jarfile)
Implements java. Specifies a JAR file with instrumentation classes to be defined by the system class loader. |
| private Map | |
| private static URL | |
| private TransformerManager | |
| public Class | getAllLoadedClasses()
Implements java. Returns an array of all classes currently loaded by the JVM. |
| private native Class | |
| public Class | getInitiatedClasses(ClassLoader loader)
Implements java. Returns an array of all classes which |
| private native Class | |
| public long | getObjectSize(Object objectToSize)
Implements java. Returns an implementation-specific approximation of the amount of storage consumed by the specified object. |
| private native long | |
| public boolean | isModifiableClass(Class<?> theClass)
Implements java. Tests whether a class is modifiable by retransformation or redefinition. |
| private native boolean | |
| public boolean | isModifiableModule(Module module)
Implements java. Tests whether a module can be modified with |
| public boolean | isNativeMethodPrefixSupported()
Implements java. Returns whether the current JVM configuration supports setting a native method prefix. |
| public boolean | isRedefineClassesSupported()
Implements java. Returns whether or not the current JVM configuration supports redefinition of classes. |
| public boolean | isRetransformClassesSupported()
Implements java. Returns whether or not the current JVM configuration supports retransformation of classes. |
| private native boolean | |
| private native String | |
| public static void | |
| private static native void | |
| private void | |
| private void | |
| private void | |
| public void | redefineClasses(ClassDefinition... definitions)
Implements java. Redefine the supplied set of classes using the supplied class files. |
| private native void | |
| public void | redefineModule(Module module, Set<Module> extraReads, Map<String, Set<Module>> extraExports, Map<String, Set<Module>> extraOpens, Set<Class<?>> extraUses, Map<Class<?>, List<Class<?>>> extraProvides)
Implements java. Redefine a module to expand the set of modules that it reads, the set of packages that it exports or opens, or the services that it uses or provides. |
| public boolean | removeTransformer(ClassFileTransformer transformer)
Implements java. Unregisters the supplied transformer. |
| public void | retransformClasses(Class<?>... classes)
Implements java. Retransform the supplied set of classes. |
| private native void | |
| private native void | |
| private native void | |
| public void | setNativeMethodPrefix(ClassFileTransformer transformer, String prefix)
Implements java. This method modifies the failure handling of native method resolution by allowing retry with a prefix applied to the name. |
| private native void | |
| private void | |
| private byte[] | transform(Module module, ClassLoader loader, String classname, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer, boolean isRetransformer)
|
| mEnvironmentSupportsNativeMethodPrefix | back to summary |
|---|---|
| private final boolean mEnvironmentSupportsNativeMethodPrefix | |
| mEnvironmentSupportsRedefineClasses | back to summary |
|---|---|
| private final boolean mEnvironmentSupportsRedefineClasses | |
| mEnvironmentSupportsRetransformClasses | back to summary |
|---|---|
| private volatile boolean mEnvironmentSupportsRetransformClasses | |
| mEnvironmentSupportsRetransformClassesKnown | back to summary |
|---|---|
| private volatile boolean mEnvironmentSupportsRetransformClassesKnown | |
| mNativeAgent | back to summary |
|---|---|
| private final long mNativeAgent | |
| mRetransfomableTransformerManager | back to summary |
|---|---|
| private TransformerManager mRetransfomableTransformerManager | |
| mTransformerManager | back to summary |
|---|---|
| private final TransformerManager mTransformerManager | |
| TRACE_USAGE | back to summary |
|---|---|
| private static final boolean TRACE_USAGE | |
| TRACE_USAGE_PROP_NAME | back to summary |
|---|---|
| private static final String TRACE_USAGE_PROP_NAME | |
| InstrumentationImpl | back to summary |
|---|---|
| private InstrumentationImpl(long nativeAgent, boolean environmentSupportsRedefineClasses, boolean environmentSupportsNativeMethodPrefix, boolean printWarning) | |
| addTransformer | back to summary |
|---|---|
| public void addTransformer(ClassFileTransformer transformer) Implements java. Doc from java. Registers the supplied transformer.
Same as
| |
| addTransformer | back to summary |
|---|---|
| public void addTransformer(ClassFileTransformer transformer, boolean canRetransform) Implements java. Doc from java. Registers the supplied transformer. All future class definitions
will be seen by the transformer, except definitions of classes upon which any
registered transformer is dependent.
The transformer is called when classes are loaded, when they are
redefined. and if This method is intended for use in instrumentation, as described in the class specification.
| |
| appendToBootstrapClassLoaderSearch | back to summary |
|---|---|
| public void appendToBootstrapClassLoaderSearch(JarFile jarfile) Implements java. Doc from java. Specifies a JAR file with instrumentation classes to be defined by the bootstrap class loader. When the virtual machine's built-in class loader, known as the "bootstrap
class loader", unsuccessfully searches for a class, the entries in the This method may be used multiple times to add multiple JAR files to be searched in the order that this method was invoked. The agent should take care to ensure that the JAR does not contain any
classes or resources other than those to be defined by the bootstrap
class loader for the purpose of instrumentation.
Failure to observe this warning could result in unexpected
behavior that is difficult to diagnose. For example, suppose there is a
loader L, and L's parent for delegation is the bootstrap class loader.
Furthermore, a method in class C, a class defined by L, makes reference to
a non-public accessor class C$1. If the JAR file contains a class C$1 then
the delegation to the bootstrap class loader will cause C$1 to be defined
by the bootstrap class loader. In this example an The Java Virtual Machine Specification specifies that a subsequent attempt to resolve a symbolic reference that the Java virtual machine has previously unsuccessfully attempted to resolve always fails with the same error that was thrown as a result of the initial resolution attempt. Consequently, if the JAR file contains an entry that corresponds to a class for which the Java virtual machine has unsuccessfully attempted to resolve a reference, then subsequent attempts to resolve that reference will fail with the same error as the initial attempt.
| |
| appendToClassLoaderSearch0 | back to summary |
|---|---|
| private native void appendToClassLoaderSearch0(long nativeAgent, String jarfile, boolean bootLoader) | |
| appendToSystemClassLoaderSearch | back to summary |
|---|---|
| public void appendToSystemClassLoaderSearch(JarFile jarfile) Implements java. Doc from java. Specifies a JAR file with instrumentation classes to be defined by the
system class loader.
When the system class loader for delegation (see
This method may be used multiple times to add multiple JAR files to be searched in the order that this method was invoked. The agent should take care to ensure that the JAR does not contain any
classes or resources other than those to be defined by the system class
loader for the purpose of instrumentation.
Failure to observe this warning could result in unexpected
behavior that is difficult to diagnose (see
The system class loader supports adding a JAR file to be searched if
it implements a method named The Java Virtual Machine Specification specifies that a subsequent attempt to resolve a symbolic reference that the Java virtual machine has previously unsuccessfully attempted to resolve always fails with the same error that was thrown as a result of the initial resolution attempt. Consequently, if the JAR file contains an entry that corresponds to a class for which the Java virtual machine has unsuccessfully attempted to resolve a reference, then subsequent attempts to resolve that reference will fail with the same error as the initial attempt. This method does not change the value of
| |
| cloneAndCheckMap | back to summary |
|---|---|
| private Map | |
| codeSource | back to summary |
|---|---|
| private static URL codeSource(Class<?> clazz) Returns the possibly-bnull code source of the given class. | |
| findTransformerManager | back to summary |
|---|---|
| private TransformerManager findTransformerManager(ClassFileTransformer transformer) | |
| getAllLoadedClasses | back to summary |
|---|---|
| public Class Implements java. Doc from java. Returns an array of all classes currently loaded by the JVM. The returned array includes all classes and interfaces, including hidden classes or interfaces, and array classes of all types.
| |
| getAllLoadedClasses0 | back to summary |
|---|---|
private native Class
| |
| getInitiatedClasses | back to summary |
|---|---|
| public Class Implements java. Doc from java. Returns an array of all classes which The returned array does not include hidden classes or interfaces or array classes whose element type is a hidden class or interface. as they cannot be discovered by any class loader.
| |
| getInitiatedClasses0 | back to summary |
|---|---|
private native Class
| |
| getObjectSize | back to summary |
|---|---|
| public long getObjectSize(Object objectToSize) Implements java. Doc from java. Returns an implementation-specific approximation of the amount of storage consumed by the specified object. The result may include some or all of the object's overhead, and thus is useful for comparison within an implementation but not between implementations. The estimate may change during a single invocation of the JVM.
| |
| getObjectSize0 | back to summary |
|---|---|
private native long getObjectSize0(long nativeAgent, Object objectToSize)
| |
| isModifiableClass | back to summary |
|---|---|
| public boolean isModifiableClass(Class<?> theClass) Implements java. Doc from java. Tests whether a class is modifiable by
retransformation
or redefinition.
If a class is modifiable then this method returns
For a class to be retransformed,
Primitive classes (for example,
| |
| isModifiableClass0 | back to summary |
|---|---|
| private native boolean isModifiableClass0(long nativeAgent, Class<?> theClass) | |
| isModifiableModule | back to summary |
|---|---|
| public boolean isModifiableModule(Module module) Implements java. Doc from java. Tests whether a module can be modified with
| |
| isNativeMethodPrefixSupported | back to summary |
|---|---|
| public boolean isNativeMethodPrefixSupported() Implements java. Doc from java. Returns whether the current JVM configuration supports
setting a native method prefix.
The ability to set a native method prefix is an optional
capability of a JVM.
Setting a native method prefix will only be supported if the
| |
| isRedefineClassesSupported | back to summary |
|---|---|
| public boolean isRedefineClassesSupported() Implements java. Doc from java. Returns whether or not the current JVM configuration supports redefinition
of classes.
The ability to redefine an already loaded class is an optional capability
of a JVM.
Redefinition will only be supported if the
| |
| isRetransformClassesSupported | back to summary |
|---|---|
| public boolean isRetransformClassesSupported() Implements java. Doc from java. Returns whether or not the current JVM configuration supports retransformation
of classes.
The ability to retransform an already loaded class is an optional capability
of a JVM.
Retransformation will only be supported if the
| |
| isRetransformClassesSupported0 | back to summary |
|---|---|
| private native boolean isRetransformClassesSupported0(long nativeAgent) | |
| jarFile | back to summary |
|---|---|
| private native String jarFile(long nativeAgent) | |
| loadAgent | back to summary |
|---|---|
| public static void loadAgent(String path) Invoked by the java launcher to load a java agent that is packaged with the main application in an executable JAR file. | |
| loadAgent0 | back to summary |
|---|---|
| private static native void loadAgent0(String path) | |
| loadClassAndCallAgentmain | back to summary |
|---|---|
| private void loadClassAndCallAgentmain(String classname, String optionsString) throws Throwable | |
| loadClassAndCallPremain | back to summary |
|---|---|
| private void loadClassAndCallPremain(String classname, String optionsString) throws Throwable | |
| loadClassAndStartAgent | back to summary |
|---|---|
| private void loadClassAndStartAgent(String classname, String methodname, String optionsString) throws Throwable | |
| redefineClasses | back to summary |
|---|---|
| public void redefineClasses(ClassDefinition... definitions) throws ClassNotFoundException Implements java. Doc from java. Redefine the supplied set of classes using the supplied class files.
This method is used to replace the definition of a class without reference
to the existing class file bytes, as one might do when recompiling from source
for fix-and-continue debugging.
Where the existing class file bytes are to be transformed (for
example in bytecode instrumentation)
This method operates on a set in order to allow interdependent changes to more than one class at the same time (a redefinition of class A can require a redefinition of class B). If a redefined method has active stack frames, those active frames continue to run the bytecodes of the original method. The redefined method will be used on new invokes. This method does not cause any initialization except that which would occur under the customary JVM semantics. In other words, redefining a class does not cause its initializers to be run. The values of static variables will remain as they were prior to the call. Instances of the redefined class are not affected. The supported class file changes are described in JVM TI RedefineClasses. The class file bytes are not checked, verified and installed until after the transformations have been applied, if the resultant bytes are in error this method will throw an exception. If this method throws an exception, no classes have been redefined. This method is intended for use in instrumentation, as described in the class specification.
| |
| redefineClasses0 | back to summary |
|---|---|
| private native void redefineClasses0(long nativeAgent, ClassDefinition[] definitions) throws ClassNotFoundException | |
| redefineModule | back to summary |
|---|---|
| public void redefineModule(Module module, Set<Module> extraReads, Map<String, Set<Module>> extraExports, Map<String, Set<Module>> extraOpens, Set<Class<?>> extraUses, Map<Class<?>, List<Class<?>>> extraProvides) Implements java. Doc from java. Redefine a module to expand the set of modules that it reads, the set of packages that it exports or opens, or the services that it uses or provides. This method facilitates the instrumentation of code in named modules where that instrumentation requires changes to the set of modules that are read, the packages that are exported or open, or the services that are used or provided. This method cannot reduce the set of modules that a module reads, nor reduce the set of packages that it exports or opens, nor reduce the set of services that it uses or provides. This method is a no-op when invoked to redefine an unnamed module. When expanding the services that a module uses or provides then the onus is on the agent to ensure that the service type will be accessible at each instrumentation site where the service type is used. This method does not check if the service type is a member of the module or in a package exported to the module by another module that it reads. The The This method is safe for concurrent use and so allows multiple agents to instrument and update the same module at around the same time.
| |
| removeTransformer | back to summary |
|---|---|
| public boolean removeTransformer(ClassFileTransformer transformer) Implements java. Doc from java. Unregisters the supplied transformer. Future class definitions will not be shown to the transformer. Removes the most-recently-added matching instance of the transformer. Due to the multi-threaded nature of class loading, it is possible for a transformer to receive calls after it has been removed. Transformers should be written defensively to expect this situation.
| |
| retransformClasses | back to summary |
|---|---|
| public void retransformClasses(Class<?>... classes) Implements java. Doc from java. Retransform the supplied set of classes.
This function facilitates the instrumentation
of already loaded classes.
When classes are initially loaded or when they are
redefined,
the initial class file bytes can be transformed with the
The order of transformation is described in
The initial class file bytes represent the bytes passed to
This method operates on a set in order to allow interdependent changes to more than one class at the same time (a retransformation of class A can require a retransformation of class B). If a retransformed method has active stack frames, those active frames continue to run the bytecodes of the original method. The retransformed method will be used on new invokes. This method does not cause any initialization except that which would occur under the customary JVM semantics. In other words, redefining a class does not cause its initializers to be run. The values of static variables will remain as they were prior to the call. Instances of the retransformed class are not affected. The supported class file changes are described in JVM TI RetransformClasses. The class file bytes are not checked, verified and installed until after the transformations have been applied, if the resultant bytes are in error this method will throw an exception. If this method throws an exception, no classes have been retransformed. This method is intended for use in instrumentation, as described in the class specification.
| |
| retransformClasses0 | back to summary |
|---|---|
| private native void retransformClasses0(long nativeAgent, Class<?>[] classes) | |
| setHasRetransformableTransformers | back to summary |
|---|---|
| private native void setHasRetransformableTransformers(long nativeAgent, boolean has) | |
| setHasTransformers | back to summary |
|---|---|
| private native void setHasTransformers(long nativeAgent, boolean has) | |
| setNativeMethodPrefix | back to summary |
|---|---|
| public void setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) Implements java. Doc from java. This method modifies the failure handling of
native method resolution by allowing retry
with a prefix applied to the name.
When used with the
Since native methods cannot be directly instrumented (they have no bytecodes), they must be wrapped with a non-native method which can be instrumented. For example, if we had: native boolean foo(int x); We could transform the class file (with the ClassFileTransformer during the initial definition of the class) so that this becomes:
boolean foo(int x) {
... record entry to foo ...
return wrapped_foo(x);
}
native boolean wrapped_foo(int x);
Where
The wrapper will allow data to be collected on the native
method call, but now the problem becomes linking up the
wrapped method with the native implementation.
That is, the method Java_somePackage_someClass_foo(JNIEnv* env, jint x)
This function allows the prefix to be specified and the
proper resolution to occur.
Specifically, when the standard resolution fails, the
resolution is retried taking the prefix into consideration.
There are two ways that resolution occurs, explicit
resolution with the JNI function
When this fails, the resolution will be retried with the specified prefix prepended to the method name, yielding the correct resolution:
For automatic resolution, the JVM will attempt:
When this fails, the resolution will be retried with the specified prefix deleted from the implementation name, yielding the correct resolution:
Note that since the prefix is only used when standard resolution fails, native methods can be wrapped selectively.
Since each
| |
| setNativeMethodPrefixes | back to summary |
|---|---|
| private native void setNativeMethodPrefixes(long nativeAgent, String[] prefixes, boolean isRetransformable) | |
| trace | back to summary |
|---|---|
| private void trace(String methodName) Prints a trace message and stack trace when tracing is enabled. | |
| transform | back to summary |
|---|---|
| private byte[] transform(Module module, ClassLoader loader, String classname, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer, boolean isRetransformer) | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final StackWalker |
| Access | Constructor and Description |
|---|---|
| private |
| walker | back to summary |
|---|---|
| pack-priv static final StackWalker walker | |
| HolderStackWalker | back to summary |
|---|---|
| private HolderStackWalker() | |