Class TypeUtils

java.lang.Object
org.openjdk.jmc.agent.util.TypeUtils

public final class TypeUtils extends Object
Helper methods for doing transforms.
  • Field Details

    • NULL_REFERENCE_STRING

      private static final String NULL_REFERENCE_STRING
      See Also:
    • INAME

      public static final 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 String INTERNAL_NAME_STRING
      See Also:
    • INTERNAL_NAME_THREAD

      public static final String INTERNAL_NAME_THREAD
    • INTERNAL_NAME_CLASS

      public static final String INTERNAL_NAME_CLASS
    • UNSAFE_JDK_7_CLASS

      private static final String UNSAFE_JDK_7_CLASS
      See Also:
    • UNSAFE_JDK_11_CLASS

      private static final String UNSAFE_JDK_11_CLASS
      See Also:
    • UNSAFE

      private static final Object UNSAFE
    • UNSAFE_DEFINE_CLASS_METHOD

      private static final Method UNSAFE_DEFINE_CLASS_METHOD
    • JAVA_FILE_EXTENSION

      public static final String JAVA_FILE_EXTENSION
      The file extension for java source files (.java).
      See Also:
  • Constructor Details

    • TypeUtils

      private TypeUtils()
  • Method Details

    • box

      public static Object box(byte val)
    • box

      public static Object box(short val)
    • box

      public static Object box(char val)
    • box

      public static Object box(int val)
    • box

      public static Object box(long val)
    • box

      public static Object box(float val)
    • box

      public static Object box(double val)
    • toString

      public static String toString(Object o)
    • defineClass

      public static Class<?> defineClass(String eventClassName, byte[] eventClass, int i, int length, ClassLoader definingClassLoader, 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(String identifier)
    • deriveIdentifierPart

      public static String deriveIdentifierPart(String str)
    • getPathPart

      public static String getPathPart(String fqcn)
    • getNamePart

      public static String getNamePart(String fqcn)
    • stringify

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

      public static String parameterize(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 String getInternalName(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 String getCanonicalName(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 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 String toString(Object o, int length)
      Type agnostic array toString() which also handles primitive arrays.
    • emitBox

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

      private static Object getUnsafe()
    • getUnsafeDefineClassMethod

      private static Method getUnsafeDefineClassMethod(Object unsafe)
    • getUnsafeClass

      private static Class<?> getUnsafeClass()