JVM(二)

一、JVM参数

有些算法适用于年轻代,有些适用于老年代**
新生代特点是重建对象少,所以用复制算法比较高

老年代的特点是对象时间存活比较长,如果用复制算法,复制来复制去耗时

所以老年代使用的是标记清除和标记整理

一般把java堆分为新生代和老年代

先来看一下默认的

1.分类

1)标准参数

不随JDK版本的变化而变化
例如:java -version

2)非标准化参数:-XX参数

主要用于JVM调优和Debug

分类:布尔类型、非布尔类型

  • 布尔类型

格式: -XX:[+/-]name
例如:-XX:+UseConcMarkSweepGC、 -XX:+UseG1GC
例子:
在启动时指定
java -XX:+UseG1GC -jar gift-0.0.1-SNAPSHOT.jar
再用jmap -heap看

+表示启动name属性
-表示禁用

  • 非布尔类型
    格式:-XX:name=value
    例如:-XX:MaxHeapSize=2048M 设置最大堆大小

3)其它(-XX参数变形)

如:-Xmx2048M,和上面等价 最大堆内存
-Xms 最小·堆内存
-Xms 500M
-Xss 线程栈的大小
-Xss128k

2.打印所有参数

把jvm参数打印出来

1)cmd

java -XX:+PrintFlagsFinal -version
在这里插入图片描述
把文件重定向到jvm.txt文件中:
java -XX:+PrintFlagsFinal -version > jvm.txt
在这里插入图片描述
下载下来有700多个,熟悉了解的需要20多个
参数若是等号即是默认值,若是:=表示非默认值,被用户或者是jvm修改的值)根据服务器情况去自动调整,自适应)

还可以过滤:java -XX:+PrintFlagsFinal -version |grep UseG1GC
在这里插入图片描述
对象的年龄,对象从新生代进入到老年代的参数,默认是15,到15后就从新生代进入老年代。
java -XX:+PrintFlagsFinal -version |grep MaxTenuringThreshold
在这里插入图片描述

[Global flags]
     intx ActiveProcessorCount                      = -1                                  {product}
    uintx AdaptiveSizeDecrementScaleFactor          = 4                                   {product}
    uintx AdaptiveSizeMajorGCDecayTimeScale         = 10                                  {product}
    uintx AdaptiveSizePausePolicy                   = 0                                   {product}
    uintx AdaptiveSizePolicyCollectionCostMargin    = 50                                  {product}
    uintx AdaptiveSizePolicyInitializingSteps       = 20                                  {product}
    uintx AdaptiveSizePolicyOutputInterval          = 0                                   {product}
    uintx AdaptiveSizePolicyWeight                  = 10                                  {product}
    uintx AdaptiveSizeThroughPutPolicy              = 0                                   {product}
    uintx AdaptiveTimeWeight                        = 25                                  {product}
     bool AdjustConcurrency                         = false                               {product}
     bool AggressiveHeap                            = false                               {product}
     bool AggressiveOpts                            = false                               {product}
     intx AliasLevel                                = 3                                   {C2 product}
     bool AlignVector                               = false                               {C2 product}
     intx AllocateInstancePrefetchLines             = 1                                   {product}
     intx AllocatePrefetchDistance                  = 192                                 {product}
     intx AllocatePrefetchInstr                     = 3                                   {product}
     intx AllocatePrefetchLines                     = 4                                   {product}
     intx AllocatePrefetchStepSize                  = 64                                  {product}
     intx AllocatePrefetchStyle                     = 1                                   {product}
     bool AllowJNIEnvProxy                          = false                               {product}
     bool AllowNonVirtualCalls                      = false                               {product}
     bool AllowParallelDefineClass                  = false                               {product}
     bool AllowUserSignalHandlers                   = false                               {product}
     bool AlwaysActAsServerClassMachine             = false                               {product}
     bool AlwaysCompileLoopMethods                  = false                               {product}
     bool AlwaysLockClassLoader                     = false                               {product}
     bool AlwaysPreTouch                            = false                               {product}
     bool AlwaysRestoreFPU                          = false                               {product}
     bool AlwaysTenure                              = false                               {product}
     bool AssertOnSuspendWaitFailure                = false                               {product}
     bool AssumeMP                                  = false                               {product}
     intx AutoBoxCacheMax                           = 128                                 {C2 product}
    uintx AutoGCSelectPauseMillis                   = 5000                                {product}
     intx BCEATraceLevel                            = 0                                   {product}
     intx BackEdgeThreshold                         = 100000                              {pd product}
     bool BackgroundCompilation                     = true                                {pd product}
    uintx BaseFootPrintEstimate                     = 268435456                           {product}
     intx BiasedLockingBulkRebiasThreshold          = 20                                  {product}
     intx BiasedLockingBulkRevokeThreshold          = 40                                  {product}
     intx BiasedLockingDecayTime                    = 25000                               {product}
     intx BiasedLockingStartupDelay                 = 4000                                {product}
     bool BindGCTaskThreadsToCPUs                   = false                               {product}
     bool BlockLayoutByFrequency                    = true                                {C2 product}
     intx BlockLayoutMinDiamondPercentage           = 20                                  {C2 product}
     bool BlockLayoutRotateLoops                    = true                                {C2 product}
     bool BranchOnRegister                          = false                               {C2 product}
     bool BytecodeVerificationLocal                 = false                               {product}
     bool BytecodeVerificationRemote                = true                                {product}
     bool C1OptimizeVirtualCallProfiling            = true                                {C1 product}
     bool C1ProfileBranches                         = true                                {C1 product}
     bool C1ProfileCalls                            = true                                {C1 product}
     bool C1ProfileCheckcasts                       = true                                {C1 product}
     bool C1ProfileInlinedCalls                     = true                                {C1 product}
     bool C1ProfileVirtualCalls                     = true                                {C1 product}
     bool C1UpdateMethodData                        = true                                {C1 product}
     intx CICompilerCount                          := 2                                   {product}
     bool CICompilerCountPerCPU                     = true                                {product}
     bool CITime                                    = false                               {product}
     bool CMSAbortSemantics                         = false                               {product}
    uintx CMSAbortablePrecleanMinWorkPerIteration   = 100                                 {product}
     intx CMSAbortablePrecleanWaitMillis            = 100                                 {manageable}
    uintx CMSBitMapYieldQuantum                     = 10485760                            {product}
    uintx CMSBootstrapOccupancy                     = 50                                  {product}
     bool CMSClassUnloadingEnabled                  = true                                {product}
    uintx CMSClassUnloadingMaxInterval              = 0                                   {product}
     bool CMSCleanOnEnter                           = true                                {product}
     bool CMSCompactWhenClearAllSoftRefs            = true                                {product}
    uintx CMSConcMarkMultiple                       = 32                                  {product}
     bool CMSConcurrentMTEnabled                    = true                                {product}
    uintx CMSCoordinatorYieldSleepCount             = 10                                  {product}
     bool CMSDumpAtPromotionFailure                 = false                               {product}
     bool CMSEdenChunksRecordAlways                 = true                                {product}
    uintx CMSExpAvgFactor                           = 50                                  {product}
     bool CMSExtrapolateSweep                       = false                               {product}
    uintx CMSFullGCsBeforeCompaction                = 0                                   {product}
    uintx CMSIncrementalDutyCycle                   = 10                                  {product}
    uintx CMSIncrementalDutyCycleMin                = 0                                   {product}
     bool CMSIncrementalMode                        = false                               {product}
    uintx CMSIncrementalOffset                      = 0                                   {product}
     bool CMSIncrementalPacing                      = true                                {product}
    uintx CMSIncrementalSafetyFactor                = 10                                  {product}
    uintx CMSIndexedFreeListReplenish               = 4                                   {product}
     intx CMSInitiatingOccupancyFraction            = -1                                  {product}
    uintx CMSIsTooFullPercentage                    = 98                                  {product}
   double CMSLargeCoalSurplusPercent                = 0.950000                            {product}
   double CMSLargeSplitSurplusPercent               = 1.000000                            {product}
     bool CMSLoopWarn                               = false                               {product}
    uintx CMSMaxAbortablePrecleanLoops              = 0                                   {product}
     intx CMSMaxAbortablePrecleanTime               = 5000                                {product}
    uintx CMSOldPLABMax                             = 1024                                {product}
    uintx CMSOldPLABMin                             = 16                                  {product}
    uintx CMSOldPLABNumRefills                      = 4                                   {product}
    uintx CMSOldPLABReactivityFactor                = 2                                   {product}
     bool CMSOldPLABResizeQuicker                   = false                               {product}
    uintx CMSOldPLABToleranceFactor                 = 4                                   {product}
     bool CMSPLABRecordAlways                       = true                                {product}
    uintx CMSParPromoteBlocksToClaim                = 16                                  {product}
     bool CMSParallelInitialMarkEnabled             = true                                {product}
     bool CMSParallelRemarkEnabled                  = true                                {product}
     bool CMSParallelSurvivorRemarkEnabled          = true                                {product}
    uintx CMSPrecleanDenominator                    = 3                                   {product}
    uintx CMSPrecleanIter                           = 3                                   {product}
    uintx CMSPrecleanNumerator                      = 2                                   {product}
     bool CMSPrecleanRefLists1                      = true                                {product}
     bool CMSPrecleanRefLists2                      = false                               {product}
     bool CMSPrecleanSurvivors1                     = false                               {product}
     bool CMSPrecleanSurvivors2                     = true                                {product}
    uintx CMSPrecleanThreshold                      = 1000                                {product}
     bool CMSPrecleaningEnabled                     = true                                {product}
     bool CMSPrintChunksInDump                      = false                               {product}
     bool CMSPrintEdenSurvivorChunks                = false                               {product}
     bool CMSPrintObjectsInDump                     = false                               {product}
    uintx CMSRemarkVerifyVariant                    = 1                                   {product}
     bool CMSReplenishIntermediate                  = true                                {product}
    uintx CMSRescanMultiple                         = 32                                  {product}
    uintx CMSSamplingGrain                          = 16384                               {product}
     bool CMSScavengeBeforeRemark                   = false                               {product}
    uintx CMSScheduleRemarkEdenPenetration          = 50                                  {product}
    uintx CMSScheduleRemarkEdenSizeThreshold        = 2097152                             {product}
    uintx CMSScheduleRemarkSamplingRatio            = 5                                   {product}
   double CMSSmallCoalSurplusPercent                = 1.050000                            {product}
   double CMSSmallSplitSurplusPercent               = 1.100000                            {product}
     bool CMSSplitIndexedFreeListBlocks             = true                                {product}
     intx CMSTriggerInterval                        = -1                                  {manageable}
    uintx CMSTriggerRatio                           = 80                                  {product}
     intx CMSWaitDuration                           = 2000                                {manageable}
    uintx CMSWorkQueueDrainThreshold                = 10                                  {product}
     bool CMSYield                                  = true                                {product}
    uintx CMSYieldSleepCount                        = 0                                   {product}
    uintx CMSYoungGenPerWorker                      = 67108864                            {pd product}
    uintx CMS_FLSPadding                            = 1                                   {product}
    uintx CMS_FLSWeight                             = 75                                  {product}
    uintx CMS_SweepPadding                          = 1                                   {product}
    uintx CMS_SweepTimerThresholdMillis             = 10                                  {product}
    uintx CMS_SweepWeight                           = 75                                  {product}
     bool CheckEndorsedAndExtDirs                   = false                               {product}
     bool CheckJNICalls                             = false                               {product}
     bool ClassUnloading                            = true                                {product}
     bool ClassUnloadingWithConcurrentMark          = true                                {product}
     intx ClearFPUAtPark                            = 0                                   {product}
     bool ClipInlining                              = true                                {product}
    uintx CodeCacheExpansionSize                    = 65536                               {pd product}
    uintx CodeCacheMinimumFreeSpace                 = 512000                              {product}
     bool CollectGen0First                          = false                               {product}
     bool CompactFields                             = true                                {product}
     intx CompilationPolicyChoice                   = 3                                   {product}
ccstrlist CompileCommand                            =                                     {product}
    ccstr CompileCommandFile                        =                                     {product}
ccstrlist CompileOnly                               =                                     {product}
     intx CompileThreshold                          = 10000                               {pd product}
     bool CompilerThreadHintNoPreempt               = true                                {product}
     intx CompilerThreadPriority                    = -1                                  {product}
     intx CompilerThreadStackSize                   = 0                                   {pd product}
    uintx CompressedClassSpaceSize                  = 1073741824                          {product}
    uintx ConcGCThreads                             = 0                                   {product}
     intx ConditionalMoveLimit                      = 3                                   {C2 pd product}
     intx ContendedPaddingWidth                     = 128                                 {product}
     bool ConvertSleepToYield                       = true                                {pd product}
     bool ConvertYieldToSleep                       = false                               {product}
     bool CrashOnOutOfMemoryError                   = false                               {product}
     bool CreateMinidumpOnCrash                     = false                               {product}
     bool CriticalJNINatives                        = true                                {product}
     bool DTraceAllocProbes                         = false                               {product}
     bool DTraceMethodProbes                        = false                               {product}
     bool DTraceMonitorProbes                       = false                               {product}
     bool Debugging                                 = false                               {product}
    uintx DefaultMaxRAMFraction                     = 4                                   {product}
     intx DefaultThreadPriority                     = -1                                  {product}
     intx DeferPollingPageLoopCount                 = -1                                  {product}
     intx DeferThrSuspendLoopCount                  = 4000                                {product}
     bool DeoptimizeRandom                          = false                               {product}
     bool DisableAttachMechanism                    = false                               {product}
     bool DisableExplicitGC                         = false                               {product}
     bool DisplayVMOutputToStderr                   = false                               {product}
     bool DisplayVMOutputToStdout                   = false                               {product}
     bool DoEscapeAnalysis                          = true                                {C2 product}
     bool DontCompileHugeMethods                    = true                                {product}
     bool DontYieldALot                             = false                               {pd product}
    ccstr DumpLoadedClassList                       =                                     {product}
     bool DumpReplayDataOnError                     = true                                {product}
     bool DumpSharedSpaces                          = false                               {product}
     bool EagerXrunInit                             = false                               {product}
     intx EliminateAllocationArraySizeLimit         = 64                                  {C2 product}
     bool EliminateAllocations                      = true                                {C2 product}
     bool EliminateAutoBox                          = true                                {C2 product}
     bool EliminateLocks                            = true                                {C2 product}
     bool EliminateNestedLocks                      = true                                {C2 product}
     intx EmitSync                                  = 0                                   {product}
     bool EnableContended                           = true                                {product}
     bool EnableResourceManagementTLABCache         = true                                {product}
     bool EnableSharedLookupCache                   = true                                {product}
     bool EnableTracing                             = false                               {product}
    uintx ErgoHeapSizeLimit                         = 0                                   {product}
    ccstr ErrorFile                                 =                                     {product}
    ccstr ErrorReportServer                         =                                     {product}
   double EscapeAnalysisTimeout                     = 20.000000                           {C2 product}
     bool EstimateArgEscape                         = true                                {product}
     bool ExitOnOutOfMemoryError                    = false                               {product}
     bool ExplicitGCInvokesConcurrent               = false                               {product}
     bool ExplicitGCInvokesConcurrentAndUnloadsClasses  = false                               {product}
     bool ExtendedDTraceProbes                      = false                               {product}
    ccstr ExtraSharedClassListFile                  =                                     {product}
     bool FLSAlwaysCoalesceLarge                    = false                               {product}
    uintx FLSCoalescePolicy                         = 2                                   {product}
   double FLSLargestBlockCoalesceProximity          = 0.990000                            {product}
     bool FailOverToOldVerifier                     = true                                {product}
     bool FastTLABRefill                            = true                                {product}
     intx FenceInstruction                          = 0                                   {ARCH product}
     intx FieldsAllocationStyle                     = 1                                   {product}
     bool FilterSpuriousWakeups                     = true                                {product}
    ccstr FlightRecorderOptions                     =                                     {product}
     bool ForceNUMA                                 = false                               {product}
     bool ForceTimeHighResolution                   = false                               {product}
     intx FreqInlineSize                            = 325                                 {pd product}
   double G1ConcMarkStepDurationMillis              = 10.000000                           {product}
    uintx G1ConcRSHotCardLimit                      = 4                                   {product}
    uintx G1ConcRSLogCacheSize                      = 10                                  {product}
     intx G1ConcRefinementGreenZone                 = 0                                   {product}
     intx G1ConcRefinementRedZone                   = 0                                   {product}
     intx G1ConcRefinementServiceIntervalMillis     = 300                                 {product}
    uintx G1ConcRefinementThreads                   = 0                                   {product}
     intx G1ConcRefinementThresholdStep             = 0                                   {product}
     intx G1ConcRefinementYellowZone                = 0                                   {product}
    uintx G1ConfidencePercent                       = 50                                  {product}
    uintx G1HeapRegionSize                          = 0                                   {product}
    uintx G1HeapWastePercent                        = 5                                   {product}
    uintx G1MixedGCCountTarget                      = 8                                   {product}
     intx G1RSetRegionEntries                       = 0                                   {product}
    uintx G1RSetScanBlockSize                       = 64                                  {product}
     intx G1RSetSparseRegionEntries                 = 0                                   {product}
     intx G1RSetUpdatingPauseTimePercent            = 10                                  {product}
     intx G1RefProcDrainInterval                    = 10                                  {product}
    uintx G1ReservePercent                          = 10                                  {product}
    uintx G1SATBBufferEnqueueingThresholdPercent    = 60                                  {product}
     intx G1SATBBufferSize                          = 1024                                {product}
     intx G1UpdateBufferSize                        = 256                                 {product}
     bool G1UseAdaptiveConcRefinement               = true                                {product}
    uintx GCDrainStackTargetSize                    = 64                                  {product}
    uintx GCHeapFreeLimit                           = 2                                   {product}
    uintx GCLockerEdenExpansionPercent              = 5                                   {product}
     bool GCLockerInvokesConcurrent                 = false                               {product}
    uintx GCLogFileSize                             = 8192                                {product}
    uintx GCPauseIntervalMillis                     = 0                                   {product}
    uintx GCTaskTimeStampEntries                    = 200                                 {product}
    uintx GCTimeLimit                               = 98                                  {product}
    uintx GCTimeRatio                               = 99                                  {product}
    uintx HeapBaseMinAddress                        = 2147483648                          {pd product}
     bool HeapDumpAfterFullGC                       = false                               {manageable}
     bool HeapDumpBeforeFullGC                      = false                               {manageable}
     bool HeapDumpOnOutOfMemoryError                = false                               {manageable}
    ccstr HeapDumpPath                              =                                     {manageable}
    uintx HeapFirstMaximumCompactionCount           = 3                                   {product}
    uintx HeapMaximumCompactionInterval             = 20                                  {product}
    uintx HeapSizePerGCThread                       = 87241520                            {product}
     bool IgnoreEmptyClassPaths                     = false                               {product}
     bool IgnoreUnrecognizedVMOptions               = false                               {product}
    uintx IncreaseFirstTierCompileThresholdAt       = 50                                  {product}
     bool IncrementalInline                         = true                                {C2 product}
    uintx InitialBootClassLoaderMetaspaceSize       = 4194304                             {product}
    uintx InitialCodeCacheSize                      = 2555904                             {pd product}
    uintx InitialHeapSize                          := 31457280                            {product}
    uintx InitialRAMFraction                        = 64                                  {product}
   double InitialRAMPercentage                      = 1.562500                            {product}
    uintx InitialSurvivorRatio                      = 8                                   {product}
    uintx InitialTenuringThreshold                  = 7                                   {product}
    uintx InitiatingHeapOccupancyPercent            = 45                                  {product}
     bool Inline                                    = true                                {product}
    ccstr InlineDataFile                            =                                     {product}
     intx InlineSmallCode                           = 2000                                {pd product}
     bool InlineSynchronizedMethods                 = true                                {C1 product}
     bool InsertMemBarAfterArraycopy                = true                                {C2 product}
     intx InteriorEntryAlignment                    = 16                                  {C2 pd product}
     intx InterpreterProfilePercentage              = 33                                  {product}
     bool JNIDetachReleasesMonitors                 = true                                {product}
     bool JavaMonitorsInStackTrace                  = true                                {product}
     intx JavaPriority10_To_OSPriority              = -1                                  {product}
     intx JavaPriority1_To_OSPriority               = -1                                  {product}
     intx JavaPriority2_To_OSPriority               = -1                                  {product}
     intx JavaPriority3_To_OSPriority               = -1                                  {product}
     intx JavaPriority4_To_OSPriority               = -1                                  {product}
     intx JavaPriority5_To_OSPriority               = -1                                  {product}
     intx JavaPriority6_To_OSPriority               = -1                                  {product}
     intx JavaPriority7_To_OSPriority               = -1                                  {product}
     intx JavaPriority8_To_OSPriority               = -1                                  {product}
     intx JavaPriority9_To_OSPriority               = -1                                  {product}
     bool LIRFillDelaySlots                         = false                               {C1 pd product}
    uintx LargePageHeapSizeThreshold                = 134217728                           {product}
    uintx LargePageSizeInBytes                      = 0                                   {product}
     bool LazyBootClassLoader                       = true                                {product}
     intx LiveNodeCountInliningCutoff               = 40000                               {C2 product}
     bool LoadExecStackDllInVMThread                = true                                {product}
     bool LogCommercialFeatures                     = false                               {product}
     intx LoopMaxUnroll                             = 16                                  {C2 product}
     intx LoopOptsCount                             = 43                                  {C2 product}
     intx LoopUnrollLimit                           = 60                                  {C2 pd product}
     intx LoopUnrollMin                             = 4                                   {C2 product}
     bool LoopUnswitching                           = true                                {C2 product}
     bool ManagementServer                          = false                               {product}
    uintx MarkStackSize                             = 4194304                             {product}
    uintx MarkStackSizeMax                          = 536870912                           {product}
    uintx MarkSweepAlwaysCompactCount               = 4                                   {product}
    uintx MarkSweepDeadRatio                        = 5                                   {product}
     intx MaxBCEAEstimateLevel                      = 5                                   {product}
     intx MaxBCEAEstimateSize                       = 150                                 {product}
    uintx MaxDirectMemorySize                       = 0                                   {product}
     bool MaxFDLimit                                = true                                {product}
    uintx MaxGCMinorPauseMillis                     = 18446744073709551615                    {product}
    uintx MaxGCPauseMillis                          = 18446744073709551615                    {product}
    uintx MaxHeapFreeRatio                          = 70                                  {manageable}
    uintx MaxHeapSize                              := 482344960                           {product}
     intx MaxInlineLevel                            = 9                                   {product}
     intx MaxInlineSize                             = 35                                  {product}
     intx MaxJNILocalCapacity                       = 65536                               {product}
     intx MaxJavaStackTraceDepth                    = 1024                                {product}
     intx MaxJumpTableSize                          = 65000                               {C2 product}
     intx MaxJumpTableSparseness                    = 5                                   {C2 product}
     intx MaxLabelRootDepth                         = 1100                                {C2 product}
     intx MaxLoopPad                                = 11                                  {C2 product}
    uintx MaxMetaspaceExpansion                     = 5451776                             {product}
    uintx MaxMetaspaceFreeRatio                     = 70                                  {product}
    uintx MaxMetaspaceSize                          = 18446744073709547520                    {product}
    uintx MaxNewSize                               := 160759808                           {product}
     intx MaxNodeLimit                              = 75000                               {C2 product}
 uint64_t MaxRAM                                    = 137438953472                        {pd product}
    uintx MaxRAMFraction                            = 4                                   {product}
   double MaxRAMPercentage                          = 25.000000                           {product}
     intx MaxRecursiveInlineLevel                   = 1                                   {product}
    uintx MaxTenuringThreshold                      = 15                                  {product}
     intx MaxTrivialSize                            = 6                                   {product}
     intx MaxVectorSize                             = 32                                  {C2 product}
    uintx MetaspaceSize                             = 21807104                            {pd product}
     bool MethodFlushing                            = true                                {product}
    uintx MinHeapDeltaBytes                        := 196608                              {product}
    uintx MinHeapFreeRatio                          = 40                                  {manageable}
     intx MinInliningThreshold                      = 250                                 {product}
     intx MinJumpTableSize                          = 10                                  {C2 pd product}
    uintx MinMetaspaceExpansion                     = 339968                              {product}
    uintx MinMetaspaceFreeRatio                     = 40                                  {product}
    uintx MinRAMFraction                            = 2                                   {product}
   double MinRAMPercentage                          = 50.000000                           {product}
    uintx MinSurvivorRatio                          = 3                                   {product}
    uintx MinTLABSize                               = 2048                                {product}
     intx MonitorBound                              = 0                                   {product}
     bool MonitorInUseLists                         = false                               {product}
     intx MultiArrayExpandLimit                     = 6                                   {C2 product}
     bool MustCallLoadClassInternal                 = false                               {product}
    uintx NUMAChunkResizeWeight                     = 20                                  {product}
    uintx NUMAInterleaveGranularity                 = 2097152                             {product}
    uintx NUMAPageScanRate                          = 256                                 {product}
    uintx NUMASpaceResizeRate                       = 1073741824                          {product}
     bool NUMAStats                                 = false                               {product}
    ccstr NativeMemoryTracking                      = off                                 {product}
     bool NeedsDeoptSuspend                         = false                               {pd product}
     bool NeverActAsServerClassMachine              = false                               {pd product}
     bool NeverTenure                               = false                               {product}
    uintx NewRatio                                  = 2                                   {product}
    uintx NewSize                                  := 10485760                            {product}
    uintx NewSizeThreadIncrease                     = 5320                                {pd product}
     intx NmethodSweepActivity                      = 10                                  {product}
     intx NmethodSweepCheckInterval                 = 5                                   {product}
     intx NmethodSweepFraction                      = 16                                  {product}
     intx NodeLimitFudgeFactor                      = 2000                                {C2 product}
    uintx NumberOfGCLogFiles                        = 0                                   {product}
     intx NumberOfLoopInstrToAlign                  = 4                                   {C2 product}
     intx ObjectAlignmentInBytes                    = 8                                   {lp64_product}
    uintx OldPLABSize                               = 1024                                {product}
    uintx OldPLABWeight                             = 50                                  {product}
    uintx OldSize                                  := 20971520                            {product}
     bool OmitStackTraceInFastThrow                 = true                                {product}
ccstrlist OnError                                   =                                     {product}
ccstrlist OnOutOfMemoryError                        =                                     {product}
     intx OnStackReplacePercentage                  = 140                                 {pd product}
     bool OptimizeFill                              = true                                {C2 product}
     bool OptimizePtrCompare                        = true                                {C2 product}
     bool OptimizeStringConcat                      = true                                {C2 product}
     bool OptoBundling                              = false                               {C2 pd product}
     intx OptoLoopAlignment                         = 16                                  {pd product}
     bool OptoScheduling                            = false                               {C2 pd product}
    uintx PLABWeight                                = 75                                  {product}
     bool PSChunkLargeArrays                        = true                                {product}
     intx ParGCArrayScanChunk                       = 50                                  {product}
    uintx ParGCDesiredObjsFromOverflowList          = 20                                  {product}
     bool ParGCTrimOverflow                         = true                                {product}
     bool ParGCUseLocalOverflow                     = false                               {product}
    uintx ParallelGCBufferWastePct                  = 10                                  {product}
    uintx ParallelGCThreads                         = 0                                   {product}
     bool ParallelGCVerbose                         = false                               {product}
    uintx ParallelOldDeadWoodLimiterMean            = 50                                  {product}
    uintx ParallelOldDeadWoodLimiterStdDev          = 80                                  {product}
     bool ParallelRefProcBalancingEnabled           = true                                {product}
     bool ParallelRefProcEnabled                    = false                               {product}
     bool PartialPeelAtUnsignedTests                = true                                {C2 product}
     bool PartialPeelLoop                           = true                                {C2 product}
     intx PartialPeelNewPhiDelta                    = 0                                   {C2 product}
    uintx PausePadding                              = 1                                   {product}
     intx PerBytecodeRecompilationCutoff            = 200                                 {product}
     intx PerBytecodeTrapLimit                      = 4                                   {product}
     intx PerMethodRecompilationCutoff              = 400                                 {product}
     intx PerMethodTrapLimit                        = 100                                 {product}
     bool PerfAllowAtExitRegistration               = false                               {product}
     bool PerfBypassFileSystemCheck                 = false                               {product}
     intx PerfDataMemorySize                        = 32768                               {product}
     intx PerfDataSamplingInterval                  = 50                                  {product}
    ccstr PerfDataSaveFile                          =                                     {product}
     bool PerfDataSaveToFile                        = false                               {product}
     bool PerfDisableSharedMem                      = false                               {product}
     intx PerfMaxStringConstLength                  = 1024                                {product}
     intx PreInflateSpin                            = 10                                  {pd product}
     bool PreferContainerQuotaForCPUCount           = true                                {product}
     bool PreferInterpreterNativeStubs              = false                               {pd product}
     intx PrefetchCopyIntervalInBytes               = 576                                 {product}
     intx PrefetchFieldsAhead                       = 1                                   {product}
     intx PrefetchScanIntervalInBytes               = 576                                 {product}
     bool PreserveAllAnnotations                    = false                               {product}
     bool PreserveFramePointer                      = false                               {pd product}
    uintx PretenureSizeThreshold                    = 0                                   {product}
     bool PrintAdaptiveSizePolicy                   = false                               {product}
     bool PrintCMSInitiationStatistics              = false                               {product}
     intx PrintCMSStatistics                        = 0                                   {product}
     bool PrintClassHistogram                       = false                               {manageable}
     bool PrintClassHistogramAfterFullGC            = false                               {manageable}
     bool PrintClassHistogramBeforeFullGC           = false                               {manageable}
     bool PrintCodeCache                            = false                               {product}
     bool PrintCodeCacheOnCompilation               = false                               {product}
     bool PrintCommandLineFlags                     = false                               {product}
     bool PrintCompilation                          = false                               {product}
     bool PrintConcurrentLocks                      = false                               {manageable}
     intx PrintFLSCensus                            = 0                                   {product}
     intx PrintFLSStatistics                        = 0                                   {product}
     bool PrintFlagsFinal                          := true                                {product}
     bool PrintFlagsInitial                         = false                               {product}
     bool PrintGC                                   = false                               {manageable}
     bool PrintGCApplicationConcurrentTime          = false                               {product}
     bool PrintGCApplicationStoppedTime             = false                               {product}
     bool PrintGCCause                              = true                                {product}
     bool PrintGCDateStamps                         = false                               {manageable}
     bool PrintGCDetails                            = false                               {manageable}
     bool PrintGCID                                 = false                               {manageable}
     bool PrintGCTaskTimeStamps                     = false                               {product}
     bool PrintGCTimeStamps                         = false                               {manageable}
     bool PrintHeapAtGC                             = false                               {product rw}
     bool PrintHeapAtGCExtended                     = false                               {product rw}
     bool PrintHeapAtSIGBREAK                       = true                                {product}
     bool PrintJNIGCStalls                          = false                               {product}
     bool PrintJNIResolving                         = false                               {product}
     bool PrintOldPLAB                              = false                               {product}
     bool PrintOopAddress                           = false                               {product}
     bool PrintPLAB                                 = false                               {product}
     bool PrintParallelOldGCPhaseTimes              = false                               {product}
     bool PrintPromotionFailure                     = false                               {product}
     bool PrintReferenceGC                          = false                               {product}
     bool PrintSafepointStatistics                  = false                               {product}
     intx PrintSafepointStatisticsCount             = 300                                 {product}
     intx PrintSafepointStatisticsTimeout           = -1                                  {product}
     bool PrintSharedArchiveAndExit                 = false                               {product}
     bool PrintSharedDictionary                     = false                               {product}
     bool PrintSharedSpaces                         = false                               {product}
     bool PrintStringDeduplicationStatistics        = false                               {product}
     bool PrintStringTableStatistics                = false                               {product}
     bool PrintTLAB                                 = false                               {product}
     bool PrintTenuringDistribution                 = false                               {product}
     bool PrintTieredEvents                         = false                               {product}
     bool PrintVMOptions                            = false                               {product}
     bool PrintVMQWaitTime                          = false                               {product}
     bool PrintWarnings                             = true                                {product}
    uintx ProcessDistributionStride                 = 4                                   {product}
     bool ProfileInterpreter                        = true                                {pd product}
     bool ProfileIntervals                          = false                               {product}
     intx ProfileIntervalsTicks                     = 100                                 {product}
     intx ProfileMaturityPercentage                 = 20                                  {product}
     bool ProfileVM                                 = false                               {product}
     bool ProfilerPrintByteCodeStatistics           = false                               {product}
     bool ProfilerRecordPC                          = false                               {product}
    uintx PromotedPadding                           = 3                                   {product}
    uintx QueuedAllocationWarningCount              = 0                                   {product}
    uintx RTMRetryCount                             = 5                                   {ARCH product}
     bool RangeCheckElimination                     = true                                {product}
     intx ReadPrefetchInstr                         = 0                                   {ARCH product}
     bool ReassociateInvariants                     = true                                {C2 product}
     bool ReduceBulkZeroing                         = true                                {C2 product}
     bool ReduceFieldZeroing                        = true                                {C2 product}
     bool ReduceInitialCardMarks                    = true                                {C2 product}
     bool ReduceSignalUsage                         = false                               {product}
     intx RefDiscoveryPolicy                        = 0                                   {product}
     bool ReflectionWrapResolutionErrors            = true                                {product}
     bool RegisterFinalizersAtInit                  = true                                {product}
     bool RelaxAccessControlCheck                   = false                               {product}
    ccstr ReplayDataFile                            =                                     {product}
     bool RequireSharedSpaces                       = false                               {product}
    uintx ReservedCodeCacheSize                     = 251658240                           {pd product}
     bool ResizeOldPLAB                             = true                                {product}
     bool ResizePLAB                                = true                                {product}
     bool ResizeTLAB                                = true                                {pd product}
     bool RestoreMXCSROnJNICalls                    = false                               {product}
     bool RestrictContended                         = true                                {product}
     bool RewriteBytecodes                          = true                                {pd product}
     bool RewriteFrequentPairs                      = true                                {pd product}
     intx SafepointPollOffset                       = 256                                 {C1 pd product}
     intx SafepointSpinBeforeYield                  = 2000                                {product}
     bool SafepointTimeout                          = false                               {product}
     intx SafepointTimeoutDelay                     = 10000                               {product}
     bool ScavengeBeforeFullGC                      = true                                {product}
     intx SelfDestructTimer                         = 0                                   {product}
    uintx SharedBaseAddress                         = 34359738368                         {product}
    ccstr SharedClassListFile                       =                                     {product}
    uintx SharedMiscCodeSize                        = 122880                              {product}
    uintx SharedMiscDataSize                        = 4194304                             {product}
    uintx SharedReadOnlySize                        = 16777216                            {product}
    uintx SharedReadWriteSize                       = 16777216                            {product}
     bool ShowMessageBoxOnError                     = false                               {product}
     intx SoftRefLRUPolicyMSPerMB                   = 1000                                {product}
     bool SpecialEncodeISOArray                     = true                                {C2 product}
     bool SplitIfBlocks                             = true                                {C2 product}
     intx StackRedPages                             = 1                                   {pd product}
     intx StackShadowPages                          = 20                                  {pd product}
     bool StackTraceInThrowable                     = true                                {product}
     intx StackYellowPages                          = 2                                   {pd product}
     bool StartAttachListener                       = false                               {product}
     intx StarvationMonitorInterval                 = 200                                 {product}
     bool StressLdcRewrite                          = false                               {product}
    uintx StringDeduplicationAgeThreshold           = 3                                   {product}
    uintx StringTableSize                           = 60013                               {product}
     bool SuppressFatalErrorMessage                 = false                               {product}
    uintx SurvivorPadding                           = 3                                   {product}
    uintx SurvivorRatio                             = 8                                   {product}
     intx SuspendRetryCount                         = 50                                  {product}
     intx SuspendRetryDelay                         = 5                                   {product}
     intx SyncFlags                                 = 0                                   {product}
    ccstr SyncKnobs                                 =                                     {product}
     intx SyncVerbose                               = 0                                   {product}
    uintx TLABAllocationWeight                      = 35                                  {product}
    uintx TLABRefillWasteFraction                   = 64                                  {product}
    uintx TLABSize                                  = 0                                   {product}
     bool TLABStats                                 = true                                {product}
    uintx TLABWasteIncrement                        = 4                                   {product}
    uintx TLABWasteTargetPercent                    = 1                                   {product}
    uintx TargetPLABWastePct                        = 10                                  {product}
    uintx TargetSurvivorRatio                       = 50                                  {product}
    uintx TenuredGenerationSizeIncrement            = 20                                  {product}
    uintx TenuredGenerationSizeSupplement           = 80                                  {product}
    uintx TenuredGenerationSizeSupplementDecay      = 2                                   {product}
     intx ThreadPriorityPolicy                      = 0                                   {product}
     bool ThreadPriorityVerbose                     = false                               {product}
    uintx ThreadSafetyMargin                        = 52428800                            {product}
     intx ThreadStackSize                           = 1024                                {pd product}
    uintx ThresholdTolerance                        = 10                                  {product}
     intx Tier0BackedgeNotifyFreqLog                = 10                                  {product}
     intx Tier0InvokeNotifyFreqLog                  = 7                                   {product}
     intx Tier0ProfilingStartPercentage             = 200                                 {product}
     intx Tier23InlineeNotifyFreqLog                = 20                                  {product}
     intx Tier2BackEdgeThreshold                    = 0                                   {product}
     intx Tier2BackedgeNotifyFreqLog                = 14                                  {product}
     intx Tier2CompileThreshold                     = 0                                   {product}
     intx Tier2InvokeNotifyFreqLog                  = 11                                  {product}
     intx Tier3BackEdgeThreshold                    = 60000                               {product}
     intx Tier3BackedgeNotifyFreqLog                = 13                                  {product}
     intx Tier3CompileThreshold                     = 2000                                {product}
     intx Tier3DelayOff                             = 2                                   {product}
     intx Tier3DelayOn                              = 5                                   {product}
     intx Tier3InvocationThreshold                  = 200                                 {product}
     intx Tier3InvokeNotifyFreqLog                  = 10                                  {product}
     intx Tier3LoadFeedback                         = 5                                   {product}
     intx Tier3MinInvocationThreshold               = 100                                 {product}
     intx Tier4BackEdgeThreshold                    = 40000                               {product}
     intx Tier4CompileThreshold                     = 15000                               {product}
     intx Tier4InvocationThreshold                  = 5000                                {product}
     intx Tier4LoadFeedback                         = 3                                   {product}
     intx Tier4MinInvocationThreshold               = 600                                 {product}
     bool TieredCompilation                         = true                                {pd product}
     intx TieredCompileTaskTimeout                  = 50                                  {product}
     intx TieredRateUpdateMaxTime                   = 25                                  {product}
     intx TieredRateUpdateMinTime                   = 1                                   {product}
     intx TieredStopAtLevel                         = 4                                   {product}
     bool TimeLinearScan                            = false                               {C1 product}
     bool TraceBiasedLocking                        = false                               {product}
     bool TraceClassLoading                         = false                               {product rw}
     bool TraceClassLoadingPreorder                 = false                               {product}
     bool TraceClassPaths                           = false                               {product}
     bool TraceClassResolution                      = false                               {product}
     bool TraceClassUnloading                       = false                               {product rw}
     bool TraceDynamicGCThreads                     = false                               {product}
     bool TraceGen0Time                             = false                               {product}
     bool TraceGen1Time                             = false                               {product}
    ccstr TraceJVMTI                                =                                     {product}
     bool TraceLoaderConstraints                    = false                               {product rw}
     bool TraceMetadataHumongousAllocation          = false                               {product}
     bool TraceMonitorInflation                     = false                               {product}
     bool TraceParallelOldGCTasks                   = false                               {product}
     intx TraceRedefineClasses                      = 0                                   {product}
     bool TraceSafepointCleanupTime                 = false                               {product}
     bool TraceSharedLookupCache                    = false                               {product}
     bool TraceSuspendWaitFailures                  = false                               {product}
     intx TrackedInitializationLimit                = 50                                  {C2 product}
     bool TransmitErrorReport                       = false                               {product}
     bool TrapBasedNullChecks                       = false                               {pd product}
     bool TrapBasedRangeChecks                      = false                               {C2 pd product}
     intx TypeProfileArgsLimit                      = 2                                   {product}
    uintx TypeProfileLevel                          = 111                                 {pd product}
     intx TypeProfileMajorReceiverPercent           = 90                                  {C2 product}
     intx TypeProfileParmsLimit                     = 2                                   {product}
     intx TypeProfileWidth                          = 2                                   {product}
     intx UnguardOnExecutionViolation               = 0                                   {product}
     bool UnlinkSymbolsALot                         = false                               {product}
     bool Use486InstrsOnly                          = false                               {ARCH product}
     bool UseAES                                    = true                                {product}
     bool UseAESIntrinsics                          = true                                {product}
     intx UseAVX                                    = 2                                   {ARCH product}
     bool UseAdaptiveGCBoundary                     = false                               {product}
     bool UseAdaptiveGenerationSizePolicyAtMajorCollection  = true                                {product}
     bool UseAdaptiveGenerationSizePolicyAtMinorCollection  = true                                {product}
     bool UseAdaptiveNUMAChunkSizing                = true                                {product}
     bool UseAdaptiveSizeDecayMajorGCCost           = true                                {product}
     bool UseAdaptiveSizePolicy                     = true                                {product}
     bool UseAdaptiveSizePolicyFootprintGoal        = true                                {product}
     bool UseAdaptiveSizePolicyWithSystemGC         = false                               {product}
     bool UseAddressNop                             = true                                {ARCH product}
     bool UseAltSigs                                = false                               {product}
     bool UseAutoGCSelectPolicy                     = false                               {product}
     bool UseBMI1Instructions                       = true                                {ARCH product}
     bool UseBMI2Instructions                       = true                                {ARCH product}
     bool UseBiasedLocking                          = true                                {product}
     bool UseBimorphicInlining                      = true                                {C2 product}
     bool UseBoundThreads                           = true                                {product}
     bool UseCLMUL                                  = true                                {ARCH product}
     bool UseCMSBestFit                             = true                                {product}
     bool UseCMSCollectionPassing                   = true                                {product}
     bool UseCMSCompactAtFullCollection             = true                                {product}
     bool UseCMSInitiatingOccupancyOnly             = false                               {product}
     bool UseCRC32Intrinsics                        = true                                {product}
     bool UseCodeCacheFlushing                      = true                                {product}
     bool UseCompiler                               = true                                {product}
     bool UseCompilerSafepoints                     = true                                {product}
     bool UseCompressedClassPointers               := true                                {lp64_product}
     bool UseCompressedOops                        := true                                {lp64_product}
     bool UseConcMarkSweepGC                        = false                               {product}
     bool UseCondCardMark                           = false                               {C2 product}
     bool UseContainerSupport                       = true                                {product}
     bool UseCountLeadingZerosInstruction           = true                                {ARCH product}
     bool UseCountTrailingZerosInstruction          = true                                {ARCH product}
     bool UseCountedLoopSafepoints                  = false                               {C2 product}
     bool UseCounterDecay                           = true                                {product}
     bool UseDivMod                                 = true                                {C2 product}
     bool UseDynamicNumberOfGCThreads               = false                               {product}
     bool UseFPUForSpilling                         = true                                {C2 product}
     bool UseFastAccessorMethods                    = false                               {product}
     bool UseFastEmptyMethods                       = false                               {product}
     bool UseFastJNIAccessors                       = true                                {product}
     bool UseFastStosb                              = true                                {ARCH product}
     bool UseG1GC                                   = false                               {product}
     bool UseGCLogFileRotation                      = false                               {product}
     bool UseGCOverheadLimit                        = true                                {product}
     bool UseGCTaskAffinity                         = false                               {product}
     bool UseHeavyMonitors                          = false                               {product}
     bool UseHugeTLBFS                              = false                               {product}
     bool UseInlineCaches                           = true                                {product}
     bool UseInterpreter                            = true                                {product}
     bool UseJumpTables                             = true                                {C2 product}
     bool UseLWPSynchronization                     = true                                {product}
     bool UseLargePages                             = false                               {pd product}
     bool UseLargePagesInMetaspace                  = false                               {product}
     bool UseLargePagesIndividualAllocation         = false                               {pd product}
     bool UseLinuxPosixThreadCPUClocks              = true                                {product}
     bool UseLockedTracing                          = false                               {product}
     bool UseLoopCounter                            = true                                {product}
     bool UseLoopInvariantCodeMotion                = true                                {C1 product}
     bool UseLoopPredicate                          = true                                {C2 product}
     bool UseMathExactIntrinsics                    = true                                {C2 product}
     bool UseMaximumCompactionOnSystemGC            = true                                {product}
     bool UseMembar                                 = false                               {pd product}
     bool UseMontgomeryMultiplyIntrinsic            = true                                {C2 product}
     bool UseMontgomerySquareIntrinsic              = true                                {C2 product}
     bool UseMulAddIntrinsic                        = true                                {C2 product}
     bool UseMultiplyToLenIntrinsic                 = true                                {C2 product}
     bool UseNUMA                                   = false                               {product}
     bool UseNUMAInterleaving                       = false                               {product}
     bool UseNewLongLShift                          = false                               {ARCH product}
     bool UseOSErrorReporting                       = false                               {pd product}
     bool UseOldInlining                            = true                                {C2 product}
     bool UseOnStackReplacement                     = true                                {pd product}
     bool UseOnlyInlinedBimorphic                   = true                                {C2 product}
     bool UseOprofile                               = false                               {product}
     bool UseOptoBiasInlining                       = true                                {C2 product}
     bool UsePSAdaptiveSurvivorSizePolicy           = true                                {product}
     bool UseParNewGC                               = false                               {product}
     bool UseParallelGC                             = false                               {product}
     bool UseParallelOldGC                          = false                               {product}
     bool UsePerfData                               = true                                {product}
     bool UsePopCountInstruction                    = true                                {product}
     bool UseRDPCForConstantTableBase               = false                               {C2 product}
     bool UseRTMDeopt                               = false                               {ARCH product}
     bool UseRTMLocking                             = false                               {ARCH product}
     bool UseSHA                                    = false                               {product}
     bool UseSHA1Intrinsics                         = false                               {product}
     bool UseSHA256Intrinsics                       = false                               {product}
     bool UseSHA512Intrinsics                       = false                               {product}
     bool UseSHM                                    = false                               {product}
     intx UseSSE                                    = 4                                   {product}
     bool UseSSE42Intrinsics                        = true                                {product}
     bool UseSerialGC                               = false                               {product}
     bool UseSharedSpaces                           = false                               {product}
     bool UseSignalChaining                         = true                                {product}
     bool UseSquareToLenIntrinsic                   = true                                {C2 product}
     bool UseStoreImmI16                            = false                               {ARCH product}
     bool UseStringDeduplication                    = false                               {product}
     bool UseSuperWord                              = true                                {C2 product}
     bool UseTLAB                                   = true                                {pd product}
     bool UseThreadPriorities                       = true                                {pd product}
     bool UseTransparentHugePages                   = false                               {product}
     bool UseTypeProfile                            = true                                {product}
     bool UseTypeSpeculation                        = true                                {C2 product}
     bool UseUnalignedLoadStores                    = true                                {ARCH product}
     bool UseVMInterruptibleIO                      = false                               {product}
     bool UseXMMForArrayCopy                        = true                                {product}
     bool UseXmmI2D                                 = false                               {ARCH product}
     bool UseXmmI2F                                 = false                               {ARCH product}
     bool UseXmmLoadAndClearUpper                   = true                                {ARCH product}
     bool UseXmmRegToRegMoveAll                     = true                                {ARCH product}
     bool VMThreadHintNoPreempt                     = false                               {product}
     intx VMThreadPriority                          = -1                                  {product}
     intx VMThreadStackSize                         = 1024                                {pd product}
     intx ValueMapInitialSize                       = 11                                  {C1 product}
     intx ValueMapMaxLoopSize                       = 8                                   {C1 product}
     intx ValueSearchLimit                          = 1000                                {C2 product}
     bool VerifyMergedCPBytecodes                   = true                                {product}
     bool VerifySharedSpaces                        = false                               {product}
     intx WorkAroundNPTLTimedWaitHang               = 1                                   {product}
    uintx YoungGenerationSizeIncrement              = 20                                  {product}
    uintx YoungGenerationSizeSupplement             = 80                                  {product}
    uintx YoungGenerationSizeSupplementDecay        = 8                                   {product}
    uintx YoungPLABSize                             = 4096                                {product}
     bool ZeroTLAB                                  = false                               {product}
     intx hashCode                                  = 5                                   {product}

"=“表示默认值
等号前加了冒号,”:="表示被用户或JVM修改后的值
值的单位是字节

2)启动项目时

即就是针对某个进程,将参数加上就行
例如:
在启动时指定
java -XX:+PrintFlagsFinal -jar gift-0.0.1-SNAPSHOT.jar
就是针对启动项目的这个进程的参数
这个项目默认是UseparallelGC这个参数是true 后面就变成:=true

java -XX:+PrintFlagsFinal -Xms30M -Xmx30M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./ -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=ip -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -jar demo-0.0.1-SNAPSHOT.jar

java -XX:+PrintFlagsFinal -XX:MetaspaceSize=32M -XX:MaxMetaspaceSize=32M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./ -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=ip -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -jar demo-0.0.1-SNAPSHOT.jar

3.修改JVM参数

1) 运行jar包时

通过命令行
java -jar -XX:+UseG1GC xxx.jar

2)配置文件

可以把jvm参数放到配置文件中
tomcat是放到catalina.sh
jmeter也可以把jvm参数放到对应的文件中

不管是通过命令,还是通过配置文件指定参数都是可以,若需要指定多个jvm参数中间用空格分割就行。

4.常用参数

可能会出现问题的区域:堆、虚拟机栈、方法区(metaspace)

1) 堆

属性后面的数值只是一个示意,需要根据实际情况配置.

4.1.1初始化堆大小(理解为最小)

-XX:InitialHeapSize=100M
-Xms100M

4. 1.2最大堆大小

-XX:MaxHeapSize=100M
-Xmx100M

4. 1.3年轻代最大大小

-XX:MaxNewSize=50M

4. 1.4设置老年代大小

-XX:OldSize=50M

4. 1.5新老生代的比值

-XX:NewRatio
默认2

两个S区和Eden区的比值
-XX:SurvivorRatio默认8

4. 1.6启动堆内存溢出自动dump(理解为把堆dump下来)

当发生oom错误时,一般会配置这个参数,把文件dump下来
-XX:+HeapDumpOnOutOfMemoryError

4. 1.7指定堆内存溢出dump目录

还可以设置dump后的位置

-XX:HeapDumpPath=heap.hprof
-XX:HeapDumpPath=./
java_pid1234.hprof

4. 1.8打印出GC日志

对jvm进行分析调优时,打印日志,对日志分析
-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:gc.log

4. 1.9提升年老代的最大临界值

-XX:MaxTenuringThreshold=16
默认值为 15
java -XX:+PrintFlagsFinal -version |grep MaxTenuringThreshold

改这种都是比较细腻的jvm调优
一般调优都是针对于影响比较大,比较常用的参数做调优。

2)栈

设置每个线程的堆栈大小
-Xss128k

3) Metaspace(相当于是非堆,用的是物理内存,不是用的jvm内存)

方法区大小需要着重关注,若 出现Metaspace溢出,基本就是方法区大小设置不合理

4.3.1设置方法区大小

-XX:MetaspaceSize=50M

4.3.2方法区最大大小

-XX:MaxMetaspaceSize=50M

4.3.3启用短指针(CCS)

启用短指针需加参数
-XX:+UseCompressedClassPointers

4.3.4CodeCache初始大小

-XX:InitialCodeCacheSize

5. 收集器相关

1)串行收集器

jdk1.8默认是ParallelGC收集器

开启:-XX:+UseSerialGC -XX:+UseSerialOldGC
-XX:+UseSerialGC,其实指定一个,也会适配去指定另一个收集器。
年轻代:-XX:+UseSerialGC
老年代 :-XX:+UseSerialOldGC

2)并行收集器(吞吐量优先)

这个是并行收集器,是多线程垃圾手机线程
开启:-XX:+UseParallelGC -XX:+UseParallelOldGC
-XX:+UseParallelGC
年轻代:-XX:+UseParallelGC ,年轻代,吞吐量优先
老年代:-XX:+UseParallelOldGC,老年代,吞吐量优先

可以设置并行GC线程数
-XX:ParallelGCThreads=n

3)并发【响应时间优先:两种方式】

CMS(老年代收集器),可以只加前面一段就ok:XX:+UseConcMarkSweepGC ,会适配一个UseParNewGC收集器,是serial的升级版本,即是多线程版本。
开启:XX:+UseConcMarkSweepGC -XX:+UseParNewGC
年轻代是-XX:+UseParNewGC
老年代是CMS : -XX:+UseConcMarkSweepGC老年代,停顿时间优先

其它
-XX:ConcGCThreads=n
并发垃圾收集器使用的线程数量,执行垃圾收集线程数多,效率会高,还可以设定一个值,可以达到fullgc
-XX:CMSInitiatingOccupancyFraction:触发FullGC
old区达到多少进行fgc,默认92%

G1
开启:-XX:+UseG1GC
同时作用于:新生代,老年代(停顿时间优先)

常用:
G1一般用户大堆,多核情况下,一般来说核数比较大,尽可能多一点,提示垃圾回收的效率。

-XX:G1HeapRegionSize=n,并发垃圾收集器使用的线程数量
-XX:MaxGCPauseMillis=200(可预测停顿时间的垃圾收集器)这里期望最大停顿时间,选择回收时满足这个停顿时间情况下,尽可能回收多一点垃圾。
region的大小:1-32M可以改大小(必须是2的n次方),最多2048个region

YoungGC,
触发全局并发标记周期比例InitiatingHeapOccupancyPercent默认是45
若这个堆的使用比例已经达到45,会触发全局并发标记(global concurrent marking)

mixedGC
触发mixedGC的参数(G1HeapWastePercent,默认触发是mixedgc5)
即就是可回收的百分比高于5就会触发mixedGC,低于5就不会触发,可以浪费5%
官网:https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/g1_gc_tuning.html#g1_gc_tuning
在这里插入图片描述

如果老年代的regin存活的对象如果超过85%不会回收(即就是不会放在seiset里)
除了有rembenr集合,还有seiset的集合(即就是清理的集合)

设置垃圾收集参数后也是可以查看,通过jinfo -flag
查看是否用G1
jinfo -flag UseG1GC PID
在这里插入图片描述
若看到:后是-号,就没有用相关收集器,+则用了相关收集器
在这里插入图片描述

可以看一下jmeter的
jmeter是java应用

jscone是jdk自带的,可以监控本地的,也可以监控远程的(需要配置远程监控的相关信息)

在这里插入图片描述

在这里插入图片描述

点击概要
可以看到jvm相关参数

-XX:+HeapDumpOnOutOfMemoryError 自动dump
-Xms1g -Xmx1g 最小堆内存最大内存设置的都是1g
-XX:MaxMetaspaceSize=256m 最大的方法区 256M
-XX:+UseG1GC 垃圾收集器用的是g1
-XX:MaxGCPauseMillis=100 停顿时间为100ms
-XX:G1ReservePercent=20 ,默认是10,Jmeter设置的是10,设置预留的百分比,可以减少竟升失败的(竟升:对象有一个从年轻代进入到老年代)
一般保持默认即可

在这里插入图片描述

点击概览
在这里插入图片描述

二、监控

1.命令

https://docs.oracle.com/javase/8/docs/technotes/tools/
在这里插入图片描述
常用工具: jconsole, jvisualvm

1)jps

jps -l

查看当前java进程
第一列为进程号
第二列就是看到完整路径,如果是类,会显示完整类名,包名都会显示。

在这里插入图片描述

jps -m 显示传递给main方法的参数

在这里插入图片描述

jps -v 显示输出jvm的参数
也可输jps -lv
也可jps -mlv

在这里插入图片描述

在这里插入图片描述

2) jinfo

设置垃圾收集参数后也是可以查看,通过jinfo -flag
查看是否用G1

jinfo -flag UseG1GC PID

在这里插入图片描述
若看到:后是-号,就没有用相关收集器,+则用了相关收集器
在这里插入图片描述

查看正在运行的jvm的参数值

jinfo pid

在这里插入图片描述
在这里插入图片描述

jinfo -flags pid

在这里插入图片描述

jinfo -flag 属性 pid

看状态
jinfo -flag UseConcMarkSweepGC pid
看数值
jinfo -flag MaxHeapSize pid
在这里插入图片描述

3)jstat(查看虚拟机运行的状态、垃圾收集相关信息)

jstat -gc

打印出的信息比较多,不太简洁
jstat -gc pid 只会打印一次
在这里插入图片描述
jstat -gc pid 1000 1s打印一次
在这里插入图片描述

第一行为c就表示总量,单位是kb,若为u表示使用量
s0表示存活区,s0c表示s0的总的大小,s1c表示的是s1的总的大小。
s0,s1大小相等,同一时刻的话就只会使用一个区域,采用了复制算法,牺牲一个区域的内存来换取规则的内存区域。
s0u表示的是s0的使用的量,只有一个区域有数据,s0有数据,即s1没有;s1有,s0没有。

E表示eden园区,EC表示eden园区总的大小,EU表示eden使用的大小。
E表示old,OC表示old区总的大小,OU表示old使用的大小。

M 表示metaspace,MC表示metaspace的大小,MU表示metaspace使用的大小。
metaspace使用的是物理内存,独立于jvm内存,把方法去逻辑归属于堆。

CCSC 压缩类总空间的大小,32位短指针存在, CCSU 表示 压缩类使用的大小量。

特别是要关注:
ou(即老年代ou使用了多少,OU快接近于oc,就会触发fgc,
Eu满了会触发Ygc,即就是把绝大部分的对象回收掉,再把放到存活区里。

不是一看到fgc多,就oom,是需要看增量。

统计信息:gc的次数,gc的耗时,
YGC 年轻代,eu快接近ec,触发ygc,次数都是累计,不是越多就有问题,而是需要看增量。
YGCT ygc的耗时,也是累加值,131/9=14.5,每次ygc是14.5ms左右
FGC FGC 累计次数
FGCT FGC 累计时间,每次fgc的时间= FGCT / FGC
GCT = FGCT + YGCT

jstat -gcutil

jstat -gcutil pid 1000
展示的是各参数百分比
在这里插入图片描述
jstat -gcutil pid 1000 5 (频率是1000ms,打印5次)
在这里插入图片描述

若fgc一直增加,并且old快接近于100%,需要去确认要么就是代码问题,要么设置是不合理(设置是不合理,可能设置的这个JVM参数都不能满足高tps的业务,一般情况下(jvm参数架构会做评估,及开发经验比较多的评估,会设置一个合理的值,我们测试再来进行压测是否有问题)

4)jmap(查看堆内存信息)

会显示用的收集器、一些参数的配置、各个区的情况
更多的是去关注的对象的统计、dump堆

jmap -heap pid
在这里插入图片描述

对象统计
jmap -histo pid
会将和进程有关的对象都打印出来,更关心的是前20或前30,因为oom,某一个对象有很多

在这里插入图片描述
jmap -histo pid | head -10
在这里插入图片描述
内存使用多时,可以哪个看哪个对象类型数量多,哪个字节数多
第一行是空行
第二行是表头
第三行是虚线
第四行是正式内容
要看公司包名相关栈信息,看对象有多少
第一列是排序,第二列是实例数,第三例是字节,第四列是包名+类名
[C表示字符数组 char[]
[B表示字节数组byte[]
[I表示整形数组int[]

dump出堆内存

Example: jmap -dump:live,format=b,file=heap.bin
jmap -dump:live,format=b,file=heap.bin 10874
b是二进制
live是存活对象
file指定是文件名
在这里插入图片描述
然后再用堆内存分析工具进行分析
一般配置都是当发生oom自动dump
还没触发oom,也可以拉取下来分析

2.可视化工具

1)jconsole

在jdk的bin目录下
在这里插入图片描述
概览展示了堆内存、线程、类、做gc的cpu占用率的使用情况
类的话是用完就会卸载
在这里插入图片描述

在这里插入图片描述

可以看堆中的eden、存活区,old区的使用情况

在这里插入图片描述
-XX:+HeapDumpOnOutOfMemoryError -Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:G1ReservePercent=20

远程连接配置
java -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=ip -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -jar demo-0.0.1-SNAPSHOT.jar

2) jvisualvm

jvisualvm其实就是jconsole的升级版
在这里插入图片描述
概览的时候可以看到jvm参数、和系统属性
在这里插入图片描述

在这里插入图片描述

抽样
本地可以做cpu的抽样
就是看哪些方法消耗的cpu多
在这里插入图片描述

这个mem就是和dump类似,看哪些对象消耗mem内存多
在这里插入图片描述

JVisualVM没有VisualGC的解决办法
点击工具–插件–可用插件–选择VisualGC–点击安装–下一步-安装–
在这里插入图片描述
重启
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
VisualGC插件安装失败的解决办法
在这里插入图片描述
VisualVM插件中心的地址是:https://visualvm.github.io/pluginscenters.html,用云服务器下载到插件。
连接阿里云服务器
curl https://visualvm.github.io/pluginscenters.html > plugin.html,获取到插件中心的地址
在这里插入图片描述
再打开 plugin.html
在这里插入图片描述
点击VisualVMhttps://visualvm.github.io/uc/release211/updates.xml.gz地址
在这里插入图片描述
再返回到插件除安装,即安装成功,再重启显示VisualGC
VisualGC会显示每个区域的情况(old、eden、存活区)、显示各个年龄的对象、显示编译时间、类的加载时间、GC的时间
在这里插入图片描述

3)grafana + prometheus

java -javaagent:/usr/local/jmx_exporter/jmx_prometheus_javaagent-0.12.0.jar=3010:/usr/local/jmx_exporter/jmx_exporter.yml -jar ~/test/demo-0.0.1-SNAPSHOT.jar

三、堆:分析、调优

1.问题定位

3.1.1堆的问题

堆溢出(堆gc耗时)
方法区溢出
定位:通过运行日志、堆快照、gc日志
若发生oom,就会有oom错误日志,gc日志工具
可以指定jvm参数在堆溢出时自动dump堆,作进一步分析
堆gc耗时,分析gc日志,用的工具

示例演示
1)oom:
A.命令
堆内存–java.lang.OutOfMemoryError:Java heap space
jmap -dump:live,format=b,file=heap.bin pid
根据业务,可能是堆不足,也可能是代码oom问题
方法区:java.lang.OutOfMemoryError
用jstat看不到,因为不是在堆内存
根据方法,可能是方法区不足,也可能是代码oom问题

老师演示的
ParallelGC
1.没有指定收集器,只需在启动时指定堆的大小(为了现象更快展示)
设置最大、最小堆内存
java -Xms32M -Xmx32M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./ -jar demo-0.0.1-SNAPSHOT.jar
http请求
查询相机信息
jmeter中的线程是5个线程,每10加载一个线程,ram-up50,持续时间110
放在压力机上跑jmeter -n -t test.jmx
开一个监控top
开始看日志
top按c看到java进程消耗的cpu多,若cpu高,就要看是哪个cpu高,看到us比较消耗的高,先看gc是否有问题,若gc没问题,需要看进程所对应的线程在做什么,即就是打栈。

先看gc是否有问题
jstat -gcutil pid ,看到老年代80%多,ygc每秒执行一次,ygc在增加93,
压力机执行的线程看到是180左右,
再看到老年代99了,增加了一次fgc,fgc增加频繁,ygc一直不增加保持在357
自动dump一个gc日志
jmap -dump:live,format=b,file=heap.bin pid
先把堆dump下来,一般用memoryAnalyzer分析
在这里插入图片描述
file-open heap -dump

在这里插入图片描述
Leak Suspects泄漏
就会猜测哪个泄漏

点overview
Lists number of instances per class 列出类的实例数
在这里插入图片描述
看公司业务代码包名
在这里插入图片描述
可进行搜索业务代码包名
在这里插入图片描述
第一轮显示类名,第二列显示创建对象的数量,第三例显示的是对象本身占用内存大小(不包含引用的),第四列包含引用大小总的大小。
根据第三例去看这个为什么会创建这么多象,是设置堆的大小有问题,还是代码有问题。
接着再看类的实例
点击右键–list objects–within coming references

显示具体的实例

在这里插入图片描述
在这里插入图片描述

也可按照工具提示的看
在这里插入图片描述

在这里插入图片描述

频繁的fgc,老年代快满了,但是对象还在引用,没法释放掉,可能就是两种情况:1是堆内存设置过小,2是代码有问题

发生oom,不一定是代码问题,结合业务量,业务量大,设置的堆内存就需要大一点。

GC日志:
除了oom问题,可能更多是要解决gc耗时,吞吐量不高问题,要分析gc日志。
java -XX:+PrintFlagsFinal -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:gc.log -Xms30M -Xmx30M -jar 0.0.1-SNAPSHOT.jar 没有指定收集器,默认使用ParallelGC

看gc日志的话用gcviewer-1.36-SNAPSHOT.jar工具看,分析gc日志的

主要看三种
1)ParallelGC
跑起来

2)CMS
-XX:+UseConcMarkSweepGC -XX:+UseParNewGC
java -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+PrintFlagsFinal -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:gc.log -Xms30M -Xmx30M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./ -jar demo-0.0.1-SNAPSHOT.jar
3)G1
-XX:+UseG1GC
java -XX:+UseG1GC -XX:+PrintFlagsFinal -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:gc.log -Xms30M -Xmx30M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./ -jar demo-0.0.1-SNAPSHOT.jar

日志分析
日志格式:ParallelGC,CMS,G1
分析工具

在这里插入图片描述
点击pause,可以看到最大最小停顿时间、以及停顿次数
在这里插入图片描述
点击memory
在这里插入图片描述

点击summary,显示吞吐量
在这里插入图片描述

在这里插入图片描述

若fullgc次数多,耗时多,若要对这个parallerGC这个优化器做优化,第一步先把内存调大。
用这个调大:java -XX:+PrintFlagsFinal -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:gc.log -Xms200M -Xmx200M -jar 0.0.1-SNAPSHOT.jar
吞吐量优先就先要提高吞吐量,停顿时间增加了,gc次数减少,fullgc次数减少

若是吞吐量收集器就要保证吞吐量,吞吐量达到了目标,就要去降低时间。
把堆调大,每一次gc停顿时间增加。

若用cms,就优先考虑停顿时间,尽可能降低停顿时间,尽量提高吞吐量。
java -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+PrintFlagsFinal -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:gc.log -Xms30M -Xmx30M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./ -jar demo-0.0.1-SNAPSHOT.jar
cms主要看老年代,年轻代用的是ParNewGC

g1也是要降低停顿时间,尽量满足在设置的停顿时间,去选择性进行回收(时间较短,重点关注吞吐量,提高吞吐量)
java -XX:+UseG1GC -XX:+PrintFlagsFinal -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:gc.log -Xms30M -Xmx30M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./ -jar demo-0.0.1-SNAPSHOT.jar

RS:remberset 记录谁引用了他
Cset就是要收集哪些:存放的是可以回收的regin集合,可以对这些regin回收效率做排序,优先回收能满足停顿时间的regin

gc日志其实就是放在gcviewer中分析,主要看停顿时间,吞吐量

并行收集器设置GC线程,可以设置更多的gc线程,执行更快,-XX:ParallelGCThreads=n
不能单调内存,gc线程小了,cpu核数多,时间也会耗费的多,考虑把线程调大。

并发就是cms,也有调线程,-XX:ConcGCThreads=n也涉及堆

g1可以调的地方多一点:
停顿时间较高,可以把目标停顿时间调低一点-XX:MaxGCPauseMillis=200,去看一下gc情况,线程数也可调-XX:ConcGCThreads=n
触发并发标记也可调(触发全局并发标记周期比例InitiatingHeapOccupancyPercent 默认45%,若次数多,可能很快就到达这个值,可以设置高一点)

若是响应时间优先,响应时间低,尽可能提高吞吐量;
若是吞吐量优先,先考虑吞吐量,尽可能提高停顿时间,
并行收集器

收集器都要考虑停顿时间,吞吐量、gc次数
gc次数过多,,要是又是吞吐量优先,停顿时间控制不好,会造成就是频繁停顿

内存分配:
非g1,比例,young与old是1;2,young使用多,可以把young调大,避免对象进入过多进入old,做fullgc,时间会更多,耗时多,考虑点。

调优参考:
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/g1_gc_tuning.html#g1_gc_tuning
在这里插入图片描述

https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/cms.html#concurrent_mark_sweep_cms_collector
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#gen_arrangement_parallel

3.1.2栈的问题

四、方法区:分析调优

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值