Package org.jboss.byteman.agent
Class HelperManager
- java.lang.Object
-
- org.jboss.byteman.agent.HelperManager
-
public class HelperManager extends java.lang.Object
class used to manage lifecycle events for rule helpers
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
HelperManager.LifecycleDetails
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
Fields Modifier and Type Field Description private static java.lang.String
ACTIVATED_NAME
name of method invoked when helper installed count transitions from 0 to positiveprivate static java.lang.Class[]
ACTIVATED_SIGNATURE
param types of method invoked when helper installed count transitions from 0 to positiveprivate static java.lang.String
DEACTIVATED_NAME
name of method invoked when helper installed count transitions from positive to 0private static java.lang.Class[]
DEACTIVATED_SIGNATURE
param types of method invoked when helper installed count transitions from positive to 0private java.util.concurrent.ConcurrentHashMap<java.lang.Class<?>,HelperManager.LifecycleDetails>
helperDetailsMap
a hashmap from helper classes to their corresponding helper details.private java.lang.instrument.Instrumentation
inst
the instrumentation object used to install the transformer.private static java.lang.String
INSTALLED_NAME
name of method invoked when rule is installed for a given helperprivate static java.lang.Class[]
INSTALLED_RULE_SIGNATURE
param types of method invoked when rule is installed for a given helperprivate static java.lang.Class[]
INSTALLED_STRING_SIGNATURE
param types of method invoked when rule is installed for a given helperprivate ModuleSystem
moduleSystem
the module system implementation.private static java.lang.String
UNINSTALLED_NAME
name of method invoked when rule is uninstalled for a given helperprivate static java.lang.Class[]
UNINSTALLED_RULE_SIGNATURE
param types of method invoked when rule is uninstalled for a given helperprivate static java.lang.Class[]
UNINSTALLED_STRING_SIGNATURE
param types of method invoked when rule is uninstalled for a given helper
-
Constructor Summary
Constructors Constructor Description HelperManager(java.lang.instrument.Instrumentation inst, ModuleSystem moduleSystem)
construct a manager
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private HelperManager.LifecycleDetails
getDetails(java.lang.Class<?> helperClass, boolean createIfAbsent, HelperManager.LifecycleDetails parent)
lookup or create a record describing the lifecycle methods of a helper class.ModuleSystem
getModuleSystem()
long
getObjectSize(java.lang.Object o)
This method exposes a capability of the Byteman agent's Instrumentation instance while avoiding exposing the instance itself.void
installed(Rule rule)
perform install processing for a ruleprivate HelperManager.LifecycleDetails
installed(Rule rule, java.lang.Class<?> helperClass)
private java.lang.reflect.Method
lookupLifecycleMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>[] paramTypes)
return a static public method with the given parameter types it exists otherwise nullprivate void
purgeDetails(HelperManager.LifecycleDetails details)
purge the details describing the lifecycle methods of a helper class.void
uninstalled(Rule rule)
perform install processing for a rulevoid
uninstalled(Rule rule, java.lang.Class<?> helperClass)
-
-
-
Field Detail
-
inst
private java.lang.instrument.Instrumentation 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
private ModuleSystem moduleSystem
the module system implementation.
-
helperDetailsMap
private java.util.concurrent.ConcurrentHashMap<java.lang.Class<?>,HelperManager.LifecycleDetails> 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
private static final java.lang.String ACTIVATED_NAME
name of method invoked when helper installed count transitions from 0 to positive- See Also:
- Constant Field Values
-
DEACTIVATED_NAME
private static final java.lang.String DEACTIVATED_NAME
name of method invoked when helper installed count transitions from positive to 0- See Also:
- Constant Field Values
-
INSTALLED_NAME
private static final java.lang.String INSTALLED_NAME
name of method invoked when rule is installed for a given helper- See Also:
- Constant Field Values
-
UNINSTALLED_NAME
private static final java.lang.String UNINSTALLED_NAME
name of method invoked when rule is uninstalled for a given helper- See Also:
- Constant Field Values
-
ACTIVATED_SIGNATURE
private static final java.lang.Class[] ACTIVATED_SIGNATURE
param types of method invoked when helper installed count transitions from 0 to positive
-
DEACTIVATED_SIGNATURE
private static final java.lang.Class[] DEACTIVATED_SIGNATURE
param types of method invoked when helper installed count transitions from positive to 0
-
INSTALLED_RULE_SIGNATURE
private static final java.lang.Class[] INSTALLED_RULE_SIGNATURE
param types of method invoked when rule is installed for a given helper
-
UNINSTALLED_RULE_SIGNATURE
private static final java.lang.Class[] UNINSTALLED_RULE_SIGNATURE
param types of method invoked when rule is uninstalled for a given helper
-
INSTALLED_STRING_SIGNATURE
private static final java.lang.Class[] INSTALLED_STRING_SIGNATURE
param types of method invoked when rule is installed for a given helper
-
UNINSTALLED_STRING_SIGNATURE
private static final java.lang.Class[] UNINSTALLED_STRING_SIGNATURE
param types of method invoked when rule is uninstalled for a given helper
-
-
Constructor Detail
-
HelperManager
public HelperManager(java.lang.instrument.Instrumentation inst, ModuleSystem moduleSystem)
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 Detail
-
installed
public void installed(Rule rule)
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
private HelperManager.LifecycleDetails installed(Rule rule, java.lang.Class<?> helperClass)
-
uninstalled
public void uninstalled(Rule rule)
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
public void uninstalled(Rule rule, java.lang.Class<?> helperClass)
-
getObjectSize
public long getObjectSize(java.lang.Object o)
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
public ModuleSystem getModuleSystem()
-
getDetails
private HelperManager.LifecycleDetails getDetails(java.lang.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
private java.lang.reflect.Method lookupLifecycleMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>[] paramTypes)
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
private void purgeDetails(HelperManager.LifecycleDetails details)
purge the details describing the lifecycle methods of a helper class. this must only be called when synchronized on the helper class.- Parameters:
details
-
-
-