8185580: Refactor Threads::possibly_parallel_oops_do() to use Threads::parallel_java_threads_do()

Reviewed-by: dholmes, coleenp
This commit is contained in:
Roman Kennke 2017-10-17 18:54:03 +02:00
parent 9adfa12663
commit b788c73f53
3 changed files with 20 additions and 20 deletions

View file

@ -563,7 +563,7 @@ public:
void work(uint worker_id) { void work(uint worker_id) {
// All threads deflate monitors and mark nmethods (if necessary). // All threads deflate monitors and mark nmethods (if necessary).
Threads::parallel_java_threads_do(&_cleanup_threads_cl); Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl);
if (!_subtasks.is_task_claimed(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) { if (!_subtasks.is_task_claimed(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) {
const char* name = "deflating idle monitors"; const char* name = "deflating idle monitors";

View file

@ -3349,20 +3349,17 @@ void Threads::threads_do(ThreadClosure* tc) {
// If CompilerThreads ever become non-JavaThreads, add them here // If CompilerThreads ever become non-JavaThreads, add them here
} }
void Threads::parallel_java_threads_do(ThreadClosure* tc) { void Threads::possibly_parallel_threads_do(bool is_par, ThreadClosure* tc) {
int cp = Threads::thread_claim_parity(); int cp = Threads::thread_claim_parity();
ALL_JAVA_THREADS(p) { ALL_JAVA_THREADS(p) {
if (p->claim_oops_do(true, cp)) { if (p->claim_oops_do(is_par, cp)) {
tc->do_thread(p); tc->do_thread(p);
} }
} }
// Thread claiming protocol requires us to claim the same interesting
// threads on all paths. Notably, Threads::possibly_parallel_threads_do
// claims all Java threads *and* the VMThread. To avoid breaking the
// claiming protocol, we have to claim VMThread on this path too, even
// if we do not apply the closure to the VMThread.
VMThread* vmt = VMThread::vm_thread(); VMThread* vmt = VMThread::vm_thread();
(void)vmt->claim_oops_do(true, cp); if (vmt->claim_oops_do(is_par, cp)) {
tc->do_thread(vmt);
}
} }
// The system initialization in the library has three phases. // The system initialization in the library has three phases.
@ -4324,17 +4321,20 @@ void Threads::assert_all_threads_claimed() {
} }
#endif // ASSERT #endif // ASSERT
class ParallelOopsDoThreadClosure : public ThreadClosure {
private:
OopClosure* _f;
CodeBlobClosure* _cf;
public:
ParallelOopsDoThreadClosure(OopClosure* f, CodeBlobClosure* cf) : _f(f), _cf(cf) {}
void do_thread(Thread* t) {
t->oops_do(_f, _cf);
}
};
void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf) { void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf) {
int cp = Threads::thread_claim_parity(); ParallelOopsDoThreadClosure tc(f, cf);
ALL_JAVA_THREADS(p) { possibly_parallel_threads_do(is_par, &tc);
if (p->claim_oops_do(is_par, cp)) {
p->oops_do(f, cf);
}
}
VMThread* vmt = VMThread::vm_thread();
if (vmt->claim_oops_do(is_par, cp)) {
vmt->oops_do(f, cf);
}
} }
#if INCLUDE_ALL_GCS #if INCLUDE_ALL_GCS

View file

@ -2052,7 +2052,7 @@ class Threads: AllStatic {
static bool includes(JavaThread* p); static bool includes(JavaThread* p);
static JavaThread* first() { return _thread_list; } static JavaThread* first() { return _thread_list; }
static void threads_do(ThreadClosure* tc); static void threads_do(ThreadClosure* tc);
static void parallel_java_threads_do(ThreadClosure* tc); static void possibly_parallel_threads_do(bool is_par, ThreadClosure* tc);
// Initializes the vm and creates the vm thread // Initializes the vm and creates the vm thread
static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain); static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);