What is the smallest you can create a bunch of Java JVM?

java accepts -Xmx1k happily as an argument, but the "experiments show" is still really something like a heap of 8 MB.

There was nothing to use in Googling, so I'm wondering what is the smallest heap size you can specify in Java?

Thanks Eric

Edit:

It seems to be slightly different in platform and version of java. On my Mac, with 1.6.0_24, the smallest I can configure without errors:

$ java -Xms1k -Xmx4097k -XX:NewSize=192k -cp . Foo 5636096 

or around 5.375M, where Foo.java is simply:

 public class Foo { public static void main(String[] args) { System.out.println(Runtime.getRuntime().totalMemory()); } } 

So my environment is:

 $ uname -a Darwin turbo.local 10.7.0 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386 $ java -version java version "1.6.0_24" Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326) Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode) 

As I mentioned in a comment below, I set up a small heap, trying to verify that an expensive algorithm doesnโ€™t really use much memory, and not trying to save money.

Thanks for the answers - I was discouraged by how little useful things came when I tried to do this.

+6
source share
3 answers

If you are not working on an extremely limited mobile device (in which case you should test on this device), even 8 MB is not much

A server costs about $ 70 / GB or about 50 cents for 8 MB.

Working with the parameters -mx1m -XX:NewSize=256k The following

 System.out.println(Runtime.getRuntime().totalMemory()/1024); 

Print

 2304 

which is 2.25 MB.

Do not forget that heap is not the whole application. You have rights and shared libraries to include in the total size.

+2
source

From the docs at http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html

-Xmxn: This value must be a multiple of 1024 greater than 2 MB

And my quick test shows that:

java -Xmx2M HelloWorld

works on 1.6.0_24

+4
source

No, he "happily" does not accept it.

 broach@broach-laptop :~/NetBeansProjects$ /usr/local/jdk1.6.0_20/bin/java -Xmx1k Error occurred during initialization of VM Too small initial heap 

This is Oracle JVM 1.6.0_20

My โ€œexperimentโ€ shows that something smaller than -Xmx5M gives you this error.

EDIT: I experimented more ... -Xmx4100k seems to be flying.

+2
source

Source: https://habr.com/ru/post/885961/


All Articles