为什么要写一个jvm的工具入门呢,一是自己也不会,二是因为不会所以想学一下,还有就是这个确实很重要,对学习jvm有很多的用处,对定位问题有很大的便利,以前毕业那会我记得有个笔试,知道JAVA_HOME/bin目录的工具吗,例举下3个以上,并说说有什么用,可以怎么使用,,,,我只能说呵呵了,写代码哪里要注意这么多哈

一、基础了解

我们一般安装java,首先都会来一个java命令(现阶段java8和11用的人比较多,我这里还是8)

D:\Data\lugh1>java
用法: java [-options] class [args...]
(执行类)
或 java [-options] -jar jarfile [args...]
(执行 jar 文件)
其中选项包括:
-d32 使用 位数据模型 (如果可用)
-d64 使用 位数据模型 (如果可用)
-server 选择 "server" VM
默认 VM 是 server. -cp <目录和 zip/jar 文件的类搜索路径>
-classpath <目录和 zip/jar 文件的类搜索路径>
用 ; 分隔的目录, JAR 档案
和 ZIP 档案列表, 用于搜索类文件。
-D<名称>=<值>
设置系统属性
-verbose:[class|gc|jni]
启用详细输出
-version 输出产品版本并退出
-version:<值>
警告: 此功能已过时, 将在
未来发行版中删除。
需要指定的版本才能运行
-showversion 输出产品版本并继续
-jre-restrict-search | -no-jre-restrict-search
警告: 此功能已过时, 将在
未来发行版中删除。
在版本搜索中包括/排除用户专用 JRE
-? -help 输出此帮助消息
-X 输出非标准选项的帮助
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
按指定的粒度启用断言
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
禁用具有指定粒度的断言
-esa | -enablesystemassertions
启用系统断言
-dsa | -disablesystemassertions
禁用系统断言
-agentlib:<libname>[=<选项>]
加载本机代理库 <libname>, 例如 -agentlib:hprof
另请参阅 -agentlib:jdwp=help 和 -agentlib:hprof=help
-agentpath:<pathname>[=<选项>]
按完整路径名加载本机代理库
-javaagent:<jarpath>[=<选项>]
加载 Java 编程语言代理, 请参阅 java.lang.instrument
-splash:<imagepath>
使用指定的图像显示启动屏幕

参数分为三类,分别是:

标准参数(很稳定的) 

-help

-version

-X参数 (非标准参数,不能保证被所有的JVM实现都支持)

-Xint

-Xcomp

-XX参数(使用率较高)

-XX:newSize

-XX:+UseSerialGC

反正以前我是不知道-X,-XX,+UseSerialGC中的+号是什么,或许现在知道,好像也比较容易忘记,因为也没经常使用呀

来试一下java -X

D:\Data\lugh1>java -X
-Xmixed 混合模式执行 (默认)
-Xint 仅解释模式执行
-Xbootclasspath:<用 ; 分隔的目录和 zip/jar 文件>
设置搜索路径以引导类和资源
-Xbootclasspath/a:<用 ; 分隔的目录和 zip/jar 文件>
附加在引导类路径末尾
-Xbootclasspath/p:<用 ; 分隔的目录和 zip/jar 文件>
置于引导类路径之前
-Xdiag 显示附加诊断消息
-Xnoclassgc 禁用类垃圾收集
-Xincgc 启用增量垃圾收集
-Xloggc:<file> 将 GC 状态记录在文件中 (带时间戳)
-Xbatch 禁用后台编译
-Xms<size> 设置初始 Java 堆大小
-Xmx<size> 设置最大 Java 堆大小
-Xss<size> 设置 Java 线程堆栈大小
-Xprof 输出 cpu 配置文件数据
-Xfuture 启用最严格的检查, 预期将来的默认值
-Xrs 减少 Java/VM 对操作系统信号的使用 (请参阅文档)
-Xcheck:jni 对 JNI 函数执行其他检查
-Xshare:off 不尝试使用共享类数据
-Xshare:auto 在可能的情况下使用共享类数据 (默认)
-Xshare:on 要求使用共享类数据, 否则将失败。
-XshowSettings 显示所有设置并继续
-XshowSettings:all
显示所有设置并继续
-XshowSettings:vm 显示所有与 vm 相关的设置并继续
-XshowSettings:properties
显示所有属性设置并继续
-XshowSettings:locale
显示所有与区域设置相关的设置并继续

-Xms<size> 设置初始 Java 堆大小
-Xmx<size> 设置最大 Java 堆大小
-Xss<size> 设置 Java 线程堆栈大小

是不是觉得上面几个参数很熟悉,就是日常调整堆和栈大小的参数呀,很好记吧,比如java ‐Xms2048m ‐Xmx2048m  class_name

在解释模式(interpreted mode)下,-Xint标记会强制JVM执行所有的字节码,当然这会降低运行速度,通常低10倍或更多

-Xcomp参数与它(-Xint)正好相反,JVM在第一次使用时会把所有的字节码编译成本地代码,从而带来最大程度的优化。然而,很多应用在使用-Xcomp也会有一些性能损失,当然这比使用-Xint损失的少,原因是-xcomp没有让JVM启用JIT编译器的全部功能。JIT编译器可以对是否需要编译做判断,如果所有代码都进行编译的话,对于一些只执行一次的代码就没有意义了
-Xmixed是混合模式,将解释模式与编译模式进行混合使用,由jvm自己决定,这是jvm默认的模式,也是推荐使用的模式

接下来了解下-XX参数

-XX参数的使用有2种方式,一种是boolean类型,一种是非boolean类型(好像有点废话)

  • boolean类型
格式:-XX:[+-]
如:-XX:+DisableExplicitGC 表示禁用手动调用gc操作,也就是说调用System.gc()无效,+表示启用,-表示禁止吧

非boolean类型

格式:-XX:
如:-XX:NewRatio= 表示新生代和老年代的比值

那么多参数怎么记得呢,可以使用java -XX:+PrintFlagsFinal查看所有参数呀

D:\MyData\lugh1>java -XX:+PrintFlagsFinal
[Global flags]
intx ActiveProcessorCount = - {product}
uintx AdaptiveSizeDecrementScaleFactor = {product}
uintx AdaptiveSizeMajorGCDecayTimeScale = {product}
uintx AdaptiveSizePausePolicy = {product}
uintx AdaptiveSizePolicyCollectionCostMargin = {product}
uintx AdaptiveSizePolicyInitializingSteps = {product}
uintx AdaptiveSizePolicyOutputInterval = {product}
uintx AdaptiveSizePolicyWeight = {product}
uintx AdaptiveSizeThroughPutPolicy = {product}
uintx AdaptiveTimeWeight = {product}
bool AdjustConcurrency = false {product}
bool AggressiveHeap = false {product}
bool AggressiveOpts = false {product}
intx AliasLevel = {C2 product}
bool AlignVector = false {C2 product}
intx AllocateInstancePrefetchLines = {product}
intx AllocatePrefetchDistance = {product}
intx AllocatePrefetchInstr = {product}
intx AllocatePrefetchLines = {product}
intx AllocatePrefetchStepSize = {product}
intx AllocatePrefetchStyle = {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 = {C2 product}
uintx AutoGCSelectPauseMillis = {product}
intx BCEATraceLevel = {product}
intx BackEdgeThreshold = {pd product}
bool BackgroundCompilation = true {pd product}
uintx BaseFootPrintEstimate = {product}
intx BiasedLockingBulkRebiasThreshold = {product}
intx BiasedLockingBulkRevokeThreshold = {product}
intx BiasedLockingDecayTime = {product}
intx BiasedLockingStartupDelay = {product}
bool BindGCTaskThreadsToCPUs = false {product}
bool BlockLayoutByFrequency = true {C2 product}
intx BlockLayoutMinDiamondPercentage = {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 := {product}
bool CICompilerCountPerCPU = true {product}
bool CITime = false {product}
bool CMSAbortSemantics = false {product}
uintx CMSAbortablePrecleanMinWorkPerIteration = {product}
intx CMSAbortablePrecleanWaitMillis = {manageable}
uintx CMSBitMapYieldQuantum = {product}
uintx CMSBootstrapOccupancy = {product}
bool CMSClassUnloadingEnabled = true {product}
uintx CMSClassUnloadingMaxInterval = {product}
bool CMSCleanOnEnter = true {product}
bool CMSCompactWhenClearAllSoftRefs = true {product}
uintx CMSConcMarkMultiple = {product}
bool CMSConcurrentMTEnabled = true {product}
uintx CMSCoordinatorYieldSleepCount = {product}
bool CMSDumpAtPromotionFailure = false {product}
bool CMSEdenChunksRecordAlways = true {product}
uintx CMSExpAvgFactor = {product}
bool CMSExtrapolateSweep = false {product}
uintx CMSFullGCsBeforeCompaction = {product}
uintx CMSIncrementalDutyCycle = {product}
uintx CMSIncrementalDutyCycleMin = {product}
bool CMSIncrementalMode = false {product}
uintx CMSIncrementalOffset = {product}
bool CMSIncrementalPacing = true {product}
uintx CMSIncrementalSafetyFactor = {product}
uintx CMSIndexedFreeListReplenish = {product}
intx CMSInitiatingOccupancyFraction = - {product}
uintx CMSIsTooFullPercentage = {product}
double CMSLargeCoalSurplusPercent = 0.950000 {product}
double CMSLargeSplitSurplusPercent = 1.000000 {product}
bool CMSLoopWarn = false {product}
uintx CMSMaxAbortablePrecleanLoops = {product}
intx CMSMaxAbortablePrecleanTime = {product}
uintx CMSOldPLABMax = {product}
uintx CMSOldPLABMin = {product}
uintx CMSOldPLABNumRefills = {product}
uintx CMSOldPLABReactivityFactor = {product}
bool CMSOldPLABResizeQuicker = false {product}
uintx CMSOldPLABToleranceFactor = {product}
bool CMSPLABRecordAlways = true {product}
uintx CMSParPromoteBlocksToClaim = {product}
bool CMSParallelInitialMarkEnabled = true {product}
bool CMSParallelRemarkEnabled = true {product}
bool CMSParallelSurvivorRemarkEnabled = true {product}
uintx CMSPrecleanDenominator = {product}
uintx CMSPrecleanIter = {product}
uintx CMSPrecleanNumerator = {product}
bool CMSPrecleanRefLists1 = true {product}
bool CMSPrecleanRefLists2 = false {product}
bool CMSPrecleanSurvivors1 = false {product}
bool CMSPrecleanSurvivors2 = true {product}
uintx CMSPrecleanThreshold = {product}
bool CMSPrecleaningEnabled = true {product}
bool CMSPrintChunksInDump = false {product}
bool CMSPrintEdenSurvivorChunks = false {product}
bool CMSPrintObjectsInDump = false {product}
uintx CMSRemarkVerifyVariant = {product}
bool CMSReplenishIntermediate = true {product}
uintx CMSRescanMultiple = {product}
uintx CMSSamplingGrain = {product}
bool CMSScavengeBeforeRemark = false {product}
uintx CMSScheduleRemarkEdenPenetration = {product}
uintx CMSScheduleRemarkEdenSizeThreshold = {product}
uintx CMSScheduleRemarkSamplingRatio = {product}
double CMSSmallCoalSurplusPercent = 1.050000 {product}
double CMSSmallSplitSurplusPercent = 1.100000 {product}
bool CMSSplitIndexedFreeListBlocks = true {product}
intx CMSTriggerInterval = - {manageable}
uintx CMSTriggerRatio = {product}
intx CMSWaitDuration = {manageable}
uintx CMSWorkQueueDrainThreshold = {product}
bool CMSYield = true {product}
uintx CMSYieldSleepCount = {product}
uintx CMSYoungGenPerWorker = {pd product}
uintx CMS_FLSPadding = {product}
uintx CMS_FLSWeight = {product}
uintx CMS_SweepPadding = {product}
uintx CMS_SweepTimerThresholdMillis = {product}
uintx CMS_SweepWeight = {product}
bool CheckEndorsedAndExtDirs = false {product}
bool CheckJNICalls = false {product}
bool ClassUnloading = true {product}
bool ClassUnloadingWithConcurrentMark = true {product}
intx ClearFPUAtPark = {product}
bool ClipInlining = true {product}
uintx CodeCacheExpansionSize = {pd product}
uintx CodeCacheMinimumFreeSpace = {product}
bool CollectGen0First = false {product}
bool CompactFields = true {product}
intx CompilationPolicyChoice = {product}
ccstrlist CompileCommand = {product}
ccstr CompileCommandFile = {product}
ccstrlist CompileOnly = {product}
intx CompileThreshold = {pd product}
bool CompilerThreadHintNoPreempt = true {product}
intx CompilerThreadPriority = - {product}
intx CompilerThreadStackSize = {pd product}
uintx CompressedClassSpaceSize = {product}
uintx ConcGCThreads = {product}
intx ConditionalMoveLimit = {C2 pd product}
intx ContendedPaddingWidth = {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 = {product}
intx DefaultThreadPriority = - {product}
intx DeferPollingPageLoopCount = - {product}
intx DeferThrSuspendLoopCount = {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 = {C2 product}
bool EliminateAllocations = true {C2 product}
bool EliminateAutoBox = true {C2 product}
bool EliminateLocks = true {C2 product}
bool EliminateNestedLocks = true {C2 product}
intx EmitSync = {product}
bool EnableContended = true {product}
bool EnableResourceManagementTLABCache = true {product}
bool EnableSharedLookupCache = true {product}
bool EnableTracing = false {product}
uintx ErgoHeapSizeLimit = {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 = {product}
double FLSLargestBlockCoalesceProximity = 0.990000 {product}
bool FailOverToOldVerifier = true {product}
bool FastTLABRefill = true {product}
intx FenceInstruction = {ARCH product}
intx FieldsAllocationStyle = {product}
bool FilterSpuriousWakeups = true {product}
ccstr FlightRecorderOptions = {product}
bool ForceNUMA = false {product}
bool ForceTimeHighResolution = false {product}
intx FreqInlineSize = {pd product}
double G1ConcMarkStepDurationMillis = 10.000000 {product}
uintx G1ConcRSHotCardLimit = {product}
uintx G1ConcRSLogCacheSize = {product}
intx G1ConcRefinementGreenZone = {product}
intx G1ConcRefinementRedZone = {product}
intx G1ConcRefinementServiceIntervalMillis = {product}
uintx G1ConcRefinementThreads = {product}
intx G1ConcRefinementThresholdStep = {product}
intx G1ConcRefinementYellowZone = {product}
uintx G1ConfidencePercent = {product}
uintx G1HeapRegionSize = {product}
uintx G1HeapWastePercent = {product}
uintx G1MixedGCCountTarget = {product}
intx G1RSetRegionEntries = {product}
uintx G1RSetScanBlockSize = {product}
intx G1RSetSparseRegionEntries = {product}
intx G1RSetUpdatingPauseTimePercent = {product}
intx G1RefProcDrainInterval = {product}
uintx G1ReservePercent = {product}
uintx G1SATBBufferEnqueueingThresholdPercent = {product}
intx G1SATBBufferSize = {product}
intx G1UpdateBufferSize = {product}
bool G1UseAdaptiveConcRefinement = true {product}
uintx GCDrainStackTargetSize = {product}
uintx GCHeapFreeLimit = {product}
uintx GCLockerEdenExpansionPercent = {product}
bool GCLockerInvokesConcurrent = false {product}
uintx GCLogFileSize = {product}
uintx GCPauseIntervalMillis = {product}
uintx GCTaskTimeStampEntries = {product}
uintx GCTimeLimit = {product}
uintx GCTimeRatio = {product}
uintx HeapBaseMinAddress = {pd product}
bool HeapDumpAfterFullGC = false {manageable}
bool HeapDumpBeforeFullGC = false {manageable}
bool HeapDumpOnOutOfMemoryError = false {manageable}
ccstr HeapDumpPath = {manageable}
uintx HeapFirstMaximumCompactionCount = {product}
uintx HeapMaximumCompactionInterval = {product}
uintx HeapSizePerGCThread = {product}
bool IgnoreEmptyClassPaths = false {product}
bool IgnoreUnrecognizedVMOptions = false {product}
uintx IncreaseFirstTierCompileThresholdAt = {product}
bool IncrementalInline = true {C2 product}
uintx InitialBootClassLoaderMetaspaceSize = {product}
uintx InitialCodeCacheSize = {pd product}
uintx InitialHeapSize := {product}
uintx InitialRAMFraction = {product}
double InitialRAMPercentage = 1.562500 {product}
uintx InitialSurvivorRatio = {product}
uintx InitialTenuringThreshold = {product}
uintx InitiatingHeapOccupancyPercent = {product}
bool Inline = true {product}
ccstr InlineDataFile = {product}
intx InlineSmallCode = {pd product}
bool InlineSynchronizedMethods = true {C1 product}
bool InsertMemBarAfterArraycopy = true {C2 product}
intx InteriorEntryAlignment = {C2 pd product}
intx InterpreterProfilePercentage = {product}
bool JNIDetachReleasesMonitors = true {product}
bool JavaMonitorsInStackTrace = true {product}
intx JavaPriority10_To_OSPriority = - {product}
intx JavaPriority1_To_OSPriority = - {product}
intx JavaPriority2_To_OSPriority = - {product}
intx JavaPriority3_To_OSPriority = - {product}
intx JavaPriority4_To_OSPriority = - {product}
intx JavaPriority5_To_OSPriority = - {product}
intx JavaPriority6_To_OSPriority = - {product}
intx JavaPriority7_To_OSPriority = - {product}
intx JavaPriority8_To_OSPriority = - {product}
intx JavaPriority9_To_OSPriority = - {product}
bool LIRFillDelaySlots = false {C1 pd product}
uintx LargePageHeapSizeThreshold = {product}
uintx LargePageSizeInBytes = {product}
bool LazyBootClassLoader = true {product}
intx LiveNodeCountInliningCutoff = {C2 product}
bool LogCommercialFeatures = false {product}
intx LoopMaxUnroll = {C2 product}
intx LoopOptsCount = {C2 product}
intx LoopUnrollLimit = {C2 pd product}
intx LoopUnrollMin = {C2 product}
bool LoopUnswitching = true {C2 product}
bool ManagementServer = false {product}
uintx MarkStackSize = {product}
uintx MarkStackSizeMax = {product}
uintx MarkSweepAlwaysCompactCount = {product}
uintx MarkSweepDeadRatio = {product}
intx MaxBCEAEstimateLevel = {product}
intx MaxBCEAEstimateSize = {product}
uintx MaxDirectMemorySize = {product}
bool MaxFDLimit = true {product}
uintx MaxGCMinorPauseMillis = {product}
uintx MaxGCPauseMillis = {product}
uintx MaxHeapFreeRatio = {manageable}
uintx MaxHeapSize := {product}
intx MaxInlineLevel = {product}
intx MaxInlineSize = {product}
intx MaxJNILocalCapacity = {product}
intx MaxJavaStackTraceDepth = {product}
intx MaxJumpTableSize = {C2 product}
intx MaxJumpTableSparseness = {C2 product}
intx MaxLabelRootDepth = {C2 product}
intx MaxLoopPad = {C2 product}
uintx MaxMetaspaceExpansion = {product}
uintx MaxMetaspaceFreeRatio = {product}
uintx MaxMetaspaceSize = {product}
uintx MaxNewSize := {product}
intx MaxNodeLimit = {C2 product}
uint64_t MaxRAM = {pd product}
uintx MaxRAMFraction = {product}
double MaxRAMPercentage = 25.000000 {product}
intx MaxRecursiveInlineLevel = {product}
uintx MaxTenuringThreshold = {product}
intx MaxTrivialSize = {product}
intx MaxVectorSize = {C2 product}
uintx MetaspaceSize = {pd product}
bool MethodFlushing = true {product}
uintx MinHeapDeltaBytes := {product}
uintx MinHeapFreeRatio = {manageable}
intx MinInliningThreshold = {product}
intx MinJumpTableSize = {C2 pd product}
uintx MinMetaspaceExpansion = {product}
uintx MinMetaspaceFreeRatio = {product}
uintx MinRAMFraction = {product}
double MinRAMPercentage = 50.000000 {product}
uintx MinSurvivorRatio = {product}
uintx MinTLABSize = {product}
intx MonitorBound = {product}
bool MonitorInUseLists = false {product}
intx MultiArrayExpandLimit = {C2 product}
bool MustCallLoadClassInternal = false {product}
uintx NUMAChunkResizeWeight = {product}
uintx NUMAInterleaveGranularity = {product}
uintx NUMAPageScanRate = {product}
uintx NUMASpaceResizeRate = {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 = {product}
uintx NewSize := {product}
uintx NewSizeThreadIncrease = {pd product}
intx NmethodSweepActivity = {product}
intx NmethodSweepCheckInterval = {product}
intx NmethodSweepFraction = {product}
intx NodeLimitFudgeFactor = {C2 product}
uintx NumberOfGCLogFiles = {product}
intx NumberOfLoopInstrToAlign = {C2 product}
intx ObjectAlignmentInBytes = {lp64_product}
uintx OldPLABSize = {product}
uintx OldPLABWeight = {product}
uintx OldSize := {product}
bool OmitStackTraceInFastThrow = true {product}
ccstrlist OnError = {product}
ccstrlist OnOutOfMemoryError = {product}
intx OnStackReplacePercentage = {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 = {pd product}
bool OptoScheduling = false {C2 pd product}
uintx PLABWeight = {product}
bool PSChunkLargeArrays = true {product}
intx ParGCArrayScanChunk = {product}
uintx ParGCDesiredObjsFromOverflowList = {product}
bool ParGCTrimOverflow = true {product}
bool ParGCUseLocalOverflow = false {product}
uintx ParallelGCBufferWastePct = {product}
uintx ParallelGCThreads = {product}
bool ParallelGCVerbose = false {product}
uintx ParallelOldDeadWoodLimiterMean = {product}
uintx ParallelOldDeadWoodLimiterStdDev = {product}
bool ParallelRefProcBalancingEnabled = true {product}
bool ParallelRefProcEnabled = false {product}
bool PartialPeelAtUnsignedTests = true {C2 product}
bool PartialPeelLoop = true {C2 product}
intx PartialPeelNewPhiDelta = {C2 product}
uintx PausePadding = {product}
intx PerBytecodeRecompilationCutoff = {product}
intx PerBytecodeTrapLimit = {product}
intx PerMethodRecompilationCutoff = {product}
intx PerMethodTrapLimit = {product}
bool PerfAllowAtExitRegistration = false {product}
bool PerfBypassFileSystemCheck = false {product}
intx PerfDataMemorySize = {product}
intx PerfDataSamplingInterval = {product}
ccstr PerfDataSaveFile = {product}
bool PerfDataSaveToFile = false {product}
bool PerfDisableSharedMem = false {product}
intx PerfMaxStringConstLength = {product}
intx PreInflateSpin = {pd product}
bool PreferInterpreterNativeStubs = false {pd product}
intx PrefetchCopyIntervalInBytes = {product}
intx PrefetchFieldsAhead = {product}
intx PrefetchScanIntervalInBytes = {product}
bool PreserveAllAnnotations = false {product}
bool PreserveFramePointer = false {pd product}
uintx PretenureSizeThreshold = {product}
bool PrintAdaptiveSizePolicy = false {product}
bool PrintCMSInitiationStatistics = false {product}
intx PrintCMSStatistics = {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 = {product}
intx PrintFLSStatistics = {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 = {product}
intx PrintSafepointStatisticsTimeout = - {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 = {product}
bool ProfileInterpreter = true {pd product}
bool ProfileIntervals = false {product}
intx ProfileIntervalsTicks = {product}
intx ProfileMaturityPercentage = {product}
bool ProfileVM = false {product}
bool ProfilerPrintByteCodeStatistics = false {product}
bool ProfilerRecordPC = false {product}
uintx PromotedPadding = {product}
uintx QueuedAllocationWarningCount = {product}
uintx RTMRetryCount = {ARCH product}
bool RangeCheckElimination = true {product}
intx ReadPrefetchInstr = {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 = {product}
bool ReflectionWrapResolutionErrors = true {product}
bool RegisterFinalizersAtInit = true {product}
bool RelaxAccessControlCheck = false {product}
ccstr ReplayDataFile = {product}
bool RequireSharedSpaces = false {product}
uintx ReservedCodeCacheSize = {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 = {C1 pd product}
intx SafepointSpinBeforeYield = {product}
bool SafepointTimeout = false {product}
intx SafepointTimeoutDelay = {product}
bool ScavengeBeforeFullGC = true {product}
intx SelfDestructTimer = {product}
uintx SharedBaseAddress = {product}
ccstr SharedClassListFile = {product}
uintx SharedMiscCodeSize = {product}
uintx SharedMiscDataSize = {product}
uintx SharedReadOnlySize = {product}
uintx SharedReadWriteSize = {product}
bool ShowMessageBoxOnError = false {product}
intx SoftRefLRUPolicyMSPerMB = {product}
bool SpecialEncodeISOArray = true {C2 product}
bool SplitIfBlocks = true {C2 product}
intx StackRedPages = {pd product}
intx StackShadowPages = {pd product}
bool StackTraceInThrowable = true {product}
intx StackYellowPages = {pd product}
bool StartAttachListener = false {product}
intx StarvationMonitorInterval = {product}
bool StressLdcRewrite = false {product}
uintx StringDeduplicationAgeThreshold = {product}
uintx StringTableSize = {product}
bool SuppressFatalErrorMessage = false {product}
uintx SurvivorPadding = {product}
uintx SurvivorRatio = {product}
intx SuspendRetryCount = {product}
intx SuspendRetryDelay = {product}
intx SyncFlags = {product}
ccstr SyncKnobs = {product}
intx SyncVerbose = {product}
uintx TLABAllocationWeight = {product}
uintx TLABRefillWasteFraction = {product}
uintx TLABSize = {product}
bool TLABStats = true {product}
uintx TLABWasteIncrement = {product}
uintx TLABWasteTargetPercent = {product}
uintx TargetPLABWastePct = {product}
uintx TargetSurvivorRatio = {product}
uintx TenuredGenerationSizeIncrement = {product}
uintx TenuredGenerationSizeSupplement = {product}
uintx TenuredGenerationSizeSupplementDecay = {product}
intx ThreadPriorityPolicy = {product}
bool ThreadPriorityVerbose = false {product}
uintx ThreadSafetyMargin = {product}
intx ThreadStackSize = {pd product}
uintx ThresholdTolerance = {product}
intx Tier0BackedgeNotifyFreqLog = {product}
intx Tier0InvokeNotifyFreqLog = {product}
intx Tier0ProfilingStartPercentage = {product}
intx Tier23InlineeNotifyFreqLog = {product}
intx Tier2BackEdgeThreshold = {product}
intx Tier2BackedgeNotifyFreqLog = {product}
intx Tier2CompileThreshold = {product}
intx Tier2InvokeNotifyFreqLog = {product}
intx Tier3BackEdgeThreshold = {product}
intx Tier3BackedgeNotifyFreqLog = {product}
intx Tier3CompileThreshold = {product}
intx Tier3DelayOff = {product}
intx Tier3DelayOn = {product}
intx Tier3InvocationThreshold = {product}
intx Tier3InvokeNotifyFreqLog = {product}
intx Tier3LoadFeedback = {product}
intx Tier3MinInvocationThreshold = {product}
intx Tier4BackEdgeThreshold = {product}
intx Tier4CompileThreshold = {product}
intx Tier4InvocationThreshold = {product}
intx Tier4LoadFeedback = {product}
intx Tier4MinInvocationThreshold = {product}
bool TieredCompilation = true {pd product}
intx TieredCompileTaskTimeout = {product}
intx TieredRateUpdateMaxTime = {product}
intx TieredRateUpdateMinTime = {product}
intx TieredStopAtLevel = {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 = {product}
bool TraceSafepointCleanupTime = false {product}
bool TraceSharedLookupCache = false {product}
bool TraceSuspendWaitFailures = false {product}
intx TrackedInitializationLimit = {C2 product}
bool TransmitErrorReport = false {product}
bool TrapBasedNullChecks = false {pd product}
bool TrapBasedRangeChecks = false {C2 pd product}
intx TypeProfileArgsLimit = {product}
uintx TypeProfileLevel = {pd product}
intx TypeProfileMajorReceiverPercent = {C2 product}
intx TypeProfileParmsLimit = {product}
intx TypeProfileWidth = {product}
intx UnguardOnExecutionViolation = {product}
bool UnlinkSymbolsALot = false {product}
bool Use486InstrsOnly = false {ARCH product}
bool UseAES = true {product}
bool UseAESIntrinsics = true {product}
intx UseAVX = {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 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 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 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 UseOptoBiasInlining = true {C2 product}
bool UsePSAdaptiveSurvivorSizePolicy = true {product}
bool UseParNewGC = false {product}
bool UseParallelGC := true {product}
bool UseParallelOldGC = true {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}
intx UseSSE = {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 UseTypeProfile = true {product}
bool UseTypeSpeculation = true {C2 product}
bool UseUTCFileTimestamp = true {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 = - {product}
intx VMThreadStackSize = {pd product}
intx ValueMapInitialSize = {C1 product}
intx ValueMapMaxLoopSize = {C1 product}
intx ValueSearchLimit = {C2 product}
bool VerifyMergedCPBytecodes = true {product}
bool VerifySharedSpaces = false {product}
intx WorkAroundNPTLTimedWaitHang = {product}
uintx YoungGenerationSizeIncrement = {product}
uintx YoungGenerationSizeSupplement = {product}
uintx YoungGenerationSizeSupplementDecay = {product}
uintx YoungPLABSize = {product}
bool ZeroTLAB = false {product}
intx hashCode = {product}
用法: java [-options] class [args...]
(执行类)
或 java [-options] -jar jarfile [args...]
(执行 jar 文件)
其中选项包括:
-d32 使用 位数据模型 (如果可用)
-d64 使用 位数据模型 (如果可用)
-server 选择 "server" VM
默认 VM 是 server. -cp <目录和 zip/jar 文件的类搜索路径>
-classpath <目录和 zip/jar 文件的类搜索路径>
用 ; 分隔的目录, JAR 档案
和 ZIP 档案列表, 用于搜索类文件。
-D<名称>=<值>
设置系统属性
-verbose:[class|gc|jni]
启用详细输出
-version 输出产品版本并退出
-version:<值>
警告: 此功能已过时, 将在
未来发行版中删除。
需要指定的版本才能运行
-showversion 输出产品版本并继续
-jre-restrict-search | -no-jre-restrict-search
警告: 此功能已过时, 将在
未来发行版中删除。
在版本搜索中包括/排除用户专用 JRE
-? -help 输出此帮助消息
-X 输出非标准选项的帮助
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
按指定的粒度启用断言
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
禁用具有指定粒度的断言
-esa | -enablesystemassertions
启用系统断言
-dsa | -disablesystemassertions
禁用系统断言
-agentlib:<libname>[=<选项>]
加载本机代理库 <libname>, 例如 -agentlib:hprof
另请参阅 -agentlib:jdwp=help 和 -agentlib:hprof=help
-agentpath:<pathname>[=<选项>]
按完整路径名加载本机代理库
-javaagent:<jarpath>[=<选项>]
加载 Java 编程语言代理, 请参阅 java.lang.instrument
-splash:<imagepath>
使用指定的图像显示启动屏幕
有关详细信息, 请参阅 http://www.oracle.com/technetwork/java/javase/documentation/index.html。

上面的参数中有等号(=和:=),分别代表的是默认值,和被修改的值啦

好了,基础够基础了吧,以后这些加(+)减(-)等于(=或:=)看的懂了

二、基础工具

$JAVA_HOME/bin目录下真的有很多的工具,这里不截图啦,直接上用的比较的工具好啦

2.1、jps

这个工具真的很实用,而且很简单呢,功能linux的ps命令类似:可以列出正在运行的虚拟机进程,并显示虚拟机执行主类(Main Class,main()函数所在的类)名称以及这些进程的本地虚拟机唯一ID(LVMID,Local Virtual Machine Identifier)

[root@hadoop apache-tomcat-8.5.]# jps -help
usage: jps [-help]
jps [-q] [-mlvV] [<hostid>] Definitions:
<hostid>: <hostname>[:<port>]
-l : 输出主类全名或jar路径
-q : 只输出LVMID
-m : 输出JVM启动时传递给main()的参数
-v : 输出JVM启动时显示指定的JVM参数

2.2、jstat

jstat(JVM Statistics Monitoring Tool)是用于监视虚拟机各种运行状态信息的命令行工具。它可以显示本地或者远程[插图]虚拟机进程中的类加载、内存、垃圾收集、即时编译等运行时数据。

[root@hadoop apache-tomcat-8.5.]# jstat -help
Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]] Definitions:
<option> An option reported by the -options option
<vmid> Virtual Machine Identifier. A vmid takes the following form:
<lvmid>[@<hostname>[:<port>]]
Where <lvmid> is the local vm identifier for the target
Java virtual machine, typically a process id; <hostname> is
the name of the host running the target Java virtual machine;
and <port> is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.
<lines> Number of samples between header lines.
<interval> Sampling interval. The following forms are allowed:
<n>["ms"|"s"]
Where <n> is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
<count> Number of samples to take before terminating.
-J<flag> Pass <flag> directly to the runtime system.

jstat -options #查看下支持的选项,如下

[root@hadoop apache-tomcat-8.5.]# jstat -options
-class #类加载器
-compiler #JIT
-gc #GC堆状态
-gccapacity #各个区的大小
-gccause #最近一次GC的统计和原因
-gcmetacapacity #元空间大小
-gcnew #新区统计
-gcnewcapacity #新区大小
-gcold #老区统计
-gcoldcapacity #老区大小
-gcutil #GC汇总统计
-printcompilation #HotSpot编译统计
Options #选项,我们一般使用 -gcutil 查看gc情况
vmid #VM的进程号,即当前运行的java进程号,可以理解我java程序的pid
interval #间隔时间,单位为秒或者毫秒
count #打印次数,如果缺省则打印无数次

对于命令格式中的VMID与LVMID需要特别说明一下:如果是本地虚拟机进程,VMID与LVMID是一致的;如果是远程虚拟机进程,那VMID的格式应当是

[protocol:][//]lvmid[@hostname][:port]/servername]

开始操作:

jstat -class 1645  #类加载的统计

Loaded:加载class的数量
Bytes:所占用空间大小
Unloaded:未加载数量
Bytes:未加载占用空间
Time:时间

jstat -gc 1645  1 3 #统计3次,每隔一秒,对gc进行统计

S0C:第一个Survivor区的大小(KB)
S1C:第二个Survivor区的大小(KB)
S0U:第一个Survivor区的使用大小(KB)
S1U:第二个Survivor区的使用大小(KB)
EC:Eden区的大小(KB)
EU:Eden区的使用大小(KB)
OC:Old区大小(KB)
OU:Old使用大小(KB)
MC:方法区大小(KB),java8方法区的实现是元数据空间,java7的方法区实现是永久代
MU:方法区使用大小(KB)
CCSC:压缩类空间大小(KB)
CCSU:压缩类空间使用大小(KB)
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间

jstat -compiler 1645 #对编译进行统计

Compiled:编译数量。
Failed:失败数量
Invalid:不可用数量
Time:时间
FailedType:失败类型
FailedMethod:失败的方法

2.3、jinfo

jinfo(Configuration Info for Java)的作用是实时查看和调整虚拟机各项参数

[root@hadoop ~]# jinfo -help
Usage:
jinfo [option] <pid>
(to connect to running process)
jinfo [option] <executable <core>
(to connect to a core file)
jinfo [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server) where <option> is one of:
-flag <name> to print the value of the named VM flag #打印单个jvm的参数
-flag [+|-]<name> to enable or disable the named VM flag #运行期修改一部分运行期可写的虚拟机参数值
-flag <name>=<value> to set the named VM flag to the given value #运行期修改一部分运行期可写的虚拟机参数值
-flags to print VM flags #打印该进程的相关的参数
-sysprops to print Java system properties #把虚拟机进程的System.getProperties()的内容打印出来
<no option> to print both of the above
-h | -help to print this help message

jinfo -flags  1645

jinfo -flag InitialHeapSize  1645

jinfo -flag InitialHeapSize  1645

[root@hadoop ~]# jinfo -sysprops
Attaching to process ID , please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.181-b13
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.181-b13
sun.boot.library.path = /home/hadoop/jdk/jre/lib/amd64
java.protocol.handler.pkgs = org.apache.catalina.webresources
shared.loader =
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) -Bit Server VM
java.util.logging.config.file = /root/apache-tomcat-8.5./conf/logging.properties
tomcat.util.buf.StringCache.byte.enabled = true
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = US
tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-taglib*.jar,log4j-web*.jar,log4javascript*.jar,slf4j-taglib*.jar
user.dir = /root/apache-tomcat-8.5.
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.8.0_181-b13
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /home/hadoop/jdk/jre/lib/endorsed
line.separator = java.io.tmpdir = /root/apache-tomcat-8.5./temp
java.vm.specification.vendor = Oracle Corporation
java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
java.naming.factory.url.pkgs = org.apache.naming
os.name = Linux
org.apache.catalina.security.SecurityListener.UMASK =
sun.jnu.encoding = UTF-
ignore.endorsed.dirs =
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.class.version = 52.0
java.specification.name = Java Platform API Specification
sun.management.compiler = HotSpot -Bit Tiered Compilers
os.version = 2.6.-754.24..el6.x86_64
java.util.concurrent.ForkJoinPool.common.threadFactory = org.apache.catalina.startup.SafeForkJoinWorkerThreadFactory
user.home = /root
user.timezone = Asia/Chongqing
catalina.useNaming = true
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-
java.specification.version = 1.8
tomcat.util.scan.StandardJarScanFilter.jarsToSkip = annotations-api.jar,ant-junit*.jar,ant-launcher.jar,ant.jar,asm-*.jar,aspectj*.jar,bootstrap.jar,catalina-ant.jar,catalina-ha.jar,catalina-jmx-remote.jar,catalina-storeconfig.jar,catalina-tribes.jar,catalina-ws.jar,catalina.jar,cglib-*.jar,cobertura-*.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,commons-daemon.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,dom4j-*.jar,easymock-*.jar,ecj-*.jar,el-api.jar,geronimo-spec-jaxrpc*.jar,h2*.jar,hamcrest-*.jar,hibernate*.jar,httpclient*.jar,icu4j-*.jar,jasper-el.jar,jasper.jar,jaspic-api.jar,jaxb-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,jmx-tools.jar,jmx.jar,jsp-api.jar,jstl.jar,jta*.jar,junit-*.jar,junit.jar,log4j*.jar,mail*.jar,objenesis-*.jar,oraclepki.jar,oro-*.jar,servlet-api-*.jar,servlet-api.jar,slf4j*.jar,taglibs-standard-spec-*.jar,tagsoup-*.jar,tomcat-api.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-i18n-*.jar,tomcat-jdbc.jar,tomcat-jni.jar,tomcat-juli-adapters.jar,tomcat-juli.jar,tomcat-util-scan.jar,tomcat-util.jar,tomcat-websocket.jar,tools.jar,websocket-api.jar,wsdl4j*.jar,xercesImpl.jar,xml-apis.jar,xmlParserAPIs-*.jar,xmlParserAPIs.jar,xom-*.jar
catalina.home = /root/apache-tomcat-8.5.
user.name = root
java.class.path = /root/apache-tomcat-8.5./bin/bootstrap.jar:/root/apache-tomcat-8.5./bin/tomcat-juli.jar
java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
java.vm.specification.version = 1.8
sun.arch.data.model =
sun.java.command = org.apache.catalina.startup.Bootstrap start
java.home = /home/hadoop/jdk/jre
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
java.vm.info = mixed mode
java.version = 1.8.0_181
java.ext.dirs = /home/hadoop/jdk/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /home/hadoop/jdk/jre/lib/resources.jar:/home/hadoop/jdk/jre/lib/rt.jar:/home/hadoop/jdk/jre/lib/sunrsasign.jar:/home/hadoop/jdk/jre/lib/jsse.jar:/home/hadoop/jdk/jre/lib/jce.jar:/home/hadoop/jdk/jre/lib/charsets.jar:/home/hadoop/jdk/jre/lib/jfr.jar:/home/hadoop/jdk/jre/classes
server.loader =
java.vendor = Oracle Corporation
catalina.base = /root/apache-tomcat-8.5.
jdk.tls.ephemeralDHKeySize =
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
common.loader = "${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat.
sun.cpu.isalist =

2.4、jmap

jmap(Memory Map for Java)命令用于生成堆转储快照(一般称为heapdump或dump文件),还可以使用“暴力”方式:-XX:+HeapDumpOnOutOfMemoryError参数,可以让虚拟机在内存溢出异常出现之后自动生成堆转储快照文件

jmap的作用并不仅仅是为了获取堆转储快照,它还可以查询finalize执行队列、Java堆和方法区的详细信息,如空间使用率、当前用的是哪种收集器等

[root@hadoop ~]# jmap -help
Usage:
jmap [option] <pid>
(to connect to running process)
jmap [option] <executable <core>
(to connect to a core file)
jmap [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server) where <option> is one of:
<none> to print same info as Solaris pmap
-heap to print java heap summary #统计堆
-histo[:live] to print histogram of java object heap; if the "live"
suboption is specified, only count live objects
-clstats to print class loader statistics
-finalizerinfo to print information on objects awaiting finalization
-dump:<dump-options> to dump java heap in hprof binary format #dump出java堆的二进制文件
dump-options:
live dump only live objects; if not specified,
all objects in the heap are dumped.
format=b binary format
file=<file> dump heap to <file>
Example: jmap -dump:live,format=b,file=heap.bin <pid>
-F force. Use with -dump:<dump-options> <pid> or -histo
to force a heap dump or histogram when <pid> does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J<flag> to pass <flag> directly to the runtime system
-heap #打印jvm heap的情况,比如参数,分代,回收器等
-histo #打印jvm heap的直方图。其输出信息包括类名,对象数量,对象占用大小。
-histo:live #同上,但是只答应存活对象的情况
-dump #生成堆转储快照,格式为-dump:[live,]format=b,file=<filename>,其中自参数说明是否只dump出存活对象
-finalizerinfo #显示在F-Queue中等待的finalizer线程执行finalize方法的对象
-clstats #打印类的加载信息
-F #强制生成dump文件

jmap -heap 1645

jmap -histo 1645 | more   #查看内存中的对象和数量

上图中的对象说明:

B byte
C char
D double
F float
I int
J long
Z boolean
[ 数组,如[I表示int[]
[L+类名 其他对象
jmap -dump:format=b,file=/root/dump.bin 1645  #将内存的使用情况dump到文件中
[root@hadoop bin]# jmap -dump:format=b,file=/root/dump.bin
Dumping heap to /root/dump.bin ...
Heap dump file created

2.5、jhat

JDK提供jhat(JVM Heap Analysis Tool)命令与jmap搭配使用,来分析jmap生成的堆转储快照。jhat内置了一个微型的HTTP/Web服务器,生成堆转储快照的分析结果后,可以在浏览器中查看(实际情况使用的不多)

[root@hadoop ~]# jhat -help
Usage: jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file> -J<flag> Pass <flag> directly to the runtime system. For
example, -J-mx512m to use a maximum heap size of 512MB
-stack false: Turn off tracking object allocation call stack.
-refs false: Turn off tracking of references to objects
-port <port>: Set the port for the HTTP server. Defaults to
-exclude <file>: Specify a file that lists data members that should
be excluded from the reachableFrom query.
-baseline <file>: Specify a baseline object dump. Objects in
both heap dumps with the same ID and same class will
be marked as not being "new".
-debug <int>: Set debug level.
: No debug output
: Debug hprof file parsing
: Debug hprof file parsing, no server
-version Report version number
-h|-help Print this help and exit
<file> The file to read For a dump file that contains multiple heap dumps,
you may specify which dump in the file
by appending "#<number>" to the file name, i.e. "foo.hprof#3". All boolean options default to "true"

jhat -port 9999 dump.bin

登录自己的地址:http://192.168.88.137:9999/

这个网址拉到最下面有一个查询功能:

如上的每一个结果都可以点进去去查看

2.6、jstack

jstack(Stack Trace for Java)命令用于生成虚拟机当前时刻的线程快照(一般称为threaddump或者javacore文件)。线程快照就是当前虚拟机内每一条线程正在执行的方法堆栈的集合,生成线程快照的目的通常是定位线程出现长时间停顿的原因,如线程间死锁、死循环、请求外部资源导致的长时间挂起等,都是导致线程长时间停顿的常见原因

[root@hadoop ~]# jstack -help
Usage:
jstack [-l] <pid>
(to connect to running process)
jstack -F [-m] [-l] <pid>
(to connect to a hung process)
jstack [-m] [-l] <executable> <core>
(to connect to a core file)
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server) Options:
-F to force a thread dump. Use when jstack <pid> does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message
-F : 当正常输出请求不被响应时,强制输出线程堆栈
-l : 除堆栈外,显示关于锁的附加信息
-m : 如果调用到本地方法的话,可以显示C/C++的堆栈

jstack 1645 | more  #查看该线程的快照信息

如上的状态信息可以参考:java多线程与并发(基础篇)

三、可视化工具

3.1、JConsole

JConsole(Java Monitoring and Management Console)是一款基于JMX(Java Manage-ment Extensions)的可视化监视、管理工具。它的主要功能是通过JMX的MBean(Managed Bean)对系统进行信息收集和参数动态调整

一、本地连接

可以看出来可以对内存,线程等进行监控。

二、远程监控

这里我们使用tomcat做实验,首先要修改catalina.sh文件,添加如下内容:参考https://blog.csdn.net/shamoshuizu/article/details/70598268

JAVA_OPTS="-Djava.rmi.server.hostname=192.168.88.137 -Dcom.sun.management.jmxremote.port=8099 -Dcom.sun.management.jmxremote.rmi.port=8099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

然后重启tomcat,接下来连接远程

这个工具使用起来并不难,只要自己要有jvm的基础啦,不然看不懂,展示出来了也是白干活。

3.2、VisualVM

VisualVM(All-in-One Java Troubleshooting Tool)是功能最强大的运行监视和故障处理程序之一,能够监控线程,内存情况,查看方法的CPU时间和内存中的对象,已被GC的对象,反向查看分配的堆栈,使用起来也很简单

双击jvisualvm.exe软件,打开该工具

同JConsole 一样可以本地和远程,直接打开本地进程

基本pid,jvm参数,主机等一览无余,还有监控页面包括cpu,堆,类,线程等监控,还可以执行垃圾回收,和dump线程呢

试试远程的,同JConsole 的设置方式对tomcate进行设置

其实工具是什么呢,就是为了方便获取信息嘛,能不能看懂,能不能还得看自己的水平够不够,能不能够发现问题,能不能解决问题了。

3.3、JMC

Java Mission Control:可持续在线的监控工具

JMC与虚拟机之间同样采取JMX协议进行通信,JMC一方面作为JMX控制台,显示来自虚拟机MBean提供的数据;另一方面作为JFR的分析工具,展示来自JFR的数据

用起来也很简单,双击jmc.exe打开工具,默认情况下会扫描出本地的进程,然后可以点击:文件->连接,来创建新的连接:

然后根据下图操作,遇到情况下一步,下一步就好,就有如下的图了:

该工具持续监控了很多东西:

一般信息:关于虚拟机、操作系统和记录的一般信息。
内存:关于内存管理和垃圾收集的信息。
代码:关于方法、异常错误、编译和类加载的信息。
线程:关于应用程序中线程和锁的信息。
I/O:关于文件和套接字输入、输出的信息。
系统:关于正在运行Java虚拟机的系统、进程和环境变量的信息。
事件:关于记录中的事件类型的信息,可以根据线程或堆栈跟踪,按照日志或图形的格式查看。

四、其他工具-MAT

MAT(Memory Analyzer Tool),一个基于Eclipse的内存分析工具,是一个快速、功能丰富的JAVA heap分析工具,它可以帮助我们查找内存泄漏和减少内存消耗。使用内存分析工具从众多的对象中进行分析,快速的计算出在内存中对象的占用大小,看看是谁阻止了垃圾收集器的回收工作,并可以通过报表直观的查看到可能造成这种结果的对象

官网:https://www.eclipse.org/mat/

下载地址:https://www.eclipse.org/mat/downloads.php

下载后,解压,双击MemoryAnalyzer.exe打开程序,然后点击文件->打开dump出的文件,就出现了如下的图

下图可以看到基本的内存可能出问题的地方:

这篇文章纯粹是一个工具的使用简单说明,没有太多的技术含量,但是我觉得工欲善其事必先利其器,所以用好一些工具对自己能力的提升,效率的提升有莫大的帮助,工具这些东西只有用到的时候才会查找,但是也要大概了解下怎么用吧,比如什么工具可以用来干嘛呢,我写这个的目的就是用来以后自己当做工具文档来查看下,技术用时方恨少,所以平时多积累些也不是一件坏事呢,好吧,好好努力撒。

想写一篇jvm的工具入门的更多相关文章

  1. 如何优雅的写一篇安利文-以Sugar ORM为例

    前言 我最近喜欢把写的十分优美的技术文章叫做安利文.首先,文章必须是原创而非软广:其次,阅读之后不仅能快速吸纳技术要点并入门开发,还能感同身受的体会作者热情洋溢的赞美和急于分享心得体验的心情,让人感觉 ...

  2. 我想写一个前端开发工具(三):优化!从vue-cli学了几招

    我从过年开始写自己的前端工具 coodev,目前已经写出一个基本的架子,大多数预想的功能都能跑通,还剩一些需要解决的问题也都已经列出来了.本来这一周打算解决对不同后端模板的前后端渲染支持的问题.但是看 ...

  3. 基于tensorflow的MNIST手写数字识别(二)--入门篇

    http://www.jianshu.com/p/4195577585e6 基于tensorflow的MNIST手写字识别(一)--白话卷积神经网络模型 基于tensorflow的MNIST手写数字识 ...

  4. 写给Android开发者的Kotlin入门

    写给Android开发者的Kotlin入门 转 https://www.jianshu.com/p/bb53cba6c8f4 Google在今年的IO大会上宣布,将Android开发的官方语言更换为K ...

  5. 通过npm写一个cli命令行工具

    前言 如果你想写一个npm插件,如果你想通过命令行来简化自己的操作,如果你也是个懒惰的人,那么这篇文章值得一看. po主的上一篇文章介绍了定制自己的模版,但这样po主还是不满足啊,项目中我们频繁的需要 ...

  6. .NET Core实战项目之CMS 第六章 入门篇-Vue的快速入门及其使用

    写在前面 上面文章我给大家介绍了Dapper这个ORM框架的简单使用,大伙会用了嘛!本来今天这篇文章是要讲Vue的快速入门的,原因是想在后面的文章中使用Vue进行这个CMS系统的后台管理界面的实现.但 ...

  7. Orange的数据挖掘工具入门使用

    Orange的数据挖掘工具入门使用 声明: 1)本报告由博客园bitpeach撰写,版权所有,免费转载,请注明出处,并请勿作商业用途. 2)若本文档内有侵权文字或图片等内容,请联系作者bitpeach ...

  8. JVM监测&amp;工具[转]

    通过工具及Java api来监测JVM的运行状态, 需要监测的数据:(内存使用情况 谁使用了内存 GC的状况) 内存使用情况--heap&PermGen @ 表示通过jmap –heap pi ...

  9. JVM系列五:JVM监测&amp;工具[整理中]

    前几篇篇文章介绍了介绍了JVM的参数设置并给出了一些生产环境的JVM参数配置参考方案.正如之前文章中提到的JVM参数的设置需要根据应用的特性来进行设置,每个参数的设置都需要对JVM进行长时间的监测,并 ...

  10. JVM系列五:JVM监测&amp;工具

    JVM系列五:JVM监测&工具[整理中]  http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html 前几篇篇文章介绍了介 ...

随机推荐

  1. 用H5中的Canvas等技术制作海报

    在去年的时候也实现过合成海报的功能,不过当时时间仓促,实现的比较简单. 就一个旋转功能,图片也不能拖动放大,也不能裁剪. 去年的实现可以参考<移动图片操作--上传>和<移动图片操作- ...

  2. Javascript身份证号码验证

    "来来来,坐这儿". "什么?我可是有身份的人,怎么能和你坐一块儿".沛笠晃了晃手里的身份证,不屑说道. "你咋不上天呢?有身份还喝油条吃豆浆&quo ...

  3. spring的Scheduled(定时任务)和多线程

    一.前言 在我们日常的开发中,经常用到数据同步的更新,这时我们采用的是spring的定时任务和java的多线程进行数据的更新,进行时实的服务调用. 二.实现思路            1.创建线程类 ...

  4. AS3从入门到放弃

    工作久了,在技术上肯定有自己的一些见解.一直以来都懒得写下来,总觉得尤其写博客的时间,还不如自己学一点新东西.但不能总找这样的接口啊,于是乎开始了这篇博客. 工作了三年,有一年半的时间是在做AS3,在 ...

  5. static关键字修饰类

    今天继续研究公司的新项目,据说是京东的架构,研究看了一番,果然很牛逼,大致是Maven+spingmvc+spring+mybatis+ehcache+velocity来搭建的,数据库用的是mysql ...

  6. tornado options

    tornado.options.define() 用来定义options选项变量的方法,定义的变量可以在全局的tornado.options.options中获取使用,传入参数: name 选项变量名 ...

  7. python部署galery集群

    galery.py文件内容 import pexpect import os import configparser HOSTNAME_DB1='db1' HOSTNAME_DB2='db2' HOS ...

  8. windows 设置ipsec防火墙

    windows server 推荐使用ipsec修改防火墙设置,默认防火墙需要手动导入导出.wfw文件,需要手动添加单条规则,维护麻烦,推荐关闭,使用ipsec管理 以下是线上防火墙配置,可参照业务环 ...

  9. poj 3294 Life Forms - 后缀数组 - 二分答案

    题目传送门 传送门I 传送门II 题目大意 给定$n$个串,询问所有出现在严格大于$\frac{n}{2}$个串的最长串.不存在输出'?' 用奇怪的字符把它们连接起来.然后求sa,hei,二分答案,按 ...

  10. django模板总结

    1. 加载静态文件 html顶部:{% load staticfiles %} 调用: <link rel="stylesheet" type="text/css& ...