Java Tools (jmap,jstack) on Linux source Analysis (i) __ data structure

Source: Internet
Author: User

In our commonly used jstack, Jmap is used to analyze the state of a Java virtual machine by running another virtual machine to track the state of another virtual machine by operating a Java file under the Sun.tools package.


If you were to design a way to track another process, you would usually consider some of these common ways.

The first is to notify the process that is being tracked, let the process execute the corresponding message, and respond to the message.

The second, through the kernel of the call, can directly access the memory of the process, stack situation, through the analysis of the memory structure of the tracked process, so as to know the status of the process currently being tracked.

The first way

Advantage:

As long as a simple communication protocol is reached between the caller and the callee, the caller does not need to know the logic and structure of the callee, simply send the command, the callee can accept the command, and respond to the command.

Disadvantages:

If the callee's state is inherently abnormal or busy, and there is no way to respond to the command, the tracking process is often in the specified wait time, unable to return the correct required information. Secondly, in the process of analysis, the caller may need to suspend other threads in the process and have some influence on the process being tracked.

The second way

Advantage:

Through kernel support, access to tracked memory, and snapshots, background analysis, rarely affect the process being tracked.

Disadvantages:

This approach requires a very good understanding of the memory allocation and use of the tracked process, which cannot be decoupled, and the system kernel calls are problematic.


The Java tool class is also roughly implemented in these 2 ways, in which the first option is selected, and if the first is found to be unsuccessful, the-f parameter, the second method, will be recommended.

Let's talk about the first way first.

Since it is necessary to send commands to the process of being tracked, there are many ways in Linux to communicate shared memory in the process, files, and so on, where the creation of sockets of the file implementation of communication is a relatively simple method.

Here's the whole flowchart:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.