5

我目前正在调查一个有趣的“java.lang.OutOfMemoryError: Metaspace”问题。我认为它“有趣”的原因是因为元空间使用量远小于最大元空间大小(1GB)。堆和 GC 配置是:

OS: Windows Server 2012 R2
Java HotSpot(TM) 64-Bit Server VM (25.92-b14) for windows-amd64 JRE (1.8.0_92-b14), built on Mar 31 2016 21:03:04 by "java_re" with MS VC++ 10.0 (VS2010)
Memory: 4k page, physical 29359668k(24768956k free), swap 37748276k(29744220k free)
CommandLine flags: -XX:CompressedClassSpaceSize=314572800 -XX:GCLogFileSize=104857600 -XX:+HeapDumpOnOutOfMemoryError -XX:InitialHeapSize=4294967296 -XX:InitiatingHeapOccupancyPercent=45 -XX:+ManagementServer -XX:MaxHeapSize=6442450944 -XX:MaxMetaspaceFreeRatio=80 -XX:MaxMetaspaceSize=1073741824 -XX:MetaspaceSize=536870912 -XX:MinMetaspaceFreeRatio=50 -XX:NumberOfGCLogFiles=20  -XX:+PrintAdaptiveSizePolicy -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseGCLogFileRotation -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC -XX:+UseParallelOldGC 

以下是 JVM 崩溃前的最后 6 次 GC 事件:

PSAdaptiveSizePolicy::compute_eden_space_size: costs minor_time: 0.001800 major_cost: 0.000613 mutator_cost: 0.997587 throughput_goal: 0.990000 live_space: 1064594816 free_space: 2587885568 old_eden_size: 1486356480 desired_eden_size: 1443889152
PSAdaptiveSizePolicy::compute_old_gen_free_space: costs minor_time: 0.001800 major_cost: 0.000613 mutator_cost: 0.997587 throughput_goal: 0.990000 live_space: 1095533824 free_space: 2545418240 old_promo_size: 1101529088 desired_promo_size: 1078460416
AdaptiveSizePolicy::old generation size: collection: 1121 (2867855360) -> (2863661056) 
AdaptiveSizeStop: collection: 1121 
[PSYoungGen: 4825K->0K(1456640K)] [ParOldGen: 2799035K->902778K(2796544K)] 2803860K->902778K(4253184K), [Metaspace: 330658K->329502K(614400K)], 1.0547274 secs] [Times: user=3.03 sys=0.00, real=1.06 secs] 
2020-02-05T07:47:01.085-0500: 23601.918: [GC (Allocation Failure) AdaptiveSizePolicy::update_averages:  survived: 55971960  promoted: 8192  overflow: false
AdaptiveSizeStart: 23601.976 collection: 1122 
  avg_survived_padded_avg: 107655896.000000  avg_promoted_padded_avg: 77367808.000000  avg_pretenured_padded_avg: 0.000000  tenuring_thresh: 1  target_size: 108003328
PSAdaptiveSizePolicy::compute_eden_space_size: costs minor_time: 0.001995 major_cost: 0.000613 mutator_cost: 0.997392 throughput_goal: 0.990000 live_space: 1098490112 free_space: 2522349568 old_eden_size: 1443889152 desired_eden_size: 1443364864
AdaptiveSizePolicy::survivor space sizes: collection: 1122 (106954752, 524288) -> (56098816, 108003328) 
AdaptiveSizeStop: collection: 1122 
[PSYoungGen: 1451520K->54660K(1464320K)] 2354298K->957446K(4260864K), 0.0585204 secs] [Times: user=0.14 sys=0.00, real=0.06 secs] 
2020-02-05T07:47:02.815-0500: 23603.648: [GC (Metadata GC Threshold) AdaptiveSizePolicy::update_averages:  survived: 10372288  promoted: 54161296  overflow: false
AdaptiveSizeStart: 23603.701 collection: 1123 
  avg_survived_padded_avg: 104833904.000000  avg_promoted_padded_avg: 84380448.000000  avg_pretenured_padded_avg: 0.000000  tenuring_thresh: 1  target_size: 104857600
PSAdaptiveSizePolicy::compute_eden_space_size: costs minor_time: 0.009104 major_cost: 0.000613 mutator_cost: 0.990283 throughput_goal: 0.990000 live_space: 1096590848 free_space: 2521825280 old_eden_size: 1443364864 desired_eden_size: 1402470400
AdaptiveSizePolicy::survivor space sizes: collection: 1123 (10485760, 56098816) -> (10485760, 104857600) 
AdaptiveSizeStop: collection: 1123 
[PSYoungGen: 221390K->10129K(1379840K)] 1124177K->965807K(4176384K), 0.0625170 secs] [Times: user=0.19 sys=0.00, real=0.06 secs] 
2020-02-05T07:47:02.878-0500: 23603.711: [Full GC (Metadata GC Threshold) AdaptiveSizeStart: 23604.878 collection: 1124 
PSAdaptiveSizePolicy::compute_eden_space_size: costs minor_time: 0.009104 major_cost: 0.012509 mutator_cost: 0.978387 throughput_goal: 0.990000 live_space: 1093844224 free_space: 2480930816 old_eden_size: 1402470400 desired_eden_size: 1520959488
PSAdaptiveSizePolicy::compute_old_gen_free_space: costs minor_time: 0.009104 major_cost: 0.012509 mutator_cost: 0.978387 throughput_goal: 0.990000 live_space: 1097600256 free_space: 2599419904 old_promo_size: 1078460416 desired_promo_size: 1328545792
AdaptiveSizeStop: collection: 1124 
[PSYoungGen: 10129K->0K(1379840K)] [ParOldGen: 955678K->804848K(2796544K)] 965807K->804848K(4176384K), [Metaspace: 336946K->336898K(620544K)], 1.1672615 secs] [Times: user=3.28 sys=0.00, real=1.17 secs] 
2020-02-05T07:47:04.046-0500: 23604.879: [GC (Last ditch collection) AdaptiveSizePolicy::update_averages:  survived: 0  promoted: 0  overflow: false
AdaptiveSizeStart: 23604.893 collection: 1125 
  avg_survived_padded_avg: 103366768.000000  avg_promoted_padded_avg: 82075424.000000  avg_pretenured_padded_avg: 0.000000  tenuring_thresh: 2  target_size: 103809024
PSAdaptiveSizePolicy::compute_eden_space_size: costs minor_time: 0.009750 major_cost: 0.012509 mutator_cost: 0.977741 throughput_goal: 0.990000 live_space: 1095128320 free_space: 2849505280 old_eden_size: 1520959488 desired_eden_size: 1525678080
AdaptiveSizePolicy::survivor space sizes: collection: 1125 (104857600, 10485760) -> (104857600, 103809024) 
AdaptiveSizeStop: collection: 1125 
[PSYoungGen: 0K->0K(1513984K)] 804848K->804848K(4310528K), 0.0142603 secs] [Times: user=0.06 sys=0.00, real=0.01 secs] 
2020-02-05T07:47:04.061-0500: 23604.893: [Full GC (Last ditch collection) AdaptiveSizeStart: 23607.663 collection: 1126 
PSAdaptiveSizePolicy::compute_eden_space_size: costs minor_time: 0.009750 major_cost: 0.258044 mutator_cost: 0.732206 throughput_goal: 0.990000 live_space: 1092903552 free_space: 2854223872 old_eden_size: 1525678080 desired_eden_size: 1456472064
PSAdaptiveSizePolicy::compute_old_gen_free_space: costs minor_time: 0.009750 major_cost: 0.258044 mutator_cost: 0.732206 throughput_goal: 0.990000 live_space: 1093117440 free_space: 2785017856 old_promo_size: 1328545792 desired_promo_size: 1713373184
AdaptiveSizeStop: collection: 1126 
[PSYoungGen: 0K->0K(1513984K)] [ParOldGen: 804848K->787083K(2796544K)] 804848K->787083K(4310528K), [Metaspace: 336962K->328764K(620544K)], 2.7696424 secs] [Times: user=6.91 sys=0.03, real=2.77 secs] 

如果您查看最后一次元空间使用情况,大约是 ~328MB: [Metaspace: 336962K->328764K(620544K)]

根据Java doc:“MaxMetaspaceSize 适用于提交的压缩类空间和其他类元数据空间的总和。”。我还检查了压缩类空间的使用情况,大约是 50MB。

我检查了虚拟内存的使用情况。没有短缺。这就是我感到困惑的地方。如您所见,Metaspace 的使用率小于 MaxMetaspaceSize 的 50%,那么为什么 JVM 正在执行“Last ditch collection”并运行到 OOM?我遇到了一些 JDK 错误吗?也不是那些“一次性”的情况,它每月发生一次/两次。我不确定我是否遗漏了什么,有人可以分享他们的想法吗?

4

0 回答 0