Class SInvocation

java.lang.Object
jadex.bytecode.invocation.SInvocation

public class SInvocation extends Object
Factory for providing fast reflective access to methods.
  • Field Details

    • NAME_SUFFIX_COUNTER

      public static AtomicLong NAME_SUFFIX_COUNTER
      Class name suffix counter.
    • DEFAULT_ACCESS

      public static boolean DEFAULT_ACCESS
      Flag if default / protected access via ASM is available. Cannot be final due to bootstrapping.
    • PRIVATE_ACCESS

      public static boolean PRIVATE_ACCESS
      Flag if private access via ASM is available. Cannot be final due to bootstrapping.
    • INVOKER_CLASSES

      protected static volatile WeakHashMap<Method,Class<IMethodInvoker>> INVOKER_CLASSES
      Cached invoker classes, the invoker class does not prevent GC (tested).
    • ACCESSOR_CLASSES

      protected static volatile WeakHashMap<Class<?>,jadex.collection.WeakKeyValueMap<Class<?>,Class<?>>> ACCESSOR_CLASSES
      Cached accessor classes.
    • EXTRACTOR_CLASSES

      protected static volatile WeakHashMap<Class<?>,jadex.collection.WeakKeyValueMap<Class<?>,Class<?>>> EXTRACTOR_CLASSES
      Cached extractor classes.
  • Constructor Details

    • SInvocation

      public SInvocation()
  • Method Details

    • invoke

      public static final Object invoke(Object obj, String methodname, Object... args)
      Directly invokes a method based on the method name and arguments. Method resolution is very basic and a performance penalty is incurred, do not use if you plan on making repeated calls or need good method resolution, use getInvoker() methods instead.
      Parameters:
      obj - Object on which the method is to be called.
      methodname - Name of the methods.
      args - Invocation arguments.
      Returns:
      Return value of invocation.
    • invoke

      public static final Object invoke(Object obj, Class<?> clazz, String methodname, Object... args)
      Directly invokes a method based on the method name and arguments. Method resolution is very basic and a performance penalty is incurred, do not use if you plan on making repeated calls or need good method resolution, use getInvoker() methods instead.
      Parameters:
      obj - Object on which the method is to be called.
      clazz - Class definition for static calls, can be null if obj is defined.
      methodname - Name of the method.
      args - Invocation arguments.
      Returns:
      Return value of invocation.
    • newInvoker

      public static final IMethodInvoker newInvoker(Method method)
      Creates a new invoker for a method.
      Parameters:
      method - The method.
      Returns:
      Instantiated invoker.
    • newInvoker

      public static final IMethodInvoker newInvoker(Method method, IByteCodeClassLoader cl)
      Creates a new invoker for a method.
      Parameters:
      method - The method.
      cl - ClassLoader to use.
      Returns:
      Instantiated invoker.
    • newInvoker

      protected static final IMethodInvoker newInvoker(Class<?> invokerclass)
      Instantiate a new method invoker from the invoker class.
      Parameters:
      invokerclass - The invoker class.
      Returns:
      Instantiated invoker.
    • getInvokerClass

      public static final Class<IMethodInvoker> getInvokerClass(Method method)
      Gets an invoker class.
      Parameters:
      clazz - The class used to map methods.
      methodidmap - The method ID map to store the mapping.
      Returns:
      The generated invoker.
    • createInvokerClass

      protected static final Class<IMethodInvoker> createInvokerClass(IByteCodeClassLoader cl, Method method)
      Creates the invoker class.
      Parameters:
      cl - ClassLoader to use for generated class.
      clazz - The class used to map methods.
      Returns:
      The generated invoker.
    • newAccessor

      public static final <T> T newAccessor(Class<T> iface, Class<?> targetclass, Object delegate)
      Creates a new accessor from an accessor class.
      Parameters:
      delegate - The delegation object / accessor target.
      accessorclass - The accessor class.
      Returns:
      Instantiated accessor.
    • getAccessorClass

      public static final <T> Class<T> getAccessorClass(Class<T> iface, Class<?> targetclazz)
      Gets class for an interface-based accessor.
      Parameters:
      iface - The accessor interface.
      targetclazz - The target class.
      Returns:
      The accessor class.
    • createAccessorClass

      public static final <T> Class<T> createAccessorClass(IByteCodeClassLoader cl, Class<T> iface, Class<?> clazz)
      Generates an accessor class based on an interface. Methods between the interface and the target class are matched.
      Parameters:
      cl - The ClassLoader used to load the generated byte code.
      iface - The accessor interface.
      clazz - The target class of the accessor.
      Returns:
      The generated class.
    • newExtractor

      public static final IExtractor newExtractor(Class<IExtractor> extractorclass)
    • createExtractorClass

      public static final Class<IExtractor> createExtractorClass(IByteCodeClassLoader cl, Class<?> clazz, String[] propnames, Member[] accessormember)
      Creates extractor class.
      Parameters:
      cl - ClassLoader to use for generated class.
      clazz - The class used to map methods.
      Returns:
      The generated invoker.
    • createClass

      protected static final SInvocation.ExtendedClassWriter createClass(Class<?> targetclass, String classname, int accesslevel, Class<?>... interfaces)
      Creates the initial setup for a new class in ASM.
      Parameters:
      classname - Simple name of the class.
      privileged - If the class should be "privileged" to allow access to non-publics.
      Returns:
      Preinitialized class writer.
    • prepareParameters

      protected static final void prepareParameters(org.objectweb.asm.MethodVisitor mv, Class<?>[] parameters)
      Readies the parameters for delegated method invocation. Converts primitives as appropriate.
      Parameters:
      mv - The MethodVisitor being used.
      parameters - The parameters of the method.
    • determineAccessLevel

      protected static final int determineAccessLevel(int currentlevel, int modifiers)
      Determines the necessary access level based on the current access level.
      Parameters:
      currentlevel - The current level.
      modifiers - Modifiers of the target
      Returns:
      Needed access level.
    • createFallbackAccessor

      protected static final <T> T createFallbackAccessor(Class<T> iface, Class<?> clazz, Object obj)
      Implements an accessor based on a dynamic proxy.
      Parameters:
      iface - The interface to implement.
      clazz - The target class.
      obj - The target class or null if all static.
      cl - ClassLoader to use.
      Returns:
      Accessor.
    • enableEnhancedAccess

      protected static final void enableEnhancedAccess()
      Tries to enable enhanced direct access.