1 /*
2 * Copyright (c) 2003, 2016, 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 */
65 MemoryNotificationInfo minfo = MemoryNotificationInfo.
66 from((CompositeData) notif.getUserData());
67
68 MemoryUtil.printMemoryNotificationInfo(minfo, type);
69 listenerInvoked++;
70 }
71 }
72 }
73
74 private static long newThreshold;
75 public static void main(String args[]) throws Exception {
76 if (args.length > 0 && args[0].equals("trace")) {
77 trace = true;
78 }
79
80 if (trace) {
81 MemoryUtil.printMemoryPools(pools);
82 MemoryUtil.printMemoryManagers(managers);
83 }
84
85 // Find the Old generation which supports low memory detection
86 ListIterator iter = pools.listIterator();
87 while (iter.hasNext()) {
88 MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
89 if (p.getType() == MemoryType.HEAP &&
90 p.isUsageThresholdSupported()) {
91 mpool = p;
92 if (trace) {
93 System.out.println("Selected memory pool for low memory " +
94 "detection.");
95 MemoryUtil.printMemoryPool(mpool);
96 }
97 break;
98 }
99 }
100
101 SensorListener listener = new SensorListener();
102 NotificationEmitter emitter = (NotificationEmitter) mm;
103 emitter.addNotificationListener(listener, null, null);
104
105 Thread allocator = new AllocatorThread();
106
107 // The chunk size needs to be larger than YOUNG_GEN_SIZE,
108 // otherwise we will get intermittent failures when objects
109 // end up in the young gen instead of the old gen.
110 final long epsilon = 1024;
111 chunkSize = YOUNG_GEN_SIZE + epsilon;
112
113 // Now set threshold
114 MemoryUsage mu = mpool.getUsage();
115 newThreshold = mu.getUsed() + (chunkSize * NUM_CHUNKS);
116
117 // Sanity check. Make sure the new threshold isn't too large.
118 // Tweak the test if this fails.
119 final long headRoom = chunkSize * 2;
|
1 /*
2 * Copyright (c) 2003, 2018, 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 */
65 MemoryNotificationInfo minfo = MemoryNotificationInfo.
66 from((CompositeData) notif.getUserData());
67
68 MemoryUtil.printMemoryNotificationInfo(minfo, type);
69 listenerInvoked++;
70 }
71 }
72 }
73
74 private static long newThreshold;
75 public static void main(String args[]) throws Exception {
76 if (args.length > 0 && args[0].equals("trace")) {
77 trace = true;
78 }
79
80 if (trace) {
81 MemoryUtil.printMemoryPools(pools);
82 MemoryUtil.printMemoryManagers(managers);
83 }
84
85 // Find a pool which which supports low memory detection
86 ListIterator iter = pools.listIterator();
87 while (iter.hasNext()) {
88 MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
89 // Only check heap pools that support a usage threshold.
90 // This is typically only the old generation space
91 // since the other spaces are expected to get filled up.
92 if (p.getType() == MemoryType.HEAP &&
93 p.isUsageThresholdSupported()) {
94 // In all collectors except G1, only the old generation supports a
95 // usage threshold. The G1 legacy mode "G1 Old Gen" also does. In
96 // G1 default mode, both the old space ("G1 Old Space": it's not
97 // really a generation in the non-G1 collector sense) and the
98 // humongous space ("G1 Humongous Space"), support a usage threshold.
99 // So, the following condition is true for all non-G1 old generations,
100 // for the G1 legacy old gen, and for the G1 default humongous space.
101 // It is not true for the G1 default old gen.
102 //
103 // We're allocating humongous objects in this test, so the G1 default
104 // mode "G1 Old Space" occupancy doesn't change, because humongous
105 // objects are allocated in the "G1 Humongous Space". If we allowed
106 // the G1 default mode "G1 Old Space", notification would never
107 // happen because no objects are allocated there.
108 if (!p.getName().equals("G1 Old Space")) {
109 mpool = p;
110 if (trace) {
111 System.out.println("Selected memory pool for low memory " +
112 "detection.");
113 MemoryUtil.printMemoryPool(mpool);
114 }
115 break;
116 }
117 }
118 }
119 if (mpool == null) {
120 throw new RuntimeException("TEST FAILED: No heap pool found");
121 }
122
123 SensorListener listener = new SensorListener();
124 NotificationEmitter emitter = (NotificationEmitter) mm;
125 emitter.addNotificationListener(listener, null, null);
126
127 Thread allocator = new AllocatorThread();
128
129 // The chunk size needs to be larger than YOUNG_GEN_SIZE,
130 // otherwise we will get intermittent failures when objects
131 // end up in the young gen instead of the old gen.
132 final long epsilon = 1024;
133 chunkSize = YOUNG_GEN_SIZE + epsilon;
134
135 // Now set threshold
136 MemoryUsage mu = mpool.getUsage();
137 newThreshold = mu.getUsed() + (chunkSize * NUM_CHUNKS);
138
139 // Sanity check. Make sure the new threshold isn't too large.
140 // Tweak the test if this fails.
141 final long headRoom = chunkSize * 2;
|