Java virtual machine microscope Serviceability Agent Introduction

Ancient martial arts people will find their desirable weapon, even Wukong far to go underwater treasure hunt. Liu Guan sworn own hand, he said immediately after the DIY weapons.

 

The same is true of our developers, we analyze the problem in the diagnostic process, Debugging  and  Troubleshooting  tools played an important role, said there is a hand tool that can save a lot of effort to quickly resolve originally takes a long time to work.

 

Of course, there are already a number of tools can be used for problem analysis and diagnosis, such as we described earlier two:

 

Java seven weapons, gun Overlord series - thread state analysis jstack

Seven weapons Java Series Queling - problem diagnosis artifact BTrace

 

But more than the underlying analytical applications, Low Level JVM tools to this level of less than.

For example, some times you use when analyzing a problem, we want to understand the application of the current memory structure, content loaded class, Stack Memory thread deadlock analysis, survival statistics and query objects and so on.

 

These, with what tool is better? These relatively low-level analysis, can only rely on the support of the JVM, in order to correct analysis. Fortunately, the official provides such a tool.

 

This is the tool we mentioned this minor, or to be precise a tool set , but the time available to us to use, similar to the one-stop feeling. In a complete tool in high demand, it is  Serviceability Agent , more often referred to as SA.

 

 

What is SA?

 

 

The Serviceability Agent is a Sun private component in the HotSpot repository that was developed by HotSpot engineers to assist in debugging HotSpot. They then realized that SA could be used to craft serviceability tools for end users since it can expose Java objects as well as HotSpot data structures both in running processes and in core files.

 

In summary, this is the Sun (Oracle) companies to provide a tool for the HotSpot runtime and Core analysis data in the file. Can attach to process or analyze data Core Java file, understand class load, is a Java API contains a large set of tools and instruments.

Moreover, SA after attatch to the process, will suspend execution of the current process, it is to get a snapshot of the process. The current process will continue after disconnect SA.

 

 

how to use

 

SA Jar file in the form of the JDK is provided, located JAVA_HOME / lib / SA-jdi.jar . And perform the same general Jar file. SA offers two ways

 

  •  GUI mode  HSDB 

  •  Command line  CLIHSDB .

 

 

For example, we use GUI, switch to the directory, execute the following command:

 

java -cp sa-jdi.jar sun.jvm.hotspot. HSDB

 

Attach choose File menu under to HotSpot Process, Java can enter pid process.

 

At this point, you will see threads of a process are demonstrated in the list.

 

 

 A series of icons at the top, you can view information about the selected thread, for example, can be Inspect, view the structure of VM-level thread object, select Stack Memory, view the data stack contains address information.

 

Followed by Jstack To get the Stack Trace.

 

In the Tools menu, there are a range of tools.

 

 

We choose a few to briefly introduce the next.

 

Class Browser

 

Through this, you can see all the JVM class loading. A method corresponding to the class information can be found naturally. It also supports the local to a class dump. For some this can only be analyzed through the core problem files can be analyzed to get the class.

Operation is simple, find the corresponding class, create class click on OK, class lib directory to the next generation.

 

 

 

Find Object by Query

 

This feature is similar to SQL and, in the text box object to be queried

Such as this:

 

select t from java.lang.Thread t 

 

 

 

Code Viewer

 

For methods within a class, sometimes need to analyze square method or the JVM instructions JIT compiler may use this tool, the address entered in the Class Method or will see the contents of the corresponding

 

 

Find Value in Heap

 

The tool can be a problem when similar GC, by specifying the address of an object to see if there are objects in the Heap.

 

 

Like the sword has longevity Baiyu Jing, many times in the big triumph in battle.

 

By SA, we are not only able to analyze Java application-level stuff, but some of the JVM level, even JIT compiler approach, GC whether recycled object, can easily understand that if a JVM microscope to assist in the SA under , problems are nowhere to hide.

 

Related Reading

80% of programmers do not understand debugging techniques

When we talk Debug, what are we talking about (Debug implementation principle)

Class loader and class conflict

 

 

I think this paper help you? Share more people to support it, thank you

Watch "  Tomcat that thing   "  , find more excellent article! Understand the principles behind and answers to frequently asked questions. Source depth analysis of the details, original content, welcome attention.

Published 56 original articles · won praise 0 · Views 7761

Guess you like

Origin blog.csdn.net/chainhou/article/details/105007766