23 //gctest02.java
24
25
26 /*
27 * @test
28 * @key gc
29 *
30 * @summary converted from VM Testbase gc/gctests/gctest02.
31 * VM Testbase keywords: [gc]
32 *
33 * @library /vmTestbase
34 * /test/lib
35 * @run driver jdk.test.lib.FileInstaller . .
36 * @run main/othervm gc.gctests.gctest02.gctest02 100
37 */
38
39 package gc.gctests.gctest02;
40
41 import nsk.share.TestFailure;
42 import nsk.share.TestBug;
43 /* stress testing
44 create 16 memory evil threads requesting to allocate
45 the object of sizes from 8 to ( 2 ^ 19).
46 The live time of objects is random (0 ~ 1000).
47 Here we let the threads that reference the objects
48 to simulate the object life time.
49 */
50
51 import java.util.Random;
52
53 class PopulationException extends Exception {
54 //this exception is used to signal that we've
55 //reached the end of the test
56 }
57
58 //the LocalRandom class is used to isolate the pseudo-random
59 //number generator from other parts of the system which might
60 //silently be using it.
61 //This is to make sure the tests are repeatable
62
63 class LocalRandom {
64 public static Random rGen = null;
65
66 public static double random() {
67 //should fail if rGen is not initialized
68 return rGen.nextDouble();
69 }
70 }
71
72 class ThreadCount {
73 static int count= 0;
74 static synchronized void inc() { count++; }
75 static synchronized void dec() { count --; }
76 static synchronized int get() { return count; }
77 }
78
79 class Person {
80 String name;
81 int ssid;
82 int age;
83 int buf[];
84 int bufsz;
85 static int populationCount = 0;
86 static int populationLimit = 0;
87
88 Person(String n, int ssid, int age, int bufsz)
89 throws PopulationException {
90 name = n;
91 this.ssid = ssid;
173 //we've reached the population limit, so we're exiting the thread
174 ThreadCount.dec();
175 }
176 }
177
178 class Escaper extends Thread {
179 public void run() {
180 while ( ThreadCount.get() > 0 ) {
181 int buf[] = new int[32];
182 {
183 Thread.yield();
184 }
185 }
186 }
187 }
188
189 public class gctest02 {
190 public static void main(String args[] ) {
191 int bufsz = 8;
192 int peopleLimit = 1000;
193 long randomSeed = System.currentTimeMillis();
194 Memevil me=null;
195 if (args.length > 0)
196 {
197 try
198 {
199 peopleLimit = new Integer(args[0]).intValue();
200 }
201 catch (NumberFormatException e)
202 {
203 throw new TestBug(
204 "Bad input to gctest02. Expected integer, got: ->"
205 + args[0] + "<-", e);
206 }
207 }
208
209 if (args.length == 2)
210 {
211 try
212 {
213 randomSeed = new Long(args[1]).longValue();
214 }
215 catch (NumberFormatException e)
216 {
217 throw new TestBug(
218 "Bad input to gctest02. Expected long, got: ->"
219 + args[0] + "<-", e);
220 }
221 }
222 Person.setPopulationLimit(peopleLimit);
223 System.out.println("Seed value: " + randomSeed);
224 for (int ii=0; ii<40; ii++) {
225 bufsz = 8;
226 LocalRandom.rGen = new Random(randomSeed);
227 Person.populationCount = 0;
228 Escaper you = new Escaper();
229 you.setName("Escaper");
230 ThreadCount.inc();
231 you.start();
232 me = new Memevil(bufsz);
233 me.setName("Memevil" + bufsz);
234 bufsz = 2*bufsz;
235 me.start();
236 Thread.yield();
237 for (int i=1; i<11; i++) {
238 ThreadCount.inc();
239 me = new Memevil(bufsz);
240 me.setName("Memevil" + bufsz);
241 bufsz = 2*bufsz;
242 me.start();
243 Thread.yield();
244 }
245 try {
246 you.join();
|
23 //gctest02.java
24
25
26 /*
27 * @test
28 * @key gc
29 *
30 * @summary converted from VM Testbase gc/gctests/gctest02.
31 * VM Testbase keywords: [gc]
32 *
33 * @library /vmTestbase
34 * /test/lib
35 * @run driver jdk.test.lib.FileInstaller . .
36 * @run main/othervm gc.gctests.gctest02.gctest02 100
37 */
38
39 package gc.gctests.gctest02;
40
41 import nsk.share.TestFailure;
42 import nsk.share.TestBug;
43 import nsk.share.test.LocalRandom;
44
45 /* stress testing
46 create 16 memory evil threads requesting to allocate
47 the object of sizes from 8 to ( 2 ^ 19).
48 The live time of objects is random (0 ~ 1000).
49 Here we let the threads that reference the objects
50 to simulate the object life time.
51 */
52
53 import java.util.Random;
54
55 class PopulationException extends Exception {
56 //this exception is used to signal that we've
57 //reached the end of the test
58 }
59
60 class ThreadCount {
61 static int count= 0;
62 static synchronized void inc() { count++; }
63 static synchronized void dec() { count --; }
64 static synchronized int get() { return count; }
65 }
66
67 class Person {
68 String name;
69 int ssid;
70 int age;
71 int buf[];
72 int bufsz;
73 static int populationCount = 0;
74 static int populationLimit = 0;
75
76 Person(String n, int ssid, int age, int bufsz)
77 throws PopulationException {
78 name = n;
79 this.ssid = ssid;
161 //we've reached the population limit, so we're exiting the thread
162 ThreadCount.dec();
163 }
164 }
165
166 class Escaper extends Thread {
167 public void run() {
168 while ( ThreadCount.get() > 0 ) {
169 int buf[] = new int[32];
170 {
171 Thread.yield();
172 }
173 }
174 }
175 }
176
177 public class gctest02 {
178 public static void main(String args[] ) {
179 int bufsz = 8;
180 int peopleLimit = 1000;
181 Memevil me=null;
182 if (args.length > 0)
183 {
184 try
185 {
186 peopleLimit = new Integer(args[0]).intValue();
187 }
188 catch (NumberFormatException e)
189 {
190 throw new TestBug(
191 "Bad input to gctest02. Expected integer, got: ->"
192 + args[0] + "<-", e);
193 }
194 }
195
196 Person.setPopulationLimit(peopleLimit);
197 for (int ii=0; ii<40; ii++) {
198 bufsz = 8;
199 Person.populationCount = 0;
200 Escaper you = new Escaper();
201 you.setName("Escaper");
202 ThreadCount.inc();
203 you.start();
204 me = new Memevil(bufsz);
205 me.setName("Memevil" + bufsz);
206 bufsz = 2*bufsz;
207 me.start();
208 Thread.yield();
209 for (int i=1; i<11; i++) {
210 ThreadCount.inc();
211 me = new Memevil(bufsz);
212 me.setName("Memevil" + bufsz);
213 bufsz = 2*bufsz;
214 me.start();
215 Thread.yield();
216 }
217 try {
218 you.join();
|