Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valid values of -Xmx flag in java

Tags:

java

In every example I see of the -Xmx flag in java documentation (and in examples on the web), it is always a power of 2. For example '-Xmx512m', '-Xmx1024m', etc.

Is this a requirement, or is it a good idea for some reason?

I understand that memory in general comes in powers of 2; this question is specifically about the java memory flags.

like image 847
juacala Avatar asked Mar 20 '17 17:03

juacala


People also ask

How do you set a flag value in Java?

Example 1 : Check if an array has any even number. There is one even number in the array. We initialize a flag variable as false, then traverse the array. As soon as we find an even element, we set flag as true and break the loop. Finally we return flag.

What is flag variable in Java?

A flag variable, it is a variable you define to have one value until some condition is true or false in which case you change the variable's value. It is a variable you can use to control the flow of a function or statement, allowing you to check for certain conditions while your function executing.

What is flag in Java with example?

The Flags class represents the set of flags on a Message. Flags are composed of predefined system flags, and user defined flags. A System flag is represented by the Flags. Flag inner class. A User defined flag is represented as a String.

Can we use flag in Java?

isFound is the flag and it gets true if the array item a[i] is equal to valueToRemove . If this flag is true it changes the value of the item to 0 enter code here and exits the loop. I used a for the array, change it to the name of your variable. I guess arraySize is a variable holding the size of the array.


1 Answers

It keeps things simple, but it is more for your benefit than anything else.

There is no particular reason to pick a power of 2, or a multiple of 50 MB (also common) e.g. -Xmx400m or -Xmx750m

Note: the JVM doesn't follow this strictly. It will use this to calculate the sizes of different regions which if you add them up tends to be lightly less than the number you provide. In my experience the heap is 1% - 2% less, but if you consider all the other memory regions the JVM uses, this doesn't make much difference.

Note: memory sizes for hardware typically a power of two (on some PCs it was 3x a power of two) This might have got people into the habit of thinking of a memory sizes as a power of two.

BTW: AFAIK, in most JVMs the actual size of each region is a multiple of the page size i.e. 4 KB.

like image 133
Peter Lawrey Avatar answered Oct 31 '22 01:10

Peter Lawrey