src/hotspot/share/runtime/thread.inline.hpp
author stefank
Mon, 25 Nov 2019 12:22:13 +0100
changeset 59247 56bf71d64d51
parent 54631 3a3e4e473622
child 59252 623722a6aeb9
permissions -rw-r--r--
8234562: Move OrderAccess::release_store*/load_acquire to Atomic Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
     4
 *
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
     8
 *
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    13
 * accompanied this code).
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    14
 *
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    18
 *
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    21
 * questions.
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    22
 *
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    23
 */
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
    25
#ifndef SHARE_RUNTIME_THREAD_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
    26
#define SHARE_RUNTIME_THREAD_INLINE_HPP
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    27
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39220
diff changeset
    28
#include "runtime/atomic.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49480
diff changeset
    29
#include "runtime/globals.hpp"
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49982
diff changeset
    30
#include "runtime/orderAccess.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
    31
#include "runtime/os.inline.hpp"
52673
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
    32
#include "runtime/safepoint.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    33
#include "runtime/thread.hpp"
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
diff changeset
    34
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    35
inline void Thread::set_suspend_flag(SuspendFlags f) {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    36
  uint32_t flags;
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    37
  do {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    38
    flags = _suspend_flags;
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    39
  }
48955
e22914003cf0 8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents: 48312
diff changeset
    40
  while (Atomic::cmpxchg((flags | f), &_suspend_flags, flags) != flags);
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    41
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    42
inline void Thread::clear_suspend_flag(SuspendFlags f) {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    43
  uint32_t flags;
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    44
  do {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    45
    flags = _suspend_flags;
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    46
  }
48955
e22914003cf0 8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents: 48312
diff changeset
    47
  while (Atomic::cmpxchg((flags & ~f), &_suspend_flags, flags) != flags);
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    48
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    49
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    50
inline void Thread::set_has_async_exception() {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    51
  set_suspend_flag(_has_async_exception);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    52
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    53
inline void Thread::clear_has_async_exception() {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    54
  clear_suspend_flag(_has_async_exception);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    55
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    56
inline void Thread::set_critical_native_unlock() {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    57
  set_suspend_flag(_critical_native_unlock);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    58
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    59
inline void Thread::clear_critical_native_unlock() {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    60
  clear_suspend_flag(_critical_native_unlock);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    61
}
46643
cb5f289ba033 8183545: Event tracing, transition hooks
rehn
parents: 40655
diff changeset
    62
inline void Thread::set_trace_flag() {
cb5f289ba033 8183545: Event tracing, transition hooks
rehn
parents: 40655
diff changeset
    63
  set_suspend_flag(_trace_flag);
cb5f289ba033 8183545: Event tracing, transition hooks
rehn
parents: 40655
diff changeset
    64
}
cb5f289ba033 8183545: Event tracing, transition hooks
rehn
parents: 40655
diff changeset
    65
inline void Thread::clear_trace_flag() {
cb5f289ba033 8183545: Event tracing, transition hooks
rehn
parents: 40655
diff changeset
    66
  clear_suspend_flag(_trace_flag);
cb5f289ba033 8183545: Event tracing, transition hooks
rehn
parents: 40655
diff changeset
    67
}
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    68
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    69
inline jlong Thread::cooked_allocated_bytes() {
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
    70
  jlong allocated_bytes = Atomic::load_acquire(&_allocated_bytes);
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    71
  if (UseTLAB) {
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    72
    size_t used_bytes = tlab().used_bytes();
39220
f08faf525113 8149085: IntegrationTest1.java fails intermittently due to use of semi-initialized TLAB
sjohanss
parents: 35201
diff changeset
    73
    if (used_bytes <= ThreadLocalAllocBuffer::max_size_in_bytes()) {
f08faf525113 8149085: IntegrationTest1.java fails intermittently due to use of semi-initialized TLAB
sjohanss
parents: 35201
diff changeset
    74
      // Comparing used_bytes with the maximum allowed size will ensure
f08faf525113 8149085: IntegrationTest1.java fails intermittently due to use of semi-initialized TLAB
sjohanss
parents: 35201
diff changeset
    75
      // that we don't add the used bytes from a semi-initialized TLAB
f08faf525113 8149085: IntegrationTest1.java fails intermittently due to use of semi-initialized TLAB
sjohanss
parents: 35201
diff changeset
    76
      // ending up with incorrect values. There is still a race between
f08faf525113 8149085: IntegrationTest1.java fails intermittently due to use of semi-initialized TLAB
sjohanss
parents: 35201
diff changeset
    77
      // incrementing _allocated_bytes and clearing the TLAB, that might
f08faf525113 8149085: IntegrationTest1.java fails intermittently due to use of semi-initialized TLAB
sjohanss
parents: 35201
diff changeset
    78
      // cause double counting in rare cases.
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    79
      return allocated_bytes + used_bytes;
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    80
    }
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    81
  }
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    82
  return allocated_bytes;
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    83
}
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
    84
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    85
inline ThreadsList* Thread::cmpxchg_threads_hazard_ptr(ThreadsList* exchange_value, ThreadsList* compare_value) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    86
  return (ThreadsList*)Atomic::cmpxchg(exchange_value, &_threads_hazard_ptr, compare_value);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    87
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    88
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    89
inline ThreadsList* Thread::get_threads_hazard_ptr() {
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
    90
  return (ThreadsList*)Atomic::load_acquire(&_threads_hazard_ptr);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    91
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    92
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    93
inline void Thread::set_threads_hazard_ptr(ThreadsList* new_list) {
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
    94
  Atomic::release_store_fence(&_threads_hazard_ptr, new_list);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    95
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    96
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    97
inline void JavaThread::set_ext_suspended() {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    98
  set_suspend_flag (_ext_suspended);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
    99
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   100
inline void JavaThread::clear_ext_suspended() {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   101
  clear_suspend_flag(_ext_suspended);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   102
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   103
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   104
inline void JavaThread::set_external_suspend() {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   105
  set_suspend_flag(_external_suspend);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   106
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   107
inline void JavaThread::clear_external_suspend() {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   108
  clear_suspend_flag(_external_suspend);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   109
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   110
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   111
inline void JavaThread::set_pending_async_exception(oop e) {
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   112
  _pending_async_exception = e;
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   113
  _special_runtime_exit_condition = _async_exception;
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   114
  set_has_async_exception();
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   115
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24351
diff changeset
   116
53606
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   117
inline JavaThreadState JavaThread::thread_state() const    {
29186
d5e61d9743aa 8069593: Changes to JavaThread::_thread_state must use acquire and release
aph
parents: 25468
diff changeset
   118
#if defined(PPC64) || defined (AARCH64)
53606
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   119
  // Use membars when accessing volatile _thread_state. See
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   120
  // Threads::create_vm() for size checks.
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
   121
  return (JavaThreadState) Atomic::load_acquire((volatile jint*)&_thread_state);
53606
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   122
#else
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   123
  return _thread_state;
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   124
#endif
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   125
}
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   126
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   127
inline void JavaThread::set_thread_state(JavaThreadState s) {
53606
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   128
#if defined(PPC64) || defined (AARCH64)
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   129
  // Use membars when accessing volatile _thread_state. See
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   130
  // Threads::create_vm() for size checks.
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
   131
  Atomic::release_store((volatile jint*)&_thread_state, (jint)s);
53606
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   132
#else
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   133
  _thread_state = s;
c153b4c52e39 8218151: Simplify JavaThread::thread_state definition
shade
parents: 53305
diff changeset
   134
#endif
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   135
}
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   136
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 53606
diff changeset
   137
inline void JavaThread::set_thread_state_fence(JavaThreadState s) {
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 53606
diff changeset
   138
  set_thread_state(s);
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 53606
diff changeset
   139
  OrderAccess::fence();
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 53606
diff changeset
   140
}
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 53606
diff changeset
   141
52673
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   142
ThreadSafepointState* JavaThread::safepoint_state() const  {
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   143
  return _safepoint_state;
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   144
}
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   145
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   146
void JavaThread::set_safepoint_state(ThreadSafepointState *state) {
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   147
  _safepoint_state = state;
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   148
}
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   149
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   150
bool JavaThread::is_at_poll_safepoint() {
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   151
  return _safepoint_state->is_at_poll_safepoint();
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   152
}
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   153
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   154
void JavaThread::enter_critical() {
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   155
  assert(Thread::current() == this ||
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   156
         (Thread::current()->is_VM_thread() &&
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   157
         SafepointSynchronize::is_synchronizing()),
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   158
         "this must be current thread or synchronizing");
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   159
  _jni_active_critical++;
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   160
}
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 50921
diff changeset
   161
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   162
inline void JavaThread::set_done_attaching_via_jni() {
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   163
  _jni_attach_state = _attached_via_jni;
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   164
  OrderAccess::fence();
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   165
}
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22827
diff changeset
   166
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   167
inline bool JavaThread::stack_guard_zone_unused() {
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   168
  return _stack_guard_state == stack_guard_unused;
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   169
}
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   170
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35071
diff changeset
   171
inline bool JavaThread::stack_yellow_reserved_zone_disabled() {
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35071
diff changeset
   172
  return _stack_guard_state == stack_guard_yellow_reserved_disabled;
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   173
}
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   174
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34633
diff changeset
   175
inline bool JavaThread::stack_reserved_zone_disabled() {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34633
diff changeset
   176
  return _stack_guard_state == stack_guard_reserved_disabled;
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34633
diff changeset
   177
}
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34633
diff changeset
   178
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   179
inline size_t JavaThread::stack_available(address cur_sp) {
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   180
  // This code assumes java stacks grow down
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   181
  address low_addr; // Limit on the address for deepest stack depth
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   182
  if (_stack_guard_state == stack_guard_unused) {
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35071
diff changeset
   183
    low_addr = stack_end();
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   184
  } else {
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35071
diff changeset
   185
    low_addr = stack_reserved_zone_base();
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   186
  }
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   187
  return cur_sp > low_addr ? cur_sp - low_addr : 0;
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   188
}
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   189
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34633
diff changeset
   190
inline bool JavaThread::stack_guards_enabled() {
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   191
#ifdef ASSERT
48005
9fd89aabb6cd 8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
dholmes
parents: 47881
diff changeset
   192
  if (os::uses_stack_guard_pages() &&
9fd89aabb6cd 8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
dholmes
parents: 47881
diff changeset
   193
      !(DisablePrimordialThreadGuardPages && os::is_primordial_thread())) {
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   194
    assert(_stack_guard_state != stack_guard_unused, "guard pages must be in use");
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   195
  }
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   196
#endif
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   197
  return _stack_guard_state == stack_guard_enabled;
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   198
}
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
   199
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   200
// The release make sure this store is done after storing the handshake
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   201
// operation or global state
50921
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50429
diff changeset
   202
inline void JavaThread::set_polling_page_release(void* poll_value) {
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
   203
  Atomic::release_store(polling_page_addr(), poll_value);
50921
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50429
diff changeset
   204
}
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50429
diff changeset
   205
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50429
diff changeset
   206
// Caller is responsible for using a memory barrier if needed.
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   207
inline void JavaThread::set_polling_page(void* poll_value) {
50921
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50429
diff changeset
   208
  *polling_page_addr() = poll_value;
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   209
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   210
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   211
// The aqcquire make sure reading of polling page is done before
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   212
// the reading the handshake operation or the global state
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   213
inline volatile void* JavaThread::get_polling_page() {
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
   214
  return Atomic::load_acquire(polling_page_addr());
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   215
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   216
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   217
inline bool JavaThread::is_exiting() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   218
  // Use load-acquire so that setting of _terminated by
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   219
  // JavaThread::exit() is seen more quickly.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   220
  TerminatedTypes l_terminated = (TerminatedTypes)
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
   221
      Atomic::load_acquire((volatile jint *) &_terminated);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   222
  return l_terminated == _thread_exiting || check_is_terminated(l_terminated);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   223
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   224
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   225
inline bool JavaThread::is_terminated() const {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   226
  // Use load-acquire so that setting of _terminated by
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   227
  // JavaThread::exit() is seen more quickly.
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   228
  TerminatedTypes l_terminated = (TerminatedTypes)
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
   229
      Atomic::load_acquire((volatile jint *) &_terminated);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   230
  return check_is_terminated(l_terminated);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   231
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   232
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   233
inline void JavaThread::set_terminated(TerminatedTypes t) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   234
  // use release-store so the setting of _terminated is seen more quickly
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
   235
  Atomic::release_store((volatile jint *) &_terminated, (jint) t);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   236
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   237
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   238
// special for Threads::remove() which is static:
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   239
inline void JavaThread::set_terminated_value() {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   240
  // use release-store so the setting of _terminated is seen more quickly
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54631
diff changeset
   241
  Atomic::release_store((volatile jint *) &_terminated, (jint) _thread_terminated);
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   242
}
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
   243
53305
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   244
// Allow tracking of class initialization monitor use
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   245
inline void JavaThread::set_class_to_be_initialized(InstanceKlass* k) {
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   246
  assert((k == NULL && _class_to_be_initialized != NULL) ||
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   247
         (k != NULL && _class_to_be_initialized == NULL), "incorrect usage");
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   248
  assert(this == Thread::current(), "Only the current thread can set this field");
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   249
  _class_to_be_initialized = k;
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   250
}
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   251
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   252
inline InstanceKlass* JavaThread::class_to_be_initialized() const {
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   253
  return _class_to_be_initialized;
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   254
}
d193d58ae79d 8213397: Stack dump should show more clearly when a thread is blocked on a class initialization monitor
dholmes
parents: 53244
diff changeset
   255
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
   256
#endif // SHARE_RUNTIME_THREAD_INLINE_HPP