Package org.jboss.byteman.agent
Class HelperManager
java.lang.Object
org.jboss.byteman.agent.HelperManager
class used to manage lifecycle events for rule helpers
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
a record of a specific helper class tracking the number of installed rules which reference it and referencing a table detailing the lifecycle methods it implements LifeCycleDetails are daisy-chained to ensure that lifecycle processing associated with a superclass are performed automatically as part of a given Helper class's lifecycle processing. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
name of method invoked when helper installed count transitions from 0 to positiveprivate static final Class[]
param types of method invoked when helper installed count transitions from 0 to positiveprivate static final String
name of method invoked when helper installed count transitions from positive to 0private static final Class[]
param types of method invoked when helper installed count transitions from positive to 0private ConcurrentHashMap
<Class<?>, HelperManager.LifecycleDetails> a hashmap from helper classes to their corresponding helper details.private Instrumentation
the instrumentation object used to install the transformer.private static final String
name of method invoked when rule is installed for a given helperprivate static final Class[]
param types of method invoked when rule is installed for a given helperprivate static final Class[]
param types of method invoked when rule is installed for a given helperprivate ModuleSystem
the module system implementation.private static final String
name of method invoked when rule is uninstalled for a given helperprivate static final Class[]
param types of method invoked when rule is uninstalled for a given helperprivate static final Class[]
param types of method invoked when rule is uninstalled for a given helper -
Constructor Summary
ConstructorsConstructorDescriptionHelperManager
(Instrumentation inst, ModuleSystem moduleSystem) construct a manager -
Method Summary
Modifier and TypeMethodDescriptionprivate HelperManager.LifecycleDetails
getDetails
(Class<?> helperClass, boolean createIfAbsent, HelperManager.LifecycleDetails parent) lookup or create a record describing the lifecycle methods of a helper class.long
This method exposes a capability of the Byteman agent's Instrumentation instance while avoiding exposing the instance itself.void
perform install processing for a ruleprivate HelperManager.LifecycleDetails
private Method
lookupLifecycleMethod
(Class<?> clazz, String name, Class<?>[] paramTypes) return a static public method with the given parameter types it exists otherwise nullprivate void
purge the details describing the lifecycle methods of a helper class.void
uninstalled
(Rule rule) perform install processing for a rulevoid
uninstalled
(Rule rule, Class<?> helperClass)
-
Field Details
-
inst
the instrumentation object used to install the transformer. If this is null then we are not running in a real agent so we do no work. -
moduleSystem
the module system implementation. -
helperDetailsMap
a hashmap from helper classes to their corresponding helper details. we don't use weak references here because there is only ever an entry here if there is a rule installed which references the class. entries get cleared when the rules are uninstalled. -
ACTIVATED_NAME
name of method invoked when helper installed count transitions from 0 to positive- See Also:
-
DEACTIVATED_NAME
name of method invoked when helper installed count transitions from positive to 0- See Also:
-
INSTALLED_NAME
name of method invoked when rule is installed for a given helper- See Also:
-
UNINSTALLED_NAME
name of method invoked when rule is uninstalled for a given helper- See Also:
-
ACTIVATED_SIGNATURE
param types of method invoked when helper installed count transitions from 0 to positive -
DEACTIVATED_SIGNATURE
param types of method invoked when helper installed count transitions from positive to 0 -
INSTALLED_RULE_SIGNATURE
param types of method invoked when rule is installed for a given helper -
UNINSTALLED_RULE_SIGNATURE
param types of method invoked when rule is uninstalled for a given helper -
INSTALLED_STRING_SIGNATURE
param types of method invoked when rule is installed for a given helper -
UNINSTALLED_STRING_SIGNATURE
param types of method invoked when rule is uninstalled for a given helper
-
-
Constructor Details
-
HelperManager
construct a manager- Parameters:
inst
- will be non-null if we are running in an agentmoduleSystem
- must be non-null, use NonModuleSystem if nothing specal is needed
-
-
Method Details
-
installed
perform install processing for a rule- Parameters:
rule
- an instantiation of a specific rule script as a Rule which has been successfully loaded into the agent, injected, type-checked and, optionally, compiled. Note that install processing happens when an injected rule is first triggered, not when it is injected. This ensures that a rule is not installed until it has been successfully type checked. It also ensures that helper life-cycle calls are not made underneath a ClassFileTransformer transform callback. This is so that execution of life-cycle code does not initiate class-loading without the desired associated transforms being applied -- transformation is not entered recursively. The same reasoning accounts for ehy type-checking is delayed until trigger-time. Note also that some given rule script may be injected into more than one method of more than one class. A METHOD spec may match more than one method when the descriptor is omitted. A CLASS or INTERFACE specification may match more than one class for a variety of reasons: multiple deployments of the same named class; omission of the package name in the specification; injection through interfaces; use of overriding injection. Every successful install into a specific method (of some given class) leads to one installed callback even when the rule is injected at multiple matching points in the bytecode of that method.
-
installed
-
uninstalled
perform install processing for a rule- Parameters:
rule
- an instantiation of a specific rule script as a Rule which has been successfully loaded into the agent, injected, type-checked and, optionally, compiled. Note that uninstall processing is performed by the Retransformer during unloading (or redefinition) of scripts after any retransform of the classesd affected by the scripts has been performed. When a script is uninstalled an uinstall event should occur for each case where there a prior install event i.e. for each method into which the rule was successfully injected, type checked and, possibly, compiled. In cases where a rule is redefined the process is slightly different. If the redefined rule fails to parse, inject or type check then any previously injected rule gets uninstalled. If a redefined rule is successfully, parsed, injected and type-checked then uninstall and reinstall of the rule is elided. The obvious benefit of elision is that the associated helper manager does not get spuriously deactivated and reactivated by a simple redefinition. However, two potentially (but only mildly) surprising consequences follow: 1) If a newly injected rule is triggered before a subsequent uninstall then it will be the target of the uninstalled call i.e. callbacks which take a Rule argument cannot rely on seeing the same rule instance at install and uninstall. Of course, both rules will still have the same name. 2) If a newly injected rule is not triggered before the uninstall happens, or is triggered and fails to type check or compile, then the previously installed rule will be used as the target of the uninstalled call i.e. callbacks which take a Rule argument cannot rely upon the uninstalled rule object being derived from the latest installed script text.
-
uninstalled
-
getObjectSize
This method exposes a capability of the Byteman agent's Instrumentation instance while avoiding exposing the instance itself. It returns an estimate of the object size or -1 in case an agent has not been installed.- Parameters:
o
- the object to be sized- Returns:
- an estimate of the size or -1
-
getModuleSystem
-
getDetails
private HelperManager.LifecycleDetails getDetails(Class<?> helperClass, boolean createIfAbsent, HelperManager.LifecycleDetails parent) lookup or create a record describing the lifecycle methods of a helper class. this must only be called when synchronized on the helper class.- Parameters:
helperClass
-createIfAbsent
- if the details are not present and this is true then create and install new detailsparent
- details for the super of helperClass required only when createIfAbsent is true and the parent class is not Object- Returns:
- the relevant details
-
lookupLifecycleMethod
return a static public method with the given parameter types it exists otherwise null- Parameters:
name
-paramTypes
-- Returns:
- the method if found otherwise null
-
purgeDetails
purge the details describing the lifecycle methods of a helper class. this must only be called when synchronized on the helper class.- Parameters:
details
-
-