8202649: Move the Parallel GC specific task creation functions out of Threads

Reviewed-by: ehelin, pliden
This commit is contained in:
Stefan Karlsson 2018-05-07 16:12:07 +02:00
parent 99072b90d7
commit c590979683
8 changed files with 50 additions and 51 deletions

View file

@ -60,15 +60,7 @@ void ThreadRootsMarkingTask::do_it(GCTaskManager* manager, uint which) {
ParCompactionManager::MarkAndPushClosure mark_and_push_closure(cm); ParCompactionManager::MarkAndPushClosure mark_and_push_closure(cm);
MarkingCodeBlobClosure mark_and_push_in_blobs(&mark_and_push_closure, !CodeBlobToOopClosure::FixRelocations); MarkingCodeBlobClosure mark_and_push_in_blobs(&mark_and_push_closure, !CodeBlobToOopClosure::FixRelocations);
if (_java_thread != NULL) _thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
_java_thread->oops_do(
&mark_and_push_closure,
&mark_and_push_in_blobs);
if (_vm_thread != NULL)
_vm_thread->oops_do(
&mark_and_push_closure,
&mark_and_push_in_blobs);
// Do the real work // Do the real work
cm->follow_marking_stacks(); cm->follow_marking_stacks();

View file

@ -67,11 +67,10 @@ class ParallelTaskTerminator;
class ThreadRootsMarkingTask : public GCTask { class ThreadRootsMarkingTask : public GCTask {
private: private:
JavaThread* _java_thread; Thread* _thread;
VMThread* _vm_thread;
public: public:
ThreadRootsMarkingTask(JavaThread* root) : _java_thread(root), _vm_thread(NULL) {} ThreadRootsMarkingTask(Thread* root) : _thread(root) {}
ThreadRootsMarkingTask(VMThread* root) : _java_thread(NULL), _vm_thread(root) {}
char* name() { return (char *)"thread-roots-marking-task"; } char* name() { return (char *)"thread-roots-marking-task"; }

View file

@ -2049,6 +2049,17 @@ GCTaskManager* const PSParallelCompact::gc_task_manager() {
return ParallelScavengeHeap::gc_task_manager(); return ParallelScavengeHeap::gc_task_manager();
} }
class PCAddThreadRootsMarkingTaskClosure : public ThreadClosure {
private:
GCTaskQueue* _q;
public:
PCAddThreadRootsMarkingTaskClosure(GCTaskQueue* q) : _q(q) { }
void do_thread(Thread* t) {
_q->enqueue(new ThreadRootsMarkingTask(t));
}
};
void PSParallelCompact::marking_phase(ParCompactionManager* cm, void PSParallelCompact::marking_phase(ParCompactionManager* cm,
bool maximum_heap_compaction, bool maximum_heap_compaction,
ParallelOldTracer *gc_tracer) { ParallelOldTracer *gc_tracer) {
@ -2077,7 +2088,8 @@ void PSParallelCompact::marking_phase(ParCompactionManager* cm,
q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe)); q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe));
q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles)); q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles));
// We scan the thread roots in parallel // We scan the thread roots in parallel
Threads::create_thread_roots_marking_tasks(q); PCAddThreadRootsMarkingTaskClosure cl(q);
Threads::java_threads_and_vm_thread_do(&cl);
q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer)); q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer));
q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management)); q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management));
q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary)); q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary));

View file

@ -242,6 +242,17 @@ bool PSScavenge::invoke() {
return full_gc_done; return full_gc_done;
} }
class PSAddThreadRootsTaskClosure : public ThreadClosure {
private:
GCTaskQueue* _q;
public:
PSAddThreadRootsTaskClosure(GCTaskQueue* q) : _q(q) { }
void do_thread(Thread* t) {
_q->enqueue(new ThreadRootsTask(t));
}
};
// This method contains no policy. You should probably // This method contains no policy. You should probably
// be calling invoke() instead. // be calling invoke() instead.
bool PSScavenge::invoke_no_policy() { bool PSScavenge::invoke_no_policy() {
@ -382,7 +393,8 @@ bool PSScavenge::invoke_no_policy() {
q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::universe)); q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::universe));
q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::jni_handles)); q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::jni_handles));
// We scan the thread roots in parallel // We scan the thread roots in parallel
Threads::create_thread_roots_tasks(q); PSAddThreadRootsTaskClosure cl(q);
Threads::java_threads_and_vm_thread_do(&cl);
q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::object_synchronizer)); q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::object_synchronizer));
q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::management)); q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::management));
q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::system_dictionary)); q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::system_dictionary));

View file

@ -119,11 +119,7 @@ void ThreadRootsTask::do_it(GCTaskManager* manager, uint which) {
PSScavengeRootsClosure roots_closure(pm); PSScavengeRootsClosure roots_closure(pm);
MarkingCodeBlobClosure roots_in_blobs(&roots_closure, CodeBlobToOopClosure::FixRelocations); MarkingCodeBlobClosure roots_in_blobs(&roots_closure, CodeBlobToOopClosure::FixRelocations);
if (_java_thread != NULL) _thread->oops_do(&roots_closure, &roots_in_blobs);
_java_thread->oops_do(&roots_closure, &roots_in_blobs);
if (_vm_thread != NULL)
_vm_thread->oops_do(&roots_closure, &roots_in_blobs);
// Do the real work // Do the real work
pm->drain_stacks(false); pm->drain_stacks(false);

View file

@ -81,11 +81,10 @@ class ScavengeRootsTask : public GCTask {
class ThreadRootsTask : public GCTask { class ThreadRootsTask : public GCTask {
private: private:
JavaThread* _java_thread; Thread* _thread;
VMThread* _vm_thread;
public: public:
ThreadRootsTask(JavaThread* root) : _java_thread(root), _vm_thread(NULL) {} ThreadRootsTask(Thread* root) : _thread(root) {}
ThreadRootsTask(VMThread* root) : _java_thread(NULL), _vm_thread(root) {}
char* name() { return (char *)"thread-roots-task"; } char* name() { return (char *)"thread-roots-task"; }

View file

@ -114,9 +114,6 @@
#include "utilities/macros.hpp" #include "utilities/macros.hpp"
#include "utilities/preserveException.hpp" #include "utilities/preserveException.hpp"
#include "utilities/vmError.hpp" #include "utilities/vmError.hpp"
#if INCLUDE_PARALLELGC
#include "gc/parallel/pcTasks.hpp"
#endif
#if INCLUDE_JVMCI #if INCLUDE_JVMCI
#include "jvmci/jvmciCompiler.hpp" #include "jvmci/jvmciCompiler.hpp"
#include "jvmci/jvmciRuntime.hpp" #include "jvmci/jvmciRuntime.hpp"
@ -3436,13 +3433,25 @@ void Threads::non_java_threads_do(ThreadClosure* tc) {
// If CompilerThreads ever become non-JavaThreads, add them here // If CompilerThreads ever become non-JavaThreads, add them here
} }
// All JavaThreads + all non-JavaThreads (i.e., every thread in the system). // All JavaThreads
void Threads::threads_do(ThreadClosure* tc) { void Threads::java_threads_do(ThreadClosure* tc) {
assert_locked_or_safepoint(Threads_lock); assert_locked_or_safepoint(Threads_lock);
// ALL_JAVA_THREADS iterates through all JavaThreads. // ALL_JAVA_THREADS iterates through all JavaThreads.
ALL_JAVA_THREADS(p) { ALL_JAVA_THREADS(p) {
tc->do_thread(p); tc->do_thread(p);
} }
}
void Threads::java_threads_and_vm_thread_do(ThreadClosure* tc) {
assert_locked_or_safepoint(Threads_lock);
java_threads_do(tc);
tc->do_thread(VMThread::vm_thread());
}
// All JavaThreads + all non-JavaThreads (i.e., every thread in the system).
void Threads::threads_do(ThreadClosure* tc) {
assert_locked_or_safepoint(Threads_lock);
java_threads_do(tc);
non_java_threads_do(tc); non_java_threads_do(tc);
} }
@ -4465,24 +4474,6 @@ void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClos
possibly_parallel_threads_do(is_par, &tc); possibly_parallel_threads_do(is_par, &tc);
} }
#if INCLUDE_PARALLELGC
// Used by ParallelScavenge
void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
ALL_JAVA_THREADS(p) {
q->enqueue(new ThreadRootsTask(p));
}
q->enqueue(new ThreadRootsTask(VMThread::vm_thread()));
}
// Used by Parallel Old
void Threads::create_thread_roots_marking_tasks(GCTaskQueue* q) {
ALL_JAVA_THREADS(p) {
q->enqueue(new ThreadRootsMarkingTask(p));
}
q->enqueue(new ThreadRootsMarkingTask(VMThread::vm_thread()));
}
#endif // INCLUDE_PARALLELGC
void Threads::nmethods_do(CodeBlobClosure* cf) { void Threads::nmethods_do(CodeBlobClosure* cf) {
ALL_JAVA_THREADS(p) { ALL_JAVA_THREADS(p) {
// This is used by the code cache sweeper to mark nmethods that are active // This is used by the code cache sweeper to mark nmethods that are active

View file

@ -2104,6 +2104,8 @@ class Threads: AllStatic {
static void add(JavaThread* p, bool force_daemon = false); static void add(JavaThread* p, bool force_daemon = false);
static void remove(JavaThread* p); static void remove(JavaThread* p);
static void non_java_threads_do(ThreadClosure* tc); static void non_java_threads_do(ThreadClosure* tc);
static void java_threads_do(ThreadClosure* tc);
static void java_threads_and_vm_thread_do(ThreadClosure* tc);
static void threads_do(ThreadClosure* tc); static void threads_do(ThreadClosure* tc);
static void possibly_parallel_threads_do(bool is_par, ThreadClosure* tc); static void possibly_parallel_threads_do(bool is_par, ThreadClosure* tc);
@ -2142,10 +2144,6 @@ class Threads: AllStatic {
static void oops_do(OopClosure* f, CodeBlobClosure* cf); static void oops_do(OopClosure* f, CodeBlobClosure* cf);
// This version may be called by sequential or parallel code. // This version may be called by sequential or parallel code.
static void possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf); static void possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf);
// This creates a list of GCTasks, one per thread.
static void create_thread_roots_tasks(GCTaskQueue* q);
// This creates a list of GCTasks, one per thread, for marking objects.
static void create_thread_roots_marking_tasks(GCTaskQueue* q);
// Apply "f->do_oop" to roots in all threads that // Apply "f->do_oop" to roots in all threads that
// are part of compiled frames // are part of compiled frames