有 Java 编程相关的问题?

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

java为什么在第一个gc之前有一个未卸载的完整gc,在gc调用之前的堆=0(完整1)?

我在gc日志中发现了一个奇怪的东西。它显示在第一次gc之前(正如我们在日志中看到的,它是次要的gc),已经触发了一个完整的gc

该应用程序使用CMS gc collector在java 8中运行

OpenJDK 64-Bit Server VM (25.232-b04) for linux-amd64 JRE (1.8.0_232-b04), built on Sep 24 2019 10:14:17 by "root" with gcc 4.8.5
Memory: 4k page, physical 98726220k(2969212k free), swap 0k(0k free)
CommandLine flags: -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:InitialHeapSize=2147483648 -XX:LargePageSizeInBytes=134217728 -XX:+ManagementServer -XX:MaxHeapSize=2147483648 -XX:MaxNewSize=715829248 -XX:MaxTenuringThreshold=6 -XX:NewSize=715829248 -XX:OldPLABSize=16 -XX:OldSize=1431654400 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:ThreadStackSize=256 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseFastAccessorMethods -XX:+UseParNewGC 
2020-04-29T11:05:44.412+0800: 2.088: [GC (CMS Initial Mark) [1 CMS-initial-mark: 0K(1398144K)] 549082K(2027264K), 0.2121146 secs] [Times: user=0.21 sys=0.00, real=0.21 secs] 
2020-04-29T11:05:44.625+0800: 2.300: [CMS-concurrent-mark-start]
2020-04-29T11:05:44.626+0800: 2.301: [CMS-concurrent-mark: 0.001/0.001 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
2020-04-29T11:05:44.626+0800: 2.301: [CMS-concurrent-preclean-start]
2020-04-29T11:05:44.629+0800: 2.304: [CMS-concurrent-preclean: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2020-04-29T11:05:44.629+0800: 2.304: [CMS-concurrent-abortable-preclean-start]
{Heap before GC invocations=0 (full 1):
 par new generation   total 629120K, used 559232K [0x0000000080000000, 0x00000000aaaa0000, 0x00000000aaaa0000)
  eden space 559232K, 100% used [0x0000000080000000, 0x00000000a2220000, 0x00000000a2220000)
  from space 69888K,   0% used [0x00000000a2220000, 0x00000000a2220000, 0x00000000a6660000)
  to   space 69888K,   0% used [0x00000000a6660000, 0x00000000a6660000, 0x00000000aaaa0000)
 concurrent mark-sweep generation total 1398144K, used 0K [0x00000000aaaa0000, 0x0000000100000000, 0x0000000100000000)
 Metaspace       used 34529K, capacity 35407K, committed 35572K, reserved 1081344K
  class space    used 4175K, capacity 4382K, committed 4440K, reserved 1048576K
2020-04-29T11:05:44.679+0800: 2.354: [GC (Allocation Failure) 2020-04-29T11:05:44.679+0800: 2.354: [ParNew: 559232K->42422K(629120K), 0.0639801 secs] 559232K->42422K(2027264K), 0.0640614 secs] [Times: user=0.41 sys=0.76, real=0.07 secs] 
Heap after GC invocations=1 (full 1):
 par new generation   total 629120K, used 42422K [0x0000000080000000, 0x00000000aaaa0000, 0x00000000aaaa0000)
  eden space 559232K,   0% used [0x0000000080000000, 0x0000000080000000, 0x00000000a2220000)
  from space 69888K,  60% used [0x00000000a6660000, 0x00000000a8fcd840, 0x00000000aaaa0000)
  to   space 69888K,   0% used [0x00000000a2220000, 0x00000000a2220000, 0x00000000a6660000)
 concurrent mark-sweep generation total 1398144K, used 0K [0x00000000aaaa0000, 0x0000000100000000, 0x0000000100000000)
 Metaspace       used 34529K, capacity 35407K, committed 35572K, reserved 1081344K
  class space    used 4175K, capacity 4382K, committed 4440K, reserved 1048576K
}
2020-04-29T11:05:46.060+0800: 3.736: [CMS-concurrent-abortable-preclean: 1.196/1.432 secs] [Times: user=7.10 sys=0.87, real=1.43 secs] 
2020-04-29T11:05:46.060+0800: 3.736: [GC (CMS Final Remark) [YG occupancy: 337273 K (629120 K)]2020-04-29T11:05:46.060+0800: 3.736: [Rescan (parallel) , 0.0166530 secs]2020-04-29T11:05:46.077+0800: 3.753: [weak refs processing, 0.0000398 secs]2020-04-29T11:05:46.077+0800: 3.753: [class unloading, 0.0089091 secs]2020-04-29T11:05:46.086+0800: 3.762: [scrub symbol table, 0.0101553 secs]2020-04-29T11:05:46.096+0800: 3.772: [scrub string table, 0.0007144 secs][1 CMS-remark: 0K(1398144K)] 337273K(2027264K), 0.0385882 secs] [Times: user=0.48 sys=0.00, real=0.04 secs] 
2020-04-29T11:05:46.099+0800: 3.775: [CMS-concurrent-sweep-start]
2020-04-29T11:05:46.099+0800: 3.775: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2020-04-29T11:05:46.099+0800: 3.775: [CMS-concurrent-reset-start]
2020-04-29T11:05:46.113+0800: 3.788: [CMS-concurrent-reset: 0.014/0.014 secs] [Times: user=0.07 sys=0.00, real=0.02 secs] 

在我做了一些在线搜索之后,我认为这是由元空间大小问题引起的。因此,我用-XX:MetaspaceSize=128m为元空间设置了一个较大的大小,完整的gc就消失了

OpenJDK 64-Bit Server VM (25.232-b04) for linux-amd64 JRE (1.8.0_232-b04), built on Sep 24 2019 10:14:17 by "root" with gcc 4.8.5
Memory: 4k page, physical 98726220k(2957504k free), swap 0k(0k free)
CommandLine flags: -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:InitialHeapSize=2147483648 -XX:LargePageSizeInBytes=134217728 -XX:+ManagementServer -XX:MaxHeapSize=2147483648 -XX:MaxNewSize=715829248 -XX:MaxTenuringThreshold=6 -XX:MetaspaceSize=134217728 -XX:NewSize=715829248 -XX:OldPLABSize=16 -XX:OldSize=1431654400 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:ThreadStackSize=256 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseFastAccessorMethods -XX:+UseParNewGC 
{Heap before GC invocations=0 (full 0):
 par new generation   total 629120K, used 559232K [0x0000000080000000, 0x00000000aaaa0000, 0x00000000aaaa0000)
  eden space 559232K, 100% used [0x0000000080000000, 0x00000000a2220000, 0x00000000a2220000)
  from space 69888K,   0% used [0x00000000a2220000, 0x00000000a2220000, 0x00000000a6660000)
  to   space 69888K,   0% used [0x00000000a6660000, 0x00000000a6660000, 0x00000000aaaa0000)
 concurrent mark-sweep generation total 1398144K, used 0K [0x00000000aaaa0000, 0x0000000100000000, 0x0000000100000000)
 Metaspace       used 34127K, capacity 35034K, committed 35200K, reserved 1079296K
  class space    used 4184K, capacity 4410K, committed 4480K, reserved 1048576K
2020-04-29T10:16:16.735+0800: 2.189: [GC (Allocation Failure) 2020-04-29T10:16:16.735+0800: 2.189: [ParNew: 559232K->42224K(629120K), 0.0639467 secs] 559232K->42224K(2027264K), 0.0640639 secs] [Times: user=0.48 sys=0.88, real=0.06 secs] 
Heap after GC invocations=1 (full 0):
 par new generation   total 629120K, used 42224K [0x0000000080000000, 0x00000000aaaa0000, 0x00000000aaaa0000)
  eden space 559232K,   0% used [0x0000000080000000, 0x0000000080000000, 0x00000000a2220000)
  from space 69888K,  60% used [0x00000000a6660000, 0x00000000a8f9c0a8, 0x00000000aaaa0000)
  to   space 69888K,   0% used [0x00000000a2220000, 0x00000000a2220000, 0x00000000a6660000)
 concurrent mark-sweep generation total 1398144K, used 0K [0x00000000aaaa0000, 0x0000000100000000, 0x0000000100000000)
 Metaspace       used 34127K, capacity 35034K, committed 35200K, reserved 1079296K
  class space    used 4184K, capacity 4410K, committed 4480K, reserved 1048576K
}

我的问题是:

  1. 为什么会有未标记的gc?我怎样才能知道它是如何触发的
  2. 如果这与调整元空间的大小有关,为什么我看不到类似Full GC (Metadata GC Threshold)的日志。这两个有什么不同吗

更新

我还对ParallelGC进行了测试,发现一个完全gc被触发,正如预期的那样,“完全gc(元数据gc阈值)”被记录。并且第一个gc被记录为“{Heap before gc invocations=1(完全0)”

OpenJDK 64-Bit Server VM (25.232-b04) for linux-amd64 JRE (1.8.0_232-b04), built on Sep 24 2019 10:14:17 by "root" with gcc 4.8.5
Memory: 4k page, physical 98726220k(4949696k free), swap 0k(0k free)
CommandLine flags: -XX:+DisableExplicitGC -XX:InitialHeapSize=2147483648 -XX:LargePageSizeInBytes=134217728 -XX:+ManagementServer -XX:MaxHeapSize=2147483648 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:ThreadStackSize=256 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastAccessorMethods -XX:+UseParallelGC 
{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 611840K, used 262425K [0x00000000d5580000, 0x0000000100000000, 0x0000000100000000)
  eden space 524800K, 50% used [0x00000000d5580000,0x00000000e55c6798,0x00000000f5600000)
  from space 87040K, 0% used [0x00000000fab00000,0x00000000fab00000,0x0000000100000000)
  to   space 87040K, 0% used [0x00000000f5600000,0x00000000f5600000,0x00000000fab00000)
 ParOldGen       total 1398272K, used 0K [0x0000000080000000, 0x00000000d5580000, 0x00000000d5580000)
  object space 1398272K, 0% used [0x0000000080000000,0x0000000080000000,0x00000000d5580000)
 Metaspace       used 20773K, capacity 21204K, committed 21296K, reserved 1069056K
  class space    used 2445K, capacity 2598K, committed 2608K, reserved 1048576K
2020-05-06T15:45:09.843+0800: 1.045: [GC (Metadata GC Threshold) [PSYoungGen: 262425K->22590K(611840K)] 262425K->22678K(2010112K), 0.0234524 secs] [Times: user=0.19 sys=0.23, real=0.03 secs] 
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 611840K, used 22590K [0x00000000d5580000, 0x0000000100000000, 0x0000000100000000)
  eden space 524800K, 0% used [0x00000000d5580000,0x00000000d5580000,0x00000000f5600000)
  from space 87040K, 25% used [0x00000000f5600000,0x00000000f6c0f960,0x00000000fab00000)
  to   space 87040K, 0% used [0x00000000fab00000,0x00000000fab00000,0x0000000100000000)
 ParOldGen       total 1398272K, used 88K [0x0000000080000000, 0x00000000d5580000, 0x00000000d5580000)
  object space 1398272K, 0% used [0x0000000080000000,0x0000000080016010,0x00000000d5580000)
 Metaspace       used 20773K, capacity 21204K, committed 21296K, reserved 1069056K
  class space    used 2445K, capacity 2598K, committed 2608K, reserved 1048576K
}
{Heap before GC invocations=2 (full 1):
 PSYoungGen      total 611840K, used 22590K [0x00000000d5580000, 0x0000000100000000, 0x0000000100000000)
  eden space 524800K, 0% used [0x00000000d5580000,0x00000000d5580000,0x00000000f5600000)
  from space 87040K, 25% used [0x00000000f5600000,0x00000000f6c0f960,0x00000000fab00000)
  to   space 87040K, 0% used [0x00000000fab00000,0x00000000fab00000,0x0000000100000000)
 ParOldGen       total 1398272K, used 88K [0x0000000080000000, 0x00000000d5580000, 0x00000000d5580000)
  object space 1398272K, 0% used [0x0000000080000000,0x0000000080016010,0x00000000d5580000)
 Metaspace       used 20773K, capacity 21204K, committed 21296K, reserved 1069056K
  class space    used 2445K, capacity 2598K, committed 2608K, reserved 1048576K
2020-05-06T15:45:09.867+0800: 1.068: [Full GC (Metadata GC Threshold) [PSYoungGen: 22590K->0K(611840K)] [ParOldGen: 88K->21585K(1398272K)] 22678K->21585K(2010112K), [Metaspace: 20773K->20771K(1069056K)], 0.1216866 secs] [Times: user=1.81 sys=0.14, real=0.12 secs] 
Heap after GC invocations=2 (full 1):
 PSYoungGen      total 611840K, used 0K [0x00000000d5580000, 0x0000000100000000, 0x0000000100000000)
  eden space 524800K, 0% used [0x00000000d5580000,0x00000000d5580000,0x00000000f5600000)
  from space 87040K, 0% used [0x00000000f5600000,0x00000000f5600000,0x00000000fab00000)
  to   space 87040K, 0% used [0x00000000fab00000,0x00000000fab00000,0x0000000100000000)
 ParOldGen       total 1398272K, used 21585K [0x0000000080000000, 0x00000000d5580000, 0x00000000d5580000)
  object space 1398272K, 1% used [0x0000000080000000,0x0000000081514778,0x00000000d5580000)
 Metaspace       used 20771K, capacity 21198K, committed 21296K, reserved 1069056K
  class space    used 2445K, capacity 2597K, committed 2608K, reserved 1048576K
}

共 (0) 个答案