Class AsmUtil

java.lang.Object
org.apache.drill.exec.compile.AsmUtil

public class AsmUtil extends Object
Utilities commonly used with ASM.

There are several class verification utilities which use CheckClassAdapter (DrillCheckClassAdapter) to ensure classes are well-formed; these are packaged as boolean functions so that they can be used in assertions.

  • Method Summary

    Modifier and Type
    Method
    Description
    static org.objectweb.asm.tree.ClassNode
    classFromBytes(byte[] classBytes, int asmReaderFlags)
    Create a ClassNode from bytecode.
    static boolean
    isClassBytesOk(org.slf4j.Logger logger, String logTag, byte[] classBytes)
    Check to see if a class is well-formed.
    static boolean
    isClassOk(org.slf4j.Logger logger, String logTag, org.objectweb.asm.tree.ClassNode classNode)
    Check to see if a class is well-formed.
    static boolean
    isXadd(int opcode)
    Determine if the given opcode is an ADD of some kind (xADD).
    static boolean
    isXconst(int opcode)
    Determine if the given opcode is a load of a constant (xCONST_y).
    static void
    logClass(org.slf4j.Logger logger, String logTag, org.objectweb.asm.tree.ClassNode classNode)
    Write a class to the log.
    static void
    logClassFromBytes(org.slf4j.Logger logger, String logTag, byte[] classBytes)
    Write a class to the log.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isClassOk

      public static boolean isClassOk(org.slf4j.Logger logger, String logTag, org.objectweb.asm.tree.ClassNode classNode)
      Check to see if a class is well-formed.
      Parameters:
      logger - the logger to write to if a problem is found
      logTag - a tag to print to the log if a problem is found
      classNode - the class to check
      Returns:
      true if the class is ok, false otherwise
    • isClassBytesOk

      public static boolean isClassBytesOk(org.slf4j.Logger logger, String logTag, byte[] classBytes)
      Check to see if a class is well-formed.
      Parameters:
      logger - the logger to write to if a problem is found
      logTag - a tag to print to the log if a problem is found
      classBytes - the bytecode of the class to check
      Returns:
      true if the class is ok, false otherwise
    • classFromBytes

      public static org.objectweb.asm.tree.ClassNode classFromBytes(byte[] classBytes, int asmReaderFlags)
      Create a ClassNode from bytecode.
      Parameters:
      classBytes - the bytecode
      asmReaderFlags - flags for ASM; see ClassReader.accept(org.objectweb.asm.ClassVisitor, int)
      Returns:
      the ClassNode
    • logClass

      public static void logClass(org.slf4j.Logger logger, String logTag, org.objectweb.asm.tree.ClassNode classNode)
      Write a class to the log.

      Writes at level TRACE.

      Parameters:
      logger - the logger to write to
      logTag - a tag to print to the log
      classNode - the class
    • logClassFromBytes

      public static void logClassFromBytes(org.slf4j.Logger logger, String logTag, byte[] classBytes)
      Write a class to the log.

      Writes at level DEBUG.

      Parameters:
      logTag - a tag to print to the log
      classBytes - the class' bytecode
      logger - the logger to write to
    • isXconst

      public static boolean isXconst(int opcode)
      Determine if the given opcode is a load of a constant (xCONST_y).
      Parameters:
      opcode - the opcode
      Returns:
      true if the opcode is one of the constant loading ones, false otherwise
    • isXadd

      public static boolean isXadd(int opcode)
      Determine if the given opcode is an ADD of some kind (xADD).
      Parameters:
      opcode - the opcode
      Returns:
      true if the opcode is one of the ADDs, false otherwise