Class TypeUtils


  • public final class TypeUtils
    extends java.lang.Object
    Helper methods for doing transforms.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TypeUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object box​(byte val)  
      static java.lang.Object box​(char val)  
      static java.lang.Object box​(double val)  
      static java.lang.Object box​(float val)  
      static java.lang.Object box​(int val)  
      static java.lang.Object box​(long val)  
      static java.lang.Object box​(short val)  
      static java.lang.Class<?> defineClass​(java.lang.String eventClassName, byte[] eventClass, int i, int length, java.lang.ClassLoader definingClassLoader, java.security.ProtectionDomain protectionDomain)  
      static java.lang.String deriveIdentifierPart​(java.lang.String str)  
      private static void emitBox​(org.objectweb.asm.MethodVisitor mv, java.lang.String desc)  
      static java.lang.String getCanonicalName​(java.lang.String binaryName)
      Converts a internal class name (binary name) into the canonical form.
      static int getConstZeroOpcode​(org.objectweb.asm.Type type)
      Returns the constant loading instruction that pushes a zero value of the given type onto the operand stack.
      static java.lang.Object getFrameVerificationType​(org.objectweb.asm.Type type)
      Returns a array element for ASM's MethodVisitor.visitFrame() method used for frame verification of a given type.
      static java.lang.String getInternalName​(java.lang.String className)
      Converts a canonical class name into the internal form (binary name).
      static java.lang.String getNamePart​(java.lang.String fqcn)  
      static java.lang.String getPathPart​(java.lang.String fqcn)  
      private static java.lang.Object getUnsafe()  
      private static java.lang.Class<?> getUnsafeClass()  
      private static java.lang.reflect.Method getUnsafeDefineClassMethod​(java.lang.Object unsafe)  
      static boolean isSupportedType​(org.objectweb.asm.Type type)
      Returns true if the type provided is supported for a JFR event field.
      static boolean isValidJavaIdentifier​(java.lang.String identifier)  
      static java.lang.String parameterize​(java.lang.String className)
      Transforms a FQN in internal form, so that it can be used in e.g.
      static void stringify​(org.objectweb.asm.MethodVisitor mv)  
      static java.lang.String toString​(java.lang.Object o)  
      private static java.lang.String toString​(java.lang.Object o, int length)
      Type agnostic array toString() which also handles primitive arrays.
      static void visitBox​(org.objectweb.asm.MethodVisitor mv, org.objectweb.asm.Type type)
      Ensure that the operand is on the stack before calling.
      • Methods inherited from class java.lang.Object

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

      • NULL_REFERENCE_STRING

        private static final java.lang.String NULL_REFERENCE_STRING
        See Also:
        Constant Field Values
      • INAME

        public static final java.lang.String INAME
        The internal name of this class.
      • TYPE_OBJECT

        public static final org.objectweb.asm.Type TYPE_OBJECT
      • TYPE_OBJECT_ARRAY

        public static final org.objectweb.asm.Type TYPE_OBJECT_ARRAY
      • TYPE_STRING

        public static final org.objectweb.asm.Type TYPE_STRING
      • INTERNAL_NAME_STRING

        public static final java.lang.String INTERNAL_NAME_STRING
        See Also:
        Constant Field Values
      • INTERNAL_NAME_THREAD

        public static final java.lang.String INTERNAL_NAME_THREAD
      • INTERNAL_NAME_CLASS

        public static final java.lang.String INTERNAL_NAME_CLASS
      • UNSAFE_JDK_7_CLASS

        private static final java.lang.String UNSAFE_JDK_7_CLASS
        See Also:
        Constant Field Values
      • UNSAFE_JDK_11_CLASS

        private static final java.lang.String UNSAFE_JDK_11_CLASS
        See Also:
        Constant Field Values
      • UNSAFE

        private static final java.lang.Object UNSAFE
      • UNSAFE_DEFINE_CLASS_METHOD

        private static final java.lang.reflect.Method UNSAFE_DEFINE_CLASS_METHOD
      • JAVA_FILE_EXTENSION

        public static final java.lang.String JAVA_FILE_EXTENSION
        The file extension for java source files (.java).
        See Also:
        Constant Field Values
    • Constructor Detail

      • TypeUtils

        private TypeUtils()
    • Method Detail

      • box

        public static java.lang.Object box​(byte val)
      • box

        public static java.lang.Object box​(short val)
      • box

        public static java.lang.Object box​(char val)
      • box

        public static java.lang.Object box​(int val)
      • box

        public static java.lang.Object box​(long val)
      • box

        public static java.lang.Object box​(float val)
      • box

        public static java.lang.Object box​(double val)
      • toString

        public static java.lang.String toString​(java.lang.Object o)
      • defineClass

        public static java.lang.Class<?> defineClass​(java.lang.String eventClassName,
                                                     byte[] eventClass,
                                                     int i,
                                                     int length,
                                                     java.lang.ClassLoader definingClassLoader,
                                                     java.security.ProtectionDomain protectionDomain)
      • visitBox

        public static void visitBox​(org.objectweb.asm.MethodVisitor mv,
                                    org.objectweb.asm.Type type)
        Ensure that the operand is on the stack before calling. If type is void, this is a noop, and depending on your use case you may instead want to push Opcodes.ACONST_NULL.
      • isValidJavaIdentifier

        public static boolean isValidJavaIdentifier​(java.lang.String identifier)
      • deriveIdentifierPart

        public static java.lang.String deriveIdentifierPart​(java.lang.String str)
      • getPathPart

        public static java.lang.String getPathPart​(java.lang.String fqcn)
      • getNamePart

        public static java.lang.String getNamePart​(java.lang.String fqcn)
      • stringify

        public static void stringify​(org.objectweb.asm.MethodVisitor mv)
      • parameterize

        public static java.lang.String parameterize​(java.lang.String className)
        Transforms a FQN in internal form, so that it can be used in e.g. formal descriptors.
        Parameters:
        className - the fully qualified class name in internal form.
        Returns:
        the transformed class name.
      • getInternalName

        public static java.lang.String getInternalName​(java.lang.String className)
        Converts a canonical class name into the internal form (binary name). eg. com.company.project converts into com/company/project
        Parameters:
        className - the canonical class name
        Returns:
        the internal form
      • getCanonicalName

        public static java.lang.String getCanonicalName​(java.lang.String binaryName)
        Converts a internal class name (binary name) into the canonical form. ie. com/company/project converts into com.company.project
        Parameters:
        binaryName - the internal class name
        Returns:
        in canonical form
      • getConstZeroOpcode

        public static int getConstZeroOpcode​(org.objectweb.asm.Type type)
        Returns the constant loading instruction that pushes a zero value of the given type onto the operand stack. A null reference is pushed if the given type is an object or an array.
        Parameters:
        type - the type of the operand
        Returns:
        the instruction
      • getFrameVerificationType

        public static java.lang.Object getFrameVerificationType​(org.objectweb.asm.Type type)
        Returns a array element for ASM's MethodVisitor.visitFrame() method used for frame verification of a given type.
        Parameters:
        type - the type of the element on the operand stack or in the local variable table.
        Returns:
        a array element for MethodVisitor.visitFrame()'s parameter.
      • isSupportedType

        public static boolean isSupportedType​(org.objectweb.asm.Type type)
        Returns true if the type provided is supported for a JFR event field.
        Parameters:
        type - the type to check.
        Returns:
        true if the type provided is supported for a JFR event field.
      • toString

        private static java.lang.String toString​(java.lang.Object o,
                                                 int length)
        Type agnostic array toString() which also handles primitive arrays.
      • emitBox

        private static void emitBox​(org.objectweb.asm.MethodVisitor mv,
                                    java.lang.String desc)
      • getUnsafe

        private static java.lang.Object getUnsafe()
      • getUnsafeDefineClassMethod

        private static java.lang.reflect.Method getUnsafeDefineClassMethod​(java.lang.Object unsafe)
      • getUnsafeClass

        private static java.lang.Class<?> getUnsafeClass()