49977
|
1 |
/*
|
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
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 |
|
|
24 |
#include "precompiled.hpp"
|
|
25 |
#include "gc/shared/oopStorage.inline.hpp"
|
|
26 |
#include "gc/shared/oopStorageParState.inline.hpp"
|
|
27 |
#include "gc/shared/workgroup.hpp"
|
|
28 |
#include "logging/log.hpp"
|
|
29 |
#include "logging/logConfiguration.hpp"
|
|
30 |
#include "memory/allocation.inline.hpp"
|
|
31 |
#include "memory/iterator.inline.hpp"
|
|
32 |
#include "runtime/interfaceSupport.inline.hpp"
|
|
33 |
#include "runtime/os.hpp"
|
|
34 |
#include "runtime/thread.hpp"
|
|
35 |
#include "runtime/vm_operations.hpp"
|
|
36 |
#include "runtime/vmThread.hpp"
|
|
37 |
#include "utilities/debug.hpp"
|
|
38 |
#include "utilities/ostream.hpp"
|
50113
|
39 |
#include "utilities/ticks.hpp"
|
49977
|
40 |
|
|
41 |
#include "unittest.hpp"
|
|
42 |
|
|
43 |
// This "test" doesn't really verify much. Rather, it's mostly a
|
|
44 |
// microbenchmark for OopStorage parallel iteration. It executes
|
|
45 |
// parallel iteration with varying numbers of threads on an storage
|
|
46 |
// object containing a large number of entries, and logs some stats
|
|
47 |
// about the distribution and performance of the iteration.
|
|
48 |
|
|
49 |
// Parallel iteration not available unless INCLUDE_ALL_GCS
|
|
50 |
#if INCLUDE_ALL_GCS
|
|
51 |
|
|
52 |
const uint _max_workers = 10;
|
|
53 |
static uint _num_workers = 0;
|
|
54 |
const size_t _storage_entries = 1000000;
|
|
55 |
|
|
56 |
class OopStorageParIterPerf : public ::testing::Test {
|
|
57 |
public:
|
|
58 |
OopStorageParIterPerf();
|
|
59 |
~OopStorageParIterPerf();
|
|
60 |
|
|
61 |
WorkGang* workers() const;
|
|
62 |
|
|
63 |
class VM_ParStateTime;
|
|
64 |
class Task;
|
|
65 |
class Closure;
|
|
66 |
|
|
67 |
Tickspan run_task(Task* task, uint nthreads);
|
|
68 |
void show_task(const Task* task, Tickspan duration, uint nthreads);
|
|
69 |
void run_test(uint nthreads);
|
|
70 |
|
|
71 |
static WorkGang* _workers;
|
|
72 |
|
|
73 |
static const int _active_rank = Mutex::leaf - 1;
|
|
74 |
static const int _allocate_rank = Mutex::leaf;
|
|
75 |
|
|
76 |
Mutex _allocate_mutex;
|
|
77 |
Mutex _active_mutex;
|
|
78 |
OopStorage _storage;
|
|
79 |
oop* _entries[_storage_entries];
|
|
80 |
};
|
|
81 |
|
|
82 |
WorkGang* OopStorageParIterPerf::_workers = NULL;
|
|
83 |
|
|
84 |
WorkGang* OopStorageParIterPerf::workers() const {
|
|
85 |
if (_workers == NULL) {
|
|
86 |
WorkGang* wg = new WorkGang("OopStorageParIterPerf workers",
|
|
87 |
_num_workers,
|
|
88 |
false,
|
|
89 |
false);
|
|
90 |
wg->initialize_workers();
|
|
91 |
wg->update_active_workers(_num_workers);
|
|
92 |
_workers = wg;
|
|
93 |
}
|
|
94 |
return _workers;
|
|
95 |
}
|
|
96 |
|
|
97 |
OopStorageParIterPerf::OopStorageParIterPerf() :
|
|
98 |
_allocate_mutex(_allocate_rank,
|
|
99 |
"test_OopStorage_parperf_allocate",
|
|
100 |
false,
|
|
101 |
Mutex::_safepoint_check_never),
|
|
102 |
_active_mutex(_active_rank,
|
|
103 |
"test_OopStorage_parperf_active",
|
|
104 |
false,
|
|
105 |
Mutex::_safepoint_check_never),
|
|
106 |
_storage("Test Storage", &_allocate_mutex, &_active_mutex)
|
|
107 |
{
|
|
108 |
for (size_t i = 0; i < _storage_entries; ++i) {
|
|
109 |
_entries[i] = _storage.allocate();
|
|
110 |
}
|
|
111 |
_num_workers = MIN2(_max_workers, (uint)os::processor_count());
|
|
112 |
}
|
|
113 |
|
|
114 |
OopStorageParIterPerf::~OopStorageParIterPerf() {
|
|
115 |
_storage.release(_entries, ARRAY_SIZE(_entries));
|
|
116 |
}
|
|
117 |
|
|
118 |
class OopStorageParIterPerf::VM_ParStateTime : public VM_GTestExecuteAtSafepoint {
|
|
119 |
public:
|
|
120 |
VM_ParStateTime(WorkGang* workers, AbstractGangTask* task, uint nthreads) :
|
|
121 |
_workers(workers), _task(task), _nthreads(nthreads)
|
|
122 |
{}
|
|
123 |
|
|
124 |
void doit() {
|
|
125 |
_workers->run_task(_task, _nthreads);
|
|
126 |
}
|
|
127 |
|
|
128 |
private:
|
|
129 |
WorkGang* _workers;
|
|
130 |
AbstractGangTask* _task;
|
|
131 |
uint _nthreads;
|
|
132 |
};
|
|
133 |
|
|
134 |
class OopStorageParIterPerf::Task : public AbstractGangTask {
|
|
135 |
typedef OopStorage::ParState<false, false> StateType;
|
|
136 |
|
|
137 |
Tickspan* _worker_times;
|
|
138 |
StateType _state;
|
|
139 |
OopClosure* _closure;
|
|
140 |
|
|
141 |
public:
|
|
142 |
Task(OopStorage* storage, OopClosure* closure, uint nthreads) :
|
|
143 |
AbstractGangTask("OopStorageParIterPerf::Task"),
|
|
144 |
_worker_times(NULL),
|
|
145 |
_state(storage, nthreads),
|
|
146 |
_closure(closure)
|
|
147 |
{
|
|
148 |
Tickspan* wtimes = NEW_C_HEAP_ARRAY(Tickspan, _num_workers, mtInternal);
|
|
149 |
for (uint i = 0; i < _num_workers; ++i) {
|
|
150 |
new (&wtimes[i]) Tickspan();
|
|
151 |
}
|
|
152 |
_worker_times = wtimes;
|
|
153 |
}
|
|
154 |
|
|
155 |
~Task() {
|
|
156 |
FREE_C_HEAP_ARRAY(Tickspan, _worker_times);
|
|
157 |
}
|
|
158 |
|
|
159 |
virtual void work(uint worker_id) {
|
|
160 |
Ticks start_time = Ticks::now();
|
|
161 |
_state.oops_do(_closure);
|
|
162 |
_worker_times[worker_id] = Ticks::now() - start_time;
|
|
163 |
}
|
|
164 |
|
|
165 |
const Tickspan* worker_times() const { return _worker_times; }
|
|
166 |
};
|
|
167 |
|
|
168 |
class OopStorageParIterPerf::Closure : public OopClosure {
|
|
169 |
public:
|
|
170 |
virtual void do_oop(oop* p) { guarantee(*p == NULL, "expected NULL"); }
|
|
171 |
virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
|
|
172 |
};
|
|
173 |
|
|
174 |
Tickspan OopStorageParIterPerf::run_task(Task* task, uint nthreads) {
|
|
175 |
tty->print_cr("Running test with %u threads", nthreads);
|
|
176 |
VM_ParStateTime op(workers(), task, nthreads);
|
|
177 |
ThreadInVMfromNative invm(JavaThread::current());
|
|
178 |
Ticks start_time = Ticks::now();
|
|
179 |
VMThread::execute(&op);
|
|
180 |
return Ticks::now() - start_time;
|
|
181 |
}
|
|
182 |
|
|
183 |
void OopStorageParIterPerf::show_task(const Task* task, Tickspan duration, uint nthreads) {
|
|
184 |
tty->print_cr("Run test with %u threads: " JLONG_FORMAT, nthreads, duration.value());
|
|
185 |
const Tickspan* wtimes = task->worker_times();
|
|
186 |
for (uint i = 0; i < _num_workers; ++i) {
|
|
187 |
if (wtimes[i] != Tickspan()) {
|
|
188 |
tty->print_cr(" %u: " JLONG_FORMAT, i, wtimes[i].value());
|
|
189 |
}
|
|
190 |
}
|
|
191 |
tty->cr();
|
|
192 |
}
|
|
193 |
|
|
194 |
void OopStorageParIterPerf::run_test(uint nthreads) {
|
|
195 |
if (nthreads <= _num_workers) {
|
|
196 |
SCOPED_TRACE(err_msg("Running test with %u threads", nthreads).buffer());
|
|
197 |
Closure closure;
|
|
198 |
Task task(&_storage, &closure, nthreads);
|
|
199 |
Tickspan t = run_task(&task, nthreads);
|
|
200 |
show_task(&task, t, nthreads);
|
|
201 |
}
|
|
202 |
}
|
|
203 |
|
|
204 |
TEST_VM_F(OopStorageParIterPerf, test) {
|
|
205 |
// Enable additional interesting logging.
|
|
206 |
#define TEST_TAGS oopstorage, blocks, stats
|
|
207 |
// There isn't an obvious way to capture the old log level so it
|
|
208 |
// can be restored here, so just use Warning as the "default".
|
|
209 |
LogLevelType old_level = LogLevel::Warning;
|
|
210 |
if (log_is_enabled(Debug, TEST_TAGS)) {
|
|
211 |
old_level = LogLevel::Debug;
|
|
212 |
} else if (log_is_enabled(Info, TEST_TAGS)) {
|
|
213 |
old_level = LogLevel::Info;
|
|
214 |
}
|
|
215 |
bool debug_enabled = old_level == LogLevel::Debug;
|
|
216 |
if (!debug_enabled) {
|
|
217 |
LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(TEST_TAGS));
|
|
218 |
}
|
|
219 |
|
|
220 |
run_test(1);
|
|
221 |
run_test(2);
|
|
222 |
run_test(3);
|
|
223 |
run_test(4);
|
|
224 |
run_test(6);
|
|
225 |
run_test(8);
|
|
226 |
run_test(10);
|
|
227 |
|
|
228 |
if (!debug_enabled) {
|
|
229 |
LogConfiguration::configure_stdout(old_level, true, LOG_TAGS(TEST_TAGS));
|
|
230 |
}
|
|
231 |
}
|
|
232 |
|
|
233 |
#endif // INCLUDE_ALL_GCS
|