Friday, December 24, 2010

Java 32 vs. 64 bit

I thought it would be a good idea to install a 64 bit version of Java on my new PC that has a 64 bit architecture. But I had to find out it's not worth the effort.

I have the following:

$ java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)

$ java32 -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)

I run tests on a huge Frege source code file that looks like this:

package Stress where
x = (((( ... ))))  // actually 1 million ( and 1 million )

Running the compiler with java32 -Xmx500m, I get

lexical analysis took 7.333s, 2000007 tokens, 272740 tokens/s
parser (including lexical analysis) took 38.364s, 2000007 tokens (52132 tokens/s)

The 64 bit Java, however, dies with an Out of Memory error. With -Xmx1g it reports:

lexical analysis took 8.818s, 2000007 tokens, 226809 tokens/s
parser (including lexical analysis) took 37.910s, 2000007 tokens (52756 tokens/s)

The speedup is barely significant. Only with 2 Gigabytes, it seems to get better:

... lexical analysis took 6.33s, 2000007 tokens, 315956 tokens/s
parser (including lexical analysis) took 34.709s, 2000007 tokens (57622 tokens/s)

10% speedup, but only if it is given 4 times the memory! And, by the way, it is seldom the case that one has to compile a 100000 lines Frege source (assuming 20 tokens per line). Even the parser (which is generated from a yacc grammar), has only some 230000 tokens on 35000 lines.
On smaller files, the 32 bit client version is unbeatable, the 64bit server version actually being 2 to 3 times slower.

2 comments:

  1. Something to try is the CompressedOops option for HotSpot. This uses the 64 bit instruction set (with extra registers etc) but 32 bit pointers (the compressed "ordinary object pointers").

    http://wikis.sun.com/display/HotSpotInternals/CompressedOops

    ReplyDelete
  2. I'll have to give it a try with the JDK7.

    ReplyDelete

Comments will be censored by me as I see fit, most likely if they contain insults or propaganda for ideologies I do not like. Comments that are on topic will not be censored. If I leave a comment uncensored this does not imply that I agree with the opinions expressed therein.