Usage of -d32 and -d64 while launching Java

2020-07-03 09:11发布

问题:

I read below excerpt from JDK FAQ's

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.

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.

After installing the JDK, when I run my java program using -d64 then everything is as expected because it is in fact a 64 bit installation but when I use -d32 then I get error saying 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 program is 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, -d32 can be used to launch it in 32 bit mode.

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 java then whichever installation (32 bit or 64 bit JDK) is in my PATH will be launched.

回答1:

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.

is valid only for the Solaris operating system.

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

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.

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.