How to determine the default Java heap size?

If I omitted from the Java command line -Xmxnoption, then the default value. According to the Java documentation

"Select Default runtime system configuration"

Which system configuration settings affect default values?


#1st Floor

Java 6 update 18 conducted a change.

Suppose we have more than 1 GB of physical memory (now very common), then it is always a quarter of your physical memory.


#2nd Floor

Ernesto was right. According to the link he posted [1]:

Update the client JVM heap configuration

The client JVM in ...

  • The default maximum heap size is half of physical memory, the maximum physical memory size is 192 MB, or a quarter, maximum physical memory size is 1 GB.

    For example, if your computer physical memory having 128 megabytes, the maximum heap size is 64 megabytes, and greater than or equal to 1 gigabyte physical memory heap size will result in a maximum of 256 megabytes.

  • Unless your program to create a sufficient number of objects requires it, or did not actually use the maximum JVM heap size. A small value is allocated during initialization JVM, called the initial heap size. ...

  • ...
  • JVM stack configuration server client ergonomic same, except that the default 32 bit JVM GB maximum heap size. 1 , corresponding to the physical size of 4 GB of memory, and 64-bit JVM default maximum heap size of 32 GB , corresponding to the physical memory size to 128 GB.

[1] http://www.oracle.com/technetwork/java/javase/6u18-142093.html


#3rd floor

On Windows, you can use the following command to find the default settings on the system running the application.

java -XX: + PrintFlagsFinal -version | findstr heap size

Find option MaxHeapSize(to -Xmx) and InitialHeapSizerespect -Xms.

On Unix / Linux systems, you can

java -XX:+ PrintFlagsFinal -version | grep HeapSize

I believe the result is output in bytes.


#4th floor

For the IBM JVM, the following command:

java -verbose:sizes -version

For more information about IBM Java SDK 8, please visit : HTTP : //www-01.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.lnx.80.doc/diag/appendixes/defaults .html? lang = en


#5th Floor

Default value is selected at run time system configuration

Take a look at the document page

The default heap size

Unless you specify the initial heap size and maximum heap size on the command line, otherwise they will be calculated based on the amount of memory on your computer.

  1. The client JVM the default initial and maximum heap size:

    The default maximum heap size is half of physical memory, the maximum physical memory size of 192 megabytes (MB) , or a quarter of physical memory, the maximum physical memory size of GB 1 .

  2. Server JVM the default initial and maximum heap size:

    On the JVM 32, if there are 4 GB or more of physical memory , the default maximum heap size GB maximum. 1 . On the JVM 64, if there is 128 GB or more physical memory, the default maximum heap size up to 32 GB.

Which system configuration settings affect default values?

You can use the logo -Xms (initial heap size) and the -Xmx (maximum heap size) to specify the initial heap size and maximum heap size. If you know how much stack an application needs to function properly, you can -Xms and -Xmx to the same value


#6th floor

Java 8 occupy more than 1/6 of physical memory Xmssize (minimum HeapSize), and -Xmxsize (maximum HeapSize) 1/4 or more of physical memory.

You can check the following ways the default Java heap size :

In the Windows :

java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize"

In the Linux :

java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'

Which system configuration settings affect default values?

Your physical memory and Java versions.


#7th floor

According to the ergonomics of the garbage collector [the Oracle] :

Initial heap size:

Computer reasonable minimum value or larger physical memory of 1/64. Before J2SE 5.0, the default initial heap size is a reasonable minimum, vary from platform to platform. You can use -Xms command-line option to override this default.

The maximum heap size:

1/4 or less than the physical memory of 1GB. Prior to J2SE 5.0, the default maximum heap size is 64MB. You can use the -Xmx command-line option to override this default.

Update:

As Tom Anderson (Tom Anderson) pointed out in the comments, the above applies to server-class computer. In 5.0 JavaTM virtual machine ergonomics in :

In the J2SE platform version 5.0, a type of machine (referred to as server-class machine) has been defined as a machine having the following features:

  • Two or more physical processors
  • 2 GB or more of physical memory

With the exception of running the Windows operating system version of the 32-bit platform. On all other platforms, the default value and the default value is the same as version 1.4.2.

In the default J2SE platform, version 1.4.2, make the following selections

  • The initial heap size of 4 MB
  • The maximum heap size is 64 MB

Building # 8

Many parameters affect generation size. The following figure illustrates the heap has been submitted to the distinction between space and virtual space. When a virtual machine is initialized, it will retain the entire space of the heap. You can use -Xmxthe options to specify the reserved space -Xmx. If the -Xmsvalue is less than the parameter -Xmxvalues of the parameters, not all of the reserved space will be immediately submitted to the virtual machine. In this figure, the unused space marked as "virtual." Different parts of the heap (permanent generation Lifetime generations and younger generations) can grow to the limit of the virtual space as needed.

Enter here captions

By default, the virtual machine is increased or reduced piled on each collection to try to free space in the proportion of each set of active objects remains within a specific range. The target parameter range XX:MinHeapFreeRatio=<minimum>and -XX:MaxHeapFreeRatio=<maximum>set as a percentage, the lower limit of the total size -Xms<min>, -Xmx<max>is -Xmx<max>.

Parameter Default

MinHeapFreeRatio 40

MaxHeapFreeRatio 70

-Xms 3670k

-Xmx 64m

The 64-bit system heap size parameter default value has increased by about 30%. This increase is to compensate for a larger size of the object on the system 64.

Using these parameters, if the available space in a generation percentage to 40% or less, the generation of will be extended in order to maintain 40% free space, until the generation of the maximum allowable size. Similarly, if the available space is more than 70%, then the generation of shrinkage, so that only 70% of the space available, the size of which depends on the minimum generation.

Large server applications often encounter two problems using these default values. One is the slow start, since the initial stack is small, and many must resize the main collection. More pressing problem is that for most server applications, the default maximum heap size is too small. The rule of thumb server applications are:

  • Unless you are having problems in terms of pause, otherwise try to allocate as much memory as a virtual machine. The default size (64MB) is generally small.
  • The -Xms and -Xmx settings may determine the decision to the same value by removing the most important size from the virtual machine to improve predictability. However, if you choose properly, the virtual machine will not be compensated.
  • In general, since the distribution can be parallelized, so as to increase the number of processors increases memory.

    There are full


House # 9

XmsAnd Xmxthe Java Virtual Machine (JVM) flags:

  • Xmsinitial and minimum JVM heap size
    • Format-Xmx<size>[g|G|m|M|k|K]
    • Default Size
      • -serverMode: 25% of available physical memory,> = 8MB and <= 64MB
      • -client mode : 25% of available physical memory,> = 8MB and <= 16MB
    • Typical Size
      • -Xms128M
      • -Xms256M
      • -Xms512M
    • Function / Effect
      • -> JVM first allocated Xmsamount of memory
  • Xmxmaximum JVM heap size
    • Format-Xmx<size>[g|G|m|M|k|K]
    • Default Size
      • <= R27.2
        • Windows: Total physical memory 75%, maximum1GB
        • Linux/Solaris: 50%Available physical memory up1GB
      • >= R27.3
        • Windows X64: Up to 2GBtotal physical memory75%
        • Linux/Solaris X64: 50%Available physical memory up2GB
        • Windows x86: Up to 1GBtotal physical memory75%
        • Linux/Solaris X86: 50%Available physical memory up1GB
    • Typical Size
      • -Xmx1g
      • -Xmx2084M
      • -Xmx4g
      • -Xmx6g
      • -Xmx8g
    • Function / Effect
      • -> JVM allows the use of Xmxthe size of the maximum memory
        • When more than Xmxthejava.lang.OutOfMemoryError
          • How to fix OutOfMemoryError?
            • Exceed Xmxthe value of
              • For example: from -Xmx4gto-Xmx8g

More details

See the official documentation: -X command-line options


#10th floor

At last!

Java 8u191 from the start, you can now choose:

-XX:InitialRAMPercentage
-XX:MaxRAMPercentage
-XX:MinRAMPercentage

It can be used to adjust the heap size as a percentage of available physical RAM. (Identical with the installed RAM, the memory used by the kernel subtracted).

For more information, see Java8 u191 release notes . Please note that these options are mentioned in Docker title, but in fact whether you are in Docker environment or in a traditional environment, they are applicable.

MaxRAMPercentageThe default value of 25%. It is very conservative.

I own rules: If your host is more or less dedicated to running a given Java application, you can without problems increase dramatically. If you are using Linux, it runs only standard daemons and install RAM from a position about 1 Gb, then I would not hesitate to use 75% of the memory as the JVM heap. Also, please remember that it is available for 75% RAM instead of the installed of RAM. The rest is other user login process may be running on the host as well as other types of memory JVM needs (for example, for the stack). Overall, this is usually very suitable for the remaining 25%. Obviously, if more RAM installed, the 75% stake will be more secure. (JDK I want people to have achieved a ladder option to specify)

Setting MaxRAMPercentageoptions are as follows:

java -XX:MaxRAMPercentage=75.0  ....

Note that the percentage value is 'double' type and therefore must specify them with a decimal point. If you use "75" instead of "75.0", some strange error occurs.

Original articles published 0 · won praise 2 · views 10000 +

Guess you like

Origin blog.csdn.net/asdfgh0077/article/details/104245046