5

There are a lot of Posts and sites about the heap size, but None of them mentions how to find out the Maximum possible heap size i can reserve when invoking the jvm.

The Task is to start my jvm dynamically with the maximum available heap size xmx=max (no Need to discuss about the object of this task here!).

One would think of reading the current available or free Memory and using that size for xms and xmx. but this does not work.

for example on a 64 bit machine and Windows os, with 24GB ram, about 1.8 GB on available virtual Memory: (Those have been determined by c# which is executing the Java command in a process)

The jvm is launched with 32 bit! And according to other sites and Posts like: Maximum Java heap size of a 32-bit JVM on a 64-bit OS it should vary above 1.4GB.

[09.07.2015 08:39:39] Total physical memory MB:        24002
[09.07.2015 08:39:39] Available physical memory MB:    16115
[09.07.2015 08:39:39] Total virtual memory MB:         2047
[09.07.2015 08:39:39] Available virtual memory MB:     1810

calling a Java program with:

java -Xms1536m -Xmx1536m myApp

lead to:

Could not reserve enough space for 1572864KB object heap

the same goes all the way down to 1136m, which is the maximum possible!

Therefor my question: how to check upfront the heap size possible for calling the jvm, without Trial an error?

UDPATE: Based on those comments i rise another question for all those Pro´s out there: How do you guys run your Java application?

  1. Choose the heap you checked the app Needs approx. and let the user die in an error if that heap is not possible
  2. Trial an error: Lower down the heap and rerun your app until a valid max heap is found
  3. Use this secret way to determine guaranteed max heap size and run it smoothly (If so, please put in your circle of trust :))

i´m absolutely curious about your answers!

trincot
  • 317,000
  • 35
  • 244
  • 286
gantners
  • 471
  • 4
  • 16
  • `only 1136m is possible!` are you using a 32bit JRE? – Fran Montero Jul 28 '15 at 11:19
  • @FranMontero sorry i forgot this, see updated answer – gantners Jul 28 '15 at 11:25
  • Actually i posted a similar question a few weeks ago XD http://stackoverflow.com/questions/31533378/unable-to-run-java-with-xmx-966m/31534282#comment51067983_31534282 – Fran Montero Jul 28 '15 at 11:33
  • @FranMontero yes, there are many like that, yet no one seems to really have a total throughview of that process. i guess this must be one of the top secrets in the world, as there are millions of Posts about it and all what People are doing is guessing and making assumptions. also my questions was more targeting at how to properly determine the Maximum size rather than why does it not work. It is sure that 32 bit is limited on heap sizes, but the big question is how to determine the Limit in General? – gantners Jul 28 '15 at 11:41
  • you didn't mention which JVM you're using – the8472 Jul 28 '15 at 11:46
  • 1
    If you have a 64-bit machine, a 64-bit OS, a 64-bit memory size, I would suggest you use a 64-bit JVM. The only reason not to is because you still have to use 32-bit DLLs, otherwise I suggest you save your sanity and switch. – Peter Lawrey Jul 28 '15 at 12:00
  • note that a 32bit binary compiled with /LARGEADDRESSAWARE may be able to use more on a 64bit system. The standard oracle VMs are not as far as I know. maybe such builds are available or you can patch the binary and try your luck. – the8472 Jul 28 '15 at 12:03
  • @PeterLawrey unfortunately legacy dlls are the barrier here :( – gantners Jul 28 '15 at 13:43
  • @gantners You can call a 32-bit JVM from a 64-bit JVM e.g. RPC , JMS, REST etc. You could run most of the application in the 64-bit JVM and just use the 32-bit JVM as an interface to the DLL. – Peter Lawrey Jul 28 '15 at 13:52
  • @PeterLawrey Sounds interesting, do you have any links for me on that? – gantners Jul 28 '15 at 15:26
  • @gantners When you communicate between processes, the two processes could be running Java, C, 32-bit, 64-bit, Intel, AMD, ARM. In paricular, this is a consequence of TCP working whether you use 32-bit or 64-bit. – Peter Lawrey Jul 28 '15 at 17:12
  • @PeterLawrey I thought there was a much shorter Approach, than building a whole tcp communication stack around that particular small Problem... – gantners Jul 30 '15 at 22:15
  • @gantners you can implement an RMI/JMS/REST messaging interaction with a few classes. It doesn't have to be complicated. – Peter Lawrey Jul 30 '15 at 22:33

1 Answers1

1

How to check upfront the heap size possible for calling the jvm, without trial and error?

There isn't a way.

Certainly, there isn't a way that gives a dependable answer based on the kind of information that you / I would have to hand.

(If there was a way, then you can be sure that Oracle would know and would have told us about it.)

The problem is that there are too many "variables" in the equation, and many of them are "hidden variables".

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Ok but, that maximum can vary one time to another? or for the same JRE;,OS, RAM, is always the same max? – Fran Montero Jul 28 '15 at 11:52
  • Yup, the maximum could vary. It could also depend on the application, JVM settings, OS tuning parameters, etcetera. – Stephen C Jul 28 '15 at 11:54
  • The maximum can vary based on how much off heap memory you want to use e.g. thread stacks, GUI components, shared libraries, direct buffers. You don't even know what just because your JVM started, that you won't run out of virtual memory later. +1 – Peter Lawrey Jul 28 '15 at 11:58