Class Code


public class Code extends Attribute
Code is used to store the Code attribute of a method in a class file. The Code attribute stores the raw bytecode of the method, the maximum stack height and maximum number of locals used by the method, and the exception handlers used in the method. Code may have several attributes. The local variable table and the line number table are modeled explicitly. All other attributes are modeled as generic attributes.
See Also:
  • Constructor Details

    • Code

      public Code(ClassInfo classInfo, DataInputStream in, int index, int len) throws IOException
      Constructor. Create a Code attribute from a data stream.
      Parameters:
      in - The data stream containing the class file.
      index - The index into the constant pool of the name of the attribute.
      len - The length of the attribute, excluding the header.
      Throws:
      IOException - If an error occurs while reading.
  • Method Details

    • writeData

      public void writeData(DataOutputStream out) throws IOException
      Write the attribute to a data stream.
      Specified by:
      writeData in class Attribute
      Parameters:
      out - The data stream of the class file.
      Throws:
      IOException - If an error occurs while writing.
    • setMaxStack

      public void setMaxStack(int maxStack)
      Set the maximum height of the operand stack used by the code.
      Parameters:
      maxStack - The maximum height of the stack.
    • setMaxLocals

      public void setMaxLocals(int maxLocals)
      Set the maximum number of locals used by the code.
      Parameters:
      maxLocals - The maximum number of locals.
    • maxStack

      public int maxStack()
      Get the maximum height of the operand stack used by the code.
      Returns:
      The maximum number of locals.
    • maxLocals

      public int maxLocals()
      Get the maximum number of locals used by the code.
      Returns:
      The maximum number of locals.
    • setExceptionHandlers

      public void setExceptionHandlers(Catch[] handlers)
      Set the exception handlers in the method.
      Parameters:
      handlers - The handlers.
    • length

      public int length()
      Get the length of the attribute.
      Overrides:
      length in class Attribute
      Returns:
      The length of the attribute.
    • lineNumbers

      public LineNumberDebugInfo[] lineNumbers()
      Get the line number debug info for the code.
      Returns:
      The line number debug info for the code.
    • locals

      public LocalDebugInfo[] locals()
      Get the local variable debug info for the code.
      Returns:
      The local variable debug info for the code.
    • setLineNumbers

      public void setLineNumbers(LineNumberDebugInfo[] lineNumbers)
      Set the line number debug info for the code.
      Parameters:
      lineNumbers - The line number debug info for the code.
    • setLocals

      public void setLocals(LocalDebugInfo[] locals)
      Set the local variable debug info for the code.
      Parameters:
      locals - The local variable debug info for the code.
    • exceptionHandlers

      public Catch[] exceptionHandlers()
      Get the exception handlers in the method.
      Returns:
      The handlers.
    • code

      public byte[] code()
      Get the bytes of the code.
      Returns:
      The code.
    • codeLength

      public int codeLength()
      Return the length of the code array
    • setCode

      public void setCode(byte[] code)
      Set the bytes of the code.
      Parameters:
      code - The code.
    • clone

      public Object clone()
      Overrides:
      clone in class Attribute
    • toString

      public String toString()
      Returns a string representation of the attribute.
      Overrides:
      toString in class Attribute