One 、 see jvm Common commands
jinfo: You can output and modify the runtime java Process opts.
jps: And unix Upper ps similar , Used to show local java process , You can see how many are running locally java Program , And show their progress number .
jstat: A very strong surveillance VM Memory tools . It can be used to monitor VM Various heap and non heap sizes in memory and their memory usage .
jmap: Print out something java process ( Use pid) All in memory ' object ' The situation of ( Such as : Produce those objects , And quantity ).
jconsole: One java GUI Surveillance tools , It can display all kinds of data in chart form . And can monitor the remote server through remote connection VM.

We need to pay attention to : Before using these tools , First use JPS Command to get each of the current JVM Process number , Then select the JVM.

Two 、jinfo
jinfo You can view the settings jvm Information about

jinfo -flag MaxHeapSize [pid]   Be able to view the maximum heap memory 
jinfo -flag ThreadStackSize [pid] 

jinfo -flags [pid]
jinfo -flag UseConcMarkSweepGC [pid]
jinfo -flag UseG1GC [pid]
jinfo -flag UseParallelGC [pid]

3、 ... and 、 see jvm Runtime parameters

1)java -XX:+PrintFlagsFinal -version
 The result is , If it is 
=  Represents the default value 
:=  It means to be used by the user or jvm Modified value 

2)-XX:+UnlockDiagnosticVMOptions  Unlock diagnostic parameters 
-XX:+PrintCommandLineFlags  Print command line parameters 

3)jps
jps There's nothing to say about this , stay linux Inside ps It's about looking at the process ,jps Namely java Of ps, see java process 
 If you execute "jps -l" You can see the entire class name 

Four 、jstat
This command is used to see jvm Statistics , There are three main categories :

1) Class loading 
jstat -class [pid] 1000 10
 This instruction refers to every 1 second (1000 Namely 1000ms) View the loading information of a class , Ten times in all . hinder 1000 and 10 Can don't 

2) garbage collection 
-gc、-gcutil、-gccause、-gcnew、-gcold

3)JIT compile 
jstat -compiler [pid]
jstat -printcompilation [pid]

5、 ... and 、jmap
jmap It's a very important order , You can see jvm Memory usage . It can be divided into two parts :

1) Export memory image file 
 Memory overflow auto export , Setting parameters can be :
+XX:HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=./
 Needless to say , Set memory overflow, automatic export and export path 

 Use jmap Command manual export :
jmap -dump:format=b,file=heap.hprof [pid]
 among format=b Represents binary export 

2) View the memory image file :
 ad locum http://www.eclipse.org/mat/downloads.php Download the memory analysis tool , And then put dump File import analysis is OK .

6、 ... and 、jstack
jstack It's also a very important order , You can view thread usage . Here we need to know several states of the scene , Refer to the following :

- NEW state : The thread has not yet started.
- RUNNABLE state :The thread is executing in the JVM.
- BLOCKED state :The thread is blocked waiting for a monitor lock.
- WAITING state :The thread is waiting indefinitely for another thread to perform a particular action.
- TIMED_WAITING state :The thread is waiting for another thread to perform an action for up to a specified waiting time.
- TERMINATED state :The thread has exited.

 How do states change ? Refer to the following :
jvm Inside the command to view thread usage "jstack [pid]", Enter the thread information into a program called stack.txt The file of :
 This stack.txt The file can be viewed jvm One of them id What is the thread used for ? If a deadlock occurs , It will be listed at the end .

 stay linux How do you know the thread execution on the line , Which threads take up a lot of memory ?
 You can use this command  "top -p [pid] -H"  You can see the threads in a single process :

 adopt printf  "%x" [pid]   Can be 10 delicate pid  Convert to 16 Base number , convert to 16 What's the use of Radix ?
 because jstack The thread coming out is hexadecimal , By just that value , Can be in jstack Find out which thread uses the most memory in the file .

7、 ... and 、jvisualvm
jvisualvm Is a visualization tool , It integrates almost all the functions of the above instructions , But it's more intuitive , therefore jvisualvm It's also important. . It's also in jdk The directory bin Under the table of contents . Monitoring local applications is simple , Open it directly jvisualvm You can see local ones . The following focuses on remote monitoring :

1) Monitoring remote tomcat
 modify tomcat Of Catalina.sh

JAVA_OPTS='-Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.1.54'   

 Parameter description :
 The first parameter is port , Needless to say ;
 The second parameter is that you don't need to ssl verification , Don't check that attribute when linking 
 The third parameter is that you don't need to verify 
 The fourth parameter is this tomcat Address of application , Notice that it's not jvisualvm The address of .

2) Monitoring remote java application :
nohup java 
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=192.168.1.54  
-Dcom.sun.management.jmxremote.port=12344
-Dcom.sun.management.jmxremote.ssl=false -
Dcom.sun.management.jmxremote.authenticate=false
-Djava.net.preferIPv4Stack=true
-jar test.jar

 The order is the same , But it's important to remember that here 192.168.1.54 It must be ours java The application address of , instead of jvisual The address of !!
 Remember to open the port ,  Then add the machine you need 192.168.1.54 Add to jvisualvm Of " long-range " Inside the label , And then in “ long-range “ Add port in tag ip Just behind you .

Let's talk about the remote monitoring. There may be a bit of a hole , Here's why :
1) First, make sure that you are in java It can be used in the application machine jvisualvm Can only be , That is to say java Call... In the application machine jvisualvm No report error ( Maybe it's just warning), Can only be .
2) May be jdk Version problem . It is possible to confirm the port and application problems for many times , But it just can't connect , So we have to see if jdk Version problem ( Maybe not. , So that's what we need to monitor java Try it on the application machine first jvisualvm)

                                                                JVM Performance optimization suggestions                                                                 

One 、JVM Heap memory partition

JDK7 And previous versions : After an object is created, it is first placed in Nursery In memory Eden Inside In storage , If you live longer than two Survivor Then it's transferred to long-term memory (Old Generation) in . Methods of storing objects in permanent memory 、 Metadata information such as variables . If there is not enough permanent memory , You get the following error :Java.lang.OutOfMemoryError: PermGen
JDK8 edition :JDK8 The permanent memory in metadata is moved from heap memory to local memory (native memory) in , So permanent memory doesn't take up heap memory , It can be avoided by growing automatically JDK7 And persistent memory errors common in previous versions (java.lang.OutOfMemoryError: PermGen).JDK8 It also provides a new setting Matespace Parameters of memory size :

-XX:MaxMetaspaceSize=128m

We need to pay attention to : If not set Matespaces Memory size parameters ,JVM The local memory space will be automatically increased according to certain policies . If you set the metamemory space too small , Your application may get the following error :java.lang.OutOfMemoryError: Metadata space

Two 、JVM Parameters
-XX Parameters are called unstable parameters , The setting of such parameters is easy to cause JVM Performance differences .

1) Unstable parameter syntax rules
Boolean type

-XX:+<option> '+' Indicates that the option is enabled 
-XX:-<option> '-' Indicates that the option is off 

Numeric type

-XX:<option>=<number>
#  Can follow the unit , for example :'m' or 'M' Represents megabytes ;'k' or 'K' kilobytes ;'g' or 'G' gigabyte .32K And 32768 It's the same size .

String type

-XX:<option>=<string>
#  Usually used to specify a file 、 Path or a list of commands . for example :-XX:HeapDumpPath=./dump.core

2) Behavior options

Options The default value is describe
-XX:-AllowUserSignalHandlers Be limited to Linux and Solaris Off by default Allow for java The process installs the signal processor .
-XX:AltStackSize=16384 Only applicable to Solaris, from 5.0 Delete in Standby signal stack size ( In bytes )
-XX:-DisableExplicitGC Off by default Prohibit explicit calls at run time System.gc(). Be careful : You're familiar with code that doesn't call System.gc(), It doesn't mean that the framework tools you rely on are not in use .
-XX:+FailOverToOldVerifier Java6 New introduction options , Enabled by default If the new Class Checker check failed , Then use the old calibrator . Resolve compatibility issues .
Associated options :-XX:+UseSplitVerifier
-XX:+HandlePromotionFailure Java1.5 Previously, it was turned off by default ,Java1.6 It is enabled by default New generation collection guarantee , Reserve memory for older generations .
-XX:+MaxFDLimit Be limited to Solaris, Enabled by default Set up java The process available file descriptor is the maximum allowed by the operating system .
-XX:PreBlockSpin Default 10 Control the number of spins for multithreading spin lock optimization
Front options :
-XX:+UseSpinning
-XX:-RelaxAccessControlCheck Off by default ,Java1.6 introduce stay Class In the calibrator , Relax the check on access control . The functions and reflection Inside setAccessible similar .
-XX:+ScavengeBeforeFullGC Enabled by default stay Full GC Trigger once before Minor GC
-XX:+UseAltSigs Be limited to Solaris
Enabled by default
To prevent conflicts with other signaling applications , Alternate signals are allowed instead of SIGUSR1 and SIGUSR2.
-XX:+UseBoundThreads Be limited to Solaris
Enabled by default
Bind all user threads to kernel threads . Reduce thread starvation ( You don't get any cpu time) The number of times .
-XX:-UseConcMarkSweepGC Off by default ,Java1.4 introduce Enable CMS Low pause garbage collector .
-XX:+UseGCOverheadLimit Enabled by default ,Java1.6 introduce Limit GC Running time of . If GC It takes too long , Just throw it OutOfMemoryError.
-XX:+UseLWPSynchronization Be limited to solaris, Enabled by default , Java1.4 introduce Use lightweight processes ( Kernel thread ) Replace thread synchronization .
-XX:-UseParallelGC -server When enabled , In other cases : Off by default , Java1.4 introduce Using parallel cleanup for the new generation , Older generations use single threading Mark-Sweep-Compact The garbage collector .
-XX:-UseParallelOldGC Off by default , Java1.5 introduce Garbage collectors that use parallel cleanup for both the old and new generations . Turning on this option will automatically turn on -XX:+UseParallelGC Options
-XX:-UseSerialGC -client When enabled , Off by default , Java1.5 introduce Using a serial garbage collector .
-XX:-UseSpinning Java1.4.2 and 1.5 Need to be enabled manually , Java1.6 Enabled by default Enable multithreaded spin lock optimization . Associated options :-XX:PreBlockSpin=10
-XX:+UseTLAB Java1.4.2 Before and after -client Option : Off by default , Other versions are enabled by default Enable thread local cache (Thread Local)
-XX:+UseSplitVerifier Java1.5 Off by default , Java1.6 Enabled by default Use the new Class Type checker . Associated options : -XX:+FailOverToOldVerifier
-XX:+UseThreadPriorities Enabled by default Use the priority of the local thread .
-XX:+UseVMInterruptibleIO Be limited to solaris, Enabled by default , Java1.6 introduce stay solaris in , Allow the runtime to interrupt threads

3) Performance options

Options The default value is describe
-XX:+AggressiveOpts Java1.5 introduce , Off by default ,Java1.6 After the default on Turn on compiler performance optimization .
-XX:CompileThreshold=10000 The default value is :1000 adopt JIT compiler , The trigger threshold for compiling a method into machine code , It can be understood as the number of times a method is called , For example, tune 1000 Time , Compile methods into machine code . [-client: 1,500]
-XX:LargePageSizeInBytes=4m The default value is :4m,amd64 position :2m Set the maximum value of heap memory .
-XX:MaxHeapFreeRatio=70 Default 70 GC after , If it is found that the free heap memory accounts for the whole estimated upper limit value 70%, Then the upper limit of the estimated value is reduced .
-XX:MaxNewSize=size 1.3.1 Sparc: 32m,1.3.1 x86: 2.5m The Cenozoic occupies the maximum of the whole heap memory . from Java1.4 Start , MaxNewSize Become NewRatio A function of
-XX:MaxPermSize=64m Java1.5 in the future ::64 bit VMs Will increase the default value 30%,1.4 amd64::96m,1.3.1 -client: 32m, Other default 64m Perm( It is commonly known as the method area ) The maximum amount of memory in the whole heap .
-XX:MinHeapFreeRatio=40 The default value is :40 GC after , If it is found that the free heap memory accounts for the whole estimated upper limit value 40%, Then increase the upper limit . Associated options :-XX:MaxHeapFreeRatio=70
-XX:NewRatio=2 Sparc -client: 8,x86 -server: 8 ,x86 -client: 12 -client: 4 (1.3) 8 (1.3.1+) ,x86: 12 , other :2 The proportion of heap memory used by the new generation and the old generation . for example 2 It means that the new generation accounts for the old generation 1/2, It takes up the whole heap memory 1/3.
-XX:NewSize=2m 5.0 in the future : 64 bit Vms Will increase the default value 30%,x86: 1m,x86, 5.0 in the future : 640k, other :2.125m The default value of the upper limit of Cenozoic prediction .
-XX:ReservedCodeCacheSize=32m Solaris 64-bit, amd64, -server x86: 48m ,1.5.0_06 Before , Solaris 64-bit ,amd64: 1024m , other :32m Set the maximum value of the code cache , Compile with .
-XX:SurvivorRatio=8 Solaris amd64: 6 ,Sparc in 1.3.1: 25 ,Solaris platforms 5.0 before : 32 , other :8 Eden And Survivor The occupancy ratio of . for example 8 Express , One survivor Area occupation 1/8 Of Eden Memory , namely 1/10 The new generation of memory , Why not 1/9? Because our new generation has 2 individual survivor, namely S1 and S22. therefore survivor All in all, it takes up the memory of the new generation 2/10,Eden And the proportion of the new generation is 8/10.
-XX:TargetSurvivorRatio=50 The default value is :50 Actually used survivor The size of space accounts for . The default is 47%, The highest 90%.
-XX:ThreadStackSize=512 Sparc: 512 ,Solaris x86: 320 (5.0 before 256) ,Sparc 64 bit: 1024 Linux amd64: 1024 (5.0 before 0) , other :512. Thread stack size ,
-XX:+UseBiasedLocking Java1.5 update 6 After the introduction of , Off by default .Java1.6 Enabled by default . Enable bias lock
-XX:+UseFastAccessorMethods Enabled by default Optimize the original type of getter Method performance .
-XX:-UseISM Enabled by default Enable solaris Of ISM
-XX:+UseLargePages Java1.5 update 5 After the introduction of , Off by default ,Java1.6 Enabled by default Enable large memory paging . Associated options :-XX:LargePageSizeInBytes=4m
-XX:+UseMPSS Java1.4.1 Previously, it was turned off by default , Other versions are enabled by default Enable solaris Of MPSS, Cannot be associated with ISM Use at the same time .
-XX:+UseStringCache Default on Cache common strings .
-XX:AllocatePrefetchLines=1 The default value is :1 In the use of JIT The number of cache rows read after the generated pre read instruction allocates the object . If the last allocated object is an instance, the default value is 1, If it's an array, it's 3
-XX:AllocatePrefetchStyle=1 The default value is :1 The generated code style of the read ahead instruction ,0- No pre read instruction generation ,1- Execute the pre read command after each allocation ,2- When the pre read instruction is executed, use TLAB() Assign the watermark pointer to retrieve the entry ,
-XX:+UseCompressedStrings Java1.6 update 21 introduce among , For not needed 16 Character string , have access to byte[] Instead of char[]. For many applications , This saves memory , But slower (5%-10%)
-XX:+OptimizeStringConcat Java1.6 update 20 introduce Optimize string join operations where possible .

4) Debugging options

Options The default value is describe
-XX:-CITime Enabled by default Print JIT The compiler takes time to compile .
-XX:ErrorFile=./hs_err_pid.log Java1.6 introduce If JVM crashed, Output the error log to the specified file path .
-XX:-ExtendedDTraceProbes Java6 introduce , Be limited to solaris, Off by default Enable dtrace The diagnosis
-XX:HeapDumpPath=./java_pid.hprof The default is java Process start location The storage file path of the heap memory snapshot .
-XX:-HeapDumpOnOutOfMemoryError Off by default stay java.lang.OutOfMemoryError When an exception occurs , Output one dump.core file , Record a snapshot of the heap memory at that time ( see -XX:HeapDumpPath Description of )
-XX:OnError=”\;\” Java1.4 introduce When java Each one ERROR when , Run the specified command line instruction set . The instruction set is related to OS Environment related , stay Linux Most of them are .sh Script ,windows Next is .bat The batch .
-XX:OnOutOfMemoryError=”\;\” Java1.4.2 update 12 and Java6 When introducing When it first happened java.lang.OutOfMemoryError when , Run the specified command line instruction set . The instruction set is related to OS Environment related , stay linux Most of them are .sh Script ,windows Next is .bat The batch .
-XX:-PrintClassHistogram Off by default stay Windows Next , Press ctrl-break or Linux Next is execution kill -3( send out SIGQUIT The signal ) when , Print class Histogram . jmap -histo pid The same function is also realized .
-XX:-PrintConcurrentLocks Off by default stay thread dump At the same time , Print java.util.concurrent Lock state of .jstack -l pid It also implements the same function .
-XX:-PrintCommandLineFlags Java1.5 introduce , Off by default Java Startup time , Go to stdout Print the currently enabled unsteady state jvm options. for example :-XX:+UseConcMarkSweepGC -XX:+HeapDumpOnOutOfMemoryError -XX:+DoEscapeAnalysis
-XX:-PrintCompilation Off by default Go to stdout The printing method is JIT Compile time information .
-XX:-PrintGC Off by default Turn on GC Log printing . Display results, such as : [Full GC 131115K->7482K(1015808K), 0.1633180 secs] , This option can be accessed through com.sun.management.HotSpotDiagnosticMXBean API and jconsole Dynamic enable .
-XX:-PrintGCDetails Java1.4 introduce , Off by default Print GC Recycling details . Display results, such as : [Full GC (System) [Tenured: 0K->2394K(466048K), 0.0624140 secs] 30822K->2394K(518464K), [Perm : 10443K->10443K(16384K)], 0.0625410 secs] [Times: user=0.05 sys=0.01, real=0.06 secs] , This option can be accessed through com.sun.management.HotSpotDiagnosticMXBean API and jconsole Dynamic enable .
-XX:-PrintGCTimeStamps Off by default Print GC The pause takes time . Display results, such as : 2.744: [Full GC (System) 2.744: [Tenured: 0K->2441K(466048K), 0.0598400 secs] 31754K->2441K(518464K), [Perm : 10717K->10717K(16384K)], 0.0599570 secs] [Times: user=0.06 sys=0.00, real=0.06 secs] , This option can be accessed through com.sun.management.HotSpotDiagnosticMXBean API and jconsole Dynamic enable .
-XX:-PrintTenuringDistribution Off by default Print the lifetime information of the object . Display results, such as : [GC Desired survivor size 4653056 bytes, new threshold 32 (max 32) - age 1: 2330640 bytes, 2330640 total - age 2: 9520 bytes, 2340160 total 204009K->21850K(515200K), 0.1563482 secs] ,Age1,2 Said in the first 1 and 2 Time GC The size of the surviving object .
-XX:-TraceClassLoading Off by default Print class Load information to stdout. remember Loaded state . for example : [Loaded java.lang.Object from /opt/taobao/install/jdk1.6.0_07/jre/lib/rt.jar]
-XX:-TraceClassLoadingPreorder 1.4.2 introduce , Off by default Press class References to / Print class loading information to stdout. differ TraceClassLoading, Only remember Loading state . for example : [Loading java.lang.Object from /home/confsrv/jdk1.6.0_14/jre/lib/rt.jar]
-XX:-TraceCla***esolution 1.4.2 introduce , Off by default Print all static classes , Constant's code reference position . be used for debug. for example : RESOLVE java.util.HashMap java.util.HashMapEntryHashMap.java:209<br> explain HashMap Class 209 Line refers to a static class java.util.HashMapEntryHashMap.java:209<br> explain HashMap Class 209 Line refers to a static class java.util.HashMapEntry
-XX:-TraceClassUnloading Off by default Print class To stdout. remember Unloaded state .
-XX:-TraceLoaderConstraints Java1.6 introduce , Off by default Print class Loading strategy change information to stdout. The loading strategy change is to implement classloader Isolation / The key technology of namespace consistency .
-XX:+PerfSaveDataToFile Enabled by default When java Process factor java.lang.OutOfMemoryError Abnormal or crashed After compulsory termination , Generate a heap snapshot file .
-XX:ParallelGCThreads=n The default value is : along with JVM Different platforms Configure the number of threads for the parallel collector , namely : How many threads do garbage collection at the same time . This value is best configured to equal the number of processors .
-XX:+UseCompressedOops 32 Bit is off by default ,64 Bit starts by default Use compressed pointers. This parameter defaults to 64bit Start by default in the environment of , But if JVM The memory reaches 32G after , This parameter will default to not start , because 32G After memory , Compression is not necessary , It takes a lot of width to manage such a large memory pointer
-XX:+AlwaysPreTouch Off by default stay JVM Initialization is done in advance for Java Pile up to find out .
-XX:AllocatePrefetchDistance=n The default value depends on the current JVM Set up Set prefetch distance for object assignment .
-XX:InlineSmallCode=n The default value depends on the current JVM Set up When the compiled code is less than the specified value , Inline compiled code .
-XX:MaxInlineSize=35 The default value is :35 The maximum number of bytes for inline methods .
-XX:FreqInlineSize=n The default value depends on the current JVM Set up Maximum bytecode size for inline frequently executed methods .
-XX:LoopUnrollLimit=n The default value depends on the current JVM Set up Open the loop body when the number of nodes is less than the given value .
-XX:InitialTenuringThreshold=7 The default value is :7 Set the maximum survival times of the initial object in the new generation .
-XX:MaxTenuringThreshold=n The default value is :15, Maximum :15 Set the maximum number of times the object survives in the new generation , Maximum 15, By default, the parallel recovery mechanism is 15,CMS The default is 4.
-Xloggc: Off by default Output GC Detailed log information to the specified file .
-XX:-UseGCLogFileRotation Off by default Turn on GC Log file segmentation function , Front options -Xloggc
-XX:NumberOfGClogFiles=1 must >=1, The default value is :1 Set segmentation GC Number of log files , File naming format :.0, .1, …, .n-1
-XX:GCLogFileSize=8K must >=8K, The default value is :8K GC Log file slice size .

3、 ... and 、 Garbage collector
1.  Serial recycler
1.1) New generation of serial recyclers
characteristic
-  It just uses a single thread for garbage collection
-  It's exclusive garbage collection
-  When recycling , Java All threads in the application need to pause (Stop-The-World)
-  Using the replication algorithm
-  fit CPU When the hardware is not very good

Set parameters

-XX:+UseSerialGC    Specifies that the new generation uses the new generation serial collector and the old generation serial collector ,  When we use client Mode runtime ,  It's the default garbage collector 

1.2) Old time serial recycler
characteristic
-  Just like the new generation of serial recyclers , Single thread , Exclusive garbage collector
-  In general, recycling in the old age takes longer than recycling in the new generation , So it may cause the application to pause for a long time

Set parameters

-XX:+UseSerialGC    The new generation ,  Older generations use serial recyclers 
-XX:+UseParNewGC    The new generation uses ParNew Recyclers ,  The old days used serial recyclers 
-XX:+UseParallelGC  The new generation uses ParallelGC Recyclers ,  The old days used serial recyclers 

2.  Parallel recycler
2.1) The new generation ParNew Recyclers
characteristic
-  Multithread serial recycling
-  Using the replication algorithm
-  Garbage collection , The application will still pause , Just because it's multithreaded , In multicore CPU On , The recovery efficiency will be higher than that of the serial recycler , On the contrary, in monocytes CPU, It's not as efficient as the serial recycler

Set parameters

-XX:+UseParNewGC  The new generation uses ParNew Recyclers ,  The old days used serial recyclers 
-XX:+UseConcMarkSweepGC  The new generation uses ParNew Recyclers ,  Used in the old days CMS Recyclers 
-XX:ParallelGCThreads=n  Gyrus digiti ParNew The number of threads that the collector works on , cpu Check for hours 8 when ,  Its value is equal to cpu Number ,  higher than 8 when , You can use the formula (3+((5*CPU_count)/8))

2.2) The new generation ParallelGC Recyclers
characteristic
-  Same as ParNew The recycler is the same , The difference is this , It's very focused on the throughput of the system ( Through parameter control )
-  Using the replication algorithm
-  Support adaptive GC Adjustment strategy

Set parameters

-XX:+UseParallelGC   New generation substitute ParallelGC Recyclers ,  The old days used serial recyclers 
-XX:+UseParallelOldGC   New generation substitute ParallelGC Recyclers ,  Used in the old days ParallelOldGC Control of throughput of reclaimer system :
-XX:MaxGCPauseMillis=n( Company ms)    Set the maximum pause time for garbage collection ,
-XX:GCTimeRatio=n(n stay 0-100 Between )   Set the size of the throughput ,  Let's say it's n,  That system will cost no more than 1/(n+1) Time for garbage collection 
-XX:+UseAdaptiveSizePolicy   Turn on adaptive GC Strategy ,  In this mode ,  The size of the new generation , eden,survivior The proportion of ,  Parameters such as the age of the person who is promoted to the old age will be automatically adjusted , To reach the heap size ,  throughput ,  The balance between pause times 

2.3) Old age ParallelOldGC Recyclers
characteristic
-  With the new generation of ParallelGC The recycler is the same , It's a multithreaded concurrent collector that focuses on throughput in the old days
-  Using label compression algorithm

Set parameters

-XX:+UseParallelOldGC   New generation substitute ParallelGC Recyclers ,  Used in the old days ParallelOldGC Recyclers ,  It's a combination of recyclers that focus on system throughput ,  It is suitable for systems with high throughput requirements 
-XX:ParallelGCThreads=n    Gyrus digiti ParNew The number of threads that the collector works on , cpu Check for hours 8 when ,  Its value is equal to cpu Number ,  higher than 8 when ,  You can use the formula (3+((5*CPU_count)/8))

3.  CMS Recyclers (Concurrent Mark Sweep, Concurrent tag removal )
3.1) Concurrency recyclers of the old days
characteristic
-  It's concurrent recycling , Non exclusive recycler , Most of the time, the application doesn't stop running
-  Recyclers for the older generation
-  Using a concurrent tag clearing algorithm , So after recycling, there will be memory fragments , You can set parameters to compress and defragment memory fragments
-  And ParallelGC and ParallelOldGC Different , CMS Focus on system pause time

Main steps
-  Initial marker
-  Concurrent Tags
-  Pre cleaning
-  Re label
-  Concurrent cleanup
-  Concurrent reset

We need to pay attention to : Initial marking and re marking are exclusive of system resources , Cannot be executed with a user thread , Other phases can be executed with the user thread

Set parameters

-XX:-CMSPrecleaningEnabled   Turn off pre cleaning ,  No pre cleaning ,  The default is after the concurrency tag ,  There will be a pre clean operation , Can reduce pause time 
-XX:+UseConcMarkSweepGC   Used in the old days CMS Recyclers ,  The new generation uses ParNew Recyclers 
-XX:ConcGCThreads=n   Set the number of concurrent threads ,
-XX:ParallelCMSThreads=n   ditto ,  Set the number of concurrent threads ,
-XX:CMSInitiatingOccupancyFraction=n   Specify the recovery threshold for the older generation ,  That is, when the memory utilization rate of the older generation reaches this value ,  Will execute once CMS Recycling , The default value is 68,  Set up skills : (Xmx-Xmn)*(100-CMSInitiatingOccupancyFraction)/100)>=Xmn
-XX:+UseCMSCompactAtFullCollection   Turn on the defragmentation of memory ,  When CMS When the garbage collection is finished ,  Do a memory defragmentation ,  Note that the defragmentation of memory is not concurrent ,  As a result, it may cause the program to pause 
-XX:CMSFullGCsBeforeCompation=n   Used to specify how many times CMS After recycling ,  One more memory compression 
-XX:+CMSParallelRemarkEnabled   In the use of UseParNewGC  Under the circumstances ,  Try to reduce  mark  Time for 
-XX:+UseCMSInitiatingOccupancyOnly   Only when the threshold is reached CMS Recycling 
-XX:+CMSConcurrentMTEnabled  When the flag is enabled , concurrent CMS Phase will be executed in multithreading , Default on 
-XX:+CMSIncrementalMode  In incremental mode ,CMS  The collector is in the concurrency phase , It won't monopolize the whole cycle , And there's a periodic pause , Wake up the application thread . The collector works the concurrency phase , Divided into fragments , It's in the secondary (minor)  Running between recycles . This requires low latency for , Run on a small amount of CPU The application on the server is very useful .

3.2)Class The recycling of ( Recycling of the permanent zone )
Set parameters

-XX:+CMSClassUnloadingEnabled   Turn on recycling Perm Area memory ,  By default ,  It needs to be triggered once FullGC
-XX:CMSInitiatingPermOccupancyFraction=n   When permanent zone occupancy reaches this n When the value of , start-up CMS Recycling ,  Use when the previous parameter is on 

4. G1 Recyclers (JDK1.7 After the brand new recycler , Used in place of CMS)
4.1) summary
characteristic
-  Unique garbage collection strategy , The utility model belongs to a generational garbage collector
-  Use partition algorithm , Does not require eden, The space between the young and the old is continuous
-  Parallelism : Recovery period , Multiple threads can work at the same time , Effective use of multi-core cpu resources
-  concurrency : Can be executed alternately with the application , Part of the work can be performed at the same time as the application
-  generational GC:: Generational collectors , Both the young and the old
-  Space arrangement : In the process of recycling , Appropriate object movement will be done , Reduce space debris
-  Predictability :G1 Some areas can be selected for recycling , It can reduce the scope of recycling , Reduce global pause

Main steps
-  The new generation GC
-  Concurrent tag cycles

 The initial marker is Cenozoic GC( This is parallel ,  The application will stop temporarily ) –>  Root area scan  –>  Concurrent Tags  –>  Re label ( This is parallel ,  The application will stop temporarily ) –>  Exclusive cleanup ( The application stops temporarily ) –>  Concurrent cleanup 

-  Mixed recycling

 At this stage, the normal young generation will be executed gc,  Some marked old age areas will also be selected for recycling ,  Deal with both the new generation and the old 

-  If you need , Will be carried out in FullGC

 blend GC There's not enough space 
 In the new generation GC when , survivor When the district and the older generation can't accommodate the surviving objects 
 Both of these can lead to a FullGC produce 

Set parameters

-XX:+UseG1GC   open G1 Collector switch ,
-XX:MaxGCPauseMillis=n   Specify the maximum pause time for the target , Any pause time that exceeds this value , G1 We will try to adjust the ratio between the new generation and the old generation ,  Resize the heap ,  Adjust the promotion age 
-XX:ParallelGCThreads=n   Used to set parallel recycling , GC Number of worker threads for 
-XX:InitiatingHeapOccpancyPercent=n   When specifying the utilization rate of the whole heap ,  Execute a concurrent marking cycle ,  Default 45,  Too much will cause the concurrent marking cycle to be delayed ,  increase FullGC The possibility of ,  Too small can lead to GC frequent ,  This can lead to a decline in application performance 

4.2) Parameter options

Options The default value is describe
-XX:+UseG1GC Off by default Use G1 Garbage disposal
-XX:MaxGCPauseMillis=n The default value is :4294967295 Set the maximum pause time for parallel collection , It's an ideal goal ,JVM We will do our best to achieve it .
-XX:InitiatingHeapOccupancyPercent=n The default value is :45 The percentage of the whole heap needed to start a concurrent garbage collection cycle . This ratio refers to the occupancy ratio of the whole heap, not a single generation ( for example G1), If the value is 0 Then represent ‘ Keep doing GC’. The default value is 45
-XX:NewRatio=n The default value is :2 Set the ratio of young generation to old generation . for example : The value is 3, The ratio of young generation to old generation is 1:3, The younger generation makes up the younger generation and the older generation 1/4.
-XX:SurvivorRatio=n The default value is :8 Young generation Eden District and two Survivor Area ratio . Be careful Survivor There are two. . Such as :3, Express Eden:Survivor=3:2, One Survivor District accounts for the whole young generation 1/5
-XX:MaxTenuringThreshold=n The default value is :15 Set the garbage maximum survival threshold . If set to 0 Words , Then the young generation does not go through Survivor District , Go straight to the old generation . For the older generation more applications , Can improve efficiency . If you set this value to a larger value , The younger generation will be in Survivor Area to be copied many times , This can increase the survival time of the younger generation , Increase the concept of being recycled in the younger generation .
-XX:ParallelGCThreads=n The default value is : along with JVM Different platforms Configure the number of threads for the parallel collector , namely : How many threads do garbage collection at the same time . This value is best configured to equal the number of processors .
-XX:ConcGCThreads=n The default value is : along with JVM Different platforms Parallel garbage collection , Number of threads used . Default and JVM Running platform .
-XX:G1ReservePercent=n The default value is :10 Set retention for false ceiling to reduce promotion ( The new generation is promoted to the old generation ) The number of heaps that are likely to fail .
-XX:G1HeapRegionSize=n The default value depends on the heap size Use G1 Garbage collector ,java The heap is divided into blocks of uniform size . This option sets the size of each block . The minimum is 1Mb, The maximum is 32Mb.

4.3) other GC Related settings
4.3.1)System.gc()

1) Ban System.gc()
-XX:+DisableExplicitGC  Prohibit calls in programs System.gc(),  Add this parameter ,  If the program has a call ,  Empty function call returned System.gc() Call to ,  Will use FullGC The whole heap is recycled in a way that ignores CMS or G1 And so on 

2)System.gc() Using concurrent recycling 
-XX:+ExplicitGCCinvokesConcurrent   Use concurrency to handle the displayed gc,  That is, after opening , System.gc() This display GC Will be collected concurrently , (CMS, G1)

4.3.2) parallel GC The new generation of extrafrontal trigger GC

1) Using parallel recyclers  (UseParallelGC perhaps UseParallelOldGC) when ,  It will trigger a new generation first GC,  The goal is to minimize pause time  
2) If you don't need this feature ,  You can use the following parameters to remove  
-XX:-ScavengeBeforeFullGC   That is to say, to remove in FullGC Before that new generation GC,  The original default value is true

4.3.3) When does the subject enter the old age

1) When an object is first created ,  It's going to be in the new generation eden District ,  If there is no GC Intervention , Will always be eden District , GC after , It's possible to enter survivor District or older generation  

2) When the object reaches a certain age  , Will leave the younger generation ,  Into the old age ,  The event that an object enters the old age is called promotion ,  And the age of the object is determined by GC It depends on the number of times , 
    every time GC, If the object is not recycled ,  Then the age of the object will be increased 1,  You can use the following parameters to control the maximum age of Cenozoic objects : 
-XX:MaxTenuringThreshold=n  Let's say it's n ,  The objects of the new generation are the most experienced n Time GC,  You'll be promoted to the old days ,  But this is not necessarily a prerequisite for promotion  
-XX:TargetSurvivorRatio=n   Used for setting up Survivor The target usage of the zone , When survivor District GC After the usage rate exceeds this value ,  You may use a younger age as the promotion age  

3) Apart from age ,  Object volume can also affect the promotion of objects ,  If the object is too large ,  The new generation cannot accommodate this object ,  Then the target may be promoted directly to the old age ,  This can be done through the following references 
    The number of users is directly promoted to the threshold of the old age ,  The unit is byte 
-XX:PretenureSizeThreshold  That is, the size of the object is greater than this value ,  It will bypass the new generation ,  Distribute directly to the older generation ,  This parameter only applies to serial recyclers and ParNew Effective recovery ,  And yes ParallelGC The recycler is not working 

4.3.4) stay TLAB Assign objects to (Thread Local Allocation Buffer, Threads allocate the cache locally )

TLAB Is a memory allocation area dedicated to threads ,  Virtual machines allocate space for threads ,  For small objects ,  Will be used preferentially TLAB,  This can speed up the allocation of objects , TLAB Is turned on by default ,  To close, you can use the following parameters to close  

-XX:-UseTLAB   close TLAB 
-XX:+UseTLAB   Turn on TLAB,  Default is also on  
-XX:+PrintTLAB  Observe TALB Usage situation  
-XX:TLABRefillWasteFraction=n   Set a ratio n,  and refill_waste The value is (TLAB_SIZE/n),  namely TLAB Less space ,  Large objects cannot be assigned to TLAB, So it will be allocated directly to the heap ,TLAB Small and easy to fill ,  So when TLAB There is not enough space to allocate a new object ,  Will consider abandoning the current TLAB Space is still allocated directly to the heap ,  This parameter will be used to judge ,  Less than refill_waste It's allowed to be abandoned ,  And new TLAB To assign objects , But more than refill_waste Just distribute it directly on the heap ,  The default is 64 
-XX:+ResizeTLAB   Turn on TLAB Auto size ,  On by default ,  To turn off + Number to - No  
-XX:TLABSize=n   Set up a TLAB Size ,  The premise is shut down first TLAB Automatic adjustment of 

5.  Performance Tuning Tools
5.1)jps  (Java Virtual Machine Process Status Tool)
It is mainly used to output JVM Status information of processes running in . The syntax is as follows :

jps [options] [hostid]

# hostid The grammar is as follows :
[protocol:][[//]hostname][:port][/servername]
protocol -  If protocol And hostname No designation , That means local agreements that are relevant to the current environment , If you specify hostname But it didn't specify protocol, that protocol The default is rmi.
hostname -  Server's IP Or the name , If it is not specified, it means that the machine .
port -  long-range rmi The port of , If not specified, it defaults to 1099.
Servername -  Sign up to RMI In the registry jstatd The name of .

#  If you don't specify hostid It defaults to the current host or server .

#  Command line parameter options 
-q  Ignore output class name 、Jar Name and pass in main Method parameters 
-m  Output incoming main Method parameters 
-l  Output main Class or Jar The full name of 
-v  Output incoming JVM Parameters of 
-V  The output is passed through the marked file to JVM Parameters of (.hotspotrc file , Or through parameters -XX:Flags=<filename> Specified file )
-J  Used to convey jvm Options to by javac Called java In the loader , for example ,“-J-Xms48m” Will set the boot memory to 48M, Use -J The options can be very convenient to add to the Java The development of the underlying virtual machine application passing parameters .

5.2)stack(Java Stack Trace)
It is mainly used to view a certain Java In process thread stack information . The syntax is as follows :

jstack [option] pid
jstack [option] executable core
jstack [option] [server-id@]remote-hostname-or-ip

#  Command line parameter options are described as follows :
-l  A long list of , Will print out additional lock information , It can be used in the lock of life and death jstack -l pid To observe lock holding 
-m mixed mode, Not only will it output Java Stack information , It will also output C/C++ Stack information ( such as Native Method )
-F  When ’jstack [-l] pid’ There is no corresponding time to force the stack information to be printed 
-h | -help Print help 

jstack You can navigate to the thread stack , Based on the stack information, we can locate the specific code , So it's in JVM It's used a lot in performance tuning .

5.3)jmap(Java Memory Map)
jmap Used to view heap memory usage , General combination jhat Use .jmap The syntax is as follows :( If it runs in 64 position JVM On , It may be necessary to specify -J-d64 Command options parameters )

jmap [option] pid
jmap [option] executable core
jmap [option] [server-id@]remote-hostname-or-ip

#  Parameter description 
executable  produce core dump Of java Executable program 
core  The message will be printed core dump file 
remote-hostname-or-ip  long-range debug The hostname or ip
server-id  only id, Suppose you have multiple remotes on a single host debug service 
pid  The phase matching information needs to be printed java process id, It can be used jps Inquiry 

#  The basic parameters 
-dump:[live,]format=b,file=<filename>  Use hprof Binary form , Output jvm Of heap Content to file =. live The suboptions are optional , If you specify live Options , Then only output live objects to the file 
-finalizerinfo  Print the information of the object waiting to be recycled 
-heap  Print heap Summary information for ,GC The algorithm used ,heap Configuration and wise heap Usage situation 
-histo[:live]  Print each class Number of instances , Memory footprint , Class full name information . VM The inner class name of is prefixed with ”*”.  If live Sub parameter plus , Count only the number of live objects 
-permstat  Print classload and jvm heap Long term information .  Include each classloader Name , vivacity , Address , Father classloader And loaded class Number .  in addition , Inside String The amount of memory used and the amount of memory used will also be printed out 
-F  Force . stay pid No corresponding time to use -dump perhaps -histo Parameters .  In this mode ,live Invalid child argument 
-h | -help  Print auxiliary information 
-J  Pass parameters to jmap Starting up jvm

5.4)jhat(Java Heap Analysis Tool)
jhat Used to deal with JAVA heap Tools for offline analysis , It can be exported from different virtual machines heap Information file analysis

# jmap -dump:format=b,file=dumpFileName pid
jmap -dump:format=b,file=/tmp/dump.dat 21711

jhat -port 9998 /tmp/dump.dat
#  Note that if Dump The file is too large , May need to add -J-Xmx512m This parameter specifies the maximum heap memory 

#  Enter the host address in the browser :9998 see 

in addition , have access to Eclipse plug-in unit MAT(Memory Analyzer Tool) Yes dump Document analysis .

5.5)jstat(Java Virtual Machine Statistics Monitoring Tool)
Jstat For monitoring based on HotSpot Of JVM, Real time command line statistics on the usage of the heap , Use jstat We can do it for the designated JVM Do the following monitoring :

Class loading and unloading situation
-  Check out the new generation 、 Capacity and usage of old generation and persistent generation
-  Check out the new generation 、 Garbage collection of the old generation and the permanent generation , Including the times of garbage collection and the time taken by garbage collection
-  Look at the new generation Eden Area and Survior Capacity and distribution in the area

grammar :

jstat [ generalOption | outputOptions vmid [interval[s|ms] [count]] ]

generalOption -  Single common command line options , Such as -help, -options,  or  -version.
outputOptions - One or more output options , By a single statOption Options make up , You can talk to -t, -h, and -J And so on .

statOption  according to jstat The dimensions of statistics are different , You can use the options in the following table to make statistics of different dimensions , Different operating systems may support different options , Can pass -options Options , View the options supported by different operating systems 

-h n  Used to specify that column headers are output every few rows , If you don't specify , By default, the column header appears only in the first row .
-J javaOption  Used to transfer a given javaOption Pass to java Application Loader , for example ,“-J-Xms48m” Will set the boot memory to 48M
-t n  Used to display a timestamp in the first column of the output , This time stamp represents JVM The time from the start to the present 
vmid VM The process number of , That is, the current running java Process number 
interval  Time interval between , The unit can be seconds or milliseconds , By designation s or ms determine , The default unit is milliseconds 
count  Number of prints , By default, it prints countless times 

=== Statistical dimension and output ===
1)class Used to view the statistics of class loading

2)compiler For viewing HotSpot The statistics of compiler compilation in

3)gc For viewing JVM Statistics of garbage collection in the middle pile

4)gccapacity For viewing the new generation 、 Storage capacity of old generation and permanent generation

5)gccause Used to view garbage collection statistics ( This and -gcutil Options as ), If there is garbage collection , It also shows why garbage collection was last and is currently taking place .

6)gcnew Used to see the new generation of garbage collection

7)gcnewcapacity Used to view the storage capacity of the new generation

8)gcold It is used to check the generation of the old generation and the generation of the permanent generation GC The situation of

9)gcoldcapacity Used to check the capacity of the old generation

10)gcpermcapacity Used to view the capacity of persistent generation

11)gcutil For viewing the new generation 、 Garbage collection of the old generation and the old generation

12)printcompilation HotSpot Statistics of compilation methods

Example

jstat -gc 1618 250 4

5.6)jvisualvm(Java Virtual Machine Monitoring, Troubleshooting, and Profiling Tool)
jvisualvm Same as jconsole It's all based on a graphical interface 、 You can view local and remote JAVA GUI Monitoring tools ,Jvisualvm Same as jconsole It's the same way , Type... Directly into the command line Jvisualvm You can start , however Jvisualvm comparison , The interface is more beautiful , Data is more real-time .

5.7)jconsole
One java GUI Surveillance tools , It can display all kinds of data in chart form . And can monitor the remote server through remote connection VM. use java Written GUI Program , Used for monitoring VM, And can monitor remote VM, Very easy to use , And it's very powerful . From the command line jconsole, Just choose the process .

We need to pay attention to : Running jconsole Before , You have to set the environment variable first DISPLAY, Otherwise, a mistake will be reported ,Linux Set the environment variables as follows :
export DISPLAY=:0.0

5.8)jprofile
JProfiler It's a fully functional one that requires commercial authorization Java Profiling tools (profiler), Dedicated to analysis J2SE and J2EE Applications .

It is the CPU、 Thread and memory profiling in a powerful application .JProfiler There are many IDE Consolidation and application server consolidation purposes .JProfiler Intuitive GUI So you can find performance bottlenecks 、 Catch memory leaks (memory leaks)、 And solve the thread problem . It gives you access to heap walker As a recycler root analysis, It's easy to find memory leaks ;heap snapshot (snapshot) Patterns are not referenced (reference) The object of 、 Slightly referenced objects 、 Or at the end of (finalization) All objects in the queue are removed ; Integrate sprites to analyze the browser's Java Plug in function .

5.9)jca
Java Thread analysis tool , Professional thread analysis tools are compatible with sun/oracle JDK dump Thread heap , Graphical display of thread summary information , Very easy positioning problem .
jca It's a class tool Starting method

java -jar jca433.jar

5.10)jinfo command  (Java Configuration Info)
jinfo You can output and modify the runtime java Process opts. It's easy to use , For output JAVA System parameters and command line parameters . Usage is jinfo -opt pid Such as : see 2788 Of MaxPerm The size can be used jinfo -flag MaxPermSize 2788.

5.11)Jdb command  (The Java Debugger)
Used to correct core Files and running Java Processes are debugged in real time , It contains a wealth of commands to help you debug .

5.12)Jstatd command  (Java Statistics Monitoring Daemon)
jstatd It's based on RMI(Remove Method Invocation) The service procedure of , It's used for monitoring based on HotSpot Of JVM The creation and destruction of resources in , It also provides a remote interface that allows remote monitoring tools to connect to local JVM Carry out orders .

jstatd Is based on RMI Of , So it's running jstatd Must exist on the server of RMI Registry Center , If you don't pass the option ”-p port” Specify the port to connect ,jstatd Will try to connect RMI The default port for the registry . I'll talk about how to connect to a default RMI Internal registry , How to prohibit the default RMI The creation of an internal registry , And how to start an external registry .
Parameter options

-nr  If RMI The registry didn't find , It won't create an internal RMI Registry Center .
-p port RMI The port number of the registry , The default is 1099.
-n rminame  The default is JStatRemoteHost; If more than one is running on the same host at the same time jstatd service ,rminame Can be used to uniquely identify a jstatd service ; There's a little bit of caution here , If this option is turned on , When monitoring client remote connection , Must specify at the same time hostid And vmid, You can only determine the service you want to connect to , This can be found in jps Section lists the remote servers Java Examples of processes .
-J  Used to convey jvm Options to by javac Called java In the loader , for example ,“-J-Xms48m” Will set the boot memory to 48M, Use -J The options can be very convenient to add to the Java The development of the underlying virtual machine application passing parameters .

Security
jstatd The service can only monitor JVM, therefore jstatd Process and monitored JVM Must run in the same user rights . But there are some special user rights , Based on UNIX(TM) For the system root user , It has access to all of the JVM Resources for , If jstatd The process runs in this permission , So it can monitor all of the JVM, But it also brings additional security issues .

Example

#  Use the inside RMI Registry Center ( The default port is 1099), start-up jstatd
jstatd -J-Djava.security.policy=jstatd.all.policy

#  Use external RMI Registry Center , start-up jstatd
rmiregistry&jstatd -J-Djava.security.policy=all.policy

#  External RMI Registry to start jstatd, The port of this registry is 2020
rmiregistry 2020&jstatd -J-Djava.security.policy=all.policy -p 2020

#  External RMI Registry to start jstatd, The port of this registry is 2020, And bound to RMI The name of the registry is AlternateJstatdServerName
rmiregistry 2020&jstatd -J-Djava.security.policy=all.policy -p 2020 -n AlternateJstatdServerName

#  No internal RMI The creation of a registry 
jstatd -J-Djava.security.policy=all.policy -nr

#  Turn on RMI Keep a diary ,jstatd Running in the open logging function RMI In registration 
jstatd -J-Djava.security.policy=all.policy -J-Djava.rmi.server.logCalls=true

5.13)httpwatch
Web data analysis tools , For client to server requests , Effective monitoring and analysis of response data .

6. Examples of production environments
6.1)Tomcat7
catalina.sh( Run only one Tomcat)

# 8G Memory 
JAVA_OPTS="
-Dfile.encoding=UTF-8
-server
-Djava.awt.headless=true
-Xms6144m
-Xmx6144m
-XX:NewSize=1024m
-XX:MaxNewSize=2048m
-XX:PermSize=512m
-XX:MaxPermSize=512m
-XX:MaxTenuringThreshold=15
-XX:NewRatio=2
-XX:+AggressiveOpts
-XX:+UseBiasedLocking
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:+CMSParallelRemarkEnabled
-XX:LargePageSizeInBytes=128m
-XX:+UseFastAccessorMethods
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+DisableExplicitGC"
 
# 16G Memory ( Garbage collection )
JAVA_OPTS="
-Dfile.encoding=UTF-8
-server
-Xms13312m
-Xmx13312m
-XX:NewSize=3072m
-XX:MaxNewSize=4096m
-XX:PermSize=512m
-XX:MaxPermSize=512m
-XX:MaxTenuringThreshold=10
-XX:NewRatio=2
-XX:+DisableExplicitGC"
 
# 32G Memory ( Garbage collection )
JAVA_OPTS="
-Dfile.encoding=UTF-8
-server
-Xms29696m
-Xmx29696m
-XX:NewSize=6144m
-XX:MaxNewSize=9216m
-XX:PermSize=1024m
-XX:MaxPermSize=1024m
-XX:MaxTenuringThreshold=10
-XX:NewRatio=2
-XX:+DisableExplicitGC"

6.2)Hadoop
Suggest Hadoop Process GC Parameters plus the following options , Many commercial versions have added... By default , This is right JDK Performance improvements help a lot

-XX:CMSInitiatingOccupancyFraction=70
-XX:+HeapDumpOnOutOfMemoryError
-XX:+UseConcMarkSweepGC
-XX:-CMSConcurrentMTEnabled
-XX:+CMSIncrementalMode
-Djava.net.preferIPv4Stack=true

7. Reference resources
JDK8 in JVM Heap memory partition

JDK8 Imported JVM Parameter change records
JVM Unstable parameters
java 8 JVM performance optimization
Java Performance optimization strategy
Jvm Garbage collector details

JVM Performance tuning monitoring tool jps、jstack、jmap、jhat、jstat、hprof The use of,
jps command (Java Virtual Machine Process Status Tool)

                                 Could not create the Java virtual machine                                 

 The general reasons are as follows :
1) Execute the program JAVA It's caused by the wrong path ! adopt "echo $JAVA_HOME" Find out JAVA route , Then update... In the program JAVA The path can be configured .
2)JVM Wrong parameters cause ( May be stack size Too small ). modify JVM_OPTIONS In the configuration JVM Parameter value is ok .
3)jdk Version incompatibility results in . adjustment jdk edition ( such as jdk Version is too low , Adjust to a higher version of jdk) that will do .