Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/TestMemoryMXBeansAndPoolsPresence.java
32281 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*/2223/* @test TestMemoryMXBeansAndPoolsPresence24* @key gc25* @bug 819156426* @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.27* @library /testlibrary28* @requires vm.gc == null29* @run main/othervm -XX:+UseParallelGC TestMemoryMXBeansAndPoolsPresence Parallel30* @run main/othervm -XX:+UseSerialGC TestMemoryMXBeansAndPoolsPresence Serial31* @run main/othervm -XX:+UseConcMarkSweepGC TestMemoryMXBeansAndPoolsPresence CMS32* @run main/othervm -XX:+UseG1GC TestMemoryMXBeansAndPoolsPresence G133*/3435import java.util.List;36import java.util.ArrayList;37import java.lang.management.*;38import java.util.stream.*;3940import com.oracle.java.testlibrary.Asserts;4142class GCBeanDescription {43public String name;44public String[] poolNames;4546public GCBeanDescription(String name, String[] poolNames) {47this.name = name;48this.poolNames = poolNames;49}50}5152public class TestMemoryMXBeansAndPoolsPresence {53public static void test(GCBeanDescription... expectedBeans) {54List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();5556List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();57Asserts.assertEQ(expectedBeans.length, gcBeans.size());5859for (GCBeanDescription desc : expectedBeans) {60List<GarbageCollectorMXBean> beans = gcBeans.stream()61.filter(b -> b.getName().equals(desc.name))62.collect(Collectors.toList());63Asserts.assertEQ(beans.size(), 1);6465GarbageCollectorMXBean bean = beans.get(0);66Asserts.assertEQ(desc.name, bean.getName());6768String[] pools = bean.getMemoryPoolNames();69Asserts.assertEQ(desc.poolNames.length, pools.length);70for (int i = 0; i < desc.poolNames.length; i++) {71Asserts.assertEQ(desc.poolNames[i], pools[i]);72}73}74}7576public static void main(String[] args) {77switch (args[0]) {78case "G1":79test(new GCBeanDescription("G1 Young Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}),80new GCBeanDescription("G1 Old Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}));81break;82case "CMS":83test(new GCBeanDescription("ParNew", new String[] {"Par Eden Space", "Par Survivor Space"}),84new GCBeanDescription("ConcurrentMarkSweep", new String[] {"Par Eden Space", "Par Survivor Space", "CMS Old Gen"}));85break;86case "Parallel":87test(new GCBeanDescription("PS Scavenge", new String[] {"PS Eden Space", "PS Survivor Space"}),88new GCBeanDescription("PS MarkSweep", new String[] {"PS Eden Space", "PS Survivor Space", "PS Old Gen"}));89break;90case "Serial":91test(new GCBeanDescription("Copy", new String[] {"Eden Space", "Survivor Space"}),92new GCBeanDescription("MarkSweepCompact", new String[] {"Eden Space", "Survivor Space", "Tenured Gen"}));93break;94default:95Asserts.assertTrue(false);96break;9798}99}100}101102103