test/gc/TestMemoryMXBeansAndPoolsPresence.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 9608
4b8584c24ff4
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

phh@9608 1 /*
phh@9608 2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
phh@9608 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
phh@9608 4 *
phh@9608 5 * This code is free software; you can redistribute it and/or modify it
phh@9608 6 * under the terms of the GNU General Public License version 2 only, as
phh@9608 7 * published by the Free Software Foundation.
phh@9608 8 *
phh@9608 9 * This code is distributed in the hope that it will be useful, but WITHOUT
phh@9608 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
phh@9608 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
phh@9608 12 * version 2 for more details (a copy is included in the LICENSE file that
phh@9608 13 * accompanied this code).
phh@9608 14 *
phh@9608 15 * You should have received a copy of the GNU General Public License version
phh@9608 16 * 2 along with this work; if not, write to the Free Software Foundation,
phh@9608 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
phh@9608 18 *
phh@9608 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
phh@9608 20 * or visit www.oracle.com if you need additional information or have any
phh@9608 21 * questions.
phh@9608 22 */
phh@9608 23
phh@9608 24 /* @test TestMemoryMXBeansAndPoolsPresence
phh@9608 25 * @key gc
phh@9608 26 * @bug 8191564
phh@9608 27 * @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.
phh@9608 28 * @library /testlibrary
phh@9608 29 * @requires vm.gc == null
phh@9608 30 * @run main/othervm -XX:+UseParallelGC TestMemoryMXBeansAndPoolsPresence Parallel
phh@9608 31 * @run main/othervm -XX:+UseSerialGC TestMemoryMXBeansAndPoolsPresence Serial
phh@9608 32 * @run main/othervm -XX:+UseConcMarkSweepGC TestMemoryMXBeansAndPoolsPresence CMS
phh@9608 33 * @run main/othervm -XX:+UseG1GC TestMemoryMXBeansAndPoolsPresence G1
phh@9608 34 */
phh@9608 35
phh@9608 36 import java.util.List;
phh@9608 37 import java.util.ArrayList;
phh@9608 38 import java.lang.management.*;
phh@9608 39 import java.util.stream.*;
phh@9608 40
phh@9608 41 import com.oracle.java.testlibrary.Asserts;
phh@9608 42
phh@9608 43 class GCBeanDescription {
phh@9608 44 public String name;
phh@9608 45 public String[] poolNames;
phh@9608 46
phh@9608 47 public GCBeanDescription(String name, String[] poolNames) {
phh@9608 48 this.name = name;
phh@9608 49 this.poolNames = poolNames;
phh@9608 50 }
phh@9608 51 }
phh@9608 52
phh@9608 53 public class TestMemoryMXBeansAndPoolsPresence {
phh@9608 54 public static void test(GCBeanDescription... expectedBeans) {
phh@9608 55 List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
phh@9608 56
phh@9608 57 List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
phh@9608 58 Asserts.assertEQ(expectedBeans.length, gcBeans.size());
phh@9608 59
phh@9608 60 for (GCBeanDescription desc : expectedBeans) {
phh@9608 61 List<GarbageCollectorMXBean> beans = gcBeans.stream()
phh@9608 62 .filter(b -> b.getName().equals(desc.name))
phh@9608 63 .collect(Collectors.toList());
phh@9608 64 Asserts.assertEQ(beans.size(), 1);
phh@9608 65
phh@9608 66 GarbageCollectorMXBean bean = beans.get(0);
phh@9608 67 Asserts.assertEQ(desc.name, bean.getName());
phh@9608 68
phh@9608 69 String[] pools = bean.getMemoryPoolNames();
phh@9608 70 Asserts.assertEQ(desc.poolNames.length, pools.length);
phh@9608 71 for (int i = 0; i < desc.poolNames.length; i++) {
phh@9608 72 Asserts.assertEQ(desc.poolNames[i], pools[i]);
phh@9608 73 }
phh@9608 74 }
phh@9608 75 }
phh@9608 76
phh@9608 77 public static void main(String[] args) {
phh@9608 78 switch (args[0]) {
phh@9608 79 case "G1":
phh@9608 80 test(new GCBeanDescription("G1 Young Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}),
phh@9608 81 new GCBeanDescription("G1 Old Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}));
phh@9608 82 break;
phh@9608 83 case "CMS":
phh@9608 84 test(new GCBeanDescription("ParNew", new String[] {"Par Eden Space", "Par Survivor Space"}),
phh@9608 85 new GCBeanDescription("ConcurrentMarkSweep", new String[] {"Par Eden Space", "Par Survivor Space", "CMS Old Gen"}));
phh@9608 86 break;
phh@9608 87 case "Parallel":
phh@9608 88 test(new GCBeanDescription("PS Scavenge", new String[] {"PS Eden Space", "PS Survivor Space"}),
phh@9608 89 new GCBeanDescription("PS MarkSweep", new String[] {"PS Eden Space", "PS Survivor Space", "PS Old Gen"}));
phh@9608 90 break;
phh@9608 91 case "Serial":
phh@9608 92 test(new GCBeanDescription("Copy", new String[] {"Eden Space", "Survivor Space"}),
phh@9608 93 new GCBeanDescription("MarkSweepCompact", new String[] {"Eden Space", "Survivor Space", "Tenured Gen"}));
phh@9608 94 break;
phh@9608 95 default:
phh@9608 96 Asserts.assertTrue(false);
phh@9608 97 break;
phh@9608 98
phh@9608 99 }
phh@9608 100 }
phh@9608 101 }

mercurial