Problem Description
Java programs deployed in the server (CentOS 64-bit) run, often encounter Oom, the server killed the Java main process. For the sake of prudence, the decision to optimize the JVM and reduce memory usage was not followed by an overbearing method of closing the Oom (a detailed analysis of the Linux kernel oom mechanism).
Solving Method
Referring to the compression of the JVM optimizations in the normal object pointer, on 64-bit machines, the 64-bit JVM consumes 1.5 times times more memory than 32-bit, because the object pointer doubles (wider addressing) under the 64-bit schema. Fortunately, starting with JDK 1.6 update14, the bit JVM has formally supported the-xx:+usecompressedoops, a new parameter that can compress the pointer and save memory footprint.
When you test setting-xmx32g on a 64-bit server, refer to the description in Enable-xx:+usecompressedoops by default,-xx:+usecompressedoops and-xx:+ Usecompressedclasspointers will fail, so the maximum JVM heap space is set to 31g, and the relevant tests are as follows:
Test 1:-xmx32g-xx:+usecompressedoops settings not in effect
-xmx31g-xx:+usecompressedoops settings take effect
[Rgf@datanode02 mqpf]$/home/rgf/java/jdk1.8.0_151/bin/java-server-xmx32g-xx:+usecompressedoops-xx:+ Usecompressedclasspointers-xx:+printflagsfinal Oops | grep Oops
Java HotSpot (TM) 64-bit Server VM warning:max heap size too large for compressed Oops
bool Usecomp Ressedoops : = False {lp64_product}
Error: Main class cannot be found or cannot be loaded Oops
[Rgf@datanode02 mqpf]$/home/rgf/java/jdk1.8.0_151/bin/java-server-xmx31g-xx:+usecompressedoops-xx:+ Usecompressedclasspointers-xx:+printflagsfinal Oops | grep Oops
bool Usecompressedoops : = True {lp64_product}
Error: Main class cannot be found or loaded Oops
Test 1:-xmx32g-xx:+usecompressedclasspointers settings not in effect
-xmx31g-xx:+usecompressedclasspointers settings take effect
[Rgf@datanode02 mqpf]$/home/rgf/java/jdk1.8.0_151/bin/java-server-xmx32g-xx:+usecompressedoops-xx:+ Usecompressedclasspointers-xx:+printflagsfinal Oops | grep pointers
Java HotSpot (TM) 64-bit Server VM warning:max heap size too large for compressed Oops
bool Compressedclasspointers : = False {lp64_product}
Error: Main class cannot be found or cannot be loaded Oops
[Rgf@datanode02 mqpf]$/home/rgf/java/jdk1.8.0_151/bin/java-server-xmx31g-xx:+usecompressedoops-xx:+ Usecompressedclasspointers-xx:+printflagsfinal Oops | grep pointers
bool Usecompressedclasspointers : = True {lp64_product}
Error: Main class cannot be found or loaded Oops