20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "gc/shared/concurrentGCThread.hpp"
28 #include "oops/instanceRefKlass.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "runtime/init.hpp"
31 #include "runtime/interfaceSupport.hpp"
32 #include "runtime/java.hpp"
33 #include "runtime/javaCalls.hpp"
34 #include "runtime/os.hpp"
35
36 ConcurrentGCThread::ConcurrentGCThread() :
37 _should_terminate(false), _has_terminated(false) {
38 };
39
40 void ConcurrentGCThread::create_and_start() {
41 if (os::create_thread(this, os::cgc_thread)) {
42 // XXX: need to set this to low priority
43 // unless "aggressive mode" set; priority
44 // should be just less than that of VMThread.
45 os::set_priority(this, NearMaxPriority);
46 if (!_should_terminate && !DisableStartThread) {
47 os::start_thread(this);
48 }
49 }
50 }
51
52 void ConcurrentGCThread::initialize_in_thread() {
53 this->record_stack_base_and_size();
54 this->initialize_named_thread();
55 this->set_active_handles(JNIHandleBlock::allocate_block());
56 // From this time Thread::current() should be working.
57 assert(this == Thread::current(), "just checking");
58 }
59
60 void ConcurrentGCThread::wait_for_universe_init() {
61 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
62 while (!is_init_completed() && !_should_terminate) {
63 CGC_lock->wait(Mutex::_no_safepoint_check_flag, 1);
64 }
65 }
71 MutexLockerEx mu(Terminator_lock,
72 Mutex::_no_safepoint_check_flag);
73 _has_terminated = true;
74 Terminator_lock->notify();
75 }
76 }
77
78 void ConcurrentGCThread::run() {
79 initialize_in_thread();
80 wait_for_universe_init();
81
82 run_service();
83
84 terminate();
85 }
86
87 void ConcurrentGCThread::stop() {
88 // it is ok to take late safepoints here, if needed
89 {
90 MutexLockerEx mu(Terminator_lock);
91 _should_terminate = true;
92 }
93
94 stop_service();
95
96 {
97 MutexLockerEx mu(Terminator_lock);
98 while (!_has_terminated) {
99 Terminator_lock->wait();
100 }
101 }
102 }
103
104 static void _sltLoop(JavaThread* thread, TRAPS) {
105 SurrogateLockerThread* slt = (SurrogateLockerThread*)thread;
106 slt->loop();
107 }
108
109 SurrogateLockerThread::SurrogateLockerThread() :
110 JavaThread(&_sltLoop),
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "gc/shared/concurrentGCThread.hpp"
28 #include "oops/instanceRefKlass.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "runtime/init.hpp"
31 #include "runtime/interfaceSupport.hpp"
32 #include "runtime/java.hpp"
33 #include "runtime/javaCalls.hpp"
34 #include "runtime/os.hpp"
35
36 ConcurrentGCThread::ConcurrentGCThread() :
37 _should_terminate(false), _has_terminated(false) {
38 };
39
40 void ConcurrentGCThread::create_and_start(ThreadPriority prio) {
41 if (os::create_thread(this, os::cgc_thread)) {
42 // XXX: need to set this to low priority
43 // unless "aggressive mode" set; priority
44 // should be just less than that of VMThread.
45 os::set_priority(this, prio);
46 if (!_should_terminate && !DisableStartThread) {
47 os::start_thread(this);
48 }
49 }
50 }
51
52 void ConcurrentGCThread::initialize_in_thread() {
53 this->record_stack_base_and_size();
54 this->initialize_named_thread();
55 this->set_active_handles(JNIHandleBlock::allocate_block());
56 // From this time Thread::current() should be working.
57 assert(this == Thread::current(), "just checking");
58 }
59
60 void ConcurrentGCThread::wait_for_universe_init() {
61 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
62 while (!is_init_completed() && !_should_terminate) {
63 CGC_lock->wait(Mutex::_no_safepoint_check_flag, 1);
64 }
65 }
71 MutexLockerEx mu(Terminator_lock,
72 Mutex::_no_safepoint_check_flag);
73 _has_terminated = true;
74 Terminator_lock->notify();
75 }
76 }
77
78 void ConcurrentGCThread::run() {
79 initialize_in_thread();
80 wait_for_universe_init();
81
82 run_service();
83
84 terminate();
85 }
86
87 void ConcurrentGCThread::stop() {
88 // it is ok to take late safepoints here, if needed
89 {
90 MutexLockerEx mu(Terminator_lock);
91 assert(!_has_terminated, "stop should only be called once");
92 assert(!_should_terminate, "stop should only be called once");
93 _should_terminate = true;
94 }
95
96 stop_service();
97
98 {
99 MutexLockerEx mu(Terminator_lock);
100 while (!_has_terminated) {
101 Terminator_lock->wait();
102 }
103 }
104 }
105
106 static void _sltLoop(JavaThread* thread, TRAPS) {
107 SurrogateLockerThread* slt = (SurrogateLockerThread*)thread;
108 slt->loop();
109 }
110
111 SurrogateLockerThread::SurrogateLockerThread() :
112 JavaThread(&_sltLoop),
|