21

From my experience with Windows 7 (64-bit) and Java, a 32-bit JRE uses less memory and runs significantly faster than a 64-bit JRE (provided you don't need or benefit from having a lot of memory). I imagine the same thing is true for Mac OSX (and other platforms) as well.

I am currently running OSX Lion (v10.7), and I have installed the standard Java app. Under Java Preferences, I see "Java SE 6" from "Apple Inc." for both CPU-types "32-bit" and "64-bit" version "1.6.0_26-b03-383". I have changed the preferred order to put the 32-bit version on top of the 64-bit version, hoping that this would make the 32-bit version default.

But "java -version" still says:

java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511c)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-383, mixed mode)

Is it possible to use the 32-bit version by default? And how?

Also, does anyone have experiences / comparative measurements regarding speed and memory efficiency between the 32/64-bit versions?

Ulrik
  • 765
  • 1
  • 6
  • 13
  • 8
    BTW, 16-bit version uses even less memory and is even more faster. –  Aug 04 '11 at 13:16

5 Answers5

21

I found out now, that the 32-bit JVM can be explicitly launched using the -d32 switch.

On my machine, "java -version -d32" says:

java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511c)
Java HotSpot(TM) Client VM (build 20.1-b02-383, mixed mode)

and although it doesn't say so, it is a 32-bit JVM.

Ulrik
  • 765
  • 1
  • 6
  • 13
  • +1 worked perfectly. I ran a java app and it showed up in Activity Monitor as Kind: `Intel` instead of `Intel (64 bit)`. For some reason the `arch` command doesn't have any affect on java. – Kelvin Jun 22 '12 at 16:25
7

The latest versions of Java 64-bit have -XX:+UseCompressedOops on by default (if your heap is less than 32 GB). This means 32-bit references are used in any case. The objects are still slightly bigger (4 bytes more overhead)

This article compares 32-bit, 64-bit with UseCompressedOops Java: How much memory do different arrays and collections consume

In terms of performance, I have found it to be 5-10% depending on what you are doing. If you are using a lot of long values it will be faster to use 64-bit.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • This is somewhat useful info, but how do I start the 32-bit JVM? The referred article compares 32- and 64-bit JVMs (although perhaps on a different platform). – Ulrik Aug 04 '11 at 15:28
  • In UNIX, I would open a shell and use the full path name to run the program I want (works for just about any program). Or I would change the default PATH to include the `bin` directory in Windows or Unix to use the 32-bit version (again nothing specific to Java) – Peter Lawrey Aug 04 '11 at 15:32
  • 1
    In Windows or UNIX this is trivial, I know... All you need to know is the install location of the JRE for finding the java binary and perhaps setting a proper JAVA_HOME environment variable. On a Mac, the Java installation is really obscure, and I have not been able to locate the 32-bit installation. BUT I think the information shown in the Java Preferences GUI implies that a 32-bit version is present somehow... somewhere... – Ulrik Aug 04 '11 at 15:37
1

in /System/Library/Frameworks/JavaVM.framework/Versions I found version 1.6 installed and changed the path for java,javac to point to /System/Library/Frameworks/JavaVM.framework/Versions/1.6/home using environment alias rather than the default link found in /usr/bin/

user3076647
  • 176
  • 3
1

Go into the "Java Preferences" App and drag java 32 bit to the top of the list.

Zanson
  • 3,991
  • 25
  • 31
1

Try the below steps:

  1. Open terminal and go to /System/Library/Frameworks/JavaVM.framework/Versions/
  2. Type ls -l to list all available Java versions
  3. Enter sudo ln -fhsv CurrentJDK

Reference: Changing Java Version

Sunil Manheri
  • 2,313
  • 2
  • 18
  • 19