1 |
|
/* |
2 |
< |
* Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved. |
2 |
> |
* Copyright (c) 2006, 2010, 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 |
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
20 |
< |
* CA 95054 USA or visit www.sun.com if you need additional information or |
21 |
< |
* have any questions. |
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 |
|
|
24 |
|
/* |
38 |
|
* Turn this up to some higher value like 1000 for stress testing: |
39 |
|
* java -Dmillis=1000 RacingCollections |
40 |
|
*/ |
41 |
< |
final static long defaultWorkTimeMillis = Long.getLong("millis", 10L); |
41 |
> |
static final long defaultWorkTimeMillis = Long.getLong("millis", 10L); |
42 |
|
|
43 |
|
/** |
44 |
|
* Whether to print debug information. |
45 |
|
*/ |
46 |
< |
final static boolean debug = Boolean.getBoolean("debug"); |
46 |
> |
static final boolean debug = Boolean.getBoolean("debug"); |
47 |
|
|
48 |
< |
final static Integer one = 1; |
49 |
< |
final static Integer two = 2; |
48 |
> |
static final Integer one = 1; |
49 |
> |
static final Integer two = 2; |
50 |
|
|
51 |
|
/** |
52 |
|
* A thread that mutates an object forever, alternating between |
62 |
|
this.start(); |
63 |
|
} |
64 |
|
|
65 |
< |
@SuppressWarnings("unchecked") void clear(Object o) { |
65 |
> |
@SuppressWarnings("unchecked") |
66 |
> |
void clear(Object o) { |
67 |
|
if (o instanceof Collection) |
68 |
|
((Collection<?>)o).clear(); |
69 |
|
else |
70 |
|
((Map<?,?>)o).clear(); |
71 |
|
} |
72 |
|
|
73 |
< |
@SuppressWarnings("unchecked") void realRun() { |
73 |
> |
@SuppressWarnings("unchecked") |
74 |
> |
void realRun() { |
75 |
|
// Mutate elLoco wildly forever, checking occasionally for "done" |
76 |
|
clear(elLoco); |
77 |
|
if (elLoco instanceof List) { |
158 |
|
quittingTime = System.nanoTime() + workTimeMillis * 1024 * 1024; |
159 |
|
} |
160 |
|
boolean keepGoing() { |
161 |
< |
return (i++ % 128 != 0) || (System.nanoTime() < quittingTime); |
161 |
> |
return (i++ % 128 != 0) || (System.nanoTime() - quittingTime < 0); |
162 |
|
} |
163 |
|
} |
164 |
|
|
235 |
|
private static List<Queue<Integer>> newConcurrentQueues() { |
236 |
|
List<Queue<Integer>> list = |
237 |
|
new ArrayList<Queue<Integer>>(newConcurrentDeques()); |
238 |
+ |
list.add(new ArrayBlockingQueue<Integer>(10)); |
239 |
|
list.add(new LinkedBlockingQueue<Integer>(10)); |
240 |
|
list.add(new LinkedTransferQueue<Integer>()); |
241 |
|
list.add(new ConcurrentLinkedQueue<Integer>()); |
343 |
|
try {realMain(args);} catch (Throwable t) {unexpected(t);} |
344 |
|
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
345 |
|
if (failed > 0) throw new AssertionError("Some tests failed");} |
346 |
< |
private static abstract class CheckedThread extends Thread { |
346 |
> |
private abstract static class CheckedThread extends Thread { |
347 |
|
abstract void realRun() throws Throwable; |
348 |
|
public void run() { |
349 |
|
try { realRun(); } catch (Throwable t) { unexpected(t); }}} |