< prev index next >

src/hotspot/share/runtime/thread.inline.hpp

Print this page
rev 47287 : Port 09.17.Thread_SMR_logging_update from JDK9 to JDK10
rev 47288 : sspitsyn, dcubed, eosterlund CR - minor changes prior to OpenJDK review.
rev 47289 : eosterlund, stefank CR - refactor code into threadSMR.cpp and threadSMR.hpp
rev 47290 : eosterlund CR - need more inline fixes.
rev 47291 : eosterlund, stefank CR - more inline and style cleanups


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREAD_INLINE_HPP
  26 #define SHARE_VM_RUNTIME_THREAD_INLINE_HPP
  27 
  28 #define SHARE_VM_RUNTIME_THREAD_INLINE_HPP_SCOPE
  29 
  30 #include "runtime/atomic.hpp"
  31 #include "runtime/os.inline.hpp"
  32 #include "runtime/thread.hpp"

  33 
  34 #undef SHARE_VM_RUNTIME_THREAD_INLINE_HPP_SCOPE
  35 
  36 inline void Thread::set_suspend_flag(SuspendFlags f) {
  37   assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
  38   uint32_t flags;
  39   do {
  40     flags = _suspend_flags;
  41   }
  42   while (Atomic::cmpxchg((jint)(flags | f),
  43                          (volatile jint*)&_suspend_flags,
  44                          (jint)flags) != (jint)flags);
  45 }
  46 inline void Thread::clear_suspend_flag(SuspendFlags f) {
  47   assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
  48   uint32_t flags;
  49   do {
  50     flags = _suspend_flags;
  51   }
  52   while (Atomic::cmpxchg((jint)(flags & ~f),
  53                          (volatile jint*)&_suspend_flags,
  54                          (jint)flags) != (jint)flags);
  55 }


  72 inline void Thread::clear_trace_flag() {
  73   clear_suspend_flag(_trace_flag);
  74 }
  75 
  76 inline jlong Thread::cooked_allocated_bytes() {
  77   jlong allocated_bytes = OrderAccess::load_acquire(&_allocated_bytes);
  78   if (UseTLAB) {
  79     size_t used_bytes = tlab().used_bytes();
  80     if (used_bytes <= ThreadLocalAllocBuffer::max_size_in_bytes()) {
  81       // Comparing used_bytes with the maximum allowed size will ensure
  82       // that we don't add the used bytes from a semi-initialized TLAB
  83       // ending up with incorrect values. There is still a race between
  84       // incrementing _allocated_bytes and clearing the TLAB, that might
  85       // cause double counting in rare cases.
  86       return allocated_bytes + used_bytes;
  87     }
  88   }
  89   return allocated_bytes;
  90 }
  91 












  92 inline void JavaThread::set_ext_suspended() {
  93   set_suspend_flag (_ext_suspended);
  94 }
  95 inline void JavaThread::clear_ext_suspended() {
  96   clear_suspend_flag(_ext_suspended);
  97 }
  98 
  99 inline void JavaThread::set_external_suspend() {
 100   set_suspend_flag(_external_suspend);
 101 }
 102 inline void JavaThread::clear_external_suspend() {
 103   clear_suspend_flag(_external_suspend);
 104 }
 105 
 106 inline void JavaThread::set_deopt_suspend() {
 107   set_suspend_flag(_deopt_suspend);
 108 }
 109 inline void JavaThread::clear_deopt_suspend() {
 110   clear_suspend_flag(_deopt_suspend);
 111 }


 146 inline size_t JavaThread::stack_available(address cur_sp) {
 147   // This code assumes java stacks grow down
 148   address low_addr; // Limit on the address for deepest stack depth
 149   if (_stack_guard_state == stack_guard_unused) {
 150     low_addr = stack_end();
 151   } else {
 152     low_addr = stack_reserved_zone_base();
 153   }
 154   return cur_sp > low_addr ? cur_sp - low_addr : 0;
 155 }
 156 
 157 inline bool JavaThread::stack_guards_enabled() {
 158 #ifdef ASSERT
 159   if (os::uses_stack_guard_pages()) {
 160     assert(_stack_guard_state != stack_guard_unused, "guard pages must be in use");
 161   }
 162 #endif
 163   return _stack_guard_state == stack_guard_enabled;
 164 }
 165 





















































































 166 #endif // SHARE_VM_RUNTIME_THREAD_INLINE_HPP


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREAD_INLINE_HPP
  26 #define SHARE_VM_RUNTIME_THREAD_INLINE_HPP
  27 


  28 #include "runtime/atomic.hpp"
  29 #include "runtime/os.inline.hpp"
  30 #include "runtime/thread.hpp"
  31 #include "runtime/threadSMR.hpp"
  32 


  33 inline void Thread::set_suspend_flag(SuspendFlags f) {
  34   assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
  35   uint32_t flags;
  36   do {
  37     flags = _suspend_flags;
  38   }
  39   while (Atomic::cmpxchg((jint)(flags | f),
  40                          (volatile jint*)&_suspend_flags,
  41                          (jint)flags) != (jint)flags);
  42 }
  43 inline void Thread::clear_suspend_flag(SuspendFlags f) {
  44   assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
  45   uint32_t flags;
  46   do {
  47     flags = _suspend_flags;
  48   }
  49   while (Atomic::cmpxchg((jint)(flags & ~f),
  50                          (volatile jint*)&_suspend_flags,
  51                          (jint)flags) != (jint)flags);
  52 }


  69 inline void Thread::clear_trace_flag() {
  70   clear_suspend_flag(_trace_flag);
  71 }
  72 
  73 inline jlong Thread::cooked_allocated_bytes() {
  74   jlong allocated_bytes = OrderAccess::load_acquire(&_allocated_bytes);
  75   if (UseTLAB) {
  76     size_t used_bytes = tlab().used_bytes();
  77     if (used_bytes <= ThreadLocalAllocBuffer::max_size_in_bytes()) {
  78       // Comparing used_bytes with the maximum allowed size will ensure
  79       // that we don't add the used bytes from a semi-initialized TLAB
  80       // ending up with incorrect values. There is still a race between
  81       // incrementing _allocated_bytes and clearing the TLAB, that might
  82       // cause double counting in rare cases.
  83       return allocated_bytes + used_bytes;
  84     }
  85   }
  86   return allocated_bytes;
  87 }
  88 
  89 inline ThreadsList* Thread::cmpxchg_threads_hazard_ptr(ThreadsList* exchange_value, ThreadsList* compare_value) {
  90   return (ThreadsList*)Atomic::cmpxchg_ptr(exchange_value, (void* volatile*)&_threads_hazard_ptr, compare_value);
  91 }
  92 
  93 inline ThreadsList* Thread::get_threads_hazard_ptr() {
  94   return (ThreadsList*)OrderAccess::load_ptr_acquire((void* volatile*)&_threads_hazard_ptr);
  95 }
  96 
  97 inline void Thread::set_threads_hazard_ptr(ThreadsList* new_list) {
  98   OrderAccess::release_store_ptr_fence((void* volatile*)&_threads_hazard_ptr, (void*)new_list);
  99 }
 100 
 101 inline void JavaThread::set_ext_suspended() {
 102   set_suspend_flag (_ext_suspended);
 103 }
 104 inline void JavaThread::clear_ext_suspended() {
 105   clear_suspend_flag(_ext_suspended);
 106 }
 107 
 108 inline void JavaThread::set_external_suspend() {
 109   set_suspend_flag(_external_suspend);
 110 }
 111 inline void JavaThread::clear_external_suspend() {
 112   clear_suspend_flag(_external_suspend);
 113 }
 114 
 115 inline void JavaThread::set_deopt_suspend() {
 116   set_suspend_flag(_deopt_suspend);
 117 }
 118 inline void JavaThread::clear_deopt_suspend() {
 119   clear_suspend_flag(_deopt_suspend);
 120 }


 155 inline size_t JavaThread::stack_available(address cur_sp) {
 156   // This code assumes java stacks grow down
 157   address low_addr; // Limit on the address for deepest stack depth
 158   if (_stack_guard_state == stack_guard_unused) {
 159     low_addr = stack_end();
 160   } else {
 161     low_addr = stack_reserved_zone_base();
 162   }
 163   return cur_sp > low_addr ? cur_sp - low_addr : 0;
 164 }
 165 
 166 inline bool JavaThread::stack_guards_enabled() {
 167 #ifdef ASSERT
 168   if (os::uses_stack_guard_pages()) {
 169     assert(_stack_guard_state != stack_guard_unused, "guard pages must be in use");
 170   }
 171 #endif
 172   return _stack_guard_state == stack_guard_enabled;
 173 }
 174 
 175 inline bool JavaThread::is_exiting() const {
 176   // Use load-acquire so that setting of _terminated by
 177   // JavaThread::exit() is seen more quickly.
 178   TerminatedTypes l_terminated = (TerminatedTypes)
 179       OrderAccess::load_acquire((volatile jint *) &_terminated);
 180   return l_terminated == _thread_exiting || check_is_terminated(l_terminated);
 181 }
 182 
 183 inline bool JavaThread::is_terminated() {
 184   // Use load-acquire so that setting of _terminated by
 185   // JavaThread::exit() is seen more quickly.
 186   TerminatedTypes l_terminated = (TerminatedTypes)
 187       OrderAccess::load_acquire((volatile jint *) &_terminated);
 188   return check_is_terminated(_terminated);
 189 }
 190 
 191 inline void JavaThread::set_terminated(TerminatedTypes t) {
 192   // use release-store so the setting of _terminated is seen more quickly
 193   OrderAccess::release_store((volatile jint *) &_terminated, t);
 194 }
 195 
 196 // special for Threads::remove() which is static:
 197 inline void JavaThread::set_terminated_value() {
 198   // use release-store so the setting of _terminated is seen more quickly
 199   OrderAccess::release_store((volatile jint *) &_terminated, _thread_terminated);
 200 }
 201 
 202 template <class T>
 203 inline void Threads::threads_do_smr(T *tc, Thread *self) {
 204   ThreadsListHandle handle(self);
 205   handle.threads_do(tc);
 206 }
 207 
 208 inline ThreadsList* Threads::get_smr_java_thread_list() {
 209   return (ThreadsList*)OrderAccess::load_ptr_acquire((void* volatile*)&_smr_java_thread_list);
 210 }
 211 
 212 inline ThreadsList* Threads::xchg_smr_java_thread_list(ThreadsList* new_list) {
 213   return (ThreadsList*)Atomic::xchg_ptr((void*)new_list, (volatile void*)&_smr_java_thread_list);
 214 }
 215 
 216 inline void Threads::inc_smr_deleted_thread_cnt() {
 217   Atomic::inc(&_smr_deleted_thread_cnt);
 218 }
 219 
 220 inline void Threads::update_smr_deleted_thread_time_max(jint new_value) {
 221   while (true) {
 222     jint cur_value = _smr_deleted_thread_time_max;
 223     if (new_value <= cur_value) {
 224       // No need to update max value so we're done.
 225       break;
 226     }
 227     if (Atomic::cmpxchg(new_value, &_smr_deleted_thread_time_max, cur_value) == cur_value) {
 228       // Updated max value so we're done. Otherwise try it all again.
 229       break;
 230     }
 231   }
 232 }
 233 
 234 inline void Threads::add_smr_deleted_thread_times(jint add_value) {
 235   Atomic::add(add_value, &_smr_deleted_thread_times);
 236 }
 237 
 238 inline void Threads::inc_smr_tlh_cnt() {
 239   Atomic::inc(&_smr_tlh_cnt);
 240 }
 241 
 242 inline void Threads::update_smr_tlh_time_max(jint new_value) {
 243   while (true) {
 244     jint cur_value = _smr_tlh_time_max;
 245     if (new_value <= cur_value) {
 246       // No need to update max value so we're done.
 247       break;
 248     }
 249     if (Atomic::cmpxchg(new_value, &_smr_tlh_time_max, cur_value) == cur_value) {
 250       // Updated max value so we're done. Otherwise try it all again.
 251       break;
 252     }
 253   }
 254 }
 255 
 256 inline void Threads::add_smr_tlh_times(jint add_value) {
 257   Atomic::add(add_value, &_smr_tlh_times);
 258 }
 259 
 260 #endif // SHARE_VM_RUNTIME_THREAD_INLINE_HPP
< prev index next >