JDK-8175375 : MemoryPoolMXBean.getCollectionUsage() does not works with -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 8,9,11,12
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2017-02-21
  • Updated: 2018-09-27
  • Resolved: 2018-09-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12
12Resolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2~bpo8+1-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)



FULL OS VERSION :
Debian 4.3.0-1-amd64
Microsoft Windows [version 10.0.14393]

A DESCRIPTION OF THE PROBLEM :
When java is started with the options  -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent, the collection usage for the largest heap   (in this case the MBean with object name java.lang:type=MemoryPool,name=G1 Old Gen) returns always 0.
If only one of this options is set, collection usage returns the expected value.

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Compile the Main.java: javac Main.java
2) Run it with and without GC flags:
     java -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent Main
     java -XX:+UseG1GC  Main
     java -XX:+ExplicitGCInvokesConcurrent Main

EXPECTED VERSUS ACTUAL BEHAVIOR :
When started with  -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent, MemoryPoolMXBean.getCollectionUsage().getUsed() always returns 0 else it returns the expected value.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
root@lanzarote:/tmp# java -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent Main
java.lang:type=MemoryPool,name=G1 Old Gen
Collection usage = 0, usage = 51,765,344
Collection usage = 0, usage = 104,388,048
Collection usage = 0, usage = 156,762,032
Collection usage = 0, usage = 209,167,296
Collection usage = 0, usage = 261,638,432

root@lanzarote:/tmp# java -XX:+UseG1GC Main
java.lang:type=MemoryPool,name=G1 Old Gen
Collection usage = 52,720,512, usage = 52,720,512
Collection usage = 105,256,688, usage = 105,256,688
Collection usage = 157,685,504, usage = 157,685,504
Collection usage = 210,114,320, usage = 210,114,320
Collection usage = 262,543,136, usage = 262,543,136

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryType;
import java.util.ArrayList;
import java.util.List;

public class Main
{

	public static void main(String[] args) throws Exception {
		MemoryPoolMXBean tenuredGenPool = null;
		List<byte[]> data = new ArrayList<>();
		// heuristic to find the tenured pool (largest heap) as seen on
		// http://www.javaspecialists.eu/archive/Issue092.html
		for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
			if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
				tenuredGenPool = pool;
			}
		}
		System.out.println(tenuredGenPool.getObjectName());
		for (int i = 0; i < 5; i++) {
			data.add(new byte[1024 * 1024 * 50]);
			Thread.sleep(100);
			System.gc();
			System.out.println("Collection usage = " + tenuredGenPool.getCollectionUsage().getUsed()
					+ ", usage = " + tenuredGenPool.getUsage().getUsed());
		}
	}
}

---------- END SOURCE ----------


Comments
Please check the detailed evlauation here - http://mail.openjdk.java.net/pipermail/hotspot-gc-dev/2018-September/023203.html
07-09-2018

Issue observed only if both the options used together "-XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent", if used either one of the option problem doesn't appear
22-02-2017

Below are the results == 8uxx - Fail (Including 8u121) 9 ea b157 - Fail ==
22-02-2017

This issue is reproducible both in 8 and 9, Below is the result on 9 ea b 157 ==without using -XX:+ExplicitGCInvokesConcurrent java.lang:type=MemoryPool,name=G1 Old Gen Collection usage = 54648400, usage = 54648400 Collection usage = 108179312, usage = 108179312 Collection usage = 161656688, usage = 161656688 Collection usage = 215134064, usage = 215134064 Collection usage = 268611440, usage = 268611440 == with -XX:+ExplicitGCInvokesConcurrent== -sh-4.1$ /opt/java/jdk-9_ea-157/bin/java -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrent Main java.lang:type=MemoryPool,name=G1 Old Gen Collection usage = 0, usage = 52576256 Collection usage = 0, usage = 106200824 Collection usage = 0, usage = 159626144 Collection usage = 0, usage = 213176528 Collection usage = 0, usage = 266575264
22-02-2017