Class JigsawAccessEnabler

  • All Implemented Interfaces:
    AccessEnabler

    public class JigsawAccessEnabler
    extends java.lang.Object
    implements AccessEnabler
    Implementation of AccessEnabler for use in a Jigsaw enabled JDK runtime n.b. this class is only exemplary and must not be compiled into the Byteman jar. It is supposed to be generated at runtime and installed by the classloader for the org.jboss.byteman.jigsaw module created by the LayerFactory.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean DEBUG
      flag to allow debug trace to be generated
      private DefaultAccessEnabler defaultAccessEnabler
      default enabler to provide reflective access in cases where we run up against an IllegalAccessException for java.base classes because of the current rather extreme restrictions provided by Jigsaw
      private java.util.Map<java.lang.String,​java.util.Set<java.lang.Module>> EMPTY_EXPORTS_MAP
      empty exports set passed to an addExports call
      private java.util.Map<java.lang.String,​java.util.Set<java.lang.Module>> EMPTY_OPENS_MAP
      empty opens set passed to an addExports call
      private java.util.Map<java.lang.Class<?>,​java.util.List<java.lang.Class<?>>> EMPTY_PROVIDES_MAP
      empty provides map passed to an addExports call
      private java.util.Set<java.lang.Module> EMPTY_READS_SET
      empty reads set passed to an addExports call
      private java.util.Set<java.lang.Class<?>> EMPTY_USES_SET
      empty uses set passed to an addExports call
      private java.lang.instrument.Instrumentation inst
      the Instrumentation instance that allows addExports to be called
      private java.lang.invoke.MethodHandles.Lookup theLookup  
      private java.lang.Module THIS_MODULE
      the single Byteman module to which reflective access is granted by exporting packages as necessary
      private java.util.Set<java.lang.Module> THIS_MODULE_SET
      singleton set passed to specify the single target module for an addExports call
      private java.lang.Module UNPRIVILEGED_MODULE
      the module to which the rest of the Byteman code belongs which should be the system or bootstrap unnamed module
    • Constructor Summary

      Constructors 
      Constructor Description
      JigsawAccessEnabler​(java.lang.instrument.Instrumentation inst)
      create an AccessEnabler that is capable of ensuring access when running inside a Jigsaw enabled JDK.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AccessibleConstructorInvoker createConstructorInvoker​(java.lang.reflect.Constructor constructor)  
      AccessibleFieldGetter createFieldGetter​(java.lang.reflect.Field field)  
      AccessibleFieldSetter createFieldSetter​(java.lang.reflect.Field field)  
      AccessibleMethodInvoker createMethodInvoker​(java.lang.reflect.Method method)  
      private void debug​(java.lang.String... args)  
      void ensureAccess​(java.lang.reflect.AccessibleObject accessible)
      ensure that accessible can be accessed using reflection or a method handle
      private void ensureModuleAccess​(java.lang.reflect.AccessibleObject accessible)
      check whether the accessible's owning class resides in a non-default module and if so ensure that the package is exported to the Byteman Jigsaw package
      boolean requiresAccess​(java.lang.Class<?> klazz)
      test whether reference to the class from a classpath class requires the use of reflection or a method handle and possibly also module jiggery-pokery.
      boolean requiresAccess​(java.lang.reflect.AccessibleObject accessible)
      test whether access to the accessible from a classpath class requires the use of reflection or a method handle and possibly also module jiggery-pokery.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEBUG

        public boolean DEBUG
        flag to allow debug trace to be generated
      • THIS_MODULE

        private java.lang.Module THIS_MODULE
        the single Byteman module to which reflective access is granted by exporting packages as necessary
      • UNPRIVILEGED_MODULE

        private java.lang.Module UNPRIVILEGED_MODULE
        the module to which the rest of the Byteman code belongs which should be the system or bootstrap unnamed module
      • THIS_MODULE_SET

        private java.util.Set<java.lang.Module> THIS_MODULE_SET
        singleton set passed to specify the single target module for an addExports call
      • EMPTY_READS_SET

        private java.util.Set<java.lang.Module> EMPTY_READS_SET
        empty reads set passed to an addExports call
      • EMPTY_EXPORTS_MAP

        private java.util.Map<java.lang.String,​java.util.Set<java.lang.Module>> EMPTY_EXPORTS_MAP
        empty exports set passed to an addExports call
      • EMPTY_OPENS_MAP

        private java.util.Map<java.lang.String,​java.util.Set<java.lang.Module>> EMPTY_OPENS_MAP
        empty opens set passed to an addExports call
      • EMPTY_USES_SET

        private java.util.Set<java.lang.Class<?>> EMPTY_USES_SET
        empty uses set passed to an addExports call
      • EMPTY_PROVIDES_MAP

        private java.util.Map<java.lang.Class<?>,​java.util.List<java.lang.Class<?>>> EMPTY_PROVIDES_MAP
        empty provides map passed to an addExports call
      • inst

        private java.lang.instrument.Instrumentation inst
        the Instrumentation instance that allows addExports to be called
      • theLookup

        private java.lang.invoke.MethodHandles.Lookup theLookup
      • defaultAccessEnabler

        private DefaultAccessEnabler defaultAccessEnabler
        default enabler to provide reflective access in cases where we run up against an IllegalAccessException for java.base classes because of the current rather extreme restrictions provided by Jigsaw
    • Constructor Detail

      • JigsawAccessEnabler

        public JigsawAccessEnabler​(java.lang.instrument.Instrumentation inst)
        create an AccessEnabler that is capable of ensuring access when running inside a Jigsaw enabled JDK. This constructor throws an exception if it is not provided with a non-null Instrumentation instance as argument, effectively limiting the use of this class to JVMTI agents.
        Parameters:
        inst - the instrumentation instance we need to use to enable access
    • Method Detail

      • requiresAccess

        public boolean requiresAccess​(java.lang.Class<?> klazz)
        test whether reference to the class from a classpath class requires the use of reflection or a method handle and possibly also module jiggery-pokery.
        Specified by:
        requiresAccess in interface AccessEnabler
        Parameters:
        klazz - the class to be checked
        Returns:
        true if reference to the class from a classpath class requires the use of reflection or a method handle and possibly module jiggery-pokery otherwise false.
      • requiresAccess

        public boolean requiresAccess​(java.lang.reflect.AccessibleObject accessible)
        Description copied from interface: AccessEnabler
        test whether access to the accessible from a classpath class requires the use of reflection or a method handle and possibly also module jiggery-pokery.
        Specified by:
        requiresAccess in interface AccessEnabler
        Parameters:
        accessible - this must be a Member
        Returns:
        true if access requires reflection or a method handle and possibly also module jiggery-pokery otherwise false.
      • ensureAccess

        public void ensureAccess​(java.lang.reflect.AccessibleObject accessible)
        ensure that accessible can be accessed using reflection or a method handle
        Specified by:
        ensureAccess in interface AccessEnabler
        Parameters:
        accessible - this must be a Member
      • ensureModuleAccess

        private void ensureModuleAccess​(java.lang.reflect.AccessibleObject accessible)
        check whether the accessible's owning class resides in a non-default module and if so ensure that the package is exported to the Byteman Jigsaw package
        Parameters:
        accessible -
      • debug

        private void debug​(java.lang.String... args)