Class HelperManager

java.lang.Object
org.jboss.byteman.agent.HelperManager

public class HelperManager extends Object
class used to manage lifecycle events for rule helpers
  • Field Details

    • inst

      private 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

      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 String ACTIVATED_NAME
      name of method invoked when helper installed count transitions from 0 to positive
      See Also:
    • DEACTIVATED_NAME

      private static final String DEACTIVATED_NAME
      name of method invoked when helper installed count transitions from positive to 0
      See Also:
    • INSTALLED_NAME

      private static final String INSTALLED_NAME
      name of method invoked when rule is installed for a given helper
      See Also:
    • UNINSTALLED_NAME

      private static final String UNINSTALLED_NAME
      name of method invoked when rule is uninstalled for a given helper
      See Also:
    • ACTIVATED_SIGNATURE

      private static final Class[] ACTIVATED_SIGNATURE
      param types of method invoked when helper installed count transitions from 0 to positive
    • DEACTIVATED_SIGNATURE

      private static final Class[] DEACTIVATED_SIGNATURE
      param types of method invoked when helper installed count transitions from positive to 0
    • INSTALLED_RULE_SIGNATURE

      private static final Class[] INSTALLED_RULE_SIGNATURE
      param types of method invoked when rule is installed for a given helper
    • UNINSTALLED_RULE_SIGNATURE

      private static final Class[] UNINSTALLED_RULE_SIGNATURE
      param types of method invoked when rule is uninstalled for a given helper
    • INSTALLED_STRING_SIGNATURE

      private static final Class[] INSTALLED_STRING_SIGNATURE
      param types of method invoked when rule is installed for a given helper
    • UNINSTALLED_STRING_SIGNATURE

      private static final Class[] UNINSTALLED_STRING_SIGNATURE
      param types of method invoked when rule is uninstalled for a given helper
  • Constructor Details

    • HelperManager

      public HelperManager(Instrumentation inst, ModuleSystem moduleSystem)
      construct a manager
      Parameters:
      inst - will be non-null if we are running in an agent
      moduleSystem - must be non-null, use NonModuleSystem if nothing specal is needed
  • Method Details

    • 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, 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, Class<?> helperClass)
    • getObjectSize

      public long getObjectSize(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(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 details
      parent - 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 Method lookupLifecycleMethod(Class<?> clazz, String name, 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 -