简体   繁体   中英

jvm heap setting pattern

Hello everybody, I have observed while setting heap size people prefer the values 64,128,256,1024.. . If I give a value in- between these numbers (say 500), won't jvm accept that value ? Why these numbers are important and preferred ? Why we also upgrade RAM in this pattern.

Please help me to understand.

Thanks in advance, Habin

JVM will accept any value, no problem with that. Using 2^n values is just a "convention", using others will have no negative effect in practice.

Well, if you think about it this way:

  • 1 byte is 8 bits

  • 1 kb = 1024 bytes

  • 1 mb = 1024 kb

  • 1 gb = 1024 mb

  • ... and so on ...

It's not just 2^n . Things in terms of memory in computing are closely related to the number eight - the number which defines one byte in most modern computers.

The main reason why bits are grouped together is to represent characters. Because of the binary nature of all things computing, ideal 'clumps' of bits come in powers of 2 ie 1, 2, 4, 8, 16, 32... . (basically because they can always be divided into smaller equal packages (it also creates shortcuts for storing size, but that's another story)). Obviously 4 bits (nybble in some circles) can give us 2^4 or 16 unique characters. As most alphabets are larger than this, 2^8 (or 256 characters) is a more suitable choice.

Machines exist that have used other length bytes (particularly 7 or 9). This has not really survived mainly because they are not as easy to manipulate. You certainly cannot split an odd number in half, which means if you were to divide bytes, you would have to keep track of the length of the bitstring.

Finally, 8 is also a convenient number, many people (psychologists and the like) claim that the human mind can generally recall only 7-8 things immediately (without playing memory tricks).

If it won't accept the value, check whether you put a megabytes ( M or m ) or gigabytes ( G or g ) modifier after the amount.

Example: java -Xms500M -Xmx500M -jar myJavaProgram.jar

Also, take a look at this link .

Why we also upgrade RAM in this pattern.

That is because memory chips / cards / come in sizes that are a power of 2 bytes. And the fundamental reason for that is that it makes the electronics simpler. And simpler means cheaper, more reliable and (probably) faster.

Except non-written convention, it has also performance impact - depending on the the architecture of the machine.

For example if a machine is ternary based, it would work better with a heap size set to a value which is a power of 3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM