- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
JVM class
file format使用 constant_pool_count
指定类常量池的大小:
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
其中 constant_pool_count
定义为
The value of the
constant_pool_count
item is equal to the number of entries in theconstant_pool
table plus one.
为什么以这种“加一”的方式指定计数而不是等于常量的数量?同时,interfaces_count
、fields_count
、methods_count
和 attributes_count
似乎不遵循这种模式。
一些猜测:
更新: This section在维基百科上并没有做太多澄清:
Due to historic choices made during the file format development, the number of constants in the constant pool table is not actually the same as the constant pool count which precedes the table. First, the table is indexed starting at 1 (rather than 0), but the count should actually be interpreted as the maximum index plus one.[3] Additionally, two types of constants (longs and doubles) take up two consecutive slots in the table, although the second such slot is a phantom index that is never directly used.
第二部分解释了为什么计数不一定等于常量的数量,如果它们中的任何一个恰好是 long
或 double
,但它仍然不是清楚为什么“加一”与基于 1 的索引有任何关系,如果它们从数组长度中减去它的话。
最佳答案
因为constant_pool_count本身包含在constant_pool(第一个常量)中。这在逻辑上是 constaint_pool[0] == constant_pool_count。
但是constant_pool_count是ClassFile结构体中的一个字段,constant_pool数组就没有必要再包含它了。
因此从 constant_pool 数组中删除 constant_pool_count,constant_pool 数组的长度将为 constant_pool_count - 1。
deleted:
BTW: as you can notice, the constant_pool_count is u2, theconstant_pool entries are cp_info(u1+u1=u2), u2 and cp_info areequivelant structure in length.
将 u2 视为 {u1; u1[1]},类似于cp_info{u1; u1[]}.
关于java - JVM 类格式 : Why is `constant_pool_count` one larger than it "should" be?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23674727/
我正在编写我的 servlet 程序并使用 jconsole 和 jmap 来监视其内存状态。我发现当我的程序运行时,内存池“PS Old Gen”变得越来越大,最后我的 servlet 无法响应任何
我正在执行从 tfs.visualstudio 到内部部署 2012 服务器的 TFS 集成迁移。我遇到了一个包含多个超过 1 MB 的二进制文件的特定变更集的问题,其中一些是 15-16 MB。 [
考虑一个带有内置整型常量的 Rust 程序 const N: u64和运行时整数值 x: u64 。我想匹配x这样值 x N分别。我的第一次尝试如下所示: const N: u64 = 3; mat
我不确定为什么,但我在使用 OG Debugger 时不断收到此警告并且 Facebook 没有加载正确的错误。它告诉我图像不够大,但图像是 404x404px,所以我不确定它的预期是什么,因为它符合
我在 PostgreSQL 中有一个包含一个数字列的表,我有一个给定的数字 x . 如果x在表格中,我想要所有数字 >= x . 如果x不在表格里,我要所有的数字> x和最大的数字 12 UNION
我想为我的用户提供显示某些 的可能性字体大小大于系统默认值的元素。 documentation仅提供该样式的编号。 我想显示带有 web-css“大”或“更大”值的文本,或者可能是 的 140%。原
您好,新年快乐, 我正在开发内核模块。有必要对某些参数进行数值计算才能正确设置设备。该函数工作完美,但 gcc 编译器(我正在使用 kbuild)给了我警告: warning: the frame s
我正在解决一些关于图表的问题。它需要存储 N 个节点的权重(N。如果一个节点连接到几乎所有其他节点,这是不好的,如果连接到几个节点,则便宜 删除边对于大社区来说也是昂贵的(在最坏的线性时间内,一个
我正在尝试实现一个读取图像宽度和高度的脚本,如果图像高度大于 600,则将 html div 的高度设置为 600。如果高度小于 600,则 div 的高度将是图像的高度。 这是我一直在尝试的。 Ja
我想用 while 循环测量计算时间。 我正在使用 C99 版本进行编程。 我的代码如下: struct timeval startingTime,endingTime; gettimeofday(&
以下算法返回数组中前一个较大的元素。它来自 these 的第 11 页笔记。 // Input: An array of numeric values a[1..n] // Returns: An a
我需要将科学信息存储在数据库 (sql server) 中。在“小于”、“大于”是信息的一部分的数据库中存储值的最佳方式是什么。 例子: 患者编号:123变异率:<3% 患者编号:999突变率:3%
在 Excel 中,是否有一个 native 函数可以返回两个值中较大的一个?我希望避免使用 IF 函数。如果值得的话,我正在使用 Excel 2010 Beta。 例如: GTR(66,24) 将返
我正在开发一个项目,需要通过 RMI 网络显示一些加密解密。我为此使用 RSA 系统。解密时,我的代码出现以下错误: javax.crypto.BadPaddingException: Message
我已从 Visual Studio 多次部署到 Azure 网站,但从几周前开始我无法再进行部署。我一遍又一遍地收到此错误 Web deployment task failed. (Error des
假设我在 h1 元素中有一个标题(任何元素都可以)。它的内容是动态的(不知道标题的长度)。它应该显示在一行中。 h1 在一个大小有限的 DIV(我们称之为容器)中。 我怎么知道元素 (h1) 是否溢出
我在基于此 real-world example 的小型项目中使用 Redux/sagas 工作流,但这些逻辑并不那么复杂。我应该如何使用更全面的 API(即 Reddit 的 API)而不会使事情变
我收到以下错误 - 显然是在保存模型时 Step = 1799 | Tensorflow Accuracy = 1.0 Step = 1799 | My Accuracy = 0.036335
我已经安装了mysql服务器5.1。当我尝试插入一个大文件时,我的 MySQL 数据库中的 BLOB 字段出现问题。有人有什么建议吗? 提前非常感谢 最佳答案 如何解决此问题: 更改 max_allo
我有以下代码 Can you click me? 目标是我可以点击“你能点击我吗”框并转到 google 并在包含 div 的任何其他地方
我是一名优秀的程序员,十分优秀!