Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the JVM troubleshooting tool

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to use the JVM troubleshooting tool", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the JVM troubleshooting tool.

I. Preface

How do you learn if you don't need it?

There is no scene, no appeal, how to learn these do not seem to need knowledge points.

In fact, the best way is to sum up, organize, practice, output, a set of combined punches down, you will master the knowledge of this series.

But in the current stage may not really need, JVM is a stable service, how can there be problems every day, which need you to constantly check. It's not like the code you wrote!

But the learning of knowledge is to base you to a higher level before you have the opportunity to come into contact with more interesting work and technological innovation. If you just learn a few instructions, it's not much fun. But when you are asked to complete a set of full-link monitoring, which contains the overall time consuming of a method call, execution path, parameter information, exception results, GC times, stack data, generational content, etc., then do you have enough knowledge reserve to develop such a system?

OK, let's see what this article is going to talk about in the above picture, and then follow in the footsteps of Brother Fu.

JVM fault handling tools II. Interview questions

Thank you for the plane. Having a weekend rest at home is boring, and I have dug up the JVM virtual machine which has already been grayed out.

Thank you plane: quack. Hey, brother, this, what is this JVM virtual machine looking at?

Interviewer: what are you looking at? I don't know where to start? Well, then you start with the problem!

Xie Ji: what's the problem? I just don't know what I don't know, and I don't know what to ask you.

Interviewer: Ah! Then let me ask you, how to use the JVM troubleshooting tool to see what parameters are configured when JVM starts?

Thank you for flying: this!? No way!

Interviewer: what are the monitoring instructions that you are familiar with? if you are asked how to count the heap memory statistics, do you know?

Thank you for flying: I don't know, ha, I seem to know what I'm going to see!

Interviewer: go ahead, take a look at the questions, and sort them out!

Basic fault handling tools 1. Jps virtual machine process status

Jps (JVM Process Status Tool), which functions like the ps command, lists the running virtual machine processes and displays the name of the virtual machine execution main class (the class where the Main Class,main () function is located) and the local virtual machine unique ID (Local Virtual Machine Identifier,LVMID) of these processes, similar to the function of ps-ef | grep java.

Although the little guy is not big, he has a single function. But it can be said that basically you have to use it for all other commands to query LVMID to determine which virtual machine process is being monitored.

Command format

Jps [options] [hostid]

Options: options, parameters, different parameters can output the required information hostid: remote view

List of options

Option description-Q outputs only the process ID, ignoring the main class information-l outputs the full name of the main class, or executes the JAR package output path-m outputs the parameter passed to the main class main () function when the virtual machine process starts-v outputs the JVM parameter when the virtual machine process starts

1.1 jps-Q, listing only processes IDE:\ itstack\ git\ github.com\ interview > jps-Q

104928

111552

26852

96276

59000

8460

76188 1.2 jps-l, which outputs the full name of the current running class E:\ itstack\ git\ github.com\ interview > jps-l

111552 org/netbeans/Main

26852

96276 org.jetbrains.jps.cmdline.Launcher

59000

62184 sun.tools.jps.Jps

8460 org/netbeans/Main

The output of 76188 sun.tools.jstatd.Jstatd is much clearer with this command, and-l is also a very common parameter option. 1.3 jps-m, listing the arguments passed to the main () function E:\ itstack\ git\ github.com\ interview > jps-m

111552 Main-branding visualvm-cachedir C:\ Users\ xiaofuge\ AppData\ Local\ VisualVM\ Cache/8u131-openid 3041391569375200

26852

96276 Launcher C:/Program Files/JetBrains/IntelliJ IDEA 2019.3.1Universe pluginsCharger Files/JetBrains/IntelliJ IDEA Files/JetBrains/IntelliJ IDEA 2019.3.1LIBUnix javac2.jarterCjudicPlus Program Files/JetBrains/IntelliJ IDEA 2019.3.1LBG pluginsUnix javaExpact 1.1.0.jarentCluginsUniqqr Files/JetBrains/IntelliJ IDEA 2019.3.1LIBUnix JNAL platform.jarexClux Clux PUA

Les/JetBrains/IntelliJ IDEA 2019.3.1According to les/JetBrains/IntelliJ IDEA 2019.3.1According to Files/JetBrains/IntelliJ IDEA 2019.3.1According to the program Files/JetBrains/IntelliJ IDEA 2019.3.1/plu, preview.jar

Gins/java/lib/aether-connector-basic-1.1.0.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2019.3.1 pluginsUniverse java Files/JetBrains/IntelliJ IDEA 2019.3.1/plu libUniverse maven Modelink builderMeim 3.9.jarterCrimsPlus Files/JetBrains/IntelliJ IDEA 2019.3.1OnlibUnix

Gins/java/lib/maven-model-3.3.9.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2019.3.1Universe pluginsswap java File, lib, aetherimplMuth1.1.0.jarterCRU, Files/JetBrains/IntelliJ IDEA, 2019.3.1, LIbSUNGSON, 2.8.5.jarX, CRU, program

59000

16844 Jps-m

8460 Main-branding visualvm-cachedir C:\ Users\ xiaofuge\ AppData\ Local\ VisualVM\ Cache/8u131-openid 30414336579200

76188 Jstatd 1.4jps-v, outputting the JVM parameter [- Xms24m-Xmx256m] E:\ itstack\ git\ github.com\ interview > jps-v when the virtual machine process starts

111552 Main-Xms24m-Xmx256m-Dsun.jvmstat.perdata.syncWaitMs=10000-Dsun.java2d.noddraw=true-Dsun.java2d.d3d=false-Dnetbeans.keyring.no.master=true-Dplugin.manager.install.global=false-add-exports=java.desktop/sun.awt=ALL-UNNAMED-add-exports=jdk.jvmstat/sun

Jvmstat.monitor.event=ALL-UNNAMED-- add-exports=jdk.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED-- add-exports=java.desktop/sun.swing=ALL-UNNAMED-- add-exports=jdk.attach/sun.tools.attach=ALL-UNNAMED-- add-modules=java.activation-XX:+IgnoreUnrecognizedVMOptions-Djdk.

Home=C:/Program Files/Java/jdk1.8.0_161-Dnetbeans.home=C:\ Program Files\ Java\ jdk1.8.0_161\ lib\ visualvm\ platform-Dnetbeans.user=C:\ Users\ xiaofuge1\ AppData\ Roaming\ VisualVM\ 8u131-Dnetbeans.default_userdir_root=C:\ Users\ xiaofuge1\ AppData\ Roaming\ VisualVM-XX:+H

EapDumpOnOutOfMemoryError-XX:HeapDumpPath=C:\ Users\ xiaofuge1\ AppData\ Roaming\ VisualVM\ 8u131\ var\ log\ heapdump.hprof-Dnetbeans.dirs=C:\ Program Files\ Java\ jdk1.8.0_161\ lib\ visualvm\ visualvm;C:\ Program

59000-Dfile.encoding=UTF-8-Xms128m-Xmx1024m-XX:MaxPermSize=256m

76188 Jstatd-Denv.class.path=.;C:\ Program Files\ Java\ jre1.8.0_161\ lib;C:\ Program Files\ Java\ jre1.8.0_161\ lib\ tool.jar;-Dapplication.home=C:\ Program Files\ Java\ jdk1.8.0_161-Xms8m-Djava.security.policy=jstatd.all.policy 1.5 jps-lv 127.0.0.1, output remote machine information

The jps link outputs JVM information remotely, and you need to register RMI, otherwise you will report an error RMI Registry not available at 127.0.0.1.

Register RMI to open jstatd to add a file named jstatd.all.policy to your C:\ Program Files\ Java\ jdk1.8.0_161\ bin directory. No other suffix

The contents of the jstatd.all.policy file are as follows:

Grant codebase "file:$ {java.home} /.. / lib/tools.jar" {

Permission java.security.AllPermission

}

After adding the configuration file, register the added jstatd.all.policy file in the bin directory: C:\ Program Files\ Java\ jdk1.8.0_161\ bin > jstatd-J-Djava.security.policy=jstatd.all.policy

If it goes well, you can now view the JVM information of the original machine, as follows:

E:\ itstack\ git\ github.com\ interview > jps-l 127.0.0.1

111552 org/netbeans/Main

26852

96276 org.jetbrains.jps.cmdline.Launcher

36056 sun.tools.jps.Jps

59000

8460 org/netbeans/Main

76188 sun.tools.jstatd.Jstatd

You can also combine the option parameters of jps, such as jps-lm 127.0.0.12. Jcmd virtual machine diagnostic command

Jcmd, a newly released JVM-related information diagnostic tool from jdk1.7, can be used to export heap and thread information, view Java processes, execute GC, and perform sampling analysis (flight recorder of the jmc tool). Note that it can only be used on the same sever of the diagnosed JVM and have the same users and groups (user and group).

Command format

Jcmd

Pid, the process IDmain class that receives the diagnostic command request, and the process main class that receives the diagnostic command request. Command, the process main class that receives diagnostic command requests. PerfCounter.print, printing the performance counters available on the target Java process. -f file, read commands from the file file, and then invoke them on the target Java process. -l to view all the process list information. -h,-help, to view help information. 2.1 jcmd pid VM.flags, check the JVM startup parameters E:\ itstack\ git\ github.com\ interview > jcmd 111552 VM.flags

111552:

-XX:CICompilerCount=4-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=C:\ Users\ xiaofuge1\ AppData\ Roaming\ VisualVM\ 8u131\ var\ log\ heapdump.hprof-XX:+IgnoreUnrecognizedVMOptions-XX:InitialHeapSize=25165824-XX:MaxHeapSize=268435456-XX:MaxNewSize=89128960-XX:Min

HeapDeltaBytes=524288-XX:NewSize=8388608-XX:OldSize=16777216-XX:+UseCompressedClassPointers-XX:+UseCompressedOops-XX:+UseFastUnorderedTimeStamps-XX:-UseLargePagesIndividualAllocation-XX:+UseParallelGC 2.2 jcmd pid VM.uptime, check the JVM runtime E:\ itstack\ git\ github.com\ interview > jcmd 111552 VM.uptime

111552:

583248.912 s 2.3 jcmd pid PerfCounter.print, check the JVM performance related parameters E:\ itstack\ git\ github.com\ interview > jcmd 111552 PerfCounter.print

111552:

Java.ci.totalTime=56082522

Java.cls.loadedClasses=5835

Java.cls.sharedLoadedClasses=0

Java.cls.sharedUnloadedClasses=0

Java.cls.unloadedClasses=37

.. 2.4 jcmd pid GC.class_histogram, view the statistics of classes in the system E:\ itstack\ git\ github.com\ interview > jcmd 111552 GC.class_histogram

111552:

Num # instances # bytes class name

-

1: 50543 3775720 [C

2: 3443 2428248 [I

3: 50138 1203312 java.lang.String

4: 25351 811232 java.util.HashMap$Node

5: 6263 712208 java.lang.Class

6: 3134 674896 [B

7: 6687 401056 [Ljava.lang.Object

8: 2468 335832 [Ljava.util.HashMap$Node; 2.5jcmd pid Thread.print, view thread stack information E:\ itstack\ git\ github.com\ interview > jcmd 111552 Thread.print

111552:

2021-01-10 23:31:13

Full thread dump Java HotSpot (TM) 64-Bit Server VM (25.161-b12 mixed mode):

"Computes values in handlers" # 52 daemon prio=5 os_prio=0 tid=0x0000000019839000 nid=0x16014 waiting for monitor entry [0x0000000026bce000]

Java.lang.Thread.State: BLOCKED (on object monitor)

At com.sun.tools.visualvm.core.model.ModelFactory.getModel (ModelFactory.java:76)

-waiting to lock (a com.sun.tools.visualvm.jvmstat.application.JvmstatApplication)

At com.sun.tools.visualvm.application.jvm.JvmFactory.getJVMFor (JvmFactory.java:45)

At com.sun.tools.visualvm.application.options.Open.openApplication (Open.java:108)

At com.sun.tools.visualvm.application.options.Open.process (Open.java:93)

At org.netbeans.spi.sendopts.Option$1.process (Option.java:348)

At org.netbeans.api.sendopts.CommandLine.process (CommandLine.java:278)

At org.netbeans.modules.sendopts.HandlerImpl.execute (HandlerImpl.java:23)

At org.netbeans.modules.sendopts.Handler.cli (Handler.java:30)

At org.netbeans.CLIHandler.notifyHandlers (CLIHandler.java:195)

At org.netbeans.core.startup.CLICoreBridge.cli (CLICoreBridge.java:43)

At org.netbeans.CLIHandler.notifyHandlers (CLIHandler.java:195)

At org.netbeans.CLIHandler$Server$1ComputingAndNotifying.run (CLIHandler.java:1176) 2.6jcmd pid VM.system_properties, check the JVM system parameters E:\ itstack\ git\ github.com\ interview > jcmd 111552 VM.system_properties

111552:

# Sun Jan 13 23:33:19 CST 2021

Java.vendor=Oracle Corporation

Netbeans.user=C\:\ Users\\ xiaofuge1\\ AppData\\ Roaming\ VisualVM\\ 8u131

Sun.java.launcher=SUN_STANDARD

Sun.management.compiler=HotSpot 64-Bit Tiered Compilers

Netbeans.autoupdate.version=1.23

Os.name=Windows 102.7 jcmd pid GC.heap_dump path, export the heap dump file E:\ itstack\ git\ github.com\ interview > jcmd 111552 GC.heap_dump C:\ Users\ xiaofuge1\ Desktop\ _ dump_0110

111552:

Heap dump file created

The exported file needs to view 2.8jcmd pid help with jvisualvm, listing the executable actions E:\ itstack\ git\ github.com\ interview > jcmd 111552 help

111552:

The following commands are available:

JFR.stop

JFR.start

JFR.dump

JFR.check 2.9jcmd pid help JFR.stop, view commands using E:\ itstack\ git\ github.com\ interview > jcmd 111552 help JFR.stop

111552:

JFR.stop

Stops a JFR recording

Impact: Low

Permission: java.lang.management.ManagementPermission (monitor)

Syntax: JFR.stop [options]

Options: (options must be specified using the or = syntax)

Name: [optional] Recording name,.e.g\ "My Recording\" (STRING, no default value)

Recording: [optional] Recording number, see JFR.check for a list of available recordings (JLONG,-1)

Discard: [optional] Skip writing data to previously specified file (if any) (BOOLEAN, false)

Filename: [optional] Copy recording data to file, e.g.\ "C:\ Users\ user\ My Recording.jfr\" (STRING, no default value)

Compress: [optional] GZip-compress "filename" destination (BOOLEAN, false) 3. Jinfo Java configuration information tool

Jinfo (Configuration Info for Java) to view and adjust the parameters of JVM in real time.

When talking about the jps-v instruction above, you can see that it prints out the explicit parameter list when the virtual machine starts, but if you want to see a specific parameter more clearly or want to know the parameter that has not been explicitly specified, you can query it through jinfo-flag.

Command format

Jinfo [option] pid

"mode of use"

E:\ itstack\ git\ github.com\ interview > jinfo-flag MetaspaceSize 111552

-XX:MetaspaceSize=21807104

E:\ itstack\ git\ github.com\ interview > jinfo-flag MaxMetaspaceSize 111552

-XX:MaxMetaspaceSize=18446744073709486080

E:\ itstack\ git\ github.com\ interview > jinfo-flag HeapDumpPath 111552

-XX:HeapDumpPath=C:\ Users\ xiaofuge\ AppData\ Roaming\ VisualVM\ 8u131\ var\ log\ heapdump.hprof

You can query all kinds of JVM parameters, so it is more convenient to display only what you want. 4. Jstat collects virtual machine running data

Jstat (JVM Statistics Monitoring Tool), which is used to monitor various running status information of virtual machines. It can view run-time data such as class loading, memory, garbage collection, just-in-time compilation, etc., in local or remote virtual machine processes.

Command format

Jstat-[- t] [- h] [[]]

Vmid: if you are viewing remote machines, you need to follow this format: [protocol:] [/ /] lvmid [@ hostname [: port] / servername] interval and count, indicating the query interval and times, for example, querying the gc collection of process ID every 1000 milliseconds, 5 times at a time. Jstat-gc 111552 1000 5

List of options

Option description-class monitors class loading, unloading, total space and time spent on class loading-gc monitors Java heap, including Eden zone, 2 Survivor zones, old age, permanent generation, or jdk1.8 metaspace, etc., capacity, used space, garbage collection time and other information-gccapacity monitoring content is basically the same as-gc But the output focuses on the maximum and minimum space used in each area of the Java heap-the gcutil monitoring content is basically the same as-gc, but the output focuses on the percentage of used space in the total space-gccause is the same as-gcutil function, but the extra output leads to the cause of the last garbage collection-gcnew monitors the new generation of garbage collection-gcnewcapacity monitoring content is basically the same as-gcnew The output mainly focuses on the maximum and minimum space used-gcold to monitor old garbage collection-gcoldcapacity monitoring content is basically the same as-gcold, and the output mainly focuses on the maximum and minimum space used-compiler output real-time compiler compiled methods, time-consuming and other information-printcompilation output has been compiled in time-gcpermcapacityjdk1.7 and below, permanent generation space statistics-gcmetacapacityjdk1.8 There are still many monitoring options for metaspace statistics jstat, but the most commonly used are the above. 4.01 jstat-class, class load statistics E:\ itstack\ git\ github.com\ interview > jstat-class 111552

Loaded Bytes Unloaded Bytes Time

5835 12059.6 37 53.5 3.88

Loaded, number of class loaded Bytes: space occupied Unloaded: number of unloaded Bytes: unloaded space Time: time 4.02 jstat-compiler, compilation statistics E:\ itstack\ git\ github.com\ interview > jstat-compiler 111552

Compiled Failed Invalid Time FailedType FailedMethod

3642 0 0 5.61 0

Compiled: number of compilations Failed: number of failures Invalid: number of unavailable Time: time FailedType: failure type FailedMethod: failure method 4.03 jstat-gc, garbage collection statistics E:\ itstack\ git\ github.com\ interview > jstat-gc 111552

S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT

1024.0 512.0 0.0 0.0 77312.0 35.1 39424.0 13622.9 37120.0 34423.3 5376.0 4579.4 60 0.649 52 3.130 3.779

S0C, S1C, the first and second survival area sizes S0U, S1U, the first and second survival areas using size EC, EU, the size of the Garden of Eden and using OC, OU, the size of the old age and the use of MC, MU, the size of the method area and the use of CCSC, CCSU, the size of compressed class space and the use of YGC, YGCT, the number of garbage collection times and time-consuming FGC and FGCT of the younger generation, the number of garbage collection times and time-consuming GCT of the old generation Total garbage collection time 4.04 jstat-gccapacity, heap memory statistics E:\ itstack\ git\ github.com\ interview > jstat-gccapacity 111552

NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC

8192.0 87040.0 80384.0 1024.0 512.0 77312.0 16384.0 175104.0 39424.0 39424.0 0.0 1081344.0 37120.0 0.0 1048576.0 5376.0 60 52

NGCMN, NGCMX, Cenozoic minimum and maximum capacity NGC, current Cenozoic capacity S0C, S1C, first and second survival area size EC, Eden Park size OGCMN, OGCMX, old age minimum and maximum capacity OGC, OC, current old age size MCMN, MCMX, metadata space minimum and maximum capacity MC, current metaspace size CCSMN, CCSMX, compressed class minimum and maximum space YGC, younger generation GC FGC times The number of GC in the old era is 4.05jstat-gcnewcapacity, and the memory statistics of the new generation E:\ itstack\ git\ github.com\ interview > jstat-gcnewcapacity 111552

NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC

8192.0 87040.0 80384.0 28672.0 1024.0 28672.0 512.086016.077312.06052 NGCMN, NGCMX, Cenozoic minimum and maximum capacity NGC, current Cenozoic capacity S0CMX, maximum surviving zone 0 size S0C, current surviving zone 0 size S1CMX, maximum surviving zone 1 size S1C, current surviving zone 1 size ECMX, maximum Eden park size EC, current Eden park size YGC FGC of the younger generation, 4.06 jstat-gcnew of the old generation, E:\ itstack\ git\ github.com\ interview > jstat-gcnew 111552

S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT

1024.0 512.0 0.0 0.0 3 15 512.0 77312.0 70.2 60 0.649

S0C, S1C, the first and second survival area sizes S0U, S1U, the first and second survival areas use TT, the number of times the object survived in the Cenozoic generation MTT, the maximum number of times the object survived in the Cenozoic generation DSS: the expected survival area size EC, the size of the Eden Park EU, the use of YGC in the Eden Park, the younger generation garbage collection times YGCT, the younger generation garbage collection time 4.07jstat-gcold Old-fashioned garbage collection statistics E:\ itstack\ git\ github.com\ interview > jstat-gcold 111552

MC MU CCSC CCSU OC OU YGC FGC FGCT GCT

37120.0 34423.3 5376.0 4579.4 39424.0 13622.9 60 52 3.130 3.779

MC, MU, size of method area and use of CCSC and CCSU, size of compressed class space and use of OC, OU, old age size and use of YGC, younger generation garbage collection times FGC, old generation garbage collection times FGCT, old generation garbage collection time GCT, total garbage collection time 4.08 jstat-gcoldcapacity, old memory statistics E:\ itstack\ git\ github.com\ interview > jstat-gcoldcapacity 111552

OGCMN OGCMX OGC OC YGC FGC FGCT GCT

16384.0 175104.0 39424.0 39424.0 60 52 3.130 3.779

OGCMN, OGCMX, minimum and maximum capacity OGC, current OC, YGC, FGC, FGCT, GCT, 4.09 jstat-gcmetacapacity, metaspace statistics E:\ itstack\ git\ github.com\ interview > jstat-gcmetacapacity 111552

MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT GCT

0.0 1081344.0 37120.0 0.0 1048576.0 5376.0 60 52 3.130 3.779

MCMN, MCMX, metaspace minimum and maximum capacity MC, current metadata space size CCSMN, CCSMX, compressed class minimum and maximum space CCSC, compressed class space size YGC, young generation garbage collection FGC, old garbage collection number FGCT, old garbage collection time GCT, total garbage collection consumption 4.10 jstat-gcutil, garbage collection statistics E:\ itstack\ git\ github.com\ interview > jstat-gcutil 111552

S0 S1 E O M CCS YGC YGCT FGC FGCT GCT

0.00 0.00 0.09 34.55 92.74 85.18 60 0.649 52 3.130 3.779

S0, S1, Survivor Zone 1 and Zone 2, current usage ratio E, Eden Park usage ratio O, seniority area usage ratio M, metadata area usage ratio CCS, compression class usage ratio YGC, younger generation garbage collection times FGC, old generation garbage collection times FGCT, old years garbage collection time GCT, total garbage collection consumption 4.11jstat-printcompilation,JVM compilation method statistics E:\ itstack\ git\ github.com\ interview > jstat-printcompilation 111552

Compiled Size Type Method

3642 9 1 java/io/BufferedWriter min

Compiled: number of recently compiled methods Size: number of bytecodes of recently compiled methods Type: compilation type of recently compiled methods Method: method name identification 5. Jmap memory mapping tool

Jmap (Memory Map for Java), used to generate heap dump snapshots (heapdump files).

In addition to taking a snapshot of the heap dump, jmap can also query the details of the finalize execution queue, Java heap, and method zone.

Command format

Jmap [option] pid

Option: option parameter pid: process that needs to print configuration information IDexecutable: Java executable file that produces core dump core: core file that needs to print configuration information server-id: optional unique id, if multiple debugging servers are running on the same remote host, use this option parameter to identify the server remote server IP or hostname: the IP address or hostname of the remote debugging server

List of options

Option description-dump generates Java heap dump snapshots. -finalizerinfo displays the object in F-Queue waiting for the Finalizer thread to execute the finalize method. Linux platform-heap displays Java heap details, such as which recycler is used, parameter configuration, and generation. Linux platform-histo displays statistics of objects in the heap, including classes, number of instances, total capacity-permstat shows permanent memory status, jdk1.7, permanent generation-F when the virtual machine process is not responsive to the-dump option, it can be forced to generate a snapshot. Linux platform 5.1 jmap, print shared object mapping E:\ itstack\ git\ github.com\ interview > jmap 111552

Attaching to process ID 111552, please wait...

Debugger attached successfully.

Server compiler detected.

JVM version is 25.161-b12

0x000000005b4a0000 1632K C:\ Program Files\ Java\ jdk1.8.0_161\ jre\ bin\ awt.dll

0x000000005b8c0000 264K C:\ Program Files\ Java\ jdk1.8.0_161\ jre\ bin\ t2k.dll

0x000000005b910000 284K C:\ Program Files\ Java\ jdk1.8.0_161\ jre\ bin\ fontmanager.dll

0x000000005b960000 224K C:\ Program Files\ Java\ jdk1.8.0_161\ jre\ bin\ splashscreen.dll

0x000000005b9a0000 68K C:\ Program Files\ Java\ jdk1.8.0_161\ jre\ bin\ nio.dll

5.2 jmap-heap, heap details E:\ itstack\ git\ github.com\ interview > jmap-heap 111552

Attaching to process ID 111552, please wait...

Debugger attached successfully.

Server compiler detected.

JVM version is 25.161-b12

Using thread-local object allocation.

Parallel GC with 8 thread (s)

Heap Configuration:

MinHeapFreeRatio = 0

MaxHeapFreeRatio = 100

MaxHeapSize = 268435456 (256.0MB)

NewSize = 8388608 (8.0MB)

MaxNewSize = 89128960 (85.0MB)

OldSize = 16777216 (16.0MB)

NewRatio = 2

SurvivorRatio = 8

MetaspaceSize = 21807104 (20.796875MB)

CompressedClassSpaceSize = 1073741824 (1024.0MB)

MaxMetaspaceSize = 17592186044415 MB

G1HeapRegionSize = 0 (0.0MB)

5.3 jmap-clstats, print load class E:\ itstack\ git\ github.com\ interview > jmap-clstats 111552

Attaching to process ID 111552, please wait...

Debugger attached successfully.

Server compiler detected.

JVM version is 25.161-b12

Finding class loader instances.. done.

Computing per loader stat.. done.

Please wait.. Computing liveness.liveness analysis may be inaccurate...

Class_loader classes bytes parent_loader alive? Type

3779 6880779 null live

0x00000000f03853b8 57 132574 0x00000000f031aac8 live org/netbeans/StandardModule$OneModuleClassLoader@0x00000001001684f0

0x00000000f01b9b98 00 0x00000000f031aac8 live org/netbeans/StandardModule$OneModuleClassLoader@0x00000001001684f0

0x00000000f005b280 00 0x00000000f031aac8 live java/util/ResourceBundle$RBClassLoader@0x00000001000c6ae0

0x00000000f01dfa98 00 0x00000000f031aac8 live org/netbeans/StandardModule$OneModuleClassLoader@0x00000001001684f0

0x00000000f01ec518 79 252894 0x00000000f031aac8 live org/netbeans/StandardModule$OneModuleClassLoader@0x00000001001684f0 5.4 jmap-dump, heap dump file E:\ itstack\ git\ github.com\ interview > jmap-dump:live,format=b,file=C:/Users/xiaofuge/Desktop/heap.bin 111552

Dumping heap to C:\ Users\ xiaofuge\ Desktop\ heap.bin...

Heap dump file created 6. Jhat heap dump snapshot analysis tool

Jhat (JVM Heap Analysis Tool), used in conjunction with jmap to analyze heap dump snapshots generated by jmap.

Jhat has a built-in small http/web server that can display the results of the heap dump snapshot analysis in a browser. However, it is of little use, and almost everyone will use other third-party tools.

Command format

Jhat [- stack] [- refs] [- port] [- baseline] [- debug] [- version] [- h |-help]

"Command use"

E:\ itstack\ git\ github.com\ interview > jhat-port 8090 C:/Users/xiaofuge1/Desktop/heap.bin

Reading from C:/Users/xiaofuge1/Desktop/heap.bin...

Dump file created Wed Jan 13 16:53:47 CST 2021

Snapshot read, resolving...

Resolving 246455 objects...

Chasing references, expect 49 dots...

Eliminating duplicate references...

Snapshot resolved.

Started HTTP server on port 8090

Server is ready.

"http://localhost:8090/"

Jhat-port 80907. Jstack Java stack trace tool

Jstack (Stack Trace for Java), which is used to generate thread snapshots (threaddump, javacore) of the current moment of the virtual machine.

A thread snapshot is a collection of method stacks that each thread is executing in the current virtual machine. The purpose of generating a thread snapshot is usually to locate the causes of thread pauses for a long time, such as thread deadlock, deadloop, hang caused by long time to request external resources, and so on.

The thread immediately looks at the call stack of each thread through jstack, and you can find out what the unresponsive thread is doing.

Command format

Jstack [option] vmid

"option parameters"

Option description-F when the normally output request is not responded, force the output thread stack-l to display additional information about the lock in addition to the stack-m can display the stack of cUniverse + if the local method is called

"Command use"

E:\ itstack\ git\ github.com\ interview > jstack 111552

2021-01-10 23:15:03

Full thread dump Java HotSpot (TM) 64-Bit Server VM (25.161-b12 mixed mode):

"Inactive RequestProcessor thread [Was:StdErr Flush/org.netbeans.core.startup.logging.PrintStreamLogger]" # 59 daemon prio=1 os_prio=-2 tid=0x000000001983a800 nid=0x688 in Object.wait () [0x0000000017fbf000]

Java.lang.Thread.State: TIMED_WAITING (on object monitor)

At java.lang.Object.wait (Native Method)

At org.openide.util.RequestProcessor$Processor.run (RequestProcessor.java:1939)

-locked (a java.lang.Object)

In the process of verifying usage, you can try to write a thread in an endless loop, and then view the thread information through jstack. Visual fault handling tool 1. Jconsole,Java Monitoring and Management console

JConsole (Java Monitoring and Management Console) is a visual monitoring and management tool based on JMX (Java Manage-ment Extensions).

Its main function is to collect and adjust the parameters of the system, not only can be managed in the virtual machine itself, but also can be developed in the software, is an open service, there are corresponding code API calls.

"JConsole start"

JConsole start

"JConsole use"

JConsole uses 2. VisualVM, multiple fault handling tools

VisualVM (All-in-One Java Troubleshooting Tool) is one of the most powerful tools for operation monitoring and fault handling.

In addition to routine operation monitoring and fault handling, it can also do performance analysis and other work. Because of its versatility and little impact on the application, it can be directly connected to the production environment.

"VisualVM IDEA installation"

VisualVM IDEA installation

"VisualVM use"

Public static void main (String [] args) throws InterruptedException {

Thread.sleep (5000)

ClassLoadingMXBean loadingBean = ManagementFactory.getClassLoadingMXBean ()

While (true) {

Enhancer enhancer = new Enhancer ()

Enhancer.setSuperclass (MetaSpaceOomMock.class)

Enhancer.setCallbackTypes (new Class [] {Dispatcher.class, MethodInterceptor.class})

Enhancer.setCallbackFilter (new CallbackFilter () {

@ Override

Public int accept (Method method) {

Return 1

}

@ Override

Public boolean equals (Object obj) {

Return super.equals (obj)

}

});

System.out.println (enhancer.createClass () .getName () + loadingBean.getTotalLoadedClassCount () + loadingBean.getLoadedClassCount () + loadingBean.getUnloadedClassCount ())

}

}

"remember to adjust the meta-space."

-XX:MetaspaceSize=8m

-XX:MaxMetaspaceSize=80m

-Djava.rmi.server.hostname=127.0.0.1

-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.port=7397

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.authenticate=false

Let's monitor the code that overflows the metaspace, java.lang.OutOfMemoryError: Metaspace

"Monitoring results"

VisualVM, the monitoring results have come to this. I believe you have a deeper understanding of "how to use the JVM troubleshooting tool". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report