gpt4 book ai didi

java - 是否可以检测堆外内存泄漏的根源?

转载 作者:行者123 更新时间:2023-12-02 02:07:43 25 4
gpt4 key购买 nike

我一直在开发的一个应用程序显示出大量看似堆外内存的使用情况。

我已将应用程序配置为使用 4096m 的 Xms 和 Xmx。然而,在 PID 上运行 top 显示该进程消耗了机器内存的 9.6%(64gb 机器 -> ~ 6.14g 应用程序占用空间)。 实例存活时间越长,该值似乎会无限增长。驻留大小约为 5.9g。使用 jvisualvm 检查进程,我发现堆使用量约为 1.5GB,并且 GC 模式正常。我已经提取了堆转储和线程转储,没有发现任何异常。

我为该进程提取了一个 pmap。堆大小与应用程序 Xms 和 Xmx 参数一致。堆栈大约为 130Kb。我注意到大量的匿名内存:

00000006c0000000 4195968K 1437248K 1437248K 1437248K      0K rw-p [anon]
00000007c01a0000 1046912K 0K 0K 0K 0K ---p [anon]
00007ff712acd000 230464K 0K 0K 0K 0K ---p [anon]
00007ff7077cb000 148452K 10452K 10452K 10452K 0K rw-p [anon]
00007ff711bdd000 15296K 15224K 15224K 15224K 0K rwxp [anon]
00007ff7109c6000 14924K 14692K 14692K 14692K 0K rw-p [anon]

GC 行为的一些示例:

Java HotSpot(TM) 64-Bit Server VM (25.40-b25) for linux-amd64 JRE (1.8.0_40-b25), built on Feb 10 2015 21:29:53 by "java_re" with gcc 4.3.0 20080428 (Red Hat 4.3.0-8)
Memory: 4k page, physical 65938804k(26225716k free), swap 4200444k(3654604k free)
CommandLine flags: -XX:InitialHeapSize=4294967296 -XX:+ManagementServer -XX:MaxHeapSize=4294967296 -XX:ParallelGCThreads=2 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
2016-06-12T17:24:21.451-0400: 1339.579: [GC (Allocation Failure) [PSYoungGen: 1048576K->33662K(1223168K)] 1048576K->33670K(4019712K), 0.0644541 secs] [Times: user=0.12 sys=0.01, real=0.07 secs]
2016-06-12T18:00:24.301-0400: 3502.429: [GC (Allocation Failure) [PSYoungGen: 1082238K->34800K(1223168K)] 1082246K->34808K(4019712K), 0.0422048 secs] [Times: user=0.08 sys=0.00, real=0.04 secs]
2016-06-12T18:33:27.654-0400: 5485.782: [GC (Allocation Failure) [PSYoungGen: 1083376K->34960K(1223168K)] 1083384K->34968K(4019712K), 0.0382536 secs] [Times: user=0.07 sys=0.00, real=0.04 secs]
2016-06-12T19:06:29.536-0400: 7467.664: [GC (Allocation Failure) [PSYoungGen: 1083536K->34903K(1223168K)] 1083544K->34911K(4019712K), 0.0377560 secs] [Times: user=0.07 sys=0.00, real=0.04 secs]
2016-06-12T19:37:32.785-0400: 9330.912: [GC (Allocation Failure) [PSYoungGen: 1083479K->34512K(1223168K)] 1083487K->34520K(4019712K), 0.0382442 secs] [Times: user=0.07 sys=0.00, real=0.04 secs]
2016-06-12T20:06:35.474-0400: 11073.602: [GC (Allocation Failure) [PSYoungGen: 1083088K->34624K(1362432K)] 1083096K->34632K(4158976K), 0.0445968 secs] [Times: user=0.07 sys=0.01, real=0.04 secs]
2016-06-12T20:45:03.191-0400: 13381.318: [GC (Allocation Failure) [PSYoungGen: 1361216K->6579K(1333248K)] 1361224K->36444K(4129792K), 0.0489775 secs] [Times: user=0.08 sys=0.01, real=0.05 secs]
2016-06-12T21:20:41.637-0400: 15519.764: [GC (Allocation Failure) [PSYoungGen: 1333171K->6080K(1349120K)] 1363036K->36112K(4145664K), 0.0122650 secs] [Times: user=0.01 sys=0.01, real=0.01 secs]
2016-06-12T21:56:05.197-0400: 17643.325: [GC (Allocation Failure) [PSYoungGen: 1313728K->5728K(1313792K)] 1343760K->36072K(4110336K), 0.0107582 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
2016-06-12T22:32:47.264-0400: 19845.391: [GC (Allocation Failure) [PSYoungGen: 1313376K->5728K(1347584K)] 1343720K->36512K(4144128K), 0.0113968 secs] [Times: user=0.03 sys=0.00, real=0.00 secs]

该应用程序大约有 15 个线程。 Sles 11 sp3 机器上的 JVM 是 jdk-1.8.0_40。

我的问题是:

  1. 这似乎是应用程序在堆外大量增长时出现的问题。这样的假设是否安全,还是我错过了什么?

  2. 有没有办法查明内存消耗的来源?

最佳答案

如果您使用 Eclipse,您可以尝试 MAT(内存分析器工具)http://www.eclipse.org/mat/以确定内存消耗来自何处。

关于java - 是否可以检测堆外内存泄漏的根源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37791607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com