Part II Java Virtual Machine Reference
4. Java Virtual Machine Capabilities
8. External PBP Porting Layer Plugin
Oracle JVM uses an Internal Memory Allocation and Statistics module for allocating memory from native heap. It provides this functionality:
Replace ANSI C (glibc, uclibc), malloc(), calloc(), realloc(), free() with the Real Time OS functionality, allowing the JVM to use these APIs on platforms which lack memory allocation features.
Gather and provide memory usage statistics (amount of memory used, time spent in allocation, etcetera) which are used to fine tune the memory behavior of the application. For example, if you know which buffer sizes are used the most you can define an exact allocation size, achieving minimal internal fragmentation without losing allocation speed.
Enable full control over the memory allocated by the VM, including deallocating all memory at VM shutdown, monitoring memory allocations per Xlet, and enabling separate pools for separate needs. For example, separate pools can be created to support different types of hardware memory, or to limit a specific pool to specific size.
See Sections 5.1 Red Zone , 5.2 Statistics , and 5.3 GC Triggered When Native Memory is Low for additional memory allocator features.
The memory allocator 'RedZone' feature, marks 32 bits right before an allocated area and 32 bits after, and checks these bytes for validity after they are freed. In the debug version a warning is printed if stamps are not valid, as the cause is most likely an out of bounds array write or something similar. This feature also improves the stability of the internal allocator, as it serves to indicate that the internal control structure which resides in the area may be damaged and should be discarded. The ‘RedZone’ is enabled by default after verification that the performance impact of the 32-bit comparisons is negligible.
The CVM's Memory Allocator module has been enhanced to record and report memory allocations at configurable granularity and size range(s).
This module provides statistics of the following kind for each configured range at the configured granularity:
Allocation type
Total number of allocation
Total number of free
Maximum outstanding buffers seen
Time spent in allocation
Time spent in free
At the Java application exit, the collected statistics would be printed on console.
Note - To avoid performance overhead at runtime, statistics collection is not enabled in the optimized binary. Statistics collection can be enable on request.
The VM memory allocator can trigger garbage collection (GC) when system malloc returns NULL. This is useful on devices where the amount of RAM is small and GC must occur to release native resources. In this case, GC is automatically triggered by the VM.