author | dfuchs |
Fri, 06 Sep 2019 14:04:44 +0100 | |
changeset 58031 | 5aaf53d4fe63 |
parent 54623 | 1126f0607c70 |
child 59325 | 3636bab5e81e |
permissions | -rw-r--r-- |
49800 | 1 |
/* |
54416
b788c494aa46
8218483: Crash in "assert(_daemon_threads_count->get_value() > daemon_count) failed: thread count mismatch 5 : 5"
dholmes
parents:
53268
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
49800 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
50966
diff
changeset
|
24 |
#ifndef GTEST_THREADHELPER_INLINE_HPP |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
50966
diff
changeset
|
25 |
#define GTEST_THREADHELPER_INLINE_HPP |
49800 | 26 |
|
27 |
#include "runtime/mutex.hpp" |
|
28 |
#include "runtime/semaphore.hpp" |
|
53268 | 29 |
#include "runtime/thread.inline.hpp" |
49800 | 30 |
#include "runtime/vmThread.hpp" |
52877
9e041366c764
8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents:
52618
diff
changeset
|
31 |
#include "runtime/vmOperations.hpp" |
49800 | 32 |
#include "unittest.hpp" |
33 |
||
34 |
class VM_StopSafepoint : public VM_Operation { |
|
35 |
public: |
|
52618 | 36 |
Semaphore* _running; |
49800 | 37 |
Semaphore* _test_complete; |
52618 | 38 |
VM_StopSafepoint(Semaphore* running, Semaphore* wait_for) : |
39 |
_running(running), _test_complete(wait_for) {} |
|
50966
f939a67fea30
8198720: Obsolete PrintSafepointStatistics, PrintSafepointStatisticsTimeout and PrintSafepointStatisticsCount options
coleenp
parents:
49800
diff
changeset
|
40 |
VMOp_Type type() const { return VMOp_None; } |
49800 | 41 |
Mode evaluation_mode() const { return _no_safepoint; } |
42 |
bool is_cheap_allocated() const { return false; } |
|
52618 | 43 |
void doit() { _running->signal(); _test_complete->wait(); } |
49800 | 44 |
}; |
45 |
||
46 |
// This class and thread keep the non-safepoint op running while we do our testing. |
|
47 |
class VMThreadBlocker : public JavaThread { |
|
48 |
public: |
|
52618 | 49 |
Semaphore _ready; |
50 |
Semaphore _unblock; |
|
51 |
VMThreadBlocker() {} |
|
49800 | 52 |
virtual ~VMThreadBlocker() {} |
53103
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
53 |
const char* get_thread_name_string(char* buf, int buflen) const { |
53105
6ac04cfbefdf
8215954: [testbug] Remove unnecessary casts in test/hotspot/gtest/threadHelper.inline.hpp
dholmes
parents:
53103
diff
changeset
|
54 |
return "VMThreadBlocker"; |
53103
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
55 |
} |
49800 | 56 |
void run() { |
57 |
this->set_thread_state(_thread_in_vm); |
|
58 |
{ |
|
59 |
MutexLocker ml(Threads_lock); |
|
60 |
Threads::add(this); |
|
61 |
} |
|
52618 | 62 |
VM_StopSafepoint ss(&_ready, &_unblock); |
49800 | 63 |
VMThread::execute(&ss); |
53103
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
64 |
} |
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
65 |
|
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
66 |
// Override as JavaThread::post_run() calls JavaThread::exit which |
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
67 |
// expects a valid thread object oop. |
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
68 |
virtual void post_run() { |
54416
b788c494aa46
8218483: Crash in "assert(_daemon_threads_count->get_value() > daemon_count) failed: thread count mismatch 5 : 5"
dholmes
parents:
53268
diff
changeset
|
69 |
Threads::remove(this, false); |
49800 | 70 |
this->smr_delete(); |
71 |
} |
|
53103
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
72 |
|
49800 | 73 |
void doit() { |
74 |
if (os::create_thread(this, os::os_thread)) { |
|
75 |
os::start_thread(this); |
|
76 |
} else { |
|
77 |
ASSERT_TRUE(false); |
|
78 |
} |
|
79 |
} |
|
52618 | 80 |
void ready() { |
81 |
_ready.wait(); |
|
82 |
} |
|
83 |
void release() { |
|
84 |
_unblock.signal(); |
|
85 |
} |
|
49800 | 86 |
}; |
87 |
||
88 |
// For testing in a real JavaThread. |
|
89 |
class JavaTestThread : public JavaThread { |
|
90 |
public: |
|
91 |
Semaphore* _post; |
|
92 |
JavaTestThread(Semaphore* post) |
|
93 |
: _post(post) { |
|
94 |
} |
|
95 |
virtual ~JavaTestThread() {} |
|
96 |
||
53103
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
97 |
const char* get_thread_name_string(char* buf, int buflen) const { |
53105
6ac04cfbefdf
8215954: [testbug] Remove unnecessary casts in test/hotspot/gtest/threadHelper.inline.hpp
dholmes
parents:
53103
diff
changeset
|
98 |
return "JavaTestThread"; |
53103
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
99 |
} |
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
100 |
|
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
101 |
void pre_run() { |
49800 | 102 |
this->set_thread_state(_thread_in_vm); |
103 |
{ |
|
104 |
MutexLocker ml(Threads_lock); |
|
105 |
Threads::add(this); |
|
106 |
} |
|
107 |
{ |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54416
diff
changeset
|
108 |
MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag); |
49800 | 109 |
} |
110 |
} |
|
111 |
||
112 |
virtual void main_run() = 0; |
|
113 |
||
114 |
void run() { |
|
115 |
main_run(); |
|
116 |
} |
|
117 |
||
53103
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
118 |
// Override as JavaThread::post_run() calls JavaThread::exit which |
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
119 |
// expects a valid thread object oop. And we need to call signal. |
67e3a8b3449c
8214097: Rework thread initialization and teardown logic
dholmes
parents:
52877
diff
changeset
|
120 |
void post_run() { |
54416
b788c494aa46
8218483: Crash in "assert(_daemon_threads_count->get_value() > daemon_count) failed: thread count mismatch 5 : 5"
dholmes
parents:
53268
diff
changeset
|
121 |
Threads::remove(this, false); |
49800 | 122 |
_post->signal(); |
123 |
this->smr_delete(); |
|
124 |
} |
|
125 |
||
126 |
void doit() { |
|
127 |
if (os::create_thread(this, os::os_thread)) { |
|
128 |
os::start_thread(this); |
|
129 |
} else { |
|
130 |
ASSERT_TRUE(false); |
|
131 |
} |
|
132 |
} |
|
133 |
}; |
|
134 |
||
135 |
template <typename FUNC> |
|
136 |
class SingleTestThread : public JavaTestThread { |
|
137 |
public: |
|
138 |
FUNC& _f; |
|
139 |
SingleTestThread(Semaphore* post, FUNC& f) |
|
140 |
: JavaTestThread(post), _f(f) { |
|
141 |
} |
|
142 |
||
143 |
virtual ~SingleTestThread(){} |
|
144 |
||
145 |
virtual void main_run() { |
|
146 |
_f(this); |
|
147 |
} |
|
148 |
}; |
|
149 |
||
150 |
template <typename TESTFUNC> |
|
151 |
static void nomt_test_doer(TESTFUNC &f) { |
|
52618 | 152 |
Semaphore post; |
153 |
||
154 |
VMThreadBlocker* blocker = new VMThreadBlocker(); |
|
49800 | 155 |
blocker->doit(); |
52618 | 156 |
blocker->ready(); |
157 |
||
49800 | 158 |
SingleTestThread<TESTFUNC>* stt = new SingleTestThread<TESTFUNC>(&post, f); |
159 |
stt->doit(); |
|
160 |
post.wait(); |
|
52618 | 161 |
|
162 |
blocker->release(); |
|
49800 | 163 |
} |
164 |
||
165 |
template <typename RUNNER> |
|
166 |
static void mt_test_doer() { |
|
52618 | 167 |
Semaphore post; |
168 |
||
169 |
VMThreadBlocker* blocker = new VMThreadBlocker(); |
|
49800 | 170 |
blocker->doit(); |
52618 | 171 |
blocker->ready(); |
172 |
||
49800 | 173 |
RUNNER* runner = new RUNNER(&post); |
174 |
runner->doit(); |
|
175 |
post.wait(); |
|
52618 | 176 |
|
177 |
blocker->release(); |
|
49800 | 178 |
} |
179 |
||
180 |
#endif // include guard |