Additionally, the garbage collector never needs to move an arraylet leaf once it has been allocated. The cost of relocating an array is therefore limited to the cost of relocating the spine, so large arrays do not contribute to higher defragmentation times.
-Note: Despite the general advantage of using arraylets, they can slow down processing when the Java Native Interface (JNI) is being used. The JNI provides flexibility by enabling Java programs to call native code; for example, C or C++, and if direct addressability to the inside of an object is needed, a JNI critical section can be used. However, that requires the object to be in a contiguous region of memory, or at least appear to be so. The JNI, therefore, creates a temporary contiguous array that is the same size as the original array and copies everything, element by element, to the temporary array. After the JNI critical section is finished, everything is copied from the temporary array back to the arraylet, element by element.
+Note: Despite the general advantage of using arraylets, they can slow down processing when the Java Native Interface (JNI) is being used. The JNI provides flexibility by enabling Java programs to call native code; for example, C or C++, and if direct addressability to the inside of an object is needed, a JNI critical section can be used. However, that requires the object to be in a contiguous region of memory, or at least appear to be so. The JNI, therefore, creates a temporary contiguous array that is the same size as the original array and copies everything, element by element, to the temporary array. After the JNI critical section is finished, everything is copied from the temporary array back to the arraylet, element by element.
The overall size of the Java heap is determined by two command-line options, -Xms
, which sets the initial size of the heap, and -Xmx
, which sets the maximum size of the heap. Finer tuning of the heap depends on the heap configuration that is being used by a GC policy. For example, an LOA within the heap can be sized by using the -Xloainitial
, -Xloaminimum
, and -Xloamaximum
command-line options. A nursery area within the heap can be sized by using the -Xmn
, -Xmns
, and -Xmnx
command-line options. For more information about policies and the heap configurations that are used, see GC policies. To determine the values that are in use for the Java heap, use the -verbose:sizes
option when you run your Java application.
When the Java heap runs out of space, OutOfMemoryError
exceptions are generated. If you are confident that your heap settings are appropriate for your application but are still receiving an OutOfMemoryError
exception, check the Java dump file that gets automatically generated when the error occurs. A Java dump file can tell you more about what your application was attempting to do at the time of the error. For example, see the Java OutOfMemoryError scenario.
At startup, the VM allocates a single contiguous area of virtual storage to match the value of -Xmx
. By default, this is 25% of the available memory up to a maximum of 25 GB. The actual Java heap size starts at the value set by -Xms
and expands automatically, as required, up to the maximum heap size. The VM can also contract the size of the Java heap. Expansion and contraction occur as part of a GC cycle when the VM has exclusive access to the heap. The only GC policy that does not support heap expansion and contraction is the metronome
GC policy, where the heap is always fully expanded.
Note: On operating systems that support paging, the VM allocates a single contiguous area that matches the value of -Xms
. Additional memory is committed as the heap expands by using the paging process.
Note: On operating systems that support paging, the VM allocates a single contiguous area that matches the value of -Xms
. Additional memory is committed as the heap expands by using the paging process.
Expansion occurs to maintain free space on the Java heap for object allocation. By default, the heap is expanded to maintain 30% free space, but this proportion can be adjusted by setting one of the following command-line options:
-Xminf
determines the minimum proportion of the heap that must be free after garbage is removed.