blob: e03df2752cee9e0c3f679ee9bccc672abba22aa2 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
2 * Copyright (C) 2013 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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_THREAD_STATE_H_
18#define ART_RUNTIME_THREAD_STATE_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Andreas Gampe8764dc32019-01-07 15:20:12 -080020#include <iosfwd>
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070021
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022namespace art {
23
Hans Boehm230beda2019-05-03 16:06:52 -070024// State stored in our C++ class Thread.
25// When we refer to "a suspended state", or when function names mention "ToSuspended" or
26// "FromSuspended", we mean any state other than kRunnable, i.e. any state in which the thread is
27// guaranteed not to access the Java heap. The kSuspended state is merely one of these.
Vladimir Markoddf4fd32021-11-22 16:31:57 +000028enum class ThreadState : uint8_t {
29 // `kRunnable` was previously 67 but it is now set to 0 so that we do not need to extract
30 // flags from the thread's `state_and_flags` to check for any flag being set while Runnable.
31 // Note: All atomic accesses for a location should use the same data size,
32 // so the incorrect old approach of reading just 16 bits has been rewritten.
33
Hans Boehm230beda2019-05-03 16:06:52 -070034 // Java
Brian Carlstrom7934ac22013-07-26 10:54:15 -070035 // Thread.State JDWP state
Dave Allison0aded082013-11-07 13:15:11 -080036 kTerminated = 66, // TERMINATED TS_ZOMBIE Thread.run has returned, but Thread* still around
Vladimir Markoddf4fd32021-11-22 16:31:57 +000037 kRunnable = 0, // RUNNABLE TS_RUNNING runnable
38 kObsoleteRunnable = 67, // --- --- obsolete value
39 kTimedWaiting = 68, // TIMED_WAITING TS_WAIT in Object.wait() with a timeout
Brian Carlstrom7934ac22013-07-26 10:54:15 -070040 kSleeping, // TIMED_WAITING TS_SLEEPING in Thread.sleep()
41 kBlocked, // BLOCKED TS_MONITOR blocked on a monitor
42 kWaiting, // WAITING TS_WAIT in Object.wait()
Alex Light77fee872017-09-05 14:51:49 -070043 kWaitingForLockInflation, // WAITING TS_WAIT blocked inflating a thin-lock
44 kWaitingForTaskProcessor, // WAITING TS_WAIT blocked waiting for taskProcessor
Brian Carlstrom7934ac22013-07-26 10:54:15 -070045 kWaitingForGcToComplete, // WAITING TS_WAIT blocked waiting for GC
46 kWaitingForCheckPointsToRun, // WAITING TS_WAIT GC waiting for checkpoints to run
47 kWaitingPerformingGc, // WAITING TS_WAIT performing GC
48 kWaitingForDebuggerSend, // WAITING TS_WAIT blocked waiting for events to be sent
49 kWaitingForDebuggerToAttach, // WAITING TS_WAIT blocked waiting for debugger to attach
50 kWaitingInMainDebuggerLoop, // WAITING TS_WAIT blocking/reading/processing debugger events
51 kWaitingForDebuggerSuspension, // WAITING TS_WAIT waiting for debugger suspend all
52 kWaitingForJniOnLoad, // WAITING TS_WAIT waiting for execution of dlopen and JNI on load code
53 kWaitingForSignalCatcherOutput, // WAITING TS_WAIT waiting for signal catcher IO to complete
54 kWaitingInMainSignalCatcherLoop, // WAITING TS_WAIT blocking/reading/processing signals
Sebastien Hertz138dbfc2013-12-04 18:15:25 +010055 kWaitingForDeoptimization, // WAITING TS_WAIT waiting for deoptimization suspend all
Sebastien Hertzbae182c2013-12-17 10:42:03 +010056 kWaitingForMethodTracingStart, // WAITING TS_WAIT waiting for method tracing to start
Hiroshi Yamauchi0c8c3032015-01-16 16:54:35 -080057 kWaitingForVisitObjects, // WAITING TS_WAIT waiting for visiting objects
Mathieu Chartierb43390c2015-05-12 10:47:11 -070058 kWaitingForGetObjectsAllocated, // WAITING TS_WAIT waiting for getting the number of allocated objects
Mathieu Chartier90ef3db2015-08-04 15:19:41 -070059 kWaitingWeakGcRootRead, // WAITING TS_WAIT waiting on the GC to read a weak root
Hiroshi Yamauchi76f55b02015-08-21 16:10:39 -070060 kWaitingForGcThreadFlip, // WAITING TS_WAIT waiting on the GC thread flip (CC collector) to finish
Koji Fukui34857b52019-03-20 19:13:00 +090061 kNativeForAbort, // WAITING TS_WAIT checking other threads are not run on abort.
Brian Carlstrom7934ac22013-07-26 10:54:15 -070062 kStarting, // NEW TS_WAIT native thread started, not yet ready to run managed code
63 kNative, // RUNNABLE TS_RUNNING running in a JNI native method
64 kSuspended, // RUNNABLE TS_RUNNING suspended by GC or debugger
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080065};
Vladimir Marko9974e3c2020-06-10 16:27:06 +010066std::ostream& operator<<(std::ostream& os, ThreadState rhs);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067
68} // namespace art
69
Brian Carlstromfc0e3212013-07-17 14:40:12 -070070#endif // ART_RUNTIME_THREAD_STATE_H_