有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Eclipse内存分析器(MAT):不显示当前正在运行的进程

我试图分析我的一个Java程序(使用Swing)中的内存泄漏,所以我下载了EclipseMat

到目前为止我所做的:

  1. 通过单击Run按钮从Eclipse中运行程序
  2. 切换到内存分析透视图
  3. 在程序运行时选择“从本地运行的VM获取堆转储”

它表明没有进程在运行。基本上是这样的:

此处的图像:MAT : Eclipse is not showing any running process

根据关于SO的大多数回答,您需要通过将其参数设置为-jdkhome:[您的jdk安装的根文件]来配置HPROF jmap转储提供程序

我已经做到了。但我仍然找不到任何正在运行的进程。如果有必要的话,我将JRE与JDK一起安装,而不是单独安装


共 (3) 个答案

  1. # 1 楼答案

    对我来说,我发现了错误 ^路径MemoryAnalyzer-1.10.0.20200225-win32.win32.x86_64\mat\workspace\.metadata\.log
    检查jps:open wincmd并键入jps返回jps不存在
    配置jps到环境的路径

  2. # 2 楼答案

    如果您想要的是堆转储,那么可以使用%JAVA_HOME%/bin/jvisualvm。exe(与JDK一起提供)对进程进行堆转储。然后可以使用MAT、jvisualvm或任何其他工具对其进行分析

  3. # 3 楼答案

    显然,这是一个更深层次的问题,与Windows中的文件夹权限有关

    根据this,本地应用程序可能无法检测到的原因有两个:

    Resolution: This can happen on Windows systems, it's caused by misconfigured jvmstat technology used to detect the running applications. There are two possible causes:

    1. Insufficient permissions for %TMP%\hsperfdata_username folder - make sure you're able to create a file in the directory and eventually update the permissions for full folder access. Alternatively you can just re-create the folder which should automatically set the correct access rights. See see this forums.sun.com thread for more details.

    2. Having %TMP%\hsperfdata_username folder on a FAT disk - by default jvmstat doesn't work on FAT disks due to security restrictions. You can bypass the security check by setting the -XX:+PerfBypassFileSystemCheck flag for both VisualVM and the monitored application. See the JDK bug #5042659 for more details.

    这是因为(according to this thread从上面存档):

    Do you mind cd'*** to the directory that TMP is defined as and see if there is a directory named hsperfdata_ where is your login. That is the directory where the instrumentation buffers are mapped (as shared memory files). Each time a java process starts it should create a file in that directory.

    因此,我从中了解到,Java应该将一个文件写入%TMP%\hsperfdata_<username>文件夹。该文件帮助内存分析器检测Java进程。缺乏适当的权限意味着无法写入文件,并且内存分析器无法检测Java进程

    所以解决方法就是给这个特定文件夹适当的权限