Class SASM


  • public class SASM
    extends java.lang.Object
    Static ASM helper methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      SASM()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static IByteCodeClassLoader createByteCodeClassLoader​(java.lang.ClassLoader... parents)
      Creates a byte code ClassLoader.
      static IByteCodeClassLoader getByteCodeClassLoader​(java.lang.ClassLoader parent)
      Generates a ByteCodeClassLoader for loading a generated class.
      static IByteCodeClassLoader getByteCodeClassLoader​(java.lang.ClassLoader parent, boolean sharedloaders)
      Generates a ByteCodeClassLoader for loading a generated class.
      static org.objectweb.asm.tree.ClassNode getClassNode​(java.lang.Class<?> clazz, java.lang.ClassLoader classloader)
      Get a class node for a class.
      static void makeBasicType​(org.objectweb.asm.tree.InsnList nl, org.objectweb.asm.Type type)
      Make a value a basic type.
      static void makeObject​(org.objectweb.asm.tree.InsnList nl, org.objectweb.asm.Type type)
      Make a value to an object.
      static int makeObject​(org.objectweb.asm.tree.InsnList nl, org.objectweb.asm.Type arg, int pos)
      Make a value to an object.
      static void makeReturn​(org.objectweb.asm.tree.InsnList nl, org.objectweb.asm.Type type)
      Make a suitable return statement.
      static void pushImmediate​(org.objectweb.asm.tree.InsnList nl, int immediate)
      Push an immediate (constant) integer value onto the stack with the best set of instructions.
      static void pushImmediate​(org.objectweb.asm.tree.InsnList nl, long immediate)
      Push an immediate (constant) long value onto the stack with the best set of instructions.
      static java.lang.Class<?> toClass​(java.lang.String name, byte[] data, java.lang.ClassLoader loader, java.security.ProtectionDomain domain)
      Transform byte Array into Class and define it in classloader.
      • Methods inherited from class java.lang.Object

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

      • SHARED_LOADERS_MODE

        public static boolean SHARED_LOADERS_MODE
        Enables the shared bytecode classloader mode. If false, a new classloader is generated for each generated class for easier unloading, but potentially wastes more memory.
    • Constructor Detail

      • SASM

        public SASM()
    • Method Detail

      • pushImmediate

        public static void pushImmediate​(org.objectweb.asm.tree.InsnList nl,
                                         int immediate)
        Push an immediate (constant) integer value onto the stack with the best set of instructions.
        Parameters:
        nl - The instruction list.
        immediate - The immediate value.
      • pushImmediate

        public static void pushImmediate​(org.objectweb.asm.tree.InsnList nl,
                                         long immediate)
        Push an immediate (constant) long value onto the stack with the best set of instructions.
        Parameters:
        nl - The instruction list.
        immediate - The immediate value.
      • makeObject

        public static void makeObject​(org.objectweb.asm.tree.InsnList nl,
                                      org.objectweb.asm.Type type)
        Make a value to an object.
        Parameters:
        nl - The instruction list.
        type - The value type.
      • makeObject

        public static int makeObject​(org.objectweb.asm.tree.InsnList nl,
                                     org.objectweb.asm.Type arg,
                                     int pos)
        Make a value to an object.
        Parameters:
        nl - The instruction list.
        type - The value type.
        pos - The position of the value on the registers (default=1, 0 is this).
        Returns:
        The updated position value.
      • makeBasicType

        public static void makeBasicType​(org.objectweb.asm.tree.InsnList nl,
                                         org.objectweb.asm.Type type)
        Make a value a basic type.
        Parameters:
        nl - The instruction list.
        type - The value type.
      • makeReturn

        public static void makeReturn​(org.objectweb.asm.tree.InsnList nl,
                                      org.objectweb.asm.Type type)
        Make a suitable return statement.
        Parameters:
        nl - The instruction list.
        type - The value type.
      • toClass

        public static java.lang.Class<?> toClass​(java.lang.String name,
                                                 byte[] data,
                                                 java.lang.ClassLoader loader,
                                                 java.security.ProtectionDomain domain)
        Transform byte Array into Class and define it in classloader.
        Returns:
        the loaded class or null, if the class is not valid, such as Map.entry "inner Classes".
      • getClassNode

        public static org.objectweb.asm.tree.ClassNode getClassNode​(java.lang.Class<?> clazz,
                                                                    java.lang.ClassLoader classloader)
        Get a class node for a class.
        Parameters:
        clazz - The clazz.
        Returns:
        The class node.
      • getByteCodeClassLoader

        public static IByteCodeClassLoader getByteCodeClassLoader​(java.lang.ClassLoader parent)
        Generates a ByteCodeClassLoader for loading a generated class.
        Parameters:
        parent - Parent ClassLoader.
        sharedloader - Set true, to use shared loaders.
        Returns:
        The ByteCodeClassLoader.
      • getByteCodeClassLoader

        public static IByteCodeClassLoader getByteCodeClassLoader​(java.lang.ClassLoader parent,
                                                                  boolean sharedloaders)
        Generates a ByteCodeClassLoader for loading a generated class.
        Parameters:
        parent - Parent ClassLoader.
        sharedloader - Set true, to use shared loaders.
        Returns:
        The ByteCodeClassLoader.
      • createByteCodeClassLoader

        public static final IByteCodeClassLoader createByteCodeClassLoader​(java.lang.ClassLoader... parents)
        Creates a byte code ClassLoader.
        Parameters:
        parents - ClassLoader parents, first parameters is the getParent() ClassLoader.
        Returns:
        The loader.