equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2007, 2013, 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. |
26 * @bug 6546089 |
26 * @bug 6546089 |
27 * @summary Basic unit test of MemoryPoolMXBean.isUsageThresholdExceeded() and |
27 * @summary Basic unit test of MemoryPoolMXBean.isUsageThresholdExceeded() and |
28 * MemoryPoolMXBean.isCollectionThresholdExceeded(). |
28 * MemoryPoolMXBean.isCollectionThresholdExceeded(). |
29 * @author Mandy Chung |
29 * @author Mandy Chung |
30 * |
30 * |
31 * @run main ThresholdTest |
31 * @run main/othervm ThresholdTest |
32 */ |
32 */ |
33 |
33 |
34 import java.lang.management.*; |
34 import java.lang.management.*; |
35 import java.util.*; |
35 import java.util.*; |
36 |
36 |
37 public class ThresholdTest { |
37 public class ThresholdTest { |
38 public static void main(String args[]) throws Exception { |
38 public static void main(String args[]) throws Exception { |
|
39 long[] bigObject = new long[1000000]; |
|
40 |
|
41 System.gc(); // force an initial full-gc |
39 List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
42 List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
40 try { |
43 try { |
41 for (MemoryPoolMXBean p : pools) { |
44 for (MemoryPoolMXBean p : pools) { |
42 // verify if isUsageThresholdExceeded() returns correct value |
45 // verify if isUsageThresholdExceeded() returns correct value |
43 checkUsageThreshold(p); |
46 checkUsageThreshold(p); |
80 " isUsageThresholdExceeded() returned true" + |
83 " isUsageThresholdExceeded() returned true" + |
81 " but threshold = 0"); |
84 " but threshold = 0"); |
82 } |
85 } |
83 |
86 |
84 p.setUsageThreshold(1); |
87 p.setUsageThreshold(1); |
|
88 // force a full gc to minimize the likelihood of running GC |
|
89 // between getting the usage and checking the threshold |
|
90 System.gc(); |
|
91 |
85 MemoryUsage u = p.getUsage(); |
92 MemoryUsage u = p.getUsage(); |
86 if (u.getUsed() >= 1) { |
93 if (u.getUsed() >= 1) { |
87 if (!p.isUsageThresholdExceeded()) { |
94 if (!p.isUsageThresholdExceeded()) { |
88 throw new RuntimeException("TEST FAILED: " + |
95 throw new RuntimeException("TEST FAILED: " + |
89 "Pool " + p.getName() + |
96 "Pool " + p.getName() + |