author | kbarrett |
Tue, 02 Apr 2019 13:08:38 -0400 | |
changeset 54385 | 9559ba212c18 |
child 54623 | 1126f0607c70 |
permissions | -rw-r--r-- |
54385
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
1 |
/* |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
4 |
* |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
8 |
* |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
13 |
* accompanied this code). |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
14 |
* |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
18 |
* |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
21 |
* questions. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
22 |
* |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
23 |
*/ |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
24 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
26 |
#include "memory/allocation.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
27 |
#include "runtime/interfaceSupport.inline.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
28 |
#include "runtime/mutexLocker.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
29 |
#include "runtime/thread.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
30 |
#include "runtime/vmOperations.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
31 |
#include "runtime/vmThread.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
32 |
#include "utilities/globalDefinitions.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
33 |
#include "utilities/ostream.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
34 |
#include "unittest.hpp" |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
35 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
36 |
struct Threads::Test : public AllStatic { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
37 |
class VM_TestClaimOverflow; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
38 |
class CountThreads; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
39 |
class CheckClaims; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
40 |
}; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
41 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
42 |
class Threads::Test::CountThreads : public ThreadClosure { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
43 |
uintx _claim_token; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
44 |
uint _java_threads_count; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
45 |
uint _non_java_threads_count; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
46 |
bool _need_claim; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
47 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
48 |
public: |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
49 |
CountThreads(uintx claim_token, bool need_claim) : |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
50 |
_claim_token(claim_token), |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
51 |
_java_threads_count(0), |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
52 |
_non_java_threads_count(0), |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
53 |
_need_claim(need_claim) |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
54 |
{} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
55 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
56 |
virtual void do_thread(Thread* t) { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
57 |
if (!_need_claim || t->claim_threads_do(true, _claim_token)) { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
58 |
if (t->is_Java_thread()) { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
59 |
++_java_threads_count; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
60 |
} else { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
61 |
++_non_java_threads_count; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
62 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
63 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
64 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
65 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
66 |
uint java_threads_count() const { return _java_threads_count; } |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
67 |
uint non_java_threads_count() const { return _non_java_threads_count; } |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
68 |
uint count() const { return _java_threads_count + _non_java_threads_count; } |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
69 |
}; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
70 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
71 |
class Threads::Test::CheckClaims : public ThreadClosure { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
72 |
uintx _claim_token; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
73 |
uint _java_threads_claimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
74 |
uint _java_threads_unclaimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
75 |
uint _non_java_threads_claimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
76 |
uint _non_java_threads_unclaimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
77 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
78 |
public: |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
79 |
CheckClaims(uintx claim_token) : |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
80 |
_claim_token(claim_token), |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
81 |
_java_threads_claimed(0), |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
82 |
_java_threads_unclaimed(0), |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
83 |
_non_java_threads_claimed(0), |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
84 |
_non_java_threads_unclaimed(0) |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
85 |
{} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
86 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
87 |
virtual void do_thread(Thread* t) { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
88 |
uintx thread_token = t->threads_do_token(); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
89 |
if (thread_token == _claim_token) { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
90 |
if (t->is_Java_thread()) { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
91 |
++_java_threads_claimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
92 |
} else { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
93 |
++_non_java_threads_claimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
94 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
95 |
} else { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
96 |
if (t->is_Java_thread()) { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
97 |
++_java_threads_unclaimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
98 |
} else { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
99 |
++_non_java_threads_unclaimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
100 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
101 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
102 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
103 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
104 |
uint java_threads_claimed() const { return _java_threads_claimed; } |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
105 |
uint java_threads_unclaimed() const { return _java_threads_unclaimed; } |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
106 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
107 |
uint non_java_threads_claimed() const { return _non_java_threads_claimed; } |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
108 |
uint non_java_threads_unclaimed() const { return _non_java_threads_unclaimed; } |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
109 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
110 |
uint claimed() const { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
111 |
return _java_threads_claimed + _non_java_threads_claimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
112 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
113 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
114 |
uint unclaimed() const { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
115 |
return _java_threads_unclaimed + _non_java_threads_unclaimed; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
116 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
117 |
}; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
118 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
119 |
class Threads::Test::VM_TestClaimOverflow : public VM_GTestExecuteAtSafepoint { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
120 |
public: |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
121 |
void doit() { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
122 |
// Prevent changes to the NJT list while we're conducting our test. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
123 |
MutexLockerEx ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
124 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
125 |
_thread_claim_token = max_uintx - 1; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
126 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
127 |
ASSERT_EQ(max_uintx - 1, thread_claim_token()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
128 |
CountThreads count1(thread_claim_token(), true); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
129 |
threads_do(&count1); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
130 |
tty->print_cr("Testing claim overflow with %u threads", count1.count()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
131 |
// At least the main thread and the VM thread. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
132 |
ASSERT_LE(2u, count1.count()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
133 |
ASSERT_LE(1u, count1.java_threads_count()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
134 |
ASSERT_LE(1u, count1.non_java_threads_count()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
135 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
136 |
ASSERT_EQ(max_uintx - 1, thread_claim_token()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
137 |
CheckClaims check1(thread_claim_token()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
138 |
threads_do(&check1); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
139 |
ASSERT_EQ(count1.count(), check1.claimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
140 |
ASSERT_EQ(count1.java_threads_count(), check1.java_threads_claimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
141 |
ASSERT_EQ(0u, check1.java_threads_unclaimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
142 |
ASSERT_EQ(count1.non_java_threads_count(), check1.non_java_threads_claimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
143 |
ASSERT_EQ(0u, check1.non_java_threads_unclaimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
144 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
145 |
change_thread_claim_token(); // No overflow yet. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
146 |
ASSERT_EQ(max_uintx, thread_claim_token()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
147 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
148 |
CountThreads count2(thread_claim_token(), false); // Claimed by PPTD below |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
149 |
possibly_parallel_threads_do(true, &count2); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
150 |
ASSERT_EQ(count1.java_threads_count(), count2.java_threads_count()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
151 |
ASSERT_EQ(1u, count2.non_java_threads_count()); // Only VM thread |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
152 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
153 |
CheckClaims check2(thread_claim_token()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
154 |
threads_do(&check2); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
155 |
ASSERT_EQ(count2.java_threads_count(), check2.java_threads_claimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
156 |
ASSERT_EQ(0u, check2.java_threads_unclaimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
157 |
ASSERT_EQ(1u, check2.non_java_threads_claimed()); // Only VM thread |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
158 |
ASSERT_EQ(count1.non_java_threads_count(), |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
159 |
check2.non_java_threads_claimed() + |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
160 |
check2.non_java_threads_unclaimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
161 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
162 |
change_thread_claim_token(); // Expect overflow. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
163 |
ASSERT_EQ(uintx(1), thread_claim_token()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
164 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
165 |
// Verify all threads have claim value of 0 after change overflow. |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
166 |
CheckClaims check3(0); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
167 |
threads_do(&check3); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
168 |
ASSERT_EQ(count1.count(), check3.claimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
169 |
ASSERT_EQ(0u, check3.unclaimed()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
170 |
} |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
171 |
}; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
172 |
|
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
173 |
// Test overflow handling in Threads::change_thread_claim_token(). |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
174 |
TEST_VM(ThreadsTest, claim_overflow) { |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
175 |
Threads::Test::VM_TestClaimOverflow op; |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
176 |
ThreadInVMfromNative invm(JavaThread::current()); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
177 |
VMThread::execute(&op); |
9559ba212c18
8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents:
diff
changeset
|
178 |
} |