1.Trace Tracking Parameters
-VERBOSE:GC -xx:+printgc -xx:+printgcdetails print GC details -xx:+printgctimestamps print CG time stamp occurred -xloggc:log/gc.log Specifies the location of the GC log, with the file output -XX:+PRINTHEAPATGC The heap information is printed after each GC -xx:+ Traceclassloading Monitoring class loading -xx:+printclasshistogram press Ctrl+break, print the class information, respectively: serial number, number of instances, total size, type
2. Heap Allocation Parameters
-xmx20m-xms5m Specifies a maximum heap of 20m and a minimum heap of 5m-xmn sets the ratio of the Cenozoic to the Cenozoic and the older generation (without the permanent zone), 4 means the new generation: the old age =1:4, the young generation Jian 1 /5 -xx:survivorratio set two survivor Area and Eden ratio, 8 represents two Survivor:eden=2:8, that is, a survivor for the younger generation 1/10 -xx : +heapdumponoutofmemoryerror oom When exporting a heap to a file -xx:+heapdumppath exporting the oom path -xx:onoutofmemoryerror when you are in Oom, execute a script
3. Stack size allocation
-XSS usually only hundreds of k, determines the depth of the function call, each thread has a separate stack space, local variables, parameters allocated on the stack
4. Permanent Zone allocation Parameters
-xx:permsize -xx:maxpermsize set the initial space and maximum space for the permanent zone
5.GC algorithm
Reference counting Method:
1) Old garbage collection Algorithm (Cenozoic) 2) recycle garbage by reference calculation 3) The implementation of reference counters is simple, for an object A, as long as any one object refers to a, then a reference counter is added 1, when the reference is invalidated, the reference counter is reduced by 1. Object A can no longer be used as long as the value of the reference counter for object A is 0. 4) Reference counting problem: Reference and dereference accompany addition and subtraction, affect performance, difficult to handle circular references
Mark-Clear:
1) The mark-and-sweep algorithm is the basic idea of modern garbage collection algorithm. The tag-purge algorithm divides garbage collection into two phases: the tagging phase and the purge phase. A feasible implementation is to mark all the objects that can be reached from the root node, first through the root node, in the tagging phase. Therefore, an object that is not marked is a garbage object that is not referenced. Then, in the purge phase, all unmarked objects are cleared.
Tag-Compression:
1) Suitable for use in many cases of survival, such as the old age. It does some optimizations based on the mark-and-sweep algorithm. Like the mark-and-sweep algorithm, the tag-compression algorithm first needs to start with the root node and mark all objects that can be reached. However, it does not simply clean up unmarked objects, but instead compresses all the surviving objects to one end of the memory. After that, clean up all the space outside the boundary.
Replication algorithm:
1) compared with the mark-clear algorithm, the replication algorithm is a relatively efficient method of recovery 2) is not suitable for the existence of a large number of occasions, such as the old age 3, the original memory space is divided into two pieces, each time only one piece, in the garbage collection, the in-use memory of the surviving objects copied into the unused memory block, Clears all objects in the memory block in use, swaps two memory roles, and completes garbage collection
6. Generational thinking:
1) According to the survival cycle of the object classification, short-lived objects are classified as the new generation, long-term objects to the old age. 2) According to the characteristics of different generations, select the appropriate collection algorithm 3) a small number of objects survive, suitable for the replication algorithm 4) a large number of objects survive, suitable for tag cleanup or tag compression
7.stop-the-world (STW)
1) A global pause in Java, a global pause, all Java code stops, native code can be executed, but not with the JVM, mostly due to GC (dump thread, deadlock check, Heap dump). 2) Damage: Long service stop, no response, encountering ha system, May cause primary and standby switching, seriously endangering the production environment.
8.GC Parametric finishing
-XX:+USESERIALGC: -xx:survivorratio -xx:newratio -XX:+USEPARNEWGC: Using the parallel collector-XX:+USEPARALLELGC in the Cenozoic : The Cenozoic uses the parallel collection collector -xx:+ USEPARALLELOLDGC: The old age uses the parallel collection collector -xx:parallelgcthreads-xx:+useconcmarksweepgc- Xx:parallelcmsthreads: Set the number of threads for the CMS -xx:cmsinitiatingoccupancyfraction: Set the CMS collector to trigger after the old age space is used -xx:+usecmscompactatfullcollection: Set whether the CMS collector will defragment the memory once the garbage collection is complete -xx:cmsfullgcsbeforecompaction: Set the number of times the CMS garbage collection, after the memory compression -xx:+cmsclassunloadingenabled : Allow recycling of class metadata -xx:cmsinitiatingpermoccupancyfraction: When the zone occupancy rate reaches this percentage, start the CMS recycle - Xx:usecmsinitiatingoccupancyonly
JVM Basic Concepts and parameters