java 常量池 index 索引位置的坑
2022-04-06 本文已影响0人
onedam
https://stackoverflow.com/questions/41541036/valid-unusable-constant-pool-index
All 8-byte constants take up two entries in the constant_pool table of the class file. If a CONSTANT_Long_info or CONSTANT_Double_info structure is the item in the constant_pool table at index n, then the next usable item in the pool is located at index n+2. The constant_pool index n+1 must be valid but is considered unusable.
In retrospect, making 8-byte constants take two constant pool entries was a poor choice.
(在类文件的常量池表中,所有8字节常量占用两个条目。如果常量Long_info或常量Double_info结构是索引n处常量池表中的项,则池中下一个可用项位于索引n+2处。常量池索引n+1必须有效,但被视为不可用。
回想起来,让8字节常量包含两个常量池条目是一个糟糕的选择。)
image.png一个long 和 double 占常量池 2个索引号. 是历史遗留问题...wori ...
image.pngasm ClassReader 解析的时候 把index 和 size 分开来计算... 这里确实 ugly