Usage of -d32 and -d64 while launching Java

46,960

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.

Share:
46,960

Related videos on Youtube

hagrawal
Author by

hagrawal

Oracle Certified Professional - Java SE Programmer Oracle Certified Expert - Web Component Developer

Updated on August 02, 2022

Comments

  • hagrawal
    hagrawal almost 2 years

    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.
    • hagrawal
      hagrawal almost 9 years
      No .. Then what's the point of Java's "compile once and run anywhere" .. You can compile a java program using 32 compiler and run it in a 64 bit JVM ..
    • Jesper
      Jesper almost 9 years
      @Danielson No, that is not how Java works. Java bytecode is platform-independent, you do not compile Java code for 32-bit or 64-bit.
    • biziclop
      biziclop almost 9 years
      AFAIK that switch only has any effect (other than error) on Solaris. This is according to table 4.4 of Java Performance: The Definitive Guide, I've never tested it myself.
    • nos
      nos almost 9 years
      @hagrawal The -d32 and -d64 works as described on Solaris as long as both 32 and 64 bit pacages are installed, but not on other platforms. (Albeit on Linux the 64 bit JVM accepts -d64 also)
  • hagrawal
    hagrawal over 8 years
    Thank you for your inputs. I did read that from JDK FAQ and that's what I asked in my 2nd question. I have to add the "bin" path in the PATH variable then essentially -d32 and -d64 will loose effect because if 32 installation is in the PATH then -d64 will not work. I agree with you on the part that -d32 and -d64 are only for Solaris.
  • hagrawal
    hagrawal over 8 years
    Thank you. Have you worked on Solaris any time? I was wondering how things happen in Solaris, is that JDK installation path will be set/exported in some env. variable or PATH? If so then what will happen if path of 32bit is set and while launching Java, -d64 is used ??
  • Ortomala Lokni
    Ortomala Lokni over 8 years
    I was working on Solaris a long time ago... In the FAQ, it's written you must first install the 32-bit SDKor JRE and then select and install the 64-bit package on top of the 32-bit version. It probably means that, there is one entry point and that the selection is then done through -d32/-d64
  • hagrawal
    hagrawal over 8 years
    I think that's the only thing which is making sense after all this discussion that in only Solaris you can use -d32 and -d64, and why because probably there both 32 and 64 bit version lies in same installation, as mentioned in JDK FAQ from this line - Since Solaris has both a 32 and 64-bit J2SE implementation contained within the same installation of Java, you can specify either version. However, I was looking for someone who has actually some hands on Solaris and did this. Anyways, thanks for your inputs. I will accept your answer.

Related