8196325: GarbageCollectionNotificationInfo has same information for before and after
Reviewed-by: mchung, sspitsyn
This commit is contained in:
parent
93691571bc
commit
3b923d063e
src
java.management/share/classes/sun/management
jdk.management/share/classes/com/sun/management/internal
test/jdk/com/sun/management/GarbageCollectorMXBean
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -47,6 +47,7 @@ import java.util.List;
|
||||
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -162,6 +163,16 @@ public class ManagementFactoryHelper {
|
||||
return LoggingMXBeanAccess.isAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the name of all memory pools. The order of the memory pools is
|
||||
* significant and maintained in the VM.
|
||||
*/
|
||||
public static String[] getAllMemoryPoolNames() {
|
||||
return Arrays.stream(MemoryImpl.getMemoryPools())
|
||||
.map(MemoryPoolMXBean::getName)
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
|
||||
// The LoggingMXBeanAccess class uses reflection to determine
|
||||
// whether java.util.logging is present, and load the actual LoggingMXBean
|
||||
// implementation.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,7 +28,6 @@ package com.sun.management.internal;
|
||||
import com.sun.management.GarbageCollectionNotificationInfo;
|
||||
import com.sun.management.GarbageCollectorMXBean;
|
||||
import com.sun.management.GcInfo;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryPoolMXBean;
|
||||
import java.util.List;
|
||||
import javax.management.ListenerNotFoundException;
|
||||
@ -38,6 +37,7 @@ import javax.management.NotificationFilter;
|
||||
import javax.management.NotificationListener;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import sun.management.GarbageCollectorImpl;
|
||||
import sun.management.ManagementFactoryHelper;
|
||||
|
||||
/**
|
||||
* Implementation class for the garbage collector.
|
||||
@ -59,12 +59,8 @@ public class GarbageCollectorExtImpl extends GarbageCollectorImpl
|
||||
private String[] poolNames = null;
|
||||
private synchronized String[] getAllPoolNames() {
|
||||
if (poolNames == null) {
|
||||
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
|
||||
poolNames = new String[pools.size()];
|
||||
int i = 0;
|
||||
for (MemoryPoolMXBean m : pools) {
|
||||
poolNames[i++] = m.getName();
|
||||
}
|
||||
// The order of all memory pool names is important as GcInfo is also created with same order.
|
||||
poolNames = ManagementFactoryHelper.getAllMemoryPoolNames();
|
||||
}
|
||||
return poolNames;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -29,8 +29,8 @@
|
||||
* @requires vm.opt.ExplicitGCInvokesConcurrent == null | vm.opt.ExplicitGCInvokesConcurrent == false
|
||||
* @modules java.management/sun.management
|
||||
* jdk.management
|
||||
* @run main/othervm GarbageCollectionNotificationContentTest
|
||||
*/
|
||||
* @run main/othervm -Xms64m -Xmx64m GarbageCollectionNotificationContentTest
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import java.lang.management.*;
|
||||
@ -97,7 +97,7 @@ public class GarbageCollectionNotificationContentTest {
|
||||
System.gc();
|
||||
// Allocation of many short living and small objects to trigger minor GC
|
||||
Object data[] = new Object[32];
|
||||
for(int i = 0; i<100000000; i++) {
|
||||
for(int i = 0; i<10000000; i++) {
|
||||
data[i%32] = new int[8];
|
||||
}
|
||||
int wakeup = 0;
|
||||
@ -139,6 +139,8 @@ public class GarbageCollectionNotificationContentTest {
|
||||
System.out.println("Usage for pool " + poolname);
|
||||
System.out.println(" Before GC: " + busage);
|
||||
System.out.println(" After GC: " + ausage);
|
||||
|
||||
checkMemoryUsage(poolname, busage, ausage);
|
||||
}
|
||||
|
||||
// check if memory usage for all memory pools are returned
|
||||
@ -150,4 +152,13 @@ public class GarbageCollectionNotificationContentTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkMemoryUsage(String poolname, MemoryUsage busage, MemoryUsage ausage) throws Exception {
|
||||
if (poolname.contains("Eden Space") && busage.getUsed() > 0) {
|
||||
// Used size at Eden Space should be decreased or
|
||||
if (busage.getUsed() <= ausage.getUsed()) {
|
||||
throw new RuntimeException("Used size at Eden Space should be decreased.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user