java 当没有指定 -d32 或 -d64 之类的选项时,64 位 JVM 是否会以 64 位模式运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10696967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:09:10  来源:igfitidea点击:

Will a 64 bit JVM run in 64 bit mode when no option like -d32 or -d64 is specified

javajvm

提问by Twaha Mehmood

I have installed a 64 bit Java on a 64 bit Centos machine. My query is that if I dont specify the -d64 option will the JVM run in 32 bit mode even if there is no 32 bit JVM installed ?

我在 64 位 Centos 机器上安装了 64 位 Java。我的疑问是,如果我不指定 -d64 选项,即使没有安装 32 位 JVM,JVM 也会以 32 位模式运行吗?

Also I was a bit curious if we can use the -d64 option with "javac". If yes, then what does it imply or where could it be used? I came across this when reading this article.

另外我有点好奇我们是否可以将 -d64 选项与“javac”一起使用。如果是,那么它意味着什么或可以在哪里使用?我在阅读这篇文章时遇到了这个问题。

Thanks

谢谢

回答by Daniel De León

The selection of the data model (bits) for the JRE is to constrain the operation of the application to only run in one mode. The java byte code is designed to work in both data models, so for the 100% pure java applications, will work according the behavior and benefits of each architecture.

JRE 数据模型(位)的选择是为了将应用程序的操作限制为仅在一种模式下运行。java 字节码被设计为在两种数据模型中都可以工作,因此对于 100% 纯 java 应用程序,将根据每种架构的行为和优势工作。

But, if your application use native libs that work only in one mode, then the application will fail under the not supported one. For that, you must explicitly indicate in which mode it should run.

但是,如果您的应用程序使用仅在一种模式下工作的本机库,那么应用程序将在不受支持的模式下失败。为此,您必须明确指出它应该在哪种模式下运行。

When you set -d32 or -d64 the JRE will not startyour application if it can't run in the selected mode.

当您设置 -d32 或 -d64 时,如果 JRE无法在所选模式下运行,JRE 将不会启动您的应用程序。

回答by Adam Mihalcin

From the Oracle document you linked to:

从您链接到的 Oracle 文档中:

How do I select between 32 and 64-bit operation? What's the default?

The options -d32 and -d64 have been added to the Java launcher to specify whether the program is to be run in a 32 or 64-bit environment. On Solaris these correspond to the ILP32 and LP64 data models, respectively. Since Solaris has both a 32 and 64-bit J2SE implementation contained within the same installation of Java, you can specify either version. If neither -d32 nor -d64 is specified, the default is to run in a 32-bit environment.
Other Java commands (javac, javadoc, etc.) will rarely need to be executed in a 64-bit environment. However, the -d32/-d64 options may be passed to these commands and then on to the Java launcher using the established -J prefix option (eg: -J-d64).
All other platforms (Windows and Linux) contain separate 32 and 64-bit installation packages. If both packages are installed on a system, you select one or the other by adding the appropriate "bin" directory to your path. For consistency, the Java implementations on Linux accept the -d64 option.

如何在 32 位和 64 位操作之间进行选择?默认是什么?

选项 -d32 和 -d64 已添加到 Java 启动器中,以指定程序是在 32 位还是 64 位环境中运行。在 Solaris 上,它们分别对应于 ILP32 和 LP64 数据模型。由于 Solaris 在同一 Java 安装中同时包含 32 位和 64 位 J2SE 实现,因此您可以指定任一版本。 如果 -d32 和 -d64 均未指定,则默认为在 32 位环境中运行。
其他 Java 命令(javac、javadoc 等)很少需要在 64 位环境中执行。但是,-d32/-d64 选项可以传递给这些命令,然后使用已建立的 -J 前缀选项(例如:-J-d64)传递给 Java 启动器。
所有其他平台(Windows 和 Linux)都包含单独的 32 位和 64 位安装包。如果两个软件包都安装在一个系统上,您可以通过将适当的“bin”目录添加到您的路径中来选择其中一个。为了保持一致性,Linux 上的 Java 实现接受 -d64 选项。

(emphasis mine)

(强调我的)

So, according to the document you linked to, the default is to run in a 32-bit JRE, and it is possible to run javac in a 64-bit JRE by passing -J-d64rather than simply -d64.

因此,根据您链接的文档,默认是在 32 位 JRE 中运行,并且可以通过传递-J-d64而不是简单地在 64 位 JRE 中运行 javac -d64

However, note that this document also says that it applies to Java 1.4, and says nothingabout more recent versions of Java.

但是,请注意,该文档还说它适用于 Java 1.4,而没有提及更新的 Java 版本。