开发者

What is the smallest you can make a (Oracle JVM) java heap?

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

Googling didn't turn up anything to use, so I'm wondering, what is the smallest heap size you can mandate in Java?

Thanks, Eric

Edit:

It seems to vary a bit by platform and java version. On my Mac, with 1.6.0_24, the smallest I can configure it without error is:

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

or about 5.375M, where Foo.java is just:

public class Foo {
    public static void main(String[] args) {
        System.out.println(Runtime.getRuntime().totalMemor开发者_运维问答y());
    }
}

My environment is thus:

$ 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 was setting a small heap trying to verify that an expensive algorithm really was using almost no memory, not trying to save money.

Thanks for the answers -- I was despondent at how little useful came up when I tried to google this.


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

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

And my quick test shows that:

java -Xmx2M HelloWorld

works on 1.6.0_24


Unless you are working on an extremely limited mobile device (in which case you should do your testing on that device) even 8MB isn't much

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

Running with options -mx1m -XX:NewSize=256k The following

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

Prints

2304

which is 2.25 MB.

Don't forget, the heap is not the entire application. You have permgen and share libraries to include in the total size.


No, it doesn't "happily" 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 anything less than -Xmx5M gives you that error.

EDIT: I Experimented more ... -Xmx4100k seems to fly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜