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

标签 java variables primitive-types

如果堆上有一个对象,并且该对象有几个实例变量,一些是原始类型,一些是其他对象。那么,如果这个对象有 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/

相关文章:

java - 根据登录的用户将JSP页面重定向到另一个JSP页面

java - 如何在 AS 级别为 EJB stub 创建我自己的代理

javascript - 带有变量的onclick mvc 4

java - TypeMirror void 从 Java 8 开始就不是 PrimitiveType

java - 是否可以在 Java 中编写交换方法?

java - 使用 Java 将目录内容从本地文件系统移动到 HDFS

java - Java 中的视频缩略图

c - 简单变量 i 和 *(&i) 之间的区别;

php - 在 PHP 中反向堆叠变量

c++ - 包装内置 C++ 类型以保证初始化