Path: blob/master/test/hotspot/jtreg/gc/TestMemoryMXBeansAndPoolsPresence.java
40930 views
/*1* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc;2425import java.util.List;26import java.lang.management.*;27import static jdk.test.lib.Asserts.*;28import java.util.stream.*;2930/* @test TestMemoryMXBeansAndPoolsPresenceG131* @bug 819156432* @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.33* @library /test/lib34* @modules java.base/jdk.internal.misc35* java.management36* @requires vm.gc.G137* @run main/othervm -XX:+UseG1GC gc.TestMemoryMXBeansAndPoolsPresence G138*/3940/* @test TestMemoryMXBeansAndPoolsPresenceParallel41* @bug 819156442* @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.43* @library /test/lib44* @modules java.base/jdk.internal.misc45* java.management46* @requires vm.gc.Parallel47* @run main/othervm -XX:+UseParallelGC gc.TestMemoryMXBeansAndPoolsPresence Parallel48*/4950/* @test TestMemoryMXBeansAndPoolsPresenceSerial51* @bug 819156452* @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.53* @library /test/lib54* @modules java.base/jdk.internal.misc55* java.management56* @requires vm.gc.Serial57* @run main/othervm -XX:+UseSerialGC gc.TestMemoryMXBeansAndPoolsPresence Serial58*/5960class GCBeanDescription {61public String name;62public String[] poolNames;6364public GCBeanDescription(String name, String[] poolNames) {65this.name = name;66this.poolNames = poolNames;67}68}6970public class TestMemoryMXBeansAndPoolsPresence {71public static void test(GCBeanDescription... expectedBeans) {72List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();7374List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();75assertEQ(expectedBeans.length, gcBeans.size());7677for (GCBeanDescription desc : expectedBeans) {78List<GarbageCollectorMXBean> beans = gcBeans.stream()79.filter(b -> b.getName().equals(desc.name))80.collect(Collectors.toList());81assertEQ(beans.size(), 1);8283GarbageCollectorMXBean bean = beans.get(0);84assertEQ(desc.name, bean.getName());8586String[] pools = bean.getMemoryPoolNames();87assertEQ(desc.poolNames.length, pools.length);88for (int i = 0; i < desc.poolNames.length; i++) {89assertEQ(desc.poolNames[i], pools[i]);90}91}92}9394public static void main(String[] args) {95switch (args[0]) {96case "G1":97test(new GCBeanDescription("G1 Young Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}),98new GCBeanDescription("G1 Old Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}));99break;100case "Parallel":101test(new GCBeanDescription("PS Scavenge", new String[] {"PS Eden Space", "PS Survivor Space"}),102new GCBeanDescription("PS MarkSweep", new String[] {"PS Eden Space", "PS Survivor Space", "PS Old Gen"}));103break;104case "Serial":105test(new GCBeanDescription("Copy", new String[] {"Eden Space", "Survivor Space"}),106new GCBeanDescription("MarkSweepCompact", new String[] {"Eden Space", "Survivor Space", "Tenured Gen"}));107break;108default:109assertTrue(false);110break;111112}113}114}115116117