author | manc |
Mon, 14 Oct 2019 18:48:10 -0700 | |
changeset 58652 | 9b67dd88a931 |
parent 52332 | d2a3503c72f7 |
child 59247 | 56bf71d64d51 |
permissions | -rw-r--r-- |
52332
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
1 |
/* |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
4 |
* |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
8 |
* |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
13 |
* accompanied this code). |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
14 |
* |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
18 |
* |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
21 |
* questions. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
22 |
*/ |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
23 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
25 |
#include "metaprogramming/isRegisteredEnum.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
26 |
#include "runtime/atomic.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
27 |
#include "runtime/orderAccess.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
28 |
#include "runtime/os.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
29 |
#include "utilities/globalCounter.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
30 |
#include "utilities/globalCounter.inline.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
31 |
#include "utilities/spinYield.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
32 |
#include "threadHelper.inline.hpp" |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
33 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
34 |
enum NestedTestState { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
35 |
START, |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
36 |
START_WAIT, |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
37 |
OUTER_ENTERED, |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
38 |
INNER_ENTERED, |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
39 |
INNER_EXITED, |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
40 |
OUTER_EXITED, |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
41 |
SYNCHRONIZING, |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
42 |
SYNCHRONIZED |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
43 |
}; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
44 |
template<> struct IsRegisteredEnum<NestedTestState> : public TrueType {}; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
45 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
46 |
class RCUNestedThread : public JavaTestThread { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
47 |
volatile NestedTestState _state; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
48 |
volatile bool _proceed; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
49 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
50 |
protected: |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
51 |
RCUNestedThread(Semaphore* post) : |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
52 |
JavaTestThread(post), |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
53 |
_state(START), |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
54 |
_proceed(false) |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
55 |
{} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
56 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
57 |
~RCUNestedThread() {} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
58 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
59 |
void set_state(NestedTestState new_state) { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
60 |
OrderAccess::release_store(&_state, new_state); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
61 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
62 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
63 |
void wait_with_state(NestedTestState new_state) { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
64 |
SpinYield spinner; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
65 |
OrderAccess::release_store(&_state, new_state); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
66 |
while (!OrderAccess::load_acquire(&_proceed)) { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
67 |
spinner.wait(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
68 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
69 |
OrderAccess::release_store(&_proceed, false); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
70 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
71 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
72 |
public: |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
73 |
NestedTestState state() const { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
74 |
return OrderAccess::load_acquire(&_state); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
75 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
76 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
77 |
void wait_for_state(NestedTestState goal) { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
78 |
SpinYield spinner; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
79 |
while (state() != goal) { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
80 |
spinner.wait(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
81 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
82 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
83 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
84 |
void proceed() { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
85 |
OrderAccess::release_store(&_proceed, true); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
86 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
87 |
}; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
88 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
89 |
class RCUNestedReaderThread : public RCUNestedThread { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
90 |
public: |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
91 |
RCUNestedReaderThread(Semaphore* post) : |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
92 |
RCUNestedThread(post) |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
93 |
{} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
94 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
95 |
virtual void main_run(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
96 |
}; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
97 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
98 |
void RCUNestedReaderThread::main_run() { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
99 |
wait_with_state(START_WAIT); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
100 |
{ |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
101 |
GlobalCounter::CriticalSection outer(Thread::current()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
102 |
wait_with_state(OUTER_ENTERED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
103 |
{ |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
104 |
GlobalCounter::CriticalSection inner(Thread::current()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
105 |
wait_with_state(INNER_ENTERED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
106 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
107 |
wait_with_state(INNER_EXITED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
108 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
109 |
wait_with_state(OUTER_EXITED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
110 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
111 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
112 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
113 |
class RCUNestedWriterThread : public RCUNestedThread { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
114 |
public: |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
115 |
RCUNestedWriterThread(Semaphore* post) : |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
116 |
RCUNestedThread(post) |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
117 |
{} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
118 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
119 |
virtual void main_run(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
120 |
}; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
121 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
122 |
void RCUNestedWriterThread::main_run() { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
123 |
wait_with_state(START_WAIT); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
124 |
set_state(SYNCHRONIZING); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
125 |
GlobalCounter::write_synchronize(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
126 |
wait_with_state(SYNCHRONIZED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
127 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
128 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
129 |
TEST_VM(GlobalCounter, nested_critical_section) { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
130 |
Semaphore post; |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
131 |
RCUNestedReaderThread* reader = new RCUNestedReaderThread(&post); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
132 |
RCUNestedWriterThread* outer = new RCUNestedWriterThread(&post); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
133 |
RCUNestedWriterThread* inner = new RCUNestedWriterThread(&post); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
134 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
135 |
reader->doit(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
136 |
outer->doit(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
137 |
inner->doit(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
138 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
139 |
reader->wait_for_state(START_WAIT); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
140 |
outer->wait_for_state(START_WAIT); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
141 |
inner->wait_for_state(START_WAIT); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
142 |
EXPECT_EQ(START_WAIT, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
143 |
EXPECT_EQ(START_WAIT, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
144 |
EXPECT_EQ(START_WAIT, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
145 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
146 |
reader->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
147 |
reader->wait_for_state(OUTER_ENTERED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
148 |
EXPECT_EQ(OUTER_ENTERED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
149 |
EXPECT_EQ(START_WAIT, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
150 |
EXPECT_EQ(START_WAIT, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
151 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
152 |
outer->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
153 |
outer->wait_for_state(SYNCHRONIZING); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
154 |
EXPECT_EQ(OUTER_ENTERED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
155 |
EXPECT_EQ(SYNCHRONIZING, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
156 |
EXPECT_EQ(START_WAIT, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
157 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
158 |
os::naked_short_sleep(100); // Give outer time in synchronization. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
159 |
EXPECT_EQ(OUTER_ENTERED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
160 |
EXPECT_EQ(SYNCHRONIZING, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
161 |
EXPECT_EQ(START_WAIT, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
162 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
163 |
reader->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
164 |
reader->wait_for_state(INNER_ENTERED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
165 |
EXPECT_EQ(INNER_ENTERED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
166 |
EXPECT_EQ(SYNCHRONIZING, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
167 |
EXPECT_EQ(START_WAIT, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
168 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
169 |
inner->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
170 |
inner->wait_for_state(SYNCHRONIZING); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
171 |
EXPECT_EQ(INNER_ENTERED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
172 |
EXPECT_EQ(SYNCHRONIZING, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
173 |
EXPECT_EQ(SYNCHRONIZING, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
174 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
175 |
os::naked_short_sleep(100); // Give writers time in synchronization. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
176 |
EXPECT_EQ(INNER_ENTERED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
177 |
EXPECT_EQ(SYNCHRONIZING, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
178 |
EXPECT_EQ(SYNCHRONIZING, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
179 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
180 |
reader->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
181 |
reader->wait_for_state(INNER_EXITED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
182 |
// inner does *not* complete synchronization here. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
183 |
EXPECT_EQ(INNER_EXITED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
184 |
EXPECT_EQ(SYNCHRONIZING, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
185 |
EXPECT_EQ(SYNCHRONIZING, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
186 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
187 |
os::naked_short_sleep(100); // Give writers more time in synchronization. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
188 |
EXPECT_EQ(INNER_EXITED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
189 |
EXPECT_EQ(SYNCHRONIZING, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
190 |
EXPECT_EQ(SYNCHRONIZING, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
191 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
192 |
reader->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
193 |
reader->wait_for_state(OUTER_EXITED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
194 |
// Both inner and outer can synchronize now. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
195 |
outer->wait_for_state(SYNCHRONIZED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
196 |
inner->wait_for_state(SYNCHRONIZED); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
197 |
EXPECT_EQ(OUTER_EXITED, reader->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
198 |
EXPECT_EQ(SYNCHRONIZED, outer->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
199 |
EXPECT_EQ(SYNCHRONIZED, inner->state()); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
200 |
|
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
201 |
// Wait for reader, outer, and inner to complete. |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
202 |
reader->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
203 |
outer->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
204 |
inner->proceed(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
205 |
for (uint i = 0; i < 3; ++i) { |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
206 |
post.wait(); |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
207 |
} |
d2a3503c72f7
8212827: GlobalCounter should support nested critical sections
kbarrett
parents:
diff
changeset
|
208 |
} |