Mercurial > hg > truffle
diff src/share/vm/runtime/thread.cpp @ 1842:6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
Summary: Under certain circumstances a safepoint could happen between a JavaThread object being created and that object being added to the Java threads list. This could cause the active field of that thread's SATB queue to get out-of-sync with respect to the other Java threads. The solution is to activate the SATB queue, when necessary, before adding the thread to the Java threads list, not when the JavaThread object is created. The changeset also includes a small fix to rename the surrogate locker thread from "Surrogate Locker Thread (CMS)" to "Surrogate Locker Thread (Concurrent GC)" since it's also used in G1.
Reviewed-by: iveresov, ysr, johnc, jcoomes
author | tonyp |
---|---|
date | Fri, 01 Oct 2010 16:43:05 -0400 |
parents | 8f6f7587d292 |
children | 0715f0cf171d |
line wrap: on
line diff
--- a/src/share/vm/runtime/thread.cpp Fri Oct 01 21:48:40 2010 -0700 +++ b/src/share/vm/runtime/thread.cpp Fri Oct 01 16:43:05 2010 -0400 @@ -1644,7 +1644,29 @@ satb_mark_queue().flush(); dirty_card_queue().flush(); } -#endif + +void JavaThread::initialize_queues() { + assert(!SafepointSynchronize::is_at_safepoint(), + "we should not be at a safepoint"); + + ObjPtrQueue& satb_queue = satb_mark_queue(); + SATBMarkQueueSet& satb_queue_set = satb_mark_queue_set(); + // The SATB queue should have been constructed with its active + // field set to false. + assert(!satb_queue.is_active(), "SATB queue should not be active"); + assert(satb_queue.is_empty(), "SATB queue should be empty"); + // If we are creating the thread during a marking cycle, we should + // set the active field of the SATB queue to true. + if (satb_queue_set.is_active()) { + satb_queue.set_active(true); + } + + DirtyCardQueue& dirty_queue = dirty_card_queue(); + // The dirty card queue should have been constructed with its + // active field set to true. + assert(dirty_queue.is_active(), "dirty card queue should be active"); +} +#endif // !SERIALGC void JavaThread::cleanup_failed_attach_current_thread() { if (get_thread_profiler() != NULL) { @@ -3626,6 +3648,10 @@ void Threads::add(JavaThread* p, bool force_daemon) { // The threads lock must be owned at this point assert_locked_or_safepoint(Threads_lock); + + // See the comment for this method in thread.hpp for its purpose and + // why it is called here. + p->initialize_queues(); p->set_next(_thread_list); _thread_list = p; _number_of_threads++;