Thu, 16 May 2013 12:14:19 -0700
Added tag jdk8-b90 for changeset 1ae0472ff3a0
kevinw@2058 | 1 | /* |
kevinw@2058 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
kevinw@2058 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
kevinw@2058 | 4 | * |
kevinw@2058 | 5 | * This code is free software; you can redistribute it and/or modify it |
kevinw@2058 | 6 | * under the terms of the GNU General Public License version 2 only, as |
kevinw@2058 | 7 | * published by the Free Software Foundation. |
kevinw@2058 | 8 | * |
kevinw@2058 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
kevinw@2058 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
kevinw@2058 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
kevinw@2058 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
kevinw@2058 | 13 | * accompanied this code). |
kevinw@2058 | 14 | * |
kevinw@2058 | 15 | * You should have received a copy of the GNU General Public License version |
kevinw@2058 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
kevinw@2058 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
kevinw@2058 | 18 | * |
kevinw@2058 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
kevinw@2058 | 20 | * or visit www.oracle.com if you need additional information or have any |
kevinw@2058 | 21 | * questions. |
kevinw@2058 | 22 | */ |
kevinw@2058 | 23 | |
kevinw@2058 | 24 | /* |
kevinw@2058 | 25 | * @test Test6581734.java |
kevinw@2058 | 26 | * @bug 6581734 |
kevinw@2058 | 27 | * @summary CMS Old Gen's collection usage is zero after GC which is incorrect |
kevinw@2058 | 28 | * @run main/othervm -Xmx512m -verbose:gc -XX:+UseConcMarkSweepGC Test6581734 |
kevinw@2058 | 29 | * |
kevinw@2058 | 30 | */ |
kevinw@2058 | 31 | import java.util.*; |
kevinw@2058 | 32 | import java.lang.management.*; |
kevinw@2058 | 33 | |
kevinw@2058 | 34 | // 6581734 states that memory pool usage via the mbean is wrong |
kevinw@2058 | 35 | // for CMS (zero, even after a collection). |
kevinw@2058 | 36 | // |
kevinw@2058 | 37 | // 6580448 states that the collection count similarly is wrong |
kevinw@2058 | 38 | // (stays at zero for CMS collections) |
kevinw@2058 | 39 | // -- closed as dup of 6581734 as the same fix resolves both. |
kevinw@2058 | 40 | |
kevinw@2058 | 41 | |
kevinw@2058 | 42 | public class Test6581734 { |
kevinw@2058 | 43 | |
kevinw@2058 | 44 | private String poolName = "CMS"; |
kevinw@2058 | 45 | private String collectorName = "ConcurrentMarkSweep"; |
kevinw@2058 | 46 | |
kevinw@2058 | 47 | public static void main(String [] args) { |
kevinw@2058 | 48 | |
kevinw@2058 | 49 | Test6581734 t = null; |
kevinw@2058 | 50 | if (args.length==2) { |
kevinw@2058 | 51 | t = new Test6581734(args[0], args[1]); |
kevinw@2058 | 52 | } else { |
kevinw@2058 | 53 | System.out.println("Defaulting to monitor CMS pool and collector."); |
kevinw@2058 | 54 | t = new Test6581734(); |
kevinw@2058 | 55 | } |
kevinw@2058 | 56 | t.run(); |
kevinw@2058 | 57 | } |
kevinw@2058 | 58 | |
kevinw@2058 | 59 | public Test6581734(String pool, String collector) { |
kevinw@2058 | 60 | poolName = pool; |
kevinw@2058 | 61 | collectorName = collector; |
kevinw@2058 | 62 | } |
kevinw@2058 | 63 | |
kevinw@2058 | 64 | public Test6581734() { |
kevinw@2058 | 65 | } |
kevinw@2058 | 66 | |
kevinw@2058 | 67 | public void run() { |
kevinw@2058 | 68 | // Use some memory, enough that we expect collections should |
kevinw@2058 | 69 | // have happened. |
kevinw@2058 | 70 | // Must run with options to ensure no stop the world full GC, |
kevinw@2058 | 71 | // but e.g. at least one CMS cycle. |
kevinw@2058 | 72 | allocationWork(300*1024*1024); |
kevinw@2058 | 73 | System.out.println("Done allocationWork"); |
kevinw@2058 | 74 | |
kevinw@2058 | 75 | // Verify some non-zero results are stored. |
kevinw@2058 | 76 | List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
kevinw@2058 | 77 | int poolsFound = 0; |
kevinw@2058 | 78 | int poolsWithStats = 0; |
kevinw@2058 | 79 | for (int i=0; i<pools.size(); i++) { |
kevinw@2058 | 80 | MemoryPoolMXBean pool = pools.get(i); |
kevinw@2058 | 81 | String name = pool.getName(); |
kevinw@2058 | 82 | System.out.println("found pool: " + name); |
kevinw@2058 | 83 | |
kevinw@2058 | 84 | if (name.contains(poolName)) { |
kevinw@2058 | 85 | long usage = pool.getCollectionUsage().getUsed(); |
kevinw@2058 | 86 | System.out.println(name + ": usage after GC = " + usage); |
kevinw@2058 | 87 | poolsFound++; |
kevinw@2058 | 88 | if (usage > 0) { |
kevinw@2058 | 89 | poolsWithStats++; |
kevinw@2058 | 90 | } |
kevinw@2058 | 91 | } |
kevinw@2058 | 92 | } |
kevinw@2058 | 93 | if (poolsFound == 0) { |
kevinw@2058 | 94 | throw new RuntimeException("No matching memory pools found: test with -XX:+UseConcMarkSweepGC"); |
kevinw@2058 | 95 | } |
kevinw@2058 | 96 | |
kevinw@2058 | 97 | List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans(); |
kevinw@2058 | 98 | int collectorsFound = 0; |
kevinw@2058 | 99 | int collectorsWithTime= 0; |
kevinw@2058 | 100 | for (int i=0; i<collectors.size(); i++) { |
kevinw@2058 | 101 | GarbageCollectorMXBean collector = collectors.get(i); |
kevinw@2058 | 102 | String name = collector.getName(); |
kevinw@2058 | 103 | System.out.println("found collector: " + name); |
kevinw@2058 | 104 | if (name.contains(collectorName)) { |
kevinw@2058 | 105 | collectorsFound++; |
kevinw@2058 | 106 | System.out.println(name + ": collection count = " |
kevinw@2058 | 107 | + collector.getCollectionCount()); |
kevinw@2058 | 108 | System.out.println(name + ": collection time = " |
kevinw@2058 | 109 | + collector.getCollectionTime()); |
kevinw@2058 | 110 | if (collector.getCollectionCount() <= 0) { |
kevinw@2058 | 111 | throw new RuntimeException("collection count <= 0"); |
kevinw@2058 | 112 | } |
kevinw@2058 | 113 | if (collector.getCollectionTime() > 0) { |
kevinw@2058 | 114 | collectorsWithTime++; |
kevinw@2058 | 115 | } |
kevinw@2058 | 116 | } |
kevinw@2058 | 117 | } |
kevinw@2058 | 118 | // verify: |
kevinw@2058 | 119 | if (poolsWithStats < poolsFound) { |
kevinw@2058 | 120 | throw new RuntimeException("pools found with zero stats"); |
kevinw@2058 | 121 | } |
kevinw@2058 | 122 | |
kevinw@2058 | 123 | if (collectorsWithTime<collectorsFound) { |
kevinw@2111 | 124 | throw new RuntimeException("collectors found with zero time"); |
kevinw@2058 | 125 | } |
kevinw@2058 | 126 | System.out.println("Test passed."); |
kevinw@2058 | 127 | } |
kevinw@2058 | 128 | |
kevinw@2058 | 129 | public void allocationWork(long target) { |
kevinw@2058 | 130 | |
kevinw@2058 | 131 | long sizeAllocated = 0; |
kevinw@2058 | 132 | List list = new LinkedList(); |
kevinw@2058 | 133 | long delay = 50; |
kevinw@2058 | 134 | long count = 0; |
kevinw@2058 | 135 | |
kevinw@2058 | 136 | while (sizeAllocated < target) { |
kevinw@2058 | 137 | int size = 1024*1024; |
kevinw@2058 | 138 | byte [] alloc = new byte[size]; |
kevinw@2058 | 139 | if (count % 2 == 0) { |
kevinw@2058 | 140 | list.add(alloc); |
kevinw@2058 | 141 | sizeAllocated+=size; |
kevinw@2058 | 142 | System.out.print("."); |
kevinw@2058 | 143 | } |
kevinw@2058 | 144 | try { Thread.sleep(delay); } catch (InterruptedException ie) { } |
kevinw@2058 | 145 | count++; |
kevinw@2058 | 146 | } |
kevinw@2058 | 147 | } |
kevinw@2058 | 148 | |
kevinw@2058 | 149 | } |