在启动 Java 时使用 -d32 和 -d64

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31078803/
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-08-11 10:37:00  来源:igfitidea点击:

Usage of -d32 and -d64 while launching Java

javacommand-line-arguments

提问by hagrawal

I read below excerpt from JDK FAQ's

我阅读了以下JDK 常见问题解答的摘录

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.

如何在 32 位和 64 位操作之间进行选择?默认是什么?选项 -d32 和 -d64 已添加到 Java 启动器中,以指定程序是在 32 位还是 64 位环境中运行。在 Solaris 上,它们分别对应于 ILP32 和 LP64 数据模型。由于 Solaris 在同一 Java 安装中同时包含 32 位和 64 位 J2SE 实现,因此您可以指定任一版本。如果 -d32 和 -d64 均未指定,则默认为在 32 位环境中运行。

Now to test this, I logged in into my 64 bit Ubuntu guest OS and installed 64 bit JDK version - Linux x64 165.24 MB jdk-8u45-linux-x64.tar.gz.

现在为了测试这个,我登录到我的 64 位 Ubuntu 来宾操作系统并安装了 64 位 JDK 版本 - Linux x64 165.24 MB jdk-8u45-linux-x64.tar.gz.

After installing the JDK, when I run my java program using -d64then everything is as expected because it is in fact a 64 bit installation but when I use -d32then I get error saying Error - This Java instance does not support 32 bit JVM.

安装 JDK 后,当我使用 java 程序运行时,-d64一切都如预期,因为它实际上是 64 位安装,但是当我使用时,-d32我收到错误提示Error - This Java instance does not support 32 bit JVM.

Error is understandable to me, but what confuses me is this line (as in above quoted para) "The options -d32 and -d64 have been added to the Java launcher to specify whether the programis to be run in a 32 or 64-bit environment."
As per this line, my understanding is that when launching Java of 64 bit version, -d32can be used to launch it in 32 bit mode.

错误对我来说是可以理解的,但让我感到困惑的是这一行(如上面引用的段落)“选项 -d32 和 -d64 已添加到 Java 启动器中,以指定程序是在 32 位还是 64 位中运行-位环境。”
根据这一行,我的理解是在启动 64 位版本的 Java 时,-d32可以使用它以 32 位模式启动它。

Questions:

问题:

  1. Is my understanding correct? And if it is correct, then I am getting error?
  2. If my understanding is not true, then why do I need these command-line arguments, because when I will launch Java using javathen whichever installation (32 bit or 64 bit JDK) is in my PATH will be launched.
  1. 我的理解正确吗?如果它是正确的,那么我就会出错?
  2. 如果我的理解不正确,那么为什么我需要这些命令行参数,因为当我将使用java我的 PATH 中的任何安装(32 位或 64 位 JDK)启动 Java 时。

采纳答案by Ortomala Lokni

The citation you made:

你的引用:

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.

选项 -d32 和 -d64 已添加到 Java 启动器中,以指定程序是在 32 位还是 64 位环境中运行。

is valid only for the Solaris operating system.

仅对 Solaris 操作系统有效。

Later in the JDK's FAQ, we can read:

稍后在JDK 的 FAQ 中,我们可以阅读:

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.

所有其他平台(Windows 和 Linux)都包含单独的 32 位和 64 位安装包。如果两个软件包都安装在一个系统上,您可以通过将适当的“bin”目录添加到您的路径中来选择其中一个。为了保持一致性,Linux 上的 Java 实现接受 -d64 选项。

So to answer your second question, in Windows and in Linux, theses flags are useless and the 32/64 bit selection is done by running the corresponding JVM installation.

所以要回答你的第二个问题,在 Windows 和 Linux 中,这些标志是没有用的,32/64 位选择是通过运行相应的 JVM 安装来完成的。