Package org.jboss.byteman.agent
Class TransformContext
java.lang.Object
org.jboss.byteman.agent.TransformContext
Class used to localise the context information employed when creating a rule from a rule script and
using it to transform a method
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
private exception class used to throw our way out of the ASM adapter code back into the transform method at the top level. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AccessEnabler
private boolean
private Rule
private HelperManager
private static final String
pattern used to identify target method specs which include a return type preceding the method name and parameter type list.private ClassLoader
a hashmap indexing Rule instances using key classname.methodnameandsig@loaderhashcode.private RuleScript
private String
private String
static final String
private Transformer
private String
-
Constructor Summary
ConstructorsConstructorDescriptionTransformContext
(Transformer transformer, RuleScript ruleScript, String triggerClassName, ClassLoader loader, HelperManager helperManager, AccessEnabler accessEnabler) -
Method Summary
Modifier and TypeMethodDescriptioncreateRule
(String triggerMethodName, String triggerMethodDescriptor) called by a check adapter to create a rule specific to a given trigger method.void
called by a check or trigger adapter to fail a transform because of a type issue.findLeastCommonSuper
(String t1, String t2) private String
return the trigger method descriptor used to construct the supplied rule keyprivate String
return the trigger method name used to construct the supplied rule keyprivate org.objectweb.asm.ClassWriter
getNonLoadingClassWriter
(int flags) get a class writer which will not attempt to load classes.private String
getRuleKey
(String triggerMethodName, String triggerMethodDescriptor) return a unique string key identifying a specific rule compiled against some class and method/signature in the context of a specific class loaderboolean
injectIntoMethod
(String name, String desc) private LinkedList
<String> listInterfaces
(ClassChecker checker) private LinkedList
<String> listSupers
(ClassChecker checker) lookupRule
(String triggerMethodName, String triggerMethodDescriptor) called by a trigger adapter to find a rule specific to a given trigger method, expects to find a rule created by the corresponding check adapter.boolean
matchTargetMethod
(int access, String name, String desc) private String
mungeMethodSpecReturnType
(String targetMethodSpec) detect a method specification which includes a return type preceding the method name and transform it so that the return type is at the end.private boolean
this gets called when a transform attempt completes without any exceptions.void
private void
this gets called when a transform attempt fails.void
byte[]
transform
(byte[] targetClassBytes) void
called by a check adapter to warn that a transform was not possible for a potential match target.
-
Field Details
-
JAVA_METHOD_SPEC_PATTERN
pattern used to identify target method specs which include a return type preceding the method name and parameter type list. note that we can only handle a return type in cases where the parameter type list is also specified.- See Also:
-
TOFU
- See Also:
-
transformer
-
ruleScript
-
triggerClassName
-
targetMethodName
-
targetDescriptor
-
loader
-
helperManager
-
accessEnabler
-
failed
private boolean failed -
ruleMap
a hashmap indexing Rule instances using key classname.methodnameandsig@loaderhashcode. rules are added to this map when they are created and removed when the transform is recorded as having succeeded or failed. a method check adapter will create a rule when it begins a method scan and a method trigger adpater will look it up in order to reuse it -
firstRule
-
-
Constructor Details
-
TransformContext
public TransformContext(Transformer transformer, RuleScript ruleScript, String triggerClassName, ClassLoader loader, HelperManager helperManager, AccessEnabler accessEnabler)
-
-
Method Details
-
transform
public byte[] transform(byte[] targetClassBytes) -
parseRule
- Throws:
Exception
-
lookupRule
called by a trigger adapter to find a rule specific to a given trigger method, expects to find a rule created by the corresponding check adapter. if no rule is found then injection must be bypassed for this method- Parameters:
triggerMethodName
- the name of a candidate method for injectiontriggerMethodDescriptor
- the descriptor of a candidate method for injection- Returns:
- the rule if it exists or NULL if not
-
createRule
called by a check adapter to create a rule specific to a given trigger method. the first such call reuses the rule created by the intiial parse. subsequent calls create a new rule.- Parameters:
triggerMethodName
- the name of a candidate method for injectiontriggerMethodDescriptor
- the descriptor of a candidate method for injection- Returns:
- the new rule
-
warn
called by a check adapter to warn that a transform was not possible for a potential match target. this inhibits injection into the method being warned about allowing other injection operations to continue.- Parameters:
triggerMethodName
- the name of a candidate method for injectiontriggerMethodDescriptor
- the descriptor of a candidate method for injectionwarningMessage
- details of the warning
-
fail
called by a check or trigger adapter to fail a transform because of a type issue. this aborts all injection into the current class not just injection into the current method.- Parameters:
failMessage
- details of the failuretriggerMethodName
- the name of a candidate method for injectiontriggerMethodDescriptor
- the descriptor of a candidate method for injection
-
recordFailedTransform
-
matchTargetMethod
-
injectIntoMethod
-
getTriggerClassName
-
notifyRules
private boolean notifyRules()this gets called when a transform attempt completes without any exceptions. if there are rules left in the rule map then they will belong successful injections. -
purgeRules
private void purgeRules()this gets called when a transform attempt fails. if there are rules left in the rule map then they will belong either to earlier successful injections or to the failed transform. in any case they need to be purged. -
getRuleKey
return a unique string key identifying a specific rule compiled against some class and method/signature in the context of a specific class loader- Returns:
- a unique string key
-
getKeyTriggerMethodName
return the trigger method name used to construct the supplied rule key- Parameters:
key
-- Returns:
- the trigger method name
-
getKeyTriggerMethodDescriptor
return the trigger method descriptor used to construct the supplied rule key- Parameters:
key
-- Returns:
- the trigger method descriptor
-
mungeMethodSpecReturnType
detect a method specification which includes a return type preceding the method name and transform it so that the return type is at the end.- Parameters:
targetMethodSpec
-- Returns:
- the method spec in the desired format
-
getNonLoadingClassWriter
private org.objectweb.asm.ClassWriter getNonLoadingClassWriter(int flags) get a class writer which will not attempt to load classes. The default classwriter tries this when a reference type local var frame slot aligns with a slot of reference type in a successor block's frame. This is merely so it can optimize a slot out of the frame change set in the special case where f1[slot].type invalid input: '<' f2[slot].type or vice versa by using the least common supereclass. We have to use the Transformer to reuse existing loaded classes and, where a class has not been loaded, to attempt to load the bytecode as a resource and identify supers via the bytecode.- Parameters:
flags
-- Returns:
- a non-loading class writer
-
findLeastCommonSuper
-
listInterfaces
-
listSupers
-