1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
49 private static final Map<String, PoolRecord> result = new HashMap<>();
50 private static boolean trace = false;
51 private static volatile int numMemoryPools = 1;
52 private static final int NUM_GCS = 3;
53 private static final int THRESHOLD = 10;
54 private static volatile int numGCs = 0;
55
56 // semaphore to signal the arrival of a low memory notification
57 private static final Semaphore signals = new Semaphore(0);
58 // barrier for the main thread to wait until the checker thread
59 // finishes checking the low memory notification result
60 private static final CyclicBarrier barrier = new CyclicBarrier(2);
61
62 /**
63 * Run the test multiple times with different GC versions.
64 * First with default command line specified by the framework.
65 * Then with GC versions specified by the test.
66 */
67 public static void main(String a[]) throws Throwable {
68 final String main = "CollectionUsageThreshold$TestMain";
69 RunUtil.runTestKeepGcOpts(main);
70 RunUtil.runTestClearGcOpts(main, "-XX:+UseSerialGC");
71 RunUtil.runTestClearGcOpts(main, "-XX:+UseParallelGC");
72 RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC");
73 RunUtil.runTestClearGcOpts(main, "-XX:+UseConcMarkSweepGC");
74 }
75
76 static class PoolRecord {
77 private final MemoryPoolMXBean pool;
78 private final AtomicInteger listenerInvoked = new AtomicInteger(0);
79 private volatile long notifCount = 0;
80 PoolRecord(MemoryPoolMXBean p) {
81 this.pool = p;
82 }
83 int getListenerInvokedCount() {
84 return listenerInvoked.get();
85 }
86 long getNotifCount() {
87 return notifCount;
88 }
89 MemoryPoolMXBean getPool() {
90 return pool;
91 }
92 void addNotification(MemoryNotificationInfo minfo) {
93 listenerInvoked.incrementAndGet();
|
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
49 private static final Map<String, PoolRecord> result = new HashMap<>();
50 private static boolean trace = false;
51 private static volatile int numMemoryPools = 1;
52 private static final int NUM_GCS = 3;
53 private static final int THRESHOLD = 10;
54 private static volatile int numGCs = 0;
55
56 // semaphore to signal the arrival of a low memory notification
57 private static final Semaphore signals = new Semaphore(0);
58 // barrier for the main thread to wait until the checker thread
59 // finishes checking the low memory notification result
60 private static final CyclicBarrier barrier = new CyclicBarrier(2);
61
62 /**
63 * Run the test multiple times with different GC versions.
64 * First with default command line specified by the framework.
65 * Then with GC versions specified by the test.
66 */
67 public static void main(String a[]) throws Throwable {
68 final String main = "CollectionUsageThreshold$TestMain";
69 String[] filterExplicitGCOptions = new String[]{"-XX:\\+ExplicitGCInvokesConcurrent"};
70
71 RunUtil.runTestKeepGcOpts(filterExplicitGCOptions, main);
72 RunUtil.runTestClearGcOpts(filterExplicitGCOptions, main, "-XX:+UseSerialGC");
73 RunUtil.runTestClearGcOpts(filterExplicitGCOptions, main, "-XX:+UseParallelGC");
74 RunUtil.runTestClearGcOpts(filterExplicitGCOptions, main, "-XX:+UseG1GC");
75 RunUtil.runTestClearGcOpts(filterExplicitGCOptions, main, "-XX:+UseConcMarkSweepGC");
76 }
77
78 static class PoolRecord {
79 private final MemoryPoolMXBean pool;
80 private final AtomicInteger listenerInvoked = new AtomicInteger(0);
81 private volatile long notifCount = 0;
82 PoolRecord(MemoryPoolMXBean p) {
83 this.pool = p;
84 }
85 int getListenerInvokedCount() {
86 return listenerInvoked.get();
87 }
88 long getNotifCount() {
89 return notifCount;
90 }
91 MemoryPoolMXBean getPool() {
92 return pool;
93 }
94 void addNotification(MemoryNotificationInfo minfo) {
95 listenerInvoked.incrementAndGet();
|