74 // A NoSafepointVerifier object will throw an assertion failure if 75 // the current thread passes a possible safepoint while this object is 76 // instantiated. A safepoint, will either be: an oop allocation, blocking 77 // on a Mutex or JavaLock, or executing a VM operation. 78 // 79 // If StrictSafepointChecks is turned off, it degrades into a NoGCVerifier 80 // 81 class NoSafepointVerifier : public NoGCVerifier { 82 friend class PauseNoSafepointVerifier; 83 84 private: 85 bool _activated; 86 Thread *_thread; 87 public: 88 #ifdef ASSERT 89 NoSafepointVerifier(bool activated = true, bool verifygc = true ) : 90 NoGCVerifier(verifygc), 91 _activated(activated) { 92 _thread = Thread::current(); 93 if (_activated) { 94 _thread->_allow_allocation_count++; 95 _thread->_allow_safepoint_count++; 96 } 97 } 98 99 ~NoSafepointVerifier() { 100 if (_activated) { 101 _thread->_allow_allocation_count--; 102 _thread->_allow_safepoint_count--; 103 } 104 } 105 #else 106 NoSafepointVerifier(bool activated = true, bool verifygc = true) : NoGCVerifier(verifygc){} 107 ~NoSafepointVerifier() {} 108 #endif 109 }; 110 111 // A PauseNoSafepointVerifier is used to temporarily pause the 112 // behavior of a NoSafepointVerifier object. If we are not in debug 113 // mode then there is nothing to do. If the NoSafepointVerifier 114 // object has an _activated value of false, then there is nothing to 115 // do for safepoint and allocation checking, but there may still be 116 // something to do for the underlying NoGCVerifier object. 117 118 class PauseNoSafepointVerifier : public PauseNoGCVerifier { 119 private: 120 NoSafepointVerifier * _nsv; 121 122 public: 123 #ifdef ASSERT 124 PauseNoSafepointVerifier(NoSafepointVerifier * nsv) 125 : PauseNoGCVerifier(nsv) { 126 127 _nsv = nsv; 128 if (_nsv->_activated) { 129 _nsv->_thread->_allow_allocation_count--; 130 _nsv->_thread->_allow_safepoint_count--; 131 } 132 } 133 134 ~PauseNoSafepointVerifier() { 135 if (_nsv->_activated) { 136 _nsv->_thread->_allow_allocation_count++; 137 _nsv->_thread->_allow_safepoint_count++; 138 } 139 } 140 #else 141 PauseNoSafepointVerifier(NoSafepointVerifier * nsv) 142 : PauseNoGCVerifier(nsv) {} 143 ~PauseNoSafepointVerifier() {} 144 #endif 145 }; 146 147 // A NoAllocVerifier object can be placed in methods where one assumes that 148 // no allocation will occur. The destructor will verify this property 149 // unless the constructor is called with argument false (not activated). 150 // 151 // The check will only be done in debug mode and if activated. 152 // Note: this only makes sense at safepoints (otherwise, other threads may 153 // allocate concurrently.) 154 155 class NoAllocVerifier : public StackObj { 156 private: 157 bool _activated; 158 159 public: 160 #ifdef ASSERT 161 NoAllocVerifier(bool activated = true) { 162 _activated = activated; 163 if (_activated) Thread::current()->_allow_allocation_count++; 164 } 165 166 ~NoAllocVerifier() { 167 if (_activated) Thread::current()->_allow_allocation_count--; 168 } 169 #else 170 NoAllocVerifier(bool activated = true) {} 171 ~NoAllocVerifier() {} 172 #endif 173 }; 174 175 #endif // SHARE_RUNTIME_SAFEPOINTVERIFIERS_HPP | 74 // A NoSafepointVerifier object will throw an assertion failure if 75 // the current thread passes a possible safepoint while this object is 76 // instantiated. A safepoint, will either be: an oop allocation, blocking 77 // on a Mutex or JavaLock, or executing a VM operation. 78 // 79 // If StrictSafepointChecks is turned off, it degrades into a NoGCVerifier 80 // 81 class NoSafepointVerifier : public NoGCVerifier { 82 friend class PauseNoSafepointVerifier; 83 84 private: 85 bool _activated; 86 Thread *_thread; 87 public: 88 #ifdef ASSERT 89 NoSafepointVerifier(bool activated = true, bool verifygc = true ) : 90 NoGCVerifier(verifygc), 91 _activated(activated) { 92 _thread = Thread::current(); 93 if (_activated) { 94 _thread->_allow_safepoint_count++; 95 } 96 } 97 98 ~NoSafepointVerifier() { 99 if (_activated) { 100 _thread->_allow_safepoint_count--; 101 } 102 } 103 #else 104 NoSafepointVerifier(bool activated = true, bool verifygc = true) : NoGCVerifier(verifygc){} 105 ~NoSafepointVerifier() {} 106 #endif 107 }; 108 109 // A PauseNoSafepointVerifier is used to temporarily pause the 110 // behavior of a NoSafepointVerifier object. If we are not in debug 111 // mode then there is nothing to do. If the NoSafepointVerifier 112 // object has an _activated value of false, then there is nothing to 113 // do for safepoint and allocation checking, but there may still be 114 // something to do for the underlying NoGCVerifier object. 115 116 class PauseNoSafepointVerifier : public PauseNoGCVerifier { 117 private: 118 NoSafepointVerifier * _nsv; 119 120 public: 121 #ifdef ASSERT 122 PauseNoSafepointVerifier(NoSafepointVerifier * nsv) 123 : PauseNoGCVerifier(nsv) { 124 125 _nsv = nsv; 126 if (_nsv->_activated) { 127 _nsv->_thread->_allow_safepoint_count--; 128 } 129 } 130 131 ~PauseNoSafepointVerifier() { 132 if (_nsv->_activated) { 133 _nsv->_thread->_allow_safepoint_count++; 134 } 135 } 136 #else 137 PauseNoSafepointVerifier(NoSafepointVerifier * nsv) 138 : PauseNoGCVerifier(nsv) {} 139 ~PauseNoSafepointVerifier() {} 140 #endif 141 }; 142 143 #endif // SHARE_RUNTIME_SAFEPOINTVERIFIERS_HPP |