Practice 4: improve performance, disable System. gc ()?, Virtual Machine system. gc
Today, we start to practice Java Virtual Machine 4: "Disable System. gc ()".
5 Series in total
- One of the actual Java virtual machines is "Heap Overflow processing"
- Practice: Java Virtual Machine 2 "virtual machine working mode"
- Java Virtual Machine 3: New Generation GC of G1"
- 4. Disable System. gc () for Java virtual machines ()"
- 5. "enable JIT compilation"
By default, System. gc () will explicitly trigger Full GC and reclaim the old and new generations. In general, we believe that garbage collection should be performed automatically without manual triggering. If garbage collection is triggered too frequently, the system performance is not good. Therefore, the virtual machine provides the DisableExplicitGC parameter to control whether to manually trigger GC.
The implementation of System. gc () is as follows:
Runtime. getRuntime (). gc ();
Runtime. gc () is a native method and is implemented in jvm. cpp as follows:
JVM_ENTRY_NO_ENV (void, JVM_GC (void) JVMWrapper ("JVM_GC"); if (! DisableExplicitGC) {Universe: heap ()-> collect (GCCause: _ java_lang_system_gc);} JVM_END
As you can see, if-XX:-+ DisableExplicitGC is set and the condition judgment cannot be true, explicit GC is disabled, making System. gc () equivalent to an empty function call.
Excerpted from