Class Code
java.lang.Object
EDU.purdue.cs.bloat.file.Attribute
EDU.purdue.cs.bloat.file.Code
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:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCode(ClassInfo classInfo, DataInputStream in, int index, int len) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionclone()byte[]code()Get the bytes of the code.intReturn the length of the code arrayCatch[]Get the exception handlers in the method.intlength()Get the length of the attribute.Get the line number debug info for the code.locals()Get the local variable debug info for the code.intGet the maximum number of locals used by the code.intmaxStack()Get the maximum height of the operand stack used by the code.voidsetCode(byte[] code) Set the bytes of the code.voidsetExceptionHandlers(Catch[] handlers) Set the exception handlers in the method.voidsetLineNumbers(LineNumberDebugInfo[] lineNumbers) Set the line number debug info for the code.voidsetLocals(LocalDebugInfo[] locals) Set the local variable debug info for the code.voidsetMaxLocals(int maxLocals) Set the maximum number of locals used by the code.voidsetMaxStack(int maxStack) Set the maximum height of the operand stack used by the code.toString()Returns a string representation of the attribute.voidWrite the attribute to a data stream.
-
Constructor Details
-
Code
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
Write the attribute to a data stream.- Specified by:
writeDatain classAttribute- 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
Set the exception handlers in the method.- Parameters:
handlers- The handlers.
-
length
-
lineNumbers
Get the line number debug info for the code.- Returns:
- The line number debug info for the code.
-
locals
Get the local variable debug info for the code.- Returns:
- The local variable debug info for the code.
-
setLineNumbers
Set the line number debug info for the code.- Parameters:
lineNumbers- The line number debug info for the code.
-
setLocals
Set the local variable debug info for the code.- Parameters:
locals- The local variable debug info for the code.
-
exceptionHandlers
-
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
-
toString
-