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 */
23 package nsk.monitoring.stress.lowmem;
24
25 import java.io.OutputStream;
26 import java.io.PrintStream;
27 import java.lang.management.ManagementFactory;
28 import java.lang.management.MemoryMXBean;
29 import java.lang.management.MemoryType;
30 import java.util.LinkedList;
31 import java.util.List;
32 import java.util.concurrent.atomic.AtomicBoolean;
33 import nsk.share.Log;
34 import nsk.share.TestFailure;
35 import nsk.share.gc.GC;
36 import nsk.share.gc.ThreadedGCTest;
37 import nsk.share.gc.gp.GarbageProducer;
38 import nsk.share.gc.gp.array.ByteArrayProducer;
39 import nsk.share.gc.gp.classload.GeneratedClassProducer;
40 import nsk.monitoring.share.*;
41 import nsk.share.test.ExecutionController;
42
43 public class lowmem001 extends ThreadedGCTest {
44
45 // The max heap usage after whih we free memory and restart
46 static final int MAX_HEAP_USAGE = 70;
47 // isOOM is used to stop allocation and free resources
48 // immediately after first OOME
49 // really it could be only if we didn't check usage in time
50 static AtomicBoolean isOOM = new AtomicBoolean(false);
51 static ArgumentHandler argHandler;
52 MemoryMonitor monitor;
53
54 public static void main(String[] args) {
55 argHandler = new ArgumentHandler(args);
56 GC.runTest(new lowmem001(), args);
57 }
58
119 @Override
120 public void run() {
121 ExecutionController stresser = getExecutionController();
122 GeneratedClassProducer gp = new GeneratedClassProducer();
123 while (stresser.continueExecution()) {
124 try {
125 gp.create(0);
126 } catch (OutOfMemoryError e) {
127 // drop 'gc', reset Thresholds and start new iteration
128 monitor.resetThresholds(MemoryType.NON_HEAP);
129 return;
130 }
131 }
132 }
133 };
134
135 class HeapStresser extends Thread {
136
137 final long chunkSize = 512;
138 List storage;
139 GarbageProducer gp = new ByteArrayProducer();
140
141
142 @Override
143 public void run() {
144 storage = new LinkedList();
145 ExecutionController stresser = getExecutionController();
146 MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
147
148 while (stresser.continueExecution()) {
149 try {
150 storage.add(gp.create(chunkSize + new Object().hashCode() % 31));
151 storage.add(gp.create(chunkSize));
152 storage.remove(0);
153 if (isOOM.get() == true || !stresser.continueExecution()) {
154 stresser.finish();
155 storage = null;
156 return;
157 }
158 if (Thread.currentThread().isInterrupted()) {
159 break;
|
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 */
23 package nsk.monitoring.stress.lowmem;
24
25 import java.io.OutputStream;
26 import java.io.PrintStream;
27 import java.lang.management.ManagementFactory;
28 import java.lang.management.MemoryMXBean;
29 import java.lang.management.MemoryType;
30 import java.util.LinkedList;
31 import java.util.List;
32 import java.util.concurrent.atomic.AtomicBoolean;
33 import nsk.share.Log;
34 import nsk.share.TestFailure;
35 import nsk.share.gc.DefaultProducer;
36 import nsk.share.gc.GC;
37 import nsk.share.gc.ThreadedGCTest;
38 import nsk.share.gc.gp.GarbageProducer;
39 import nsk.share.gc.gp.classload.GeneratedClassProducer;
40 import nsk.monitoring.share.*;
41 import nsk.share.test.ExecutionController;
42
43 public class lowmem001 extends ThreadedGCTest {
44
45 // The max heap usage after whih we free memory and restart
46 static final int MAX_HEAP_USAGE = 70;
47 // isOOM is used to stop allocation and free resources
48 // immediately after first OOME
49 // really it could be only if we didn't check usage in time
50 static AtomicBoolean isOOM = new AtomicBoolean(false);
51 static ArgumentHandler argHandler;
52 MemoryMonitor monitor;
53
54 public static void main(String[] args) {
55 argHandler = new ArgumentHandler(args);
56 GC.runTest(new lowmem001(), args);
57 }
58
119 @Override
120 public void run() {
121 ExecutionController stresser = getExecutionController();
122 GeneratedClassProducer gp = new GeneratedClassProducer();
123 while (stresser.continueExecution()) {
124 try {
125 gp.create(0);
126 } catch (OutOfMemoryError e) {
127 // drop 'gc', reset Thresholds and start new iteration
128 monitor.resetThresholds(MemoryType.NON_HEAP);
129 return;
130 }
131 }
132 }
133 };
134
135 class HeapStresser extends Thread {
136
137 final long chunkSize = 512;
138 List storage;
139 GarbageProducer gp = new DefaultProducer();
140
141
142 @Override
143 public void run() {
144 storage = new LinkedList();
145 ExecutionController stresser = getExecutionController();
146 MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
147
148 while (stresser.continueExecution()) {
149 try {
150 storage.add(gp.create(chunkSize + new Object().hashCode() % 31));
151 storage.add(gp.create(chunkSize));
152 storage.remove(0);
153 if (isOOM.get() == true || !stresser.continueExecution()) {
154 stresser.finish();
155 storage = null;
156 return;
157 }
158 if (Thread.currentThread().isInterrupted()) {
159 break;
|