ClassFileTransformer
Retransformer
public class Transformer extends Object implements ClassFileTransformer
Modifier and Type | Field | Description |
---|---|---|
static String |
ALLOW_CONFIG_UPDATE |
system property which determines whether or not byteman configuration can be updated at runtime
via the byteman agent listener
|
static String |
BYTEMAN_PACKAGE_PREFIX |
prefix for byteman package
|
static String |
BYTEMAN_SAMPLE_PACKAGE_PREFIX |
prefix for byteman sample package
|
static String |
BYTEMAN_TEST_PACKAGE_PREFIX |
prefix for byteman test package
|
protected CheckerCache |
checkerCache |
|
static String |
COMPILE_TO_BYTECODE |
system property set (to any value) in order to switch on compilation of rules and left unset
if rules are to be interpreted.
|
static String |
COMPILE_TO_BYTECODE_COMPATIBILITY |
retained for compatibility
|
static String |
DEBUG |
system property set (to any value) in order to switch on debug statements in the default Helper
|
static String |
DISALLOW_DOWNCAST |
system property which disables downcasts in bindings
|
static String |
DUMP_CFG |
system property set (to any value) in order to switch on dumping of control flow graph for
triger method after construction
|
static String |
DUMP_CFG_PARTIAL |
system property set (to any value) in order to switch on dumping of control flow graph for
trigger method at each stage of construction
|
static String |
DUMP_GENERATED_CLASSES |
system property set (to any value) in order to switch on dumping of generated bytecode to .class files
|
static String |
DUMP_GENERATED_CLASSES_DIR |
system property identifying directory in which to dump generated bytecode .class files
|
static String |
DUMP_GENERATED_CLASSES_INTERMEDIATE |
system property set (to any value) in order to switch on dumping of intermediate generated bytecode to .class files
|
protected HelperManager |
helperManager |
a manager for helper lifecycle events which can be safely handed on to rules
|
protected Instrumentation |
inst |
the instrumentation interface to the JVM
|
protected boolean |
isRedefine |
true if the instrumentor allows redefinition
|
static String |
JAVA_LANG_PACKAGE_PREFIX |
prefix for org.jboss package
|
protected ScriptRepository |
scriptRepository |
a mapping from target class names which appear in rules to a script object holding the
rule details
|
static String |
SKIP_OVERRIDE_RULES |
system property which turns off injection into overriding methods
|
static String |
SYSPROPS_STRICT_MODE |
system property which enables the restriction that only byteman specific system properties
will be gettable/settable via a client using the LISTSYSPROPS and SETSYSPROPS commands.
|
static String |
TRANSFORM_ALL |
system property set to true in order to enable transform of java.lang classes
|
static String |
TRANSFORM_ALL_COMPATIBILITY |
retained for compatibility
|
static String |
VERBOSE |
system property set (to any value) in order to switch on dumping of generated bytecode to .class files
|
static String |
VERIFY_TRANSFORMED_BYTES |
system property which enables the restriction that only byteman specific system properties
will be gettable/settable via a client using the LISTSYSPROPS and SETSYSPROPS commands.
|
Constructor | Description |
---|---|
Transformer(Instrumentation inst,
ModuleSystem moduleSystem,
List<String> scriptPaths,
List<String> scriptTexts,
boolean isRedefine) |
constructor allowing this transformer to be provided with access to the JVM's instrumentation
implementation
|
Modifier and Type | Method | Description |
---|---|---|
static boolean |
allowConfigUpdate() |
check whether changes to org.jboss.byteman.* system properties will affect the agent configuration.
|
static boolean |
computeDumpGeneratedClasses() |
|
static String |
computeDumpGeneratedClassesDir() |
|
static boolean |
computeDumpGeneratedClassesIntermediate() |
|
static boolean |
disableTriggers(boolean isUser) |
disable triggering of rules inside the current thread
|
static boolean |
disallowDowncast() |
check whether downcasts in bindings are disallowed.
|
protected void |
dumpScript(RuleScript ruleScript) |
|
static boolean |
enableTriggers(boolean isReset) |
enable triggering of rules inside the current thread
|
ClassChecker |
getClassChecker(String name,
ClassLoader baseLoader) |
return a checker object which can be used to retrieve the super and interfaces of a class from its name and
classloader without forcing a load of the class.
|
protected static String |
getDumpGeneratedClassesDir() |
|
void |
installBootScripts() |
ensure that scripts which apply to classes loaded before
registering the transformer are installed by retransforming the
relevant classes
|
void |
installPolicy() |
|
boolean |
isBlacklisted(String triggerClassName,
String targetMethodName,
String targetDescriptor) |
check whether we are unwilling to inject into a given target method
|
static boolean |
isBytemanClass(String className) |
test whether a class with a given name is located in the byteman package
|
static boolean |
isCompileToBytecode() |
check whether compilation of rules is enabled or disabled
|
static boolean |
isDebug() |
check whether debug mode for rule processing is enabled or disabled
|
static boolean |
isDumpCFG() |
check whether dumping of the control flow graph for the trigger class is enabled
|
static boolean |
isDumpCFGPartial() |
check whether dumping of the control flow graph for the trigger class during construction is enabled
|
protected static boolean |
isDumpGeneratedClasses() |
|
protected static boolean |
isDumpGeneratedClassesIntermediate() |
|
protected boolean |
isSkipClass(Class<?> clazz) |
check whether a class should not be considered for transformation
|
protected boolean |
isTransformable(String className) |
test whether a class with a given name is a potential candidate for insertion of event notifications
|
static boolean |
isTriggeringEnabled() |
check if triggering of rules is enabled inside the current thread
|
static boolean |
isVerbose() |
check whether verbose mode for rule processing is enabled or disabled
|
static void |
maybeDumpClass(String fullName,
byte[] bytes) |
|
static void |
maybeDumpClassIntermediate(String fullName,
byte[] bytes) |
|
boolean |
skipOverrideRules() |
check whether compilation of rules is enabled or disabled
|
byte[] |
transform(ClassLoader originalLoader,
String className,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,
byte[] classfileBuffer) |
The implementation of this method may transform the supplied class file and
return a new replacement class file.
|
byte[] |
transform(RuleScript ruleScript,
ClassLoader loader,
String className,
byte[] targetClassBytes) |
The routine which actually does the real bytecode transformation.
|
void |
updateConfiguration(String property) |
notify a change to an org.jboss.byteman.* system property so that the agent can choose to update its
configuration.
|
transform
public static final String BYTEMAN_PACKAGE_PREFIX
public static final String BYTEMAN_TEST_PACKAGE_PREFIX
public static final String BYTEMAN_SAMPLE_PACKAGE_PREFIX
public static final String JAVA_LANG_PACKAGE_PREFIX
public static final String VERBOSE
public static final String DUMP_CFG_PARTIAL
public static final String DUMP_CFG
public static final String DEBUG
public static final String COMPILE_TO_BYTECODE_COMPATIBILITY
public static final String COMPILE_TO_BYTECODE
public static final String DUMP_GENERATED_CLASSES
public static final String DUMP_GENERATED_CLASSES_INTERMEDIATE
public static final String DUMP_GENERATED_CLASSES_DIR
public static final String TRANSFORM_ALL
public static final String TRANSFORM_ALL_COMPATIBILITY
public static final String SKIP_OVERRIDE_RULES
public static final String SYSPROPS_STRICT_MODE
public static final String VERIFY_TRANSFORMED_BYTES
public static final String ALLOW_CONFIG_UPDATE
public static final String DISALLOW_DOWNCAST
protected final Instrumentation inst
protected boolean isRedefine
protected final ScriptRepository scriptRepository
protected final CheckerCache checkerCache
protected final HelperManager helperManager
public Transformer(Instrumentation inst, ModuleSystem moduleSystem, List<String> scriptPaths, List<String> scriptTexts, boolean isRedefine) throws Exception
inst
- the instrumentation object used to interface to the JVMscriptPaths
- list of file paths for each input scriptscriptTexts
- the text of each input scriptisRedefine
- true if class redefinition is allowed false if notmoduleSystem
- the module system to use in transformationException
- if a script is in errorpublic void installBootScripts() throws Exception
Exception
- if the retransform failspublic void installPolicy()
public byte[] transform(ClassLoader originalLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException
Instrumentation.addTransformer
,
the transformer will be called for every new class definition and every class redefinition.
The request for a new class definition is made with
ClassLoader.defineClass
.
The request for a class redefinition is made with
Instrumentation.redefineClasses
or its native equivalents.
The transformer is called during the processing of the request, before the class file bytes
have been verified or applied.
If the implementing method determines that no transformations are needed,
it should return null
.
Otherwise, it should create a new byte[]
array,
copy the input classfileBuffer
into it,
along with all desired transformations, and return the new array.
The input classfileBuffer
must not be modified.
In the redefine case, the transformer must support the redefinition semantics.
If a class that the transformer changed during initial definition is later redefined, the
transformer must insure that the second class output class file is a legal
redefinition of the first output class file.
If the transformer believes the classFileBuffer
does not
represent a validly formatted class file, it should throw
an IllegalClassFormatException
. Subsequent transformers
will still be called and the load or redefine will still
be attempted. Throwing an IllegalClassFormatException
thus
has the same effect as returning null but facilitates the
logging or debugging of format corruptions.transform
in interface ClassFileTransformer
originalLoader
- the defining loader of the class to be transformed,
may be null
if the bootstrap loaderclassName
- the name of the class in the internal form of fully
qualified class and interface names as defined in
The Java Virtual Machine Specification.
For example, "java/util/List"
.classBeingRedefined
- if this is a redefine, the class being redefined,
otherwise null
protectionDomain
- the protection domain of the class being defined or redefinedclassfileBuffer
- the input byte buffer in class file format - must not be modifiednull
if no transform is performed.IllegalClassFormatException
- if the input does not represent a well-formed class fileInstrumentation.redefineClasses(java.lang.instrument.ClassDefinition...)
public static boolean disableTriggers(boolean isUser)
isUser
- true if this was called by rule code false if called internally by Bytemanpublic static boolean enableTriggers(boolean isReset)
isReset
- true if this was called by rule code and hence should reset a setting
enabled by rule code false if called internally by Byteman and hence
should nto reset a setting enabled by rule codepublic static boolean isTriggeringEnabled()
public static boolean isVerbose()
public static boolean isDumpCFG()
public static boolean isDumpCFGPartial()
protected static boolean isDumpGeneratedClasses()
protected static String getDumpGeneratedClassesDir()
protected static boolean isDumpGeneratedClassesIntermediate()
public static boolean isDebug()
public static boolean isCompileToBytecode()
public static boolean disallowDowncast()
public boolean skipOverrideRules()
public static boolean allowConfigUpdate()
public void updateConfiguration(String property)
property
- an org.jboss.byteman.* system property which has been updated.protected boolean isTransformable(String className)
className
- name of the class to testpublic static void maybeDumpClassIntermediate(String fullName, byte[] bytes)
public static void maybeDumpClass(String fullName, byte[] bytes)
public byte[] transform(RuleScript ruleScript, ClassLoader loader, String className, byte[] targetClassBytes)
ruleScript
- the scriptloader
- the loader of the class being injected intoclassName
- the name of the class being injected intotargetClassBytes
- the current class bytecodeprotected boolean isSkipClass(Class<?> clazz)
clazz
- the class to checkprotected void dumpScript(RuleScript ruleScript)
public ClassChecker getClassChecker(String name, ClassLoader baseLoader)
name
- the name of the superclass being checkedbaseLoader
- the class loader of the subclass's bytecodepublic boolean isBlacklisted(String triggerClassName, String targetMethodName, String targetDescriptor)
triggerClassName
- the name of the target classtargetMethodName
- the name of the target methodtargetDescriptor
- the descriptor of the target method ignored at presentpublic static boolean isBytemanClass(String className)
className
- the name to be checkedpublic static boolean computeDumpGeneratedClasses()
public static boolean computeDumpGeneratedClassesIntermediate()
public static String computeDumpGeneratedClassesDir()
Copyright © 2018. All rights reserved.