gpt4 book ai didi

java - Java如何识别一个位置是否持有原始或引用

转载 作者:搜寻专家 更新时间:2023-11-01 03:18:37 26 4
gpt4 key购买 nike

如果堆上有一个对象,并且该对象有几个实例变量,一些是原始类型,一些是其他对象。那么,如果这个对象有 5 个字段,对象在内存中的结构是怎样的?具体... Java将每个字段的数据类型存储在哪里?是否有一些“标志字节”和一些“数据字节”,其中“标志字节”标识接下来几个“数据字节”的数据类型?

我指的是超出此答案的一些其他细节: https://stackoverflow.com/a/19623603/1364747

这个答案提出了更多关于数据本身如何存储在内存中的细节: https://stackoverflow.com/a/1907455/1364747

但它仍然没有说明标志存储在哪里,表示数据类型是 int/long/double/float/reference。

最佳答案

这是一个更具体的答案,恐怕仍然无法回答您的所有问题。这是来自 java 7 文档的链接,相关部分是“2.11。指令集摘要”:https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html

我将复制并粘贴其中的一些内容:

2.11.1。类型和 Java 虚拟机

Most of the instructions in the Java Virtual Machine instruction set encode type information about the operations they perform. For instance, the iload instruction (§iload) loads the contents of a local variable, which must be an int, onto the operand stack. The fload instruction (§fload) does the same with a float value. The two instructions may have identical implementations, but have distinct opcodes.

For the majority of typed instructions, the instruction type is represented explicitly in the opcode mnemonic by a letter: i for an int operation, l for long, s for short, b for byte, c for char, f for float, d for double, and a for reference.

2.11.2。加载和存储说明

The load and store instructions transfer values between the local variables (§2.6.1) and the operand stack (§2.6.2) of a Java Virtual Machine frame (§2.6).

Instructions that access fields of objects and elements of arrays (§2.11.5) also transfer data to and from the operand stack.

还有很多。有趣的阅​​读。

关于java - Java如何识别一个位置是否持有原始或引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38727219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com