当前位置:网站首页>ClassFile - Attributes - Code
ClassFile - Attributes - Code
2022-07-02 09:20:00 【kq1983】
The Code
Attribute
The Code
attribute is a variable-length attribute in the attributes
table of a method_info
structure ( §4.6). A Code
attribute contains the Java Virtual Machine instructions and auxiliary information for a method, including an instance initialization method or a class or interface initialization method ( §2.9).
If the method is either native
or abstract
, its method_info
structure must not have a Code
attribute in its attributes
table. Otherwise, its method_info
structure must have exactly one Code
attribute in its attributes
table.
The Code
attribute has the following format:
Code_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 max_stack;
u2 max_locals;
u4 code_length; # What is the instruction length
u1 code[code_length]; # take code_length length Instructions
u2 exception_table_length;
{ u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
} exception_table[exception_table_length];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
The items of the Code_attribute
structure are as follows:
attribute_name_index
The value of the attribute_name_index
item must be a valid index into the constant_pool
table. The constant_pool
entry at that index must be a CONSTANT_Utf8_info
structure ( §4.4.7) representing the string "Code
".
attribute_length
The value of the attribute_length
item indicates the length of the attribute, excluding the initial six bytes.
max_stack
The value of the max_stack
item gives the maximum depth of the operand stack of this method ( §2.6.2) at any point during execution of the method.
max_locals
The value of the max_locals
item gives the number of local variables in the local variable array allocated upon invocation of this method ( §2.6.1), including the local variables used to pass parameters to the method on its invocation.
The greatest local variable index for a value of type long
or double
is max_locals - 2
. The greatest local variable index for a value of any other type is max_locals - 1
.
code_length
The value of the code_length
item gives the number of bytes in the code
array for this method.
The value of code_length
must be greater than zero (as the code
array must not be empty) and less than 65536.
code[]
The code
array gives the actual bytes of Java Virtual Machine code that implement the method.
When the code
array is read into memory on a byte-addressable machine, if the first byte of the array is aligned on a 4-byte boundary, the tableswitch and lookupswitch 32-bit offsets will be 4-byte aligned. (Refer to the descriptions of those instructions for more information on the consequences of code
array alignment.)
The detailed constraints on the contents of the code
array are extensive and are given in a separate section ( §4.9).
exception_table_length
The value of the exception_table_length
item gives the number of entries in the exception_table
table.
exception_table[]
Each entry in the exception_table
array describes one exception handler in the code
array. The order of the handlers in the exception_table
array is significant ( §2.10).
Each exception_table
entry contains the following four items:
start_pc, end_pc
The values of the two items start_pc
and end_pc
indicate the ranges in the code
array at which the exception handler is active. The value of start_pc
must be a valid index into the code
array of the opcode of an instruction. The value of end_pc
either must be a valid index into the code
array of the opcode of an instruction or must be equal to code_length
, the length of the code
array. The value of start_pc
must be less than the value of end_pc
.
The start_pc
is inclusive and end_pc
is exclusive; that is, the exception handler must be active while the program counter is within the interval [start_pc
, end_pc
).
The fact that end_pc
is exclusive is a historical mistake in the design of the Java Virtual Machine: if the Java Virtual Machine code for a method is exactly 65535 bytes long and ends with an instruction that is 1 byte long, then that instruction cannot be protected by an exception handler. A compiler writer can work around this bug by limiting the maximum size of the generated Java Virtual Machine code for any method, instance initialization method, or static initializer (the size of any code array) to 65534 bytes.
handler_pc
The value of the handler_pc
item indicates the start of the exception handler. The value of the item must be a valid index into the code
array and must be the index of the opcode of an instruction.
catch_type
If the value of the catch_type
item is nonzero, it must be a valid index into the constant_pool
table. The constant_pool
entry at that index must be a CONSTANT_Class_info
structure ( §4.4.1) representing a class of exceptions that this exception handler is designated to catch. The exception handler will be called only if the thrown exception is an instance of the given class or one of its subclasses.
The verifier checks that the class is Throwable
or a subclass of Throwable
( §4.9.2).
If the value of the catch_type
item is zero, this exception handler is called for all exceptions.
This is used to implement finally
( §3.13).
attributes_count
The value of the attributes_count
item indicates the number of attributes of the Code
attribute.
attributes[]
Each value of the attributes
table must be an attribute_info
structure ( §4.7).
A Code
attribute can have any number of optional attributes associated with it.
The attributes defined by this specification as appearing in the attributes
table of a Code
attribute are listed in Table 4.7-C.
The rules concerning attributes defined to appear in the attributes
table of a Code
attribute are given in §4.7.
The rules concerning non-predefined attributes in the attributes
table of a Code
attribute are given in §4.7.1.
边栏推荐
- Ora-12514 problem solving method
- 十年開發經驗的程序員告訴你,你還缺少哪些核心競爭力?
- Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
- Sentinel reports failed to fetch metric connection timeout and connection rejection
- 机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
- Leetcode sword finger offer brush questions - day 22
- Oracle modifies tablespace names and data files
- 【Go实战基础】如何安装和使用 gin
- Insight into cloud native | microservices and microservice architecture
- win10使用docker拉取redis镜像报错read-only file system: unknown
猜你喜欢
I've taken it. MySQL table 500W rows, but someone doesn't partition it?
概念到方法,绝了《统计学习方法》——第三章、k近邻法
How to realize asynchronous programming in a synchronous way?
Shengshihaotong and Guoao (Shenzhen) new energy Co., Ltd. build the charging pile industry chain
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
Watermelon book -- Chapter 5 neural network
京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
Matplotlib swordsman Tour - an artist tutorial to accommodate all rivers
cmd窗口中中文呈现乱码解决方法
【Go实战基础】如何安装和使用 gin
随机推荐
十年开发经验的程序员告诉你,你还缺少哪些核心竞争力?
聊聊消息队列高性能的秘密——零拷贝技术
Cartoon rendering - average normal stroke
[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the
微服务实战|熔断器Hystrix初体验
[go practical basis] gin efficient artifact, how to bind parameters to structures
MYSQL安装出现问题(The service already exists)
Ora-12514 problem solving method
Leetcode sword finger offer brush questions - day 22
Matplotlib swordsman Tour - an artist tutorial to accommodate all rivers
Break the cocoon | one article explains what is the real cloud primordial
十年開發經驗的程序員告訴你,你還缺少哪些核心競爭力?
[go practical basis] how can gin get the request parameters of get and post
数构(C语言)——第四章、矩阵的压缩存储(下)
Redis zadd导致的一次线上问题排查和处理
JVM instruction mnemonic
双非本科生进大厂,而我还在底层默默地爬树(上)
Win10 uses docker to pull the redis image and reports an error read only file system: unknown
破茧|一文说透什么是真正的云原生
1、 QT's core class QObject