author | jlahoda |
Wed, 12 Dec 2012 20:26:56 +0100 | |
changeset 14803 | 88347e495d34 |
parent 10046 | f80878957a13 |
permissions | -rw-r--r-- |
10046
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
1 |
/* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
4 |
* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
8 |
* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
13 |
* accompanied this code). |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
14 |
* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
18 |
* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
21 |
* questions. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
22 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
23 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
24 |
import java.util.concurrent.atomic.AtomicInteger; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
25 |
import java.util.concurrent.BrokenBarrierException; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
26 |
import java.util.concurrent.CyclicBarrier; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
27 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
28 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
29 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
30 |
* RacingThreadsTest is a support class for creating a test |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
31 |
* where multiple threads are needed to exercise a code path. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
32 |
* The RacingThreadsTest class is typically used as follows: |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
33 |
* <ul> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
34 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
35 |
* Extend RacingThreadsTest class in order to provide the test |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
36 |
* specific variables and/or code, e.g., <br> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
37 |
* public class MyRacingThreadsTest extends RacingThreadsTest |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
38 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
39 |
* Use |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
40 |
* "new MyRacingThreadsTest(name, n_threads, n_loops, n_secs)" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
41 |
* to create your test with the specified name and the specified |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
42 |
* number of WorkerThreads that execute the test code in parallel |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
43 |
* up to n_loops iterations or n_secs seconds. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
44 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
45 |
* Use |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
46 |
* "new DriverThread(test)" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
47 |
* to create the test DriverThread that manages all the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
48 |
* WorkerThreads. The DriverThread class can be extended to |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
49 |
* provide test specific code and/or variables. However, that |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
50 |
* is typically done in your test's subclass. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
51 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
52 |
* Use |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
53 |
* "new WorkerThread(workerNum, test)" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
54 |
* to create WorkerThread-workerNum that executes the test code. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
55 |
* The WorkerThread class can be extended to provide test thread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
56 |
* specific code and/or variables. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
57 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
58 |
* Use |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
59 |
* "RacingThreadsTest.runTest(driver, workers)" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
60 |
* to run the test. If the test fails, then a RuntimeException |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
61 |
* is thrown. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
62 |
* </ul> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
63 |
* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
64 |
* The RacingThreadsTest class provides many methods that can be |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
65 |
* overridden in order to provide test specific semantics at each |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
66 |
* identified test execution point. At a minimum, your test's |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
67 |
* subclass needs to override the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
68 |
* "void executeRace(WorkerThread)" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
69 |
* method in order to exercise your race condition and it needs to |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
70 |
* override the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
71 |
* "void checkRaceResults(DriverThread)" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
72 |
* method in order to check the results of the race. Your |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
73 |
* checkRaceResults() method should call the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
74 |
* "int incAndGetFailCnt()" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
75 |
* method when it detects a failure. It can also call the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
76 |
* "void unexpectedException(Thread, Exception)" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
77 |
* method if it detects an unexpected exception; this will cause |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
78 |
* an error message to be output and the failure count to be |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
79 |
* incremented. When the RacingThreadsTest.runTest() method is |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
80 |
* done running the races, if there is a non-zero failure count, |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
81 |
* then a RuntimeException will be thrown. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
82 |
* <p> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
83 |
* The RacingThreadsTest class uses three internal barriers to |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
84 |
* coordinate actions between the DriverThread and the WorkerThreads. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
85 |
* These barriers should not be managed or used by your test's |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
86 |
* subclass and are only mentioned here to provide clarity about |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
87 |
* interactions between the DriverThread and the WorkerThreads. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
88 |
* The following transaction diagram shows when the different |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
89 |
* RacingThreadsTest methods are called relative to the different |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
90 |
* barriers: |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
91 |
* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
92 |
* <pre> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
93 |
* DriverThread WorkerThread-0 WorkerThread-N-1 |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
94 |
* --------------------- --------------------- --------------------- |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
95 |
* run(workers) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
96 |
* oneTimeDriverInit() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
97 |
* <start WorkerThreads> run() run() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
98 |
* <top of race loop> : : |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
99 |
* perRaceDriverInit() oneTimeWorkerInit() oneTimeWorkerInit() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
100 |
* : <top of race loop> <top of race loop> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
101 |
* : perRaceWorkerInit() perRaceWorkerInit() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
102 |
* startBarrier startBarrier startBarrier |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
103 |
* : executeRace() executeRace() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
104 |
* finishBarrier finishBarrier finishBarrier |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
105 |
* checkRaceResults() : : |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
106 |
* resetBarrier resetBarrier resetBarrier |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
107 |
* perRaceDriverEpilog() perRaceWorkerEpilog() perRaceWorkerEpilog() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
108 |
* <repeat race or done> <repeat race or done> <repeat race or done> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
109 |
* : oneTimeWorkerEpilog() oneTimeWorkerEpilog() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
110 |
* <join WorkerThreads> <WorkerThread ends> <WorkerThread ends> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
111 |
* oneTimeDriverEpilog() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
112 |
* <DriverThread ends> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
113 |
* </pre> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
114 |
* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
115 |
* Just to be clear about the parallel parts of this infrastructure: |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
116 |
* <ul> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
117 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
118 |
* After the DriverThread starts the WorkerThreads, the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
119 |
* and the WorkerThreads are running in parallel until the startBarrier |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
120 |
* is reached. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
121 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
122 |
* After the WorkerThreads leave the startBarrier, they are running |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
123 |
* the code in executeRace() in parallel which is the whole point |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
124 |
* of this class. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
125 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
126 |
* The DriverThread heads straight to the finishBarrier and waits for |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
127 |
* the WorkerThreads to get there. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
128 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
129 |
* After the DriverThread leaves the finishBarrier, it checks the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
130 |
* results of the race. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
131 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
132 |
* The WorkerThreads head straight to the resetBarrier and wait for |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
133 |
* the DriverThread to get there. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
134 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
135 |
* If this is not the last race, then after the DriverThread and |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
136 |
* WorkerThreads leave the resetBarrier, the DriverThread and the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
137 |
* WorkerThreads are running in parallel until the startBarrier |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
138 |
* is reached. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
139 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
140 |
* If this is the last race, then after the DriverThread and |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
141 |
* WorkerThreads leave the resetBarrier, the DriverThread and the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
142 |
* WorkerThreads are running in parallel as each WorkerThread ends. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
143 |
* <li> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
144 |
* The DriverThread waits for the WorkerThreads to end and |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
145 |
* then it ends |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
146 |
* </ul> |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
147 |
* |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
148 |
* Once the DriverThread has ended, the RacingThreadsTest.runTest() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
149 |
* method checks the failure count. If there were no failures, then |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
150 |
* a "Test PASSed" message is printed. Otherwise, the failure count |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
151 |
* is printed, a "Test FAILed" message is printed and a RuntimeException |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
152 |
* is thrown. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
153 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
154 |
public class RacingThreadsTest { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
155 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
156 |
* name of the test |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
157 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
158 |
public final String TEST_NAME; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
159 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
160 |
* maximum number of test iterations (race loops) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
161 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
162 |
public final int N_LOOPS; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
163 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
164 |
* the maximum number of seconds to execute the test loop |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
165 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
166 |
public final int N_SECS; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
167 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
168 |
* number of WorkerThreads |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
169 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
170 |
public final int N_THREADS; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
171 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
172 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
173 |
* Creates a test with the specified name and the specified number |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
174 |
* of WorkerThreads that execute the test code in parallel up to |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
175 |
* n_loops iterations or n_secs seconds. The RacingThreadsTest |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
176 |
* class is extended in order to provide the test specific variables |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
177 |
* and/or code. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
178 |
* @param name the name of the test |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
179 |
* @param n_threads the number of WorkerThreads |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
180 |
* @param n_loops the maximum number of test iterations |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
181 |
* @param n_secs the maximum number of seconds to execute the test loop |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
182 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
183 |
RacingThreadsTest(String name, int n_threads, int n_loops, int n_secs) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
184 |
TEST_NAME = name; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
185 |
N_THREADS = n_threads; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
186 |
N_LOOPS = n_loops; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
187 |
N_SECS = n_secs; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
188 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
189 |
finishBarrier = new CyclicBarrier(N_THREADS + 1); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
190 |
resetBarrier = new CyclicBarrier(N_THREADS + 1); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
191 |
startBarrier = new CyclicBarrier(N_THREADS + 1); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
192 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
193 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
194 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
195 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
196 |
* Entry point for exercising the RacingThreadsTest class. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
197 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
198 |
public static void main(String[] args) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
199 |
// a dummy test: |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
200 |
// - 2 threads |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
201 |
// - 3 loops |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
202 |
// - 2 seconds |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
203 |
// - standard DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
204 |
// - standard WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
205 |
RacingThreadsTest test = new RacingThreadsTest("dummy", 2, 3, 2); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
206 |
DriverThread driver = new DriverThread(test); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
207 |
WorkerThread[] workers = new WorkerThread[2]; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
208 |
for (int i = 0; i < workers.length; i++) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
209 |
workers[i] = new WorkerThread(i, test); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
210 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
211 |
test.runTest(driver, workers); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
212 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
213 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
214 |
private static volatile boolean done = false; // test done flag |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
215 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
216 |
// # of fails; AtomicInteger since any WorkerThread can increment |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
217 |
private static final AtomicInteger failCnt = new AtomicInteger(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
218 |
// # of loops; volatile is OK since only DriverThread increments |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
219 |
// but using AtomicInteger for consistency |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
220 |
private static final AtomicInteger loopCnt = new AtomicInteger(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
221 |
private static boolean verbose |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
222 |
= Boolean.getBoolean("RacingThreadsTest.verbose"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
223 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
224 |
// barriers for starting, finishing and resetting the race |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
225 |
private final CyclicBarrier finishBarrier; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
226 |
private final CyclicBarrier resetBarrier; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
227 |
private final CyclicBarrier startBarrier; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
228 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
229 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
230 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
231 |
* Get current done flag value. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
232 |
* @return the current done flag value |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
233 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
234 |
public boolean getDone() { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
235 |
return done; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
236 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
237 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
238 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
239 |
* Set done flag to specified value. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
240 |
* @param v the new done flag value |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
241 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
242 |
public void setDone(boolean v) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
243 |
done = v; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
244 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
245 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
246 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
247 |
* Get current failure counter value. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
248 |
* @return the current failure count |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
249 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
250 |
public int getFailCnt() { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
251 |
return failCnt.get(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
252 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
253 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
254 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
255 |
* Increment and get current failure counter value. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
256 |
* @return the current failure count after incrementing |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
257 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
258 |
public int incAndGetFailCnt() { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
259 |
return failCnt.incrementAndGet(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
260 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
261 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
262 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
263 |
* Get current loop counter value. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
264 |
* @return the current loop count |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
265 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
266 |
public int getLoopCnt() { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
267 |
return loopCnt.get(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
268 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
269 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
270 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
271 |
* Increment and get current loop counter value. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
272 |
* @return the current loop count after incrementing |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
273 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
274 |
public int incAndGetLoopCnt() { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
275 |
return loopCnt.incrementAndGet(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
276 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
277 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
278 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
279 |
* Get current verbose flag value. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
280 |
* @return the current verbose flag value |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
281 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
282 |
public boolean getVerbose() { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
283 |
return verbose; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
284 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
285 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
286 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
287 |
* Set verbose flag to specified value. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
288 |
* @param v the new verbose flag value |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
289 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
290 |
public void setVerbose(boolean v) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
291 |
verbose = v; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
292 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
293 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
294 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
295 |
* Run the test with the specified DriverThread and the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
296 |
* specified WorkerThreads. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
297 |
* @param driver the DriverThread for running the test |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
298 |
* @param workers the WorkerThreads for executing the race |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
299 |
* @exception RuntimeException the test has failed |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
300 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
301 |
public void runTest(DriverThread driver, WorkerThread[] workers) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
302 |
driver.run(workers); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
303 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
304 |
try { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
305 |
driver.join(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
306 |
} catch (InterruptedException ie) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
307 |
unexpectedException(Thread.currentThread(), ie); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
308 |
// fall through to test failed below |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
309 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
310 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
311 |
if (failCnt.get() == 0) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
312 |
System.out.println(TEST_NAME + ": Test PASSed."); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
313 |
} else { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
314 |
System.out.println(TEST_NAME + ": failCnt=" + failCnt.get()); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
315 |
System.out.println(TEST_NAME + ": Test FAILed."); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
316 |
throw new RuntimeException("Test Failed"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
317 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
318 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
319 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
320 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
321 |
* Helper method for reporting an unexpected Exception and |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
322 |
* calling incAndGetFailCnt(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
323 |
* @param t the Thread that caught the exception |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
324 |
* @param e the Exception that was caught |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
325 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
326 |
public void unexpectedException(Thread t, Exception e) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
327 |
System.err.println(t.getName() + ": ERROR: unexpected exception: " + e); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
328 |
incAndGetFailCnt(); // ignore return |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
329 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
330 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
331 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
332 |
// The following methods are typically overridden by the subclass |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
333 |
// of RacingThreadsTest to provide test specific semantics at each |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
334 |
// identified test execution point: |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
335 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
336 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
337 |
* Initialize 1-time items for the DriverThread. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
338 |
* Called by the DriverThread before WorkerThreads are started. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
339 |
* @param dt the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
340 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
341 |
public void oneTimeDriverInit(DriverThread dt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
342 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
343 |
System.out.println(dt.getName() + ": oneTimeDriverInit() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
344 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
345 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
346 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
347 |
* Initialize 1-time items for a WorkerThread. Called by a |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
348 |
* WorkerThread after oneTimeDriverInit() and before the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
349 |
* WorkerThread checks in with startBarrier. May execute in |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
350 |
* parallel with perRaceDriverInit() or with another |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
351 |
* WorkerThread's oneTimeWorkerInit() call or another |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
352 |
* WorkerThread's perRaceWorkerInit() call. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
353 |
* @param wt the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
354 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
355 |
public void oneTimeWorkerInit(WorkerThread wt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
356 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
357 |
System.out.println(wt.getName() + ": oneTimeWorkerInit() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
358 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
359 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
360 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
361 |
* Initialize per-race items for the DriverThread. Called by the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
362 |
* DriverThread before it checks in with startBarrier. May execute |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
363 |
* in parallel with oneTimeWorkerInit() and perRaceWorkerInit() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
364 |
* calls. After any race except for the last race, this method may |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
365 |
* execute in parallel with perRaceWorkerEpilog(). |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
366 |
* @param dt the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
367 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
368 |
public void perRaceDriverInit(DriverThread dt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
369 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
370 |
System.out.println(dt.getName() + ": perRaceDriverInit() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
371 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
372 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
373 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
374 |
* Initialize per-race items for a WorkerThread. Called by each |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
375 |
* WorkerThread before it checks in with startBarrier. On the first |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
376 |
* call, this method may execute in parallel with another |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
377 |
* WorkerThread's oneTimeWorkerInit() call. On any call, this method |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
378 |
* may execute in parallel with perRaceDriverInit() or another |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
379 |
* WorkerThread's perRaceWorkerInit() call. After any race except |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
380 |
* for the last race, this method may execute in parallel with |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
381 |
* perRaceDriverEpilog() or another WorkerThread's |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
382 |
* perRaceWorkerEpilog() call. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
383 |
* @param wt the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
384 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
385 |
public void perRaceWorkerInit(WorkerThread wt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
386 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
387 |
System.out.println(wt.getName() + ": perRaceWorkerInit() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
388 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
389 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
390 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
391 |
* Execute the race in a WorkerThread. Called by each WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
392 |
* after it has been released from startBarrier. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
393 |
* @param wt the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
394 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
395 |
public void executeRace(WorkerThread wt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
396 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
397 |
System.out.println(wt.getName() + ": executeRace() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
398 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
399 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
400 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
401 |
* Check race results in the DriverThread. Called by the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
402 |
* after it has been released from finishBarrier and before the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
403 |
* DriverThread checks in with resetBarrier. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
404 |
* @param dt the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
405 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
406 |
public void checkRaceResults(DriverThread dt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
407 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
408 |
System.out.println(dt.getName() + ": checkRaceResults() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
409 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
410 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
411 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
412 |
* Handle end-of-race items for the DriverThread. Called by the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
413 |
* DriverThread after it has been released from resetBarrier and |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
414 |
* before the DriverThread checks in again with startBarrier. Can |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
415 |
* execute in parallel with perRaceWorkerEpilog(). If this is not |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
416 |
* the last race, can execute in parallel with perRaceWorkerInit(). |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
417 |
* If this is the last race, can execute in parallel with |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
418 |
* oneTimeWorkerEpilog(). |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
419 |
* @param dt the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
420 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
421 |
public void perRaceDriverEpilog(DriverThread dt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
422 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
423 |
System.out.println(dt.getName() + ": perRaceDriverEpilog() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
424 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
425 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
426 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
427 |
* Handle end-of-race items for a WorkerThread. Called by each |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
428 |
* WorkerThread after it has been released from resetBarrier and |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
429 |
* before the WorkerThread checks in again with startBarrier. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
430 |
* Can execute in parallel with perRaceDriverEpilog() or another |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
431 |
* WorkerThread's perRaceWorkerEpilog() call. If this is not the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
432 |
* last race, can execute in parallel with perRaceDriverInit(), |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
433 |
* or another WorkerThread's perRaceWorkerInit() call. If this |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
434 |
* is the last race, can execute in parallel with another |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
435 |
* WorkerThread's oneTimeWorkerEpilog() call. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
436 |
* @param wt the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
437 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
438 |
public void perRaceWorkerEpilog(WorkerThread wt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
439 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
440 |
System.out.println(wt.getName() + ": perRaceWorkerEpilog() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
441 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
442 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
443 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
444 |
* Handle end-of-test items for a WorkerThread. Called by each |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
445 |
* WorkerThread after it has detected that all races are done and |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
446 |
* before oneTimeDriverEpilog() is called. Can execute in parallel |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
447 |
* with perRaceDriverEpilog(), with another WorkerThread's |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
448 |
* perRaceWorkerEpilog() call or with another WorkerThread's |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
449 |
* oneTimeWorkerEpilog() call. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
450 |
* @param wt the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
451 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
452 |
public void oneTimeWorkerEpilog(WorkerThread wt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
453 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
454 |
System.out.println(wt.getName() + ": oneTimeWorkerEpilog() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
455 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
456 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
457 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
458 |
* Handle end-of-test items for the DriverThread. Called by the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
459 |
* DriverThread after all the WorkerThreads have called |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
460 |
* oneTimeWorkerEpilog(). |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
461 |
* @param dt the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
462 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
463 |
public void oneTimeDriverEpilog(DriverThread dt) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
464 |
if (verbose) |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
465 |
System.out.println(dt.getName() + ": oneTimeDriverEpilog() called"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
466 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
467 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
468 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
469 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
470 |
* DriverThread for executing the test. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
471 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
472 |
public static class DriverThread extends Thread { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
473 |
private final RacingThreadsTest test; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
474 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
475 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
476 |
* Create the test DriverThread that manages all the WorkerThreads. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
477 |
* The DriverThread class can be extended to provide test specific |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
478 |
* variables and/or code. However, that is typically done in the |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
479 |
* subclass of RacingThreadsTest. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
480 |
* @parameter test the RacingThreadsTest being run |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
481 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
482 |
DriverThread(RacingThreadsTest test) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
483 |
super("DriverThread"); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
484 |
this.test = test; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
485 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
486 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
487 |
private void run(WorkerThread[] workers) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
488 |
System.out.println(getName() + ": is starting."); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
489 |
System.out.println(getName() + ": # WorkerThreads: " + test.N_THREADS); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
490 |
System.out.println(getName() + ": max # loops: " + test.N_LOOPS); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
491 |
System.out.println(getName() + ": max # secs: " + test.N_SECS); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
492 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
493 |
// initialize 1-time items for the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
494 |
test.oneTimeDriverInit(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
495 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
496 |
// start all the threads |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
497 |
for (int i = 0; i < workers.length; i++) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
498 |
workers[i].start(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
499 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
500 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
501 |
// All WorkerThreads call oneTimeWorkerInit() and |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
502 |
// perRaceWorkerInit() on the way to startBarrier. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
503 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
504 |
long endTime = System.currentTimeMillis() + test.N_SECS * 1000; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
505 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
506 |
for (; !test.getDone() && test.getLoopCnt() < test.N_LOOPS; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
507 |
test.incAndGetLoopCnt()) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
508 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
509 |
if (test.getVerbose() && (test.N_LOOPS < 10 || |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
510 |
(test.getLoopCnt() % (test.N_LOOPS / 10)) == 0)) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
511 |
System.out.println(getName() + ": race loop #" |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
512 |
+ test.getLoopCnt()); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
513 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
514 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
515 |
// initialize per-race items for the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
516 |
test.perRaceDriverInit(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
517 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
518 |
try { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
519 |
// we've setup the race so start it when all |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
520 |
// WorkerThreads get to the startBarrier |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
521 |
test.startBarrier.await(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
522 |
} catch (BrokenBarrierException bbe) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
523 |
test.unexpectedException(this, bbe); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
524 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
525 |
} catch (InterruptedException ie) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
526 |
test.unexpectedException(this, ie); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
527 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
528 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
529 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
530 |
// All WorkerThreads are racing via executeRace() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
531 |
// at this point |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
532 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
533 |
// wait for all threads to finish the race |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
534 |
try { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
535 |
test.finishBarrier.await(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
536 |
} catch (BrokenBarrierException bbe) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
537 |
test.unexpectedException(this, bbe); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
538 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
539 |
} catch (InterruptedException ie) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
540 |
test.unexpectedException(this, ie); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
541 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
542 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
543 |
// All WorkerThreads are heading to resetBarrier at this |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
544 |
// point so we can check the race results before we reset |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
545 |
// for another race (or bail because we are done). |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
546 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
547 |
test.checkRaceResults(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
548 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
549 |
if (test.getLoopCnt() + 1 >= test.N_LOOPS || |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
550 |
System.currentTimeMillis() >= endTime) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
551 |
// This is the last loop or we're out of time. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
552 |
// Let test threads know we are done before we release |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
553 |
// them from resetBarrier |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
554 |
test.setDone(true); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
555 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
556 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
557 |
// release the WorkerThreads from resetBarrier |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
558 |
try { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
559 |
test.resetBarrier.await(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
560 |
} catch (BrokenBarrierException bbe) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
561 |
test.unexpectedException(this, bbe); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
562 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
563 |
} catch (InterruptedException ie) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
564 |
test.unexpectedException(this, ie); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
565 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
566 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
567 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
568 |
// All WorkerThreads call perRaceWorkerEpilog(). If |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
569 |
// this is not the last loop, then all WorkerThreads |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
570 |
// will also call perRaceWorkerInit() on the way to |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
571 |
// startBarrier. If this is the last loop, then all |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
572 |
// WorkerThreads will call oneTimeWorkerEpilog() on |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
573 |
// their way to ending. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
574 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
575 |
// handle end-of-race items for the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
576 |
test.perRaceDriverEpilog(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
577 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
578 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
579 |
System.out.println(getName() + ": completed " + test.getLoopCnt() |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
580 |
+ " race loops."); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
581 |
if (test.getLoopCnt() < test.N_LOOPS) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
582 |
System.out.println(getName() + ": race stopped @ " + test.N_SECS |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
583 |
+ " seconds."); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
584 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
585 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
586 |
for (int i = 0; i < workers.length; i++) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
587 |
try { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
588 |
workers[i].join(); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
589 |
} catch (InterruptedException ie) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
590 |
test.unexpectedException(this, ie); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
591 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
592 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
593 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
594 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
595 |
// handle end-of-test items for the DriverThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
596 |
test.oneTimeDriverEpilog(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
597 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
598 |
System.out.println(getName() + ": is done."); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
599 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
600 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
601 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
602 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
603 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
604 |
* WorkerThread for executing the race. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
605 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
606 |
public static class WorkerThread extends Thread { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
607 |
private final RacingThreadsTest test; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
608 |
private final int workerNum; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
609 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
610 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
611 |
* Creates WorkerThread-N that executes the test code. The |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
612 |
* WorkerThread class can be extended to provide test thread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
613 |
* specific variables and/or code. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
614 |
* @param workerNum the number for the new WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
615 |
* @parameter test the RacingThreadsTest being run |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
616 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
617 |
WorkerThread(int workerNum, RacingThreadsTest test) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
618 |
super("WorkerThread-" + workerNum); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
619 |
this.test = test; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
620 |
this.workerNum = workerNum; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
621 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
622 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
623 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
624 |
* get the WorkerThread's number |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
625 |
* @return the WorkerThread's number |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
626 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
627 |
public int getWorkerNum() { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
628 |
return workerNum; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
629 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
630 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
631 |
/** |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
632 |
* Run the race in a WorkerThread. |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
633 |
*/ |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
634 |
public void run() { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
635 |
System.out.println(getName() + ": is running."); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
636 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
637 |
// initialize 1-time items for the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
638 |
test.oneTimeWorkerInit(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
639 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
640 |
while (!test.getDone()) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
641 |
// initialize per-race items for the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
642 |
test.perRaceWorkerInit(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
643 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
644 |
try { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
645 |
test.startBarrier.await(); // wait for race to start |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
646 |
} catch (BrokenBarrierException bbe) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
647 |
test.unexpectedException(this, bbe); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
648 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
649 |
} catch (InterruptedException ie) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
650 |
test.unexpectedException(this, ie); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
651 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
652 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
653 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
654 |
// execute the race for the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
655 |
test.executeRace(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
656 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
657 |
try { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
658 |
test.finishBarrier.await(); // this thread is done |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
659 |
} catch (BrokenBarrierException bbe) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
660 |
test.unexpectedException(this, bbe); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
661 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
662 |
} catch (InterruptedException ie) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
663 |
test.unexpectedException(this, ie); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
664 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
665 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
666 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
667 |
try { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
668 |
test.resetBarrier.await(); // wait for race to reset |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
669 |
} catch (BrokenBarrierException bbe) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
670 |
test.unexpectedException(this, bbe); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
671 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
672 |
} catch (InterruptedException ie) { |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
673 |
test.unexpectedException(this, ie); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
674 |
return; |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
675 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
676 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
677 |
// handle end-of-race items for the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
678 |
test.perRaceWorkerEpilog(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
679 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
680 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
681 |
// handle end-of-test items for the WorkerThread |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
682 |
test.oneTimeWorkerEpilog(this); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
683 |
|
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
684 |
System.out.println(getName() + ": is ending."); |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
685 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
686 |
} |
f80878957a13
7045594: 4/4 fix for 6977677 introduced a ResourceBundle race
dcubed
parents:
diff
changeset
|
687 |
} |