31 #include "runtime/vmOperations.hpp" 32 #include "unittest.hpp" 33 34 class VM_StopSafepoint : public VM_Operation { 35 public: 36 Semaphore* _running; 37 Semaphore* _test_complete; 38 VM_StopSafepoint(Semaphore* running, Semaphore* wait_for) : 39 _running(running), _test_complete(wait_for) {} 40 VMOp_Type type() const { return VMOp_None; } 41 Mode evaluation_mode() const { return _no_safepoint; } 42 bool is_cheap_allocated() const { return false; } 43 void doit() { _running->signal(); _test_complete->wait(); } 44 }; 45 46 // This class and thread keep the non-safepoint op running while we do our testing. 47 class VMThreadBlocker : public JavaThread { 48 public: 49 Semaphore _ready; 50 Semaphore _unblock; 51 VMThreadBlocker() {} 52 virtual ~VMThreadBlocker() {} 53 void run() { 54 this->set_thread_state(_thread_in_vm); 55 { 56 MutexLocker ml(Threads_lock); 57 Threads::add(this); 58 } 59 VM_StopSafepoint ss(&_ready, &_unblock); 60 VMThread::execute(&ss); 61 Threads::remove(this); 62 this->smr_delete(); 63 } 64 void doit() { 65 if (os::create_thread(this, os::os_thread)) { 66 os::start_thread(this); 67 } else { 68 ASSERT_TRUE(false); 69 } 70 } 71 void ready() { 72 _ready.wait(); 73 } 74 void release() { 75 _unblock.signal(); 76 } 77 }; 78 79 // For testing in a real JavaThread. 80 class JavaTestThread : public JavaThread { 81 public: 82 Semaphore* _post; 83 JavaTestThread(Semaphore* post) 84 : _post(post) { 85 } 86 virtual ~JavaTestThread() {} 87 88 void prerun() { 89 this->set_thread_state(_thread_in_vm); 90 { 91 MutexLocker ml(Threads_lock); 92 Threads::add(this); 93 } 94 { 95 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); 96 } 97 } 98 99 virtual void main_run() = 0; 100 101 void run() { 102 prerun(); 103 main_run(); 104 postrun(); 105 } 106 107 void postrun() { 108 Threads::remove(this); 109 _post->signal(); 110 this->smr_delete(); 111 } 112 113 void doit() { 114 if (os::create_thread(this, os::os_thread)) { 115 os::start_thread(this); 116 } else { 117 ASSERT_TRUE(false); 118 } 119 } 120 }; 121 122 template <typename FUNC> 123 class SingleTestThread : public JavaTestThread { 124 public: 125 FUNC& _f; 126 SingleTestThread(Semaphore* post, FUNC& f) 127 : JavaTestThread(post), _f(f) { | 31 #include "runtime/vmOperations.hpp" 32 #include "unittest.hpp" 33 34 class VM_StopSafepoint : public VM_Operation { 35 public: 36 Semaphore* _running; 37 Semaphore* _test_complete; 38 VM_StopSafepoint(Semaphore* running, Semaphore* wait_for) : 39 _running(running), _test_complete(wait_for) {} 40 VMOp_Type type() const { return VMOp_None; } 41 Mode evaluation_mode() const { return _no_safepoint; } 42 bool is_cheap_allocated() const { return false; } 43 void doit() { _running->signal(); _test_complete->wait(); } 44 }; 45 46 // This class and thread keep the non-safepoint op running while we do our testing. 47 class VMThreadBlocker : public JavaThread { 48 public: 49 Semaphore _ready; 50 Semaphore _unblock; 51 VMThreadBlocker() { } 52 virtual ~VMThreadBlocker() {} 53 const char* get_thread_name_string(char* buf, int buflen) const { 54 return (char*) "VMThreadBlocker"; 55 } 56 void run() { 57 this->set_thread_state(_thread_in_vm); 58 { 59 MutexLocker ml(Threads_lock); 60 Threads::add(this); 61 } 62 VM_StopSafepoint ss(&_ready, &_unblock); 63 VMThread::execute(&ss); 64 } 65 66 // Override as JavaThread::post_run() calls JavaThread::exit which 67 // expects a valid thread object oop. 68 virtual void post_run() { 69 Threads::remove(this); 70 this->smr_delete(); 71 } 72 73 void doit() { 74 if (os::create_thread(this, os::os_thread)) { 75 os::start_thread(this); 76 } else { 77 ASSERT_TRUE(false); 78 } 79 } 80 void ready() { 81 _ready.wait(); 82 } 83 void release() { 84 _unblock.signal(); 85 } 86 }; 87 88 // For testing in a real JavaThread. 89 class JavaTestThread : public JavaThread { 90 public: 91 Semaphore* _post; 92 JavaTestThread(Semaphore* post) 93 : _post(post) { 94 } 95 virtual ~JavaTestThread() {} 96 97 const char* get_thread_name_string(char* buf, int buflen) const { 98 return (char*) "JavaTestThread"; 99 } 100 101 void pre_run() { 102 this->set_thread_state(_thread_in_vm); 103 { 104 MutexLocker ml(Threads_lock); 105 Threads::add(this); 106 } 107 { 108 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); 109 } 110 } 111 112 virtual void main_run() = 0; 113 114 void run() { 115 main_run(); 116 } 117 118 // Override as JavaThread::post_run() calls JavaThread::exit which 119 // expects a valid thread object oop. And we need to call signal. 120 void post_run() { 121 Threads::remove(this); 122 _post->signal(); 123 this->smr_delete(); 124 } 125 126 void doit() { 127 if (os::create_thread(this, os::os_thread)) { 128 os::start_thread(this); 129 } else { 130 ASSERT_TRUE(false); 131 } 132 } 133 }; 134 135 template <typename FUNC> 136 class SingleTestThread : public JavaTestThread { 137 public: 138 FUNC& _f; 139 SingleTestThread(Semaphore* post, FUNC& f) 140 : JavaTestThread(post), _f(f) { |