- 论坛徽章:
- 0
|
在编一个读.class file的java程序。
程序基本正常,但是当源程序中有double或long常量的时候,对constant pool的读取就会出问题。读取的序号会发生混乱。我调了很久也没能解决。
jvm的规范说遇到这两种常量在读.class文件时要跳过一个entry。我的理解是正常读下一个entry,然后把序号加一,从再下一个entry开始视为有效entry。可是这样做了之后,发现总的entry少了一个。读到最后一个constant已经越界了。
这个问题不好说清楚。有谁做过类似的事情,能说一下对jvm规范里下面这句话的正确理解吗。
All eight-byte constants take up two entries in the constant_pool table of the class file, as well as in the in-memory version of the constant pool that is constructed when a class file is read. If a CONSTANT_Long_info or CONSTANT_Double_info structure is the item in the constant_pool table at index n, then the next valid item in the pool is located at index n+2. The constant_pool index n+1 must be considered invalid and must not be used.
先谢谢了! |
|