1

Heap is part of RAM.But still there is a limit that we can not define heap size beyond some percentage of RAM.For example:- i have 32 bit winodws xp OS and 4 GB RAM. But i can not declare the heap size more than 1600 MB. My question here why we can not declare heap size to some large value say 3GB which is lower than my 4GB RAM(as in 32 Bit can ustilize up to 4gb of RAM)? This is true for single process.

I mean i can start two tomcat or any other java process allocating 1600MB heap size to each but i can not allocate 3200MB to single process.what is the reason that behind that?

M Sach
  • 33,416
  • 76
  • 221
  • 314

2 Answers2

1

32-bit windows only allows 2GB of address space to a single process (without special extensions enabled.) The OS keeps the other 2GB for itself. Then on top of that Heap is not all of the memory that JVM needs. There is permgen space, and the memory that the code of the JVM itself uses.

Affe
  • 47,174
  • 11
  • 83
  • 83
  • Affe. Thats correct. But basically what i want to know when we can start two parallel process each with 1.5GB heap why not we can start a single process with 3GB heap – M Sach Apr 24 '12 at 08:38
  • 2
    It is a limitation of the operating system. Microsoft built it that way! It has nothing to do with Java. – Affe Apr 24 '12 at 08:42
  • 1
    If you run on the 32-bit JVM on Solaris, you can access up to 3 GB. – Peter Lawrey Apr 24 '12 at 08:56
  • @M Sach, you will find you have the same issue with other 32-bit applications. Load a very large file into Excel and it will max out at about 1.5 GB. – Peter Lawrey Apr 24 '12 at 08:56
  • @Peter. You mean 3 GB for a single process on solaris Right? – M Sach Apr 24 '12 at 09:01
  • @MSach Correct. A 3 GB heap. I haven't tried a 32-bit JVM on Linux. For the last 4 years, I have only used 64-bit JVM & OSes. – Peter Lawrey Apr 24 '12 at 09:10
  • Thanks Peter one last question.At http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap, it is said that You would use the stack if you know exactly how much data you need to allocate before compile time and it is not too big. Is stack of fixed size always? I mean in all local variables are stored on stack, but we never get stackover flow error except in case of recursion.So it mean that stack size is big enough to acomodate all the local data in method irrespective of how big the function is and how much memory local variables consume? – M Sach Apr 24 '12 at 09:35
  • You have no direct control over what is on the stack or the heap in java. From a language perspective there is only heap memory. In practice there are some things you can safely say the JIT will "always" put on the thread stack, but that's not guaranteed anywhere. I think you are confusing "local variables are on the stack" with "the *pointers* to local variables are on the stack." – Affe Apr 24 '12 at 18:22
0

If its not 64 bit 4GB cannot be allocated.

Stefan
  • 12,108
  • 5
  • 47
  • 66