1

I have a Java SE desktop application which uses a lot of memory (1,1 GB would be desired). All target machines (Win 7, Win Vista) have plenty of physical memory (at least 4GB, most of them have more). There is also enough free memory.

Now, when the machines have some uptime and a lot of programs were started and terminated, the memory becomes fragmented (this is what I assume). This leads to the following error when the JVM is started:

  JVM creation failed
  Error occurred during initialization of VM
  Could not reserve enough space for object heap

Even closing all running programs doesn't help in such a situation (despite Task Manager and other tools report enough free memory). The only thing thas helps is to reboot the machine and fire up the Java applicaton as one of the first programs launched. As far as I've investigated, the Oracle VM requires one contiguous chunk of memory.

Is there any other way to assign about 1,1 GB of heap to my java application when this amount is available but may be fragmented?

I start my JVM with the following arguments:

-J-client -J-Xss2m -J-Xms512m -J-Xmx1100m -J-XX:PermSize=64m -J-Dsun.zip.disableMemoryMapping=true
trincot
  • 317,000
  • 35
  • 244
  • 286
t3chris
  • 1,390
  • 1
  • 15
  • 25

1 Answers1

2

Is there any other way to assign about 1,1 GB of heap to my java application when this amount is available but may be fragmented?

Use an OS which doesn't get fragmented virtual memory. e.g. 64-bit windows or any version of UNIX.

BTW It is hard for me to imagine how this is possible in the first place but I know it to be the case. Each process has its own virtual memory so its arrangement of virtual memory shouldn't depend on anything which is already running or has run before.

I believe it might be a hang over from the MS-DOS TSR days. Shared libraries loaded are given absolute addresses (added to the end of the signed address space, 2 GB, the high half is reserved for the OS and the last 512 MB for the BIOS) in memory meaning they must use the same address range in every program they are used in. Over time the maximum address is determined by the lowest shared library loaded or used (I don't know which one by I suspect the lowest loaded)

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Well, the thing with the fragmented memory was just my assumption based on my investigations. May be there's another reason for the problem. When I significantly lower the -Xmx value the application can be started. – t3chris Oct 23 '12 at 11:43
  • +1 - If the problem is fragmentation of the virtual memory (or more precisely, the page file) then there is nothing you can do about it in Java. – Stephen C Oct 23 '12 at 11:45
  • @PeterLawrey You recommended using an OS which doesn't fragment virtual memory. I have the same situation on Windows 7-64bit although using a 32-bit-JVM. I assume the memory mapping and adressing is different for 32 and 64-bit processes? – t3chris Oct 23 '12 at 11:53
  • Interesting, I have only used the 64-bit JVM on Windows for the last few years. I believe the 64-bit Windows has an emulator for 32-bit windows which works like a virtual machine inside the system so it can emulate Windows XP. It may be that due to compatibility it also has the same limitations. – Peter Lawrey Oct 23 '12 at 11:56
  • 1
    BTW, here are some details on the contiguous address space thing: http://stackoverflow.com/a/2111084/602762 – t3chris Oct 23 '12 at 12:03