首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >The Java® Virtual Machine Specification Java SE 26 Edition 中文版简介第二小节:The Java Virtual Machine

The Java® Virtual Machine Specification Java SE 26 Edition 中文版简介第二小节:The Java Virtual Machine

作者头像
jack.yang
发布2026-04-13 07:51:33
发布2026-04-13 07:51:33
830
举报

原文:

1.2 The Java Virtual Machine

The Java Virtual Machine is the cornerstone of the Java platform. It is the component of the technology responsible for its hardware- and operating systemindependence, the small size of its compiled code, and its ability to protect users from malicious programs.

The Java Virtual Machine is an abstract computing machine. Like a real computingmachine, it has an instruction set and manipulates various memory areas at run time.It is reasonably common to implement a programming language using a virtualmachine; the best-known virtual machine may be the P-Code machine of UCSDPascal.

The first prototype implementation of the Java Virtual Machine, done at Sun Microsystems, Inc., emulated the Java Virtual Machine instruction set in software hosted by a handheld device that resembled a contemporary Personal Digital Assistant (PDA). Oracle's current implementations emulate the Java Virtual Machine on mobile, desktop and server devices, but the Java Virtual Machine does not assume any particular implementation technology, host hardware, or host operating system. It is not inherently interpreted, but can just as well be implemented by compiling its instruction set to that of a silicon CPU. It may also be implemented in microcode or directly in silicon.

The Java Virtual Machine knows nothing of the Java programming language, only of a particular binary format, the class file format. A class file contains Java Virtual Machine instructions (or bytecodes) and a symbol table, as well as other ancillary information.

For the sake of security, the Java Virtual Machine imposes strong syntactic and structural constraints on the code in a class file. However, any language with functionality that can be expressed in terms of a valid class file can be hosted by the Java Virtual Machine. Attracted by a generally available, machine-independent platform, implementors of other languages can turn to the Java Virtual Machine as a delivery vehicle for their languages.

The class file format is versioned: every class file declares a version number, of the form major.minor, which indicates the file's dependency on a particular release of Java SE, and influences the interpretation of the file by the Java Virtual Machine. The Java Virtual Machine specified here is compatible with Java SE 26, and supports the Java programming language specified in The Java Language Specification, Java SE 26 Edition. It supports class files with major version numbers 45 through 70, inclusive. Tools that generate class files will typically adopt the latest major version number in order to take advantage of the latest features; but a class file with an older major version number can generally expect to be supported in future Java Virtual Machine releases.

For reference, the following table shows the class file major version numbers supported by each release of Java SE, up to Java SE 26. The third column, "Earliest", shows the earliest class file major version number supported by the Java Virtual Machine in that release. The fourth column, "Latest", shows the latest class file major version number supported by the Java Virtual Machine in that release. (For very early releases, the JDK version is shown instead of the Java SE release.)


大意:

1.2 Java 虚拟机

Java 虚拟机(Java Virtual Machine,JVM)是 Java 平台的基石。它是该技术中负责实现硬件与操作系统无关性、编译后代码体积小巧,以及保护用户免受恶意程序侵害的核心组件。

Java 虚拟机是一种抽象的计算机器。与真实的计算机器类似,它拥有自己的指令集,并在运行时操作多种内存区域。使用虚拟机来实现编程语言的做法相当普遍;其中最著名的虚拟机或许是 UCSD Pascal 的 P-Code 机。

Java 虚拟机的第一个原型实现由 Sun Microsystems 公司完成,它通过软件模拟 Java 虚拟机指令集,运行在一款类似于当时个人数字助理(PDA)的手持设备上。如今,Oracle 的实现可在移动设备、桌面计算机和服务器上模拟 Java 虚拟机。但 Java 虚拟机本身并不依赖于任何特定的实现技术、宿主硬件或宿主操作系统。它并非天生就是解释执行的,同样也可以通过将它的指令集编译为硅基 CPU 的本地指令来实现。此外,它还可以用微码实现,甚至直接以硬件(硅片)形式实现。

Java 虚拟机对 Java 编程语言本身一无所知,它只认识一种特定的二进制格式——类文件格式(class file format)。类文件包含 Java 虚拟机指令(即字节码)、符号表以及其他辅助信息。

出于安全考虑,Java 虚拟机对类文件中的代码施加了严格的语法和结构约束。然而,任何语言只要其功能可以表达为合法的类文件格式,就可以运行在 Java 虚拟机之上。由于 Java 虚拟机提供了一个广泛可用且与机器无关的平台,其他语言的实现者纷纷将其作为自己语言的交付载体。

类文件格式是有版本号的:每个类文件都声明一个形如 major.minor 的版本号,用于表明该文件对特定 Java SE 发布版本的依赖关系,并影响 Java 虚拟机对该文件的解析方式。本文所规范的 Java 虚拟机兼容 Java SE 26,支持《The Java Language Specification, Java SE 26 Edition》中所规定的 Java 编程语言。它支持主版本号(major version number)从 45 到 70(含)的类文件。

通常,生成类文件的工具会采用最新的主版本号,以便利用最新的语言或虚拟机特性;而使用较早主版本号的类文件,一般也能在未来的 Java 虚拟机版本中继续得到支持。

为便于参考,下表列出了截至 Java SE 26 为止,各 Java SE 版本所支持的类文件主版本号范围。第三列“最早”(Earliest)表示该版本 Java 虚拟机所支持的最小类文件主版本号,第四列“最新”(Latest)表示其所支持的最大类文件主版本号。(对于非常早期的版本,表中列出的是 JDK 版本号而非 Java SE 版本号。)

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2026-04-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 原文:
    • 1.2 The Java Virtual Machine
  • 大意:
    • 1.2 Java 虚拟机
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档