From: Thomas Pornin on
According to DuncanIdaho <Duncan.Idaho2008(a)googlemail.com>:
> If I develop against a 64bit JVM (say because I gotta have the 'latest
> and greatest' no other reason) and then compile the code on a client
> machine against a 32bit JVM

Java source code is actually never compiled against a 64-bit or 32-bit
JVM; it is compiled against _the_ Java Virtual Machine, i.e. a
theoretical architecture which has no "register size". A Java compiler
should produce, for a given set of source file, the exact same .class
files, regardless of whether the compiler runs on a 64-bit, 32-bit or
whatever system.

The compiled code, i.e. the .class files (usually stored in .jar
archives), can be fed unchanged to a 64-bit or a 32-bit JVM, and will
run to produce the exact same results(*) on both. I routinely compile
Java code on a 64-bit Linux system, and the .jar files are deployed to
all kinds of systems, including 32-bit Windows and the like. This is
the point of using a virtual machine as compilation target.


> then the only possible problem could be that I'm using some humoungous
> great data structure that needs bigger that 32 bit addresses in which
> case I should probably be sacked anyway ...

It is not really a problem of address size -- it is a problem of RAM
size. If your code requires more than 4 GB of RAM, then it will not run
on a 32-bit system since 32-bit systems can use only 4 GB(**). A system
has registers wide enough to address all the RAM it can use, so you will
not be limited by the register size, but by the RAM size.

And if your code needs 4 GB, chances are that you will notice it...


--Thomas Pornin

(*) Except for performance, i.e. how much time is used to perform said
operations; also, there can be some rounding issues with floating-point
types in non-strictfp code.

(**) With PAE, available since the Pentium Pro (that's more than twelve
years ago), a 32-bit x86 system may use up to 64 GB of RAM, but not
simultaneously: each single process may use only 4 GB.
From: Lew on
Thomas Pornin wrote:
> (**) With PAE, available since the Pentium Pro (that's more than twelve
> years ago), a 32-bit x86 system may use up to 64 GB of RAM, but not
> simultaneously: each single process may use only 4 GB.

I'm aware of no 32b JVM that can specify a heap over about 1.8 GB; most are
lower. 32b Windows only allows up to 2GB per process or 3GB with a switch.
The JVM and permanent generation use some of that, leaving less for the heap.

--
Lew
From: Nigel Wade on
On Wed, 25 Nov 2009 09:19:16 -0500, Lew wrote:

> Thomas Pornin wrote:
>> (**) With PAE, available since the Pentium Pro (that's more than twelve
>> years ago), a 32-bit x86 system may use up to 64 GB of RAM, but not
>> simultaneously: each single process may use only 4 GB.
>
> I'm aware of no 32b JVM that can specify a heap over about 1.8 GB; most
> are lower. 32b Windows only allows up to 2GB per process or 3GB with a
> switch. The JVM and permanent generation use some of that, leaving less
> for the heap.

$ java -version
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Server VM (build 14.1-b02, mixed mode)

$ java -jar -Xmx3700m some.jar
....

$ java -jar -Xmx3800m some.jar
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

So, the limit on this particular Java application is somewhere between
3.7GB and 3.8GB of heap.

I should point out that this is a 32bit JVM running on a 64bit system
with 32GB of RAM. Nonetheless, the limit on a 32bit application is still
4GB despite the 64bit OS. What it does mean, though, is that any
individual application has got a much greater chance of getting the max.
address space because the entire system isn't limited to 4GB.

The same may be true of a PAE system, I don't know and can't test it.

--
Nigel Wade
From: Thomas Pornin on
According to Lew <noone(a)lewscanon.com>:
> I'm aware of no 32b JVM that can specify a heap over about 1.8 GB;
> most are lower.

Sun's JVM can. Right now, with Sun's JDK 1.6.0_16, 32-bit version for
Linux, I can specify a 3.68 GB heap with '-Xmx3683m', and use it
(I made a simple Java code which successfully stored 3683 byte[],
each newly allocated of size 1048576, into an ArrayList).

The trick here is that while the JDK is a 32-bit binary and runs
in a 32-bit system, the Linux kernel itself is a 64-bit kernel. The
limit on 2 or 3 GB per process is due to the need for the kernel
code to be able to access its own code and the user address space
with special access rights (not those seen from user space), which
basically means that memory seen by the application is mapped twice
(for the 3 GB limit, the kernel must employ various trickeries
such as messing with the MMU tables, which are cumbersome and
potentially expensive). When the kernel itself is a 64-bit kernel,
it can map the full 32-bit address space (4 GB) twice in its own,
much wider 64-bit address space; hence, application may then have
their (almost) full complement of 4 GB.

As far as I know, this is also what happens when a 64-bit Windows
system runs a 32-bit application.


Running a full 32-bit system with a 64-bit kernel is a possible
compromise which is actually recommended when there are many 32-bit
legacy, binary only applications to run, but the machine has more
than 2 or 3 GB of RAM and the CPU supports the 64-bit amd64 mode.


--Thomas Pornin
From: DuncanIdaho on
Nigel Wade wrote:
> On Wed, 25 Nov 2009 09:19:16 -0500, Lew wrote:
>
>> Thomas Pornin wrote:
>>> (**) With PAE, available since the Pentium Pro (that's more than twelve
>>> years ago), a 32-bit x86 system may use up to 64 GB of RAM, but not
>>> simultaneously: each single process may use only 4 GB.
>> I'm aware of no 32b JVM that can specify a heap over about 1.8 GB; most
>> are lower.

snip

> I should point out that this is a 32bit JVM running on a 64bit system
> with 32GB of RAM. Nonetheless, the limit on a 32bit application is still
> 4GB despite the 64bit OS. What it does mean, though, is that any
> individual application has got a much greater chance of getting the max.
> address space because the entire system isn't limited to 4GB.
>
> The same may be true of a PAE system, I don't know and can't test it.
>

OK well I've ordered my new laptop with Windows 7

By the way http://java.sun.com/javase/downloads/widget/jdk6.jsp offers
JDK 6 Update 17 for Windows and Windows x64 where the archive for the 64
bit version is smaller than that for the 32 bit version by around 8MB,
interesting huh, also, apparently the 64 bit release can be used in 32
bit mode...

Anyway, it will be interesting to see just how big the heap can be with
a 64bit JVM running on a 64bit system. Roll on delivery day.

-- Idaho