Tue, 28 Jan 2014 14:56:01 -0800
Added tag jdk8u5-b06 for changeset 956c0e048ef2
ehelin@5716 | 1 | /* |
ehelin@5716 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
ehelin@5716 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ehelin@5716 | 4 | * |
ehelin@5716 | 5 | * This code is free software; you can redistribute it and/or modify it |
ehelin@5716 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ehelin@5716 | 7 | * published by the Free Software Foundation. |
ehelin@5716 | 8 | * |
ehelin@5716 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ehelin@5716 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ehelin@5716 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ehelin@5716 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ehelin@5716 | 13 | * accompanied this code). |
ehelin@5716 | 14 | * |
ehelin@5716 | 15 | * You should have received a copy of the GNU General Public License version |
ehelin@5716 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ehelin@5716 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ehelin@5716 | 18 | * |
ehelin@5716 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ehelin@5716 | 20 | * or visit www.oracle.com if you need additional information or have any |
ehelin@5716 | 21 | * questions. |
ehelin@5716 | 22 | */ |
ehelin@5716 | 23 | |
ehelin@5716 | 24 | import java.util.List; |
ehelin@5716 | 25 | import java.lang.management.*; |
ehelin@5716 | 26 | |
ehelin@5716 | 27 | import com.oracle.java.testlibrary.*; |
ehelin@5716 | 28 | import static com.oracle.java.testlibrary.Asserts.*; |
ehelin@5716 | 29 | |
ehelin@5716 | 30 | /* @test TestPerfCountersAndMemoryPools |
ehelin@5716 | 31 | * @bug 8023476 |
ehelin@5816 | 32 | * @library /testlibrary |
ehelin@5716 | 33 | * @summary Tests that a MemoryPoolMXBeans and PerfCounters for metaspace |
ehelin@5716 | 34 | * report the same data. |
ehelin@5816 | 35 | * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools |
ehelin@5816 | 36 | * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools |
ehelin@5716 | 37 | */ |
ehelin@5716 | 38 | public class TestPerfCountersAndMemoryPools { |
ehelin@5716 | 39 | public static void main(String[] args) throws Exception { |
ehelin@5716 | 40 | checkMemoryUsage("Metaspace", "sun.gc.metaspace"); |
ehelin@5716 | 41 | |
ehelin@5716 | 42 | if (InputArguments.contains("-XX:+UseCompressedKlassPointers") && Platform.is64bit()) { |
ehelin@5716 | 43 | checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace"); |
ehelin@5716 | 44 | } |
ehelin@5716 | 45 | } |
ehelin@5716 | 46 | |
ehelin@5816 | 47 | private static MemoryPoolMXBean getMemoryPool(String memoryPoolName) { |
ehelin@5716 | 48 | List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
ehelin@5716 | 49 | for (MemoryPoolMXBean pool : pools) { |
ehelin@5716 | 50 | if (pool.getName().equals(memoryPoolName)) { |
ehelin@5816 | 51 | return pool; |
ehelin@5716 | 52 | } |
ehelin@5716 | 53 | } |
ehelin@5716 | 54 | |
ehelin@5716 | 55 | throw new RuntimeException("Excpted to find a memory pool with name " + |
ehelin@5716 | 56 | memoryPoolName); |
ehelin@5716 | 57 | } |
ehelin@5716 | 58 | |
ehelin@5716 | 59 | private static void checkMemoryUsage(String memoryPoolName, String perfNS) |
ehelin@5716 | 60 | throws Exception { |
ehelin@5816 | 61 | MemoryPoolMXBean pool = getMemoryPool(memoryPoolName); |
ehelin@5716 | 62 | |
ehelin@5816 | 63 | // Must do a GC to update performance counters |
ehelin@5716 | 64 | System.gc(); |
ehelin@5816 | 65 | assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit()); |
ehelin@5716 | 66 | |
ehelin@5816 | 67 | // Must do a second GC to update the perfomance counters again, since |
ehelin@5816 | 68 | // the call pool.getUsage().getInit() could have allocated some |
ehelin@5816 | 69 | // metadata. |
ehelin@5716 | 70 | System.gc(); |
ehelin@5816 | 71 | assertEQ(getUsed(perfNS), pool.getUsage().getUsed()); |
ehelin@5816 | 72 | assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted()); |
ehelin@5716 | 73 | } |
ehelin@5716 | 74 | |
ehelin@5716 | 75 | private static long getMinCapacity(String ns) throws Exception { |
ehelin@5716 | 76 | return PerfCounters.findByName(ns + ".minCapacity").longValue(); |
ehelin@5716 | 77 | } |
ehelin@5716 | 78 | |
ehelin@5716 | 79 | private static long getCapacity(String ns) throws Exception { |
ehelin@5716 | 80 | return PerfCounters.findByName(ns + ".capacity").longValue(); |
ehelin@5716 | 81 | } |
ehelin@5716 | 82 | |
ehelin@5716 | 83 | private static long getUsed(String ns) throws Exception { |
ehelin@5716 | 84 | return PerfCounters.findByName(ns + ".used").longValue(); |
ehelin@5716 | 85 | } |
ehelin@5716 | 86 | } |