Java JVM max heap size reservable upfront

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?

  • Choose the heap you checked the app Needs approx. and let the user die in an error if that heap is not possible
  • Trial an error: Lower down the heap and rerun your app until a valid max heap is found
  • 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!


    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".

    链接地址: http://www.djcxy.com/p/82898.html

    上一篇: Java:什么决定了Linux机器中可能的最大堆大小

    下一篇: 预先存储Java JVM最大堆大小