Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_THREAD_INL_H_ |
| 18 | #define ART_RUNTIME_THREAD_INL_H_ |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 19 | |
| 20 | #include "thread.h" |
| 21 | |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame^] | 22 | #ifdef ART_TARGET_ANDROID |
Andreas Gampe | 4382f1e | 2015-08-05 01:08:53 +0000 | [diff] [blame] | 23 | #include <bionic_tls.h> // Access to our own TLS slot. |
| 24 | #endif |
| 25 | |
Ian Rogers | 02ed4c0 | 2013-09-06 13:10:04 -0700 | [diff] [blame] | 26 | #include <pthread.h> |
| 27 | |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 28 | #include "base/casts.h" |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 29 | #include "base/mutex-inl.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 30 | #include "gc/heap.h" |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 31 | #include "jni_env_ext.h" |
Mathieu Chartier | 3cf2253 | 2015-07-09 15:15:09 -0700 | [diff] [blame] | 32 | #include "thread_pool.h" |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 33 | |
| 34 | namespace art { |
| 35 | |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 36 | // Quickly access the current thread from a JNIEnv. |
| 37 | static inline Thread* ThreadForEnv(JNIEnv* env) { |
| 38 | JNIEnvExt* full_env(down_cast<JNIEnvExt*>(env)); |
| 39 | return full_env->self; |
| 40 | } |
| 41 | |
Ian Rogers | 02ed4c0 | 2013-09-06 13:10:04 -0700 | [diff] [blame] | 42 | inline Thread* Thread::Current() { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 43 | // We rely on Thread::Current returning null for a detached thread, so it's not obvious |
Ian Rogers | 02ed4c0 | 2013-09-06 13:10:04 -0700 | [diff] [blame] | 44 | // that we can replace this with a direct %fs access on x86. |
| 45 | if (!is_started_) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 46 | return nullptr; |
Ian Rogers | 02ed4c0 | 2013-09-06 13:10:04 -0700 | [diff] [blame] | 47 | } else { |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame^] | 48 | #ifdef ART_TARGET_ANDROID |
Andreas Gampe | 4382f1e | 2015-08-05 01:08:53 +0000 | [diff] [blame] | 49 | void* thread = __get_tls()[TLS_SLOT_ART_THREAD_SELF]; |
| 50 | #else |
Ian Rogers | 02ed4c0 | 2013-09-06 13:10:04 -0700 | [diff] [blame] | 51 | void* thread = pthread_getspecific(Thread::pthread_key_self_); |
Andreas Gampe | 4382f1e | 2015-08-05 01:08:53 +0000 | [diff] [blame] | 52 | #endif |
Ian Rogers | 02ed4c0 | 2013-09-06 13:10:04 -0700 | [diff] [blame] | 53 | return reinterpret_cast<Thread*>(thread); |
| 54 | } |
| 55 | } |
| 56 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 57 | inline void Thread::AllowThreadSuspension() { |
| 58 | DCHECK_EQ(Thread::Current(), this); |
| 59 | if (UNLIKELY(TestAllFlags())) { |
| 60 | CheckSuspend(); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | inline void Thread::CheckSuspend() { |
| 65 | DCHECK_EQ(Thread::Current(), this); |
| 66 | for (;;) { |
| 67 | if (ReadFlag(kCheckpointRequest)) { |
| 68 | RunCheckpointFunction(); |
| 69 | } else if (ReadFlag(kSuspendRequest)) { |
| 70 | FullSuspendCheck(); |
| 71 | } else { |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 77 | inline ThreadState Thread::SetState(ThreadState new_state) { |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 78 | // Should only be used to change between suspended states. |
| 79 | // Cannot use this code to change into or from Runnable as changing to Runnable should |
| 80 | // fail if old_state_and_flags.suspend_request is true and changing from Runnable might |
| 81 | // miss passing an active suspend barrier. |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 82 | DCHECK_NE(new_state, kRunnable); |
Andreas Gampe | ef048f6 | 2014-11-25 22:12:27 -0800 | [diff] [blame] | 83 | if (kIsDebugBuild && this != Thread::Current()) { |
| 84 | std::string name; |
| 85 | GetThreadName(name); |
| 86 | LOG(FATAL) << "Thread \"" << name << "\"(" << this << " != Thread::Current()=" |
| 87 | << Thread::Current() << ") changing state to " << new_state; |
| 88 | } |
Chris Dearman | 59cde53 | 2013-12-04 18:53:49 -0800 | [diff] [blame] | 89 | union StateAndFlags old_state_and_flags; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 90 | old_state_and_flags.as_int = tls32_.state_and_flags.as_int; |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 91 | CHECK_NE(old_state_and_flags.as_struct.state, kRunnable); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 92 | tls32_.state_and_flags.as_struct.state = new_state; |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 93 | return static_cast<ThreadState>(old_state_and_flags.as_struct.state); |
| 94 | } |
| 95 | |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 96 | inline void Thread::AssertThreadSuspensionIsAllowable(bool check_locks) const { |
Ian Rogers | f3d874c | 2014-07-17 18:52:42 -0700 | [diff] [blame] | 97 | if (kIsDebugBuild) { |
Nicolas Geoffray | db97871 | 2014-12-09 13:33:38 +0000 | [diff] [blame] | 98 | if (gAborting == 0) { |
| 99 | CHECK_EQ(0u, tls32_.no_thread_suspension) << tlsPtr_.last_no_thread_suspension_cause; |
| 100 | } |
Ian Rogers | f3d874c | 2014-07-17 18:52:42 -0700 | [diff] [blame] | 101 | if (check_locks) { |
| 102 | bool bad_mutexes_held = false; |
| 103 | for (int i = kLockLevelCount - 1; i >= 0; --i) { |
| 104 | // We expect no locks except the mutator_lock_ or thread list suspend thread lock. |
Ian Rogers | 4ad5cd3 | 2014-11-11 23:08:07 -0800 | [diff] [blame] | 105 | if (i != kMutatorLock) { |
Ian Rogers | f3d874c | 2014-07-17 18:52:42 -0700 | [diff] [blame] | 106 | BaseMutex* held_mutex = GetHeldMutex(static_cast<LockLevel>(i)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 107 | if (held_mutex != nullptr) { |
Ian Rogers | f3d874c | 2014-07-17 18:52:42 -0700 | [diff] [blame] | 108 | LOG(ERROR) << "holding \"" << held_mutex->GetName() |
| 109 | << "\" at point where thread suspension is expected"; |
| 110 | bad_mutexes_held = true; |
| 111 | } |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 112 | } |
| 113 | } |
Nicolas Geoffray | db97871 | 2014-12-09 13:33:38 +0000 | [diff] [blame] | 114 | if (gAborting == 0) { |
| 115 | CHECK(!bad_mutexes_held); |
| 116 | } |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 117 | } |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 118 | } |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Mathieu Chartier | 8ac9c91 | 2015-10-01 15:58:41 -0700 | [diff] [blame] | 121 | inline void Thread::TransitionToSuspendedAndRunCheckpoints(ThreadState new_state) { |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 122 | DCHECK_NE(new_state, kRunnable); |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 123 | DCHECK_EQ(GetState(), kRunnable); |
| 124 | union StateAndFlags old_state_and_flags; |
| 125 | union StateAndFlags new_state_and_flags; |
Dave Allison | 0f5f6bb | 2013-11-22 17:39:19 -0800 | [diff] [blame] | 126 | while (true) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 127 | old_state_and_flags.as_int = tls32_.state_and_flags.as_int; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 128 | if (UNLIKELY((old_state_and_flags.as_struct.flags & kCheckpointRequest) != 0)) { |
| 129 | RunCheckpointFunction(); |
| 130 | continue; |
| 131 | } |
Dave Allison | 0f5f6bb | 2013-11-22 17:39:19 -0800 | [diff] [blame] | 132 | // Change the state but keep the current flags (kCheckpointRequest is clear). |
| 133 | DCHECK_EQ((old_state_and_flags.as_struct.flags & kCheckpointRequest), 0); |
| 134 | new_state_and_flags.as_struct.flags = old_state_and_flags.as_struct.flags; |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 135 | new_state_and_flags.as_struct.state = new_state; |
Ian Rogers | b8e087e | 2014-07-09 21:12:06 -0700 | [diff] [blame] | 136 | |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 137 | // CAS the value with a memory ordering. |
Ian Rogers | b8e087e | 2014-07-09 21:12:06 -0700 | [diff] [blame] | 138 | bool done = |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 139 | tls32_.state_and_flags.as_atomic_int.CompareExchangeWeakRelease(old_state_and_flags.as_int, |
Ian Rogers | b8e087e | 2014-07-09 21:12:06 -0700 | [diff] [blame] | 140 | new_state_and_flags.as_int); |
| 141 | if (LIKELY(done)) { |
Dave Allison | 0f5f6bb | 2013-11-22 17:39:19 -0800 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | } |
Mathieu Chartier | 8ac9c91 | 2015-10-01 15:58:41 -0700 | [diff] [blame] | 145 | } |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 146 | |
Mathieu Chartier | 8ac9c91 | 2015-10-01 15:58:41 -0700 | [diff] [blame] | 147 | inline void Thread::PassActiveSuspendBarriers() { |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 148 | while (true) { |
| 149 | uint16_t current_flags = tls32_.state_and_flags.as_struct.flags; |
| 150 | if (LIKELY((current_flags & (kCheckpointRequest | kActiveSuspendBarrier)) == 0)) { |
| 151 | break; |
| 152 | } else if ((current_flags & kActiveSuspendBarrier) != 0) { |
| 153 | PassActiveSuspendBarriers(this); |
| 154 | } else { |
| 155 | // Impossible |
Mathieu Chartier | 8ac9c91 | 2015-10-01 15:58:41 -0700 | [diff] [blame] | 156 | LOG(FATAL) << "Fatal, thread transitioned into suspended without running the checkpoint"; |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 157 | } |
| 158 | } |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Mathieu Chartier | 8ac9c91 | 2015-10-01 15:58:41 -0700 | [diff] [blame] | 161 | inline void Thread::TransitionFromRunnableToSuspended(ThreadState new_state) { |
| 162 | AssertThreadSuspensionIsAllowable(); |
| 163 | DCHECK_EQ(this, Thread::Current()); |
| 164 | // Change to non-runnable state, thereby appearing suspended to the system. |
| 165 | TransitionToSuspendedAndRunCheckpoints(new_state); |
| 166 | // Mark the release of the share of the mutator_lock_. |
| 167 | Locks::mutator_lock_->TransitionFromRunnableToSuspended(this); |
| 168 | // Once suspended - check the active suspend barrier flag |
| 169 | PassActiveSuspendBarriers(); |
| 170 | } |
| 171 | |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 172 | inline ThreadState Thread::TransitionFromSuspendedToRunnable() { |
Chris Dearman | 59cde53 | 2013-12-04 18:53:49 -0800 | [diff] [blame] | 173 | union StateAndFlags old_state_and_flags; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 174 | old_state_and_flags.as_int = tls32_.state_and_flags.as_int; |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 175 | int16_t old_state = old_state_and_flags.as_struct.state; |
| 176 | DCHECK_NE(static_cast<ThreadState>(old_state), kRunnable); |
| 177 | do { |
| 178 | Locks::mutator_lock_->AssertNotHeld(this); // Otherwise we starve GC.. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 179 | old_state_and_flags.as_int = tls32_.state_and_flags.as_int; |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 180 | DCHECK_EQ(old_state_and_flags.as_struct.state, old_state); |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 181 | if (LIKELY(old_state_and_flags.as_struct.flags == 0)) { |
| 182 | // Optimize for the return from native code case - this is the fast path. |
| 183 | // Atomically change from suspended to runnable if no suspend request pending. |
| 184 | union StateAndFlags new_state_and_flags; |
| 185 | new_state_and_flags.as_int = old_state_and_flags.as_int; |
| 186 | new_state_and_flags.as_struct.state = kRunnable; |
| 187 | // CAS the value with a memory barrier. |
| 188 | if (LIKELY(tls32_.state_and_flags.as_atomic_int.CompareExchangeWeakAcquire( |
| 189 | old_state_and_flags.as_int, |
| 190 | new_state_and_flags.as_int))) { |
| 191 | // Mark the acquisition of a share of the mutator_lock_. |
| 192 | Locks::mutator_lock_->TransitionFromSuspendedToRunnable(this); |
| 193 | break; |
| 194 | } |
| 195 | } else if ((old_state_and_flags.as_struct.flags & kActiveSuspendBarrier) != 0) { |
| 196 | PassActiveSuspendBarriers(this); |
| 197 | } else if ((old_state_and_flags.as_struct.flags & kCheckpointRequest) != 0) { |
| 198 | // Impossible |
Mathieu Chartier | dabdccc | 2015-10-01 14:46:29 -0700 | [diff] [blame] | 199 | LOG(FATAL) << "Transitioning to runnable with checkpoint flag, " |
| 200 | << " flags=" << old_state_and_flags.as_struct.flags |
| 201 | << " state=" << old_state_and_flags.as_struct.state; |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 202 | } else if ((old_state_and_flags.as_struct.flags & kSuspendRequest) != 0) { |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 203 | // Wait while our suspend count is non-zero. |
| 204 | MutexLock mu(this, *Locks::thread_suspend_count_lock_); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 205 | old_state_and_flags.as_int = tls32_.state_and_flags.as_int; |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 206 | DCHECK_EQ(old_state_and_flags.as_struct.state, old_state); |
| 207 | while ((old_state_and_flags.as_struct.flags & kSuspendRequest) != 0) { |
| 208 | // Re-check when Thread::resume_cond_ is notified. |
| 209 | Thread::resume_cond_->Wait(this); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 210 | old_state_and_flags.as_int = tls32_.state_and_flags.as_int; |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 211 | DCHECK_EQ(old_state_and_flags.as_struct.state, old_state); |
| 212 | } |
| 213 | DCHECK_EQ(GetSuspendCount(), 0); |
| 214 | } |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 215 | } while (true); |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 216 | // Run the flip function, if set. |
| 217 | Closure* flip_func = GetFlipFunction(); |
| 218 | if (flip_func != nullptr) { |
| 219 | flip_func->Run(this); |
| 220 | } |
| 221 | return static_cast<ThreadState>(old_state); |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 224 | inline void Thread::VerifyStack() { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 225 | if (kVerifyStack) { |
| 226 | if (Runtime::Current()->GetHeap()->IsObjectValidationEnabled()) { |
| 227 | VerifyStackImpl(); |
| 228 | } |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 232 | inline size_t Thread::TlabSize() const { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 233 | return tlsPtr_.thread_local_end - tlsPtr_.thread_local_pos; |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 236 | inline mirror::Object* Thread::AllocTlab(size_t bytes) { |
| 237 | DCHECK_GE(TlabSize(), bytes); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 238 | ++tlsPtr_.thread_local_objects; |
| 239 | mirror::Object* ret = reinterpret_cast<mirror::Object*>(tlsPtr_.thread_local_pos); |
| 240 | tlsPtr_.thread_local_pos += bytes; |
Mathieu Chartier | 692fafd | 2013-11-29 17:24:40 -0800 | [diff] [blame] | 241 | return ret; |
| 242 | } |
| 243 | |
Hiroshi Yamauchi | f5b0e20 | 2014-02-11 17:02:22 -0800 | [diff] [blame] | 244 | inline bool Thread::PushOnThreadLocalAllocationStack(mirror::Object* obj) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 245 | DCHECK_LE(tlsPtr_.thread_local_alloc_stack_top, tlsPtr_.thread_local_alloc_stack_end); |
| 246 | if (tlsPtr_.thread_local_alloc_stack_top < tlsPtr_.thread_local_alloc_stack_end) { |
Hiroshi Yamauchi | f5b0e20 | 2014-02-11 17:02:22 -0800 | [diff] [blame] | 247 | // There's room. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 248 | DCHECK_LE(reinterpret_cast<uint8_t*>(tlsPtr_.thread_local_alloc_stack_top) + |
Mathieu Chartier | cb535da | 2015-01-23 13:50:03 -0800 | [diff] [blame] | 249 | sizeof(StackReference<mirror::Object>), |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 250 | reinterpret_cast<uint8_t*>(tlsPtr_.thread_local_alloc_stack_end)); |
Mathieu Chartier | cb535da | 2015-01-23 13:50:03 -0800 | [diff] [blame] | 251 | DCHECK(tlsPtr_.thread_local_alloc_stack_top->AsMirrorPtr() == nullptr); |
| 252 | tlsPtr_.thread_local_alloc_stack_top->Assign(obj); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 253 | ++tlsPtr_.thread_local_alloc_stack_top; |
Hiroshi Yamauchi | f5b0e20 | 2014-02-11 17:02:22 -0800 | [diff] [blame] | 254 | return true; |
| 255 | } |
| 256 | return false; |
| 257 | } |
| 258 | |
Mathieu Chartier | cb535da | 2015-01-23 13:50:03 -0800 | [diff] [blame] | 259 | inline void Thread::SetThreadLocalAllocationStack(StackReference<mirror::Object>* start, |
| 260 | StackReference<mirror::Object>* end) { |
Hiroshi Yamauchi | f5b0e20 | 2014-02-11 17:02:22 -0800 | [diff] [blame] | 261 | DCHECK(Thread::Current() == this) << "Should be called by self"; |
| 262 | DCHECK(start != nullptr); |
| 263 | DCHECK(end != nullptr); |
Mathieu Chartier | cb535da | 2015-01-23 13:50:03 -0800 | [diff] [blame] | 264 | DCHECK_ALIGNED(start, sizeof(StackReference<mirror::Object>)); |
| 265 | DCHECK_ALIGNED(end, sizeof(StackReference<mirror::Object>)); |
Hiroshi Yamauchi | f5b0e20 | 2014-02-11 17:02:22 -0800 | [diff] [blame] | 266 | DCHECK_LT(start, end); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 267 | tlsPtr_.thread_local_alloc_stack_end = end; |
| 268 | tlsPtr_.thread_local_alloc_stack_top = start; |
Hiroshi Yamauchi | f5b0e20 | 2014-02-11 17:02:22 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | inline void Thread::RevokeThreadLocalAllocationStack() { |
| 272 | if (kIsDebugBuild) { |
| 273 | // Note: self is not necessarily equal to this thread since thread may be suspended. |
| 274 | Thread* self = Thread::Current(); |
| 275 | DCHECK(this == self || IsSuspended() || GetState() == kWaitingPerformingGc) |
| 276 | << GetState() << " thread " << this << " self " << self; |
| 277 | } |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 278 | tlsPtr_.thread_local_alloc_stack_end = nullptr; |
| 279 | tlsPtr_.thread_local_alloc_stack_top = nullptr; |
Hiroshi Yamauchi | f5b0e20 | 2014-02-11 17:02:22 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 282 | } // namespace art |
| 283 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 284 | #endif // ART_RUNTIME_THREAD_INL_H_ |