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

What is JVM's secret space?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "what is the secret space of JVM". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In software running or program development, sometimes you need to write some temporary files, so where is the directory to write these temporary files? Different software, different languages, and different operating systems are different. In the world of the Java language, because it is a cross-platform language and everyone has different settings, this corresponds to where the temporary files of the current system are, by getting environment variables in the code.

System.getProperty ("java.io.tmpdir").

Apart from the fact that we can use this directory as a temporary directory, is it not necessary for us to use it when we do not write files?

Actually, it's not. This directory is the equivalent of JVM's "secret garden", where virtual machines record a lot of information.

For example, each java process will generate a file corresponding to the process ID in the `process (your own user name) `directory under the temporary directory.

Some people may encounter this problem, the Java program can execute normally, but the process cannot be listed through the jps command. This is generally related to tmpdir, which directly checks whether the corresponding write permission is available and whether the disk is full.

In the future, if you need to provide a list of Java processes, it will be read here whenever you need to execute jps commands or other monitoring and diagnostic applications that need to attach to JVM. And this process file is not an empty file, it has a lot of content.

So our commonly used jstat, as well as the JConsole, JVisualVM, SA and other tools mentioned in our previous articles, will read from this file and then show it.

Where did the contents of the document come from?

This supports the monitoring of JVM, and a piece of memory is specially opened up in the virtual machine to store the data related to these performance statistics, collectively referred to as PerfData, which is why the previous directory is called hsperfdata. With the continuous running of the Java process, those constantly changing monitoring values, the virtual machine will generally map the memory to this file by sharing memory. And refresh to the file when the data changes.

For example, we can use commands to view information about loading classes, as well as some data like gc.

Jstat-class file:////hsperfdata/ jstat-gc file:////hsperfdata/

Not enough, you can try this command to see more monitoring information.

Jstat-J-Djstat.showUnsupported=true-snap pid

The option is enabled by default, and the impact on performance can be ignored. If you want to turn it off, you can use-XX:-UsePerData to operate it.

The JVM parameter is officially described as follows

-XX:+UsePerfData

Enables the perfdata feature. This option is enabled by default to allow JVM monitoring and performance testing. Disabling it suppresses the creation of the hsperfdata_userid directories. To disable the perfdata feature, specify-XX:-UsePerfData.

This file is what we read when we went to JVM through the external monitoring tool attach.

This secret space, which is uniformly managed within JVM through the module of PerfMemory, is responsible for creation, allocation and destruction.

Normally, when JVM exits, the file will be deleted synchronously, but if there is an exception to kill, the file will be retained. The next time a simple command such as jps is executed, as long as the java process is started, it will determine whether the process corresponding to the file in this directory exists, and if not, it will be deleted.

This is the end of "what is the Secret Space of JVM". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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