Class AgentModule

java.lang.Object
org.jacoco.agent.rt.internal.AgentModule

public class AgentModule extends Object
An isolated class loader and distinct module to encapsulate JaCoCo runtime classes. This isolated environment allows to specifically open JDK packages to the agent runtime without changing package accessibility for the application under test.

The implementation uses the property that the unnamed module is distinct from all run-time modules (including unnamed modules) bound to other class loaders.

  • Field Details

  • Constructor Details

    • AgentModule

      public AgentModule() throws Exception
      Creates a new isolated module.
      Throws:
      Exception - if it cannot be created
  • Method Details

    • isSupported

      public static boolean isSupported()
      Checks whether Java modules are supported by the current Java runtime.
      Returns:
      true is modules are supported
    • openPackage

      public void openPackage(Instrumentation instrumentation, Class<?> classInPackage) throws Exception
      Opens the package of the provided class to the module created in this AgentModule() instance.
      Parameters:
      instrumentation - service provided to the agent by the Java runtime
      classInPackage - example class of the package to open
      Throws:
      Exception - if package cannot be opened
    • loadClassInModule

      public <T> Class<T> loadClassInModule(Class<T> original) throws Exception
      Loads a copy of the given class in the isolated classloader. Also any inner classes are loader from the isolated classloader.
      Type Parameters:
      T - type of the class to load
      Parameters:
      original - original class definition which is used as source
      Returns:
      class object from the isolated class loader
      Throws:
      Exception - if the class cannot be loaded
    • addToScopeWithInnerClasses

      private void addToScopeWithInnerClasses(Class<?> c)
    • getModuleClass

      private static Class<?> getModuleClass() throws ClassNotFoundException
      Throws:
      ClassNotFoundException