Package jadex.bytecode.invocation
Class SInvocation
java.lang.Object
jadex.bytecode.invocation.SInvocation
Factory for providing fast reflective access to methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Class used to test access level via ASM.protected static class
Class writer with some meta information.protected static class
Fallback invoker using reflection in case a byte-engineered variant is not available.protected static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static WeakHashMap
<Class<?>, jadex.collection.WeakKeyValueMap<Class<?>, Class<?>>> Cached accessor classes.static boolean
Flag if default / protected access via ASM is available.protected static WeakHashMap
<Class<?>, jadex.collection.WeakKeyValueMap<Class<?>, Class<?>>> Cached extractor classes.protected static WeakHashMap
<Method, Class<IMethodInvoker>> Cached invoker classes, the invoker class does not prevent GC (tested).static AtomicLong
Class name suffix counter.static boolean
Flag if private access via ASM is available. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final <T> Class
<T> createAccessorClass
(IByteCodeClassLoader cl, Class<T> iface, Class<?> clazz) Generates an accessor class based on an interface.protected static final SInvocation.ExtendedClassWriter
createClass
(Class<?> targetclass, String classname, int accesslevel, Class<?>... interfaces) Creates the initial setup for a new class in ASM.static final Class
<IExtractor> createExtractorClass
(IByteCodeClassLoader cl, Class<?> clazz, String[] propnames, Member[] accessormember) Creates extractor class.protected static final <T> T
createFallbackAccessor
(Class<T> iface, Class<?> clazz, Object obj) Implements an accessor based on a dynamic proxy.protected static final Class
<IMethodInvoker> createInvokerClass
(IByteCodeClassLoader cl, Method method) Creates the invoker class.protected static final int
determineAccessLevel
(int currentlevel, int modifiers) Determines the necessary access level based on the current access level.protected static final void
Tries to enable enhanced direct access.static final <T> Class
<T> getAccessorClass
(Class<T> iface, Class<?> targetclazz) Gets class for an interface-based accessor.static final Class
<IMethodInvoker> getInvokerClass
(Method method) Gets an invoker class.static final Object
Directly invokes a method based on the method name and arguments.static final Object
Directly invokes a method based on the method name and arguments.static final <T> T
newAccessor
(Class<T> iface, Class<?> targetclass, Object delegate) Creates a new accessor from an accessor class.static final IExtractor
newExtractor
(Class<IExtractor> extractorclass) protected static final IMethodInvoker
newInvoker
(Class<?> invokerclass) Instantiate a new method invoker from the invoker class.static final IMethodInvoker
newInvoker
(Method method) Creates a new invoker for a method.static final IMethodInvoker
newInvoker
(Method method, IByteCodeClassLoader cl) Creates a new invoker for a method.protected static final void
prepareParameters
(org.objectweb.asm.MethodVisitor mv, Class<?>[] parameters) Readies the parameters for delegated method invocation.
-
Field Details
-
NAME_SUFFIX_COUNTER
Class name suffix counter. -
DEFAULT_ACCESS
public static boolean DEFAULT_ACCESSFlag if default / protected access via ASM is available. Cannot be final due to bootstrapping. -
PRIVATE_ACCESS
public static boolean PRIVATE_ACCESSFlag if private access via ASM is available. Cannot be final due to bootstrapping. -
INVOKER_CLASSES
Cached invoker classes, the invoker class does not prevent GC (tested). -
ACCESSOR_CLASSES
protected static volatile WeakHashMap<Class<?>,jadex.collection.WeakKeyValueMap<Class<?>, ACCESSOR_CLASSESClass<?>>> Cached accessor classes. -
EXTRACTOR_CLASSES
protected static volatile WeakHashMap<Class<?>,jadex.collection.WeakKeyValueMap<Class<?>, EXTRACTOR_CLASSESClass<?>>> Cached extractor classes.
-
-
Constructor Details
-
SInvocation
public SInvocation()
-
-
Method Details
-
invoke
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
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
Creates a new invoker for a method.- Parameters:
method
- The method.- Returns:
- Instantiated invoker.
-
newInvoker
Creates a new invoker for a method.- Parameters:
method
- The method.cl
- ClassLoader to use.- Returns:
- Instantiated invoker.
-
newInvoker
Instantiate a new method invoker from the invoker class.- Parameters:
invokerclass
- The invoker class.- Returns:
- Instantiated invoker.
-
getInvokerClass
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
Creates a new accessor from an accessor class.- Parameters:
delegate
- The delegation object / accessor target.accessorclass
- The accessor class.- Returns:
- Instantiated accessor.
-
getAccessorClass
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
-
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
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.
-