Java的虚拟机的Endianness [英] Java's Virtual Machine's Endianness

查看:152
本文介绍了Java的虚拟机的Endianness的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java在其虚拟机中使用了什么字节顺序?我记得在哪里读取它取决于它运行的物理机器,然后我读到的其他地方,我相信它始终是大端。哪个是正确的?

What endianness does Java use in its virtual machine? I remember reading somewhere that it depends on the physical machine it's running on, and then other places I have read that it is always, I believe, big endian. Which is correct?

推荐答案

存储文件中的多字节数据big-endian。

Multibyte data in the class files are stored big-endian.

来自 Java虚拟机规范,Java SE 7 Edition 第4章:文件格式

From The Java Virtual Machine Specification, Java SE 7 Edition, Chapter 4: The class File Format:


类文件由
8位字节流组成。所有16位,32位和
64位数量均由
构成,分别读取两个,四个和八个
连续8位字节。
多字节数据项总是以big-endian顺序存储
,其中高
字节优先。

A class file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first.

此外,字节码指令中的操作数如果跨越多个字节也是big-endian。

Furthermore, the operand in an bytecode instruction is also big-endian if it spans multiple bytes.

来自 Java虚拟机规范,Java SE 7 Edition 第2.11节:指令集摘要


如果一个操作数在
大小中超过一个字节,那么它首先存储在big-endian
order-high-order字节中。对于
示例,
的无符号16位索引将局部变量存储为两个
无符号字节, byte1 byte2 ,例如
,其值为(byte1<< 8)| byte2

所以是的,我认为可以说Java虚拟机使用的是big-endian 。

So yes, I think it can be said that the Java Virtual Machine uses big-endian.

这篇关于Java的虚拟机的Endianness的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆