test/jdk/com/sun/management/GarbageCollectorMXBean/GarbageCollectionNotificationContentTest.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
27 * @summary Check that GarbageCollectionNotification contents are reasonable |
27 * @summary Check that GarbageCollectionNotification contents are reasonable |
28 * @author Frederic Parain |
28 * @author Frederic Parain |
29 * @requires vm.opt.ExplicitGCInvokesConcurrent == null | vm.opt.ExplicitGCInvokesConcurrent == false |
29 * @requires vm.opt.ExplicitGCInvokesConcurrent == null | vm.opt.ExplicitGCInvokesConcurrent == false |
30 * @modules java.management/sun.management |
30 * @modules java.management/sun.management |
31 * jdk.management |
31 * jdk.management |
32 * @run main/othervm GarbageCollectionNotificationContentTest |
32 * @run main/othervm -Xms64m -Xmx64m GarbageCollectionNotificationContentTest |
33 */ |
33 */ |
34 |
34 |
35 import java.util.*; |
35 import java.util.*; |
36 import java.lang.management.*; |
36 import java.lang.management.*; |
37 import java.lang.reflect.*; |
37 import java.lang.reflect.*; |
38 import javax.management.*; |
38 import javax.management.*; |
95 } |
95 } |
96 // Invocation of System.gc() to trigger major GC |
96 // Invocation of System.gc() to trigger major GC |
97 System.gc(); |
97 System.gc(); |
98 // Allocation of many short living and small objects to trigger minor GC |
98 // Allocation of many short living and small objects to trigger minor GC |
99 Object data[] = new Object[32]; |
99 Object data[] = new Object[32]; |
100 for(int i = 0; i<100000000; i++) { |
100 for(int i = 0; i<10000000; i++) { |
101 data[i%32] = new int[8]; |
101 data[i%32] = new int[8]; |
102 } |
102 } |
103 int wakeup = 0; |
103 int wakeup = 0; |
104 synchronized(synchronizer) { |
104 synchronized(synchronizer) { |
105 while(count != number) { |
105 while(count != number) { |
137 " for " + poolname); |
137 " for " + poolname); |
138 } |
138 } |
139 System.out.println("Usage for pool " + poolname); |
139 System.out.println("Usage for pool " + poolname); |
140 System.out.println(" Before GC: " + busage); |
140 System.out.println(" Before GC: " + busage); |
141 System.out.println(" After GC: " + ausage); |
141 System.out.println(" After GC: " + ausage); |
|
142 |
|
143 checkMemoryUsage(poolname, busage, ausage); |
142 } |
144 } |
143 |
145 |
144 // check if memory usage for all memory pools are returned |
146 // check if memory usage for all memory pools are returned |
145 List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
147 List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
146 for (MemoryPoolMXBean p : pools ) { |
148 for (MemoryPoolMXBean p : pools ) { |
148 throw new RuntimeException("GcInfo does not contain " + |
150 throw new RuntimeException("GcInfo does not contain " + |
149 "memory usage for pool " + p.getName()); |
151 "memory usage for pool " + p.getName()); |
150 } |
152 } |
151 } |
153 } |
152 } |
154 } |
|
155 |
|
156 private static void checkMemoryUsage(String poolname, MemoryUsage busage, MemoryUsage ausage) throws Exception { |
|
157 if (poolname.contains("Eden Space") && busage.getUsed() > 0) { |
|
158 // Used size at Eden Space should be decreased or |
|
159 if (busage.getUsed() <= ausage.getUsed()) { |
|
160 throw new RuntimeException("Used size at Eden Space should be decreased."); |
|
161 } |
|
162 } |
|
163 } |
153 } |
164 } |