• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #ifndef ART_RUNTIME_THREAD_STATE_H_
18 #define ART_RUNTIME_THREAD_STATE_H_
19 
20 #include <iosfwd>
21 
22 #include "base/macros.h"
23 
24 namespace art HIDDEN {
25 
26 // State stored in our C++ class Thread.
27 // When we refer to "a suspended state", or when function names mention "ToSuspended" or
28 // "FromSuspended", we mean any state other than kRunnable, i.e. any state in which the thread is
29 // guaranteed not to access the Java heap. The kSuspended state is merely one of these.
30 enum class ThreadState : uint8_t {
31   // `kRunnable` was previously 67 but it is now set to 0 so that we do not need to extract
32   // flags from the thread's `state_and_flags` to check for any flag being set while Runnable.
33   // Note: All atomic accesses for a location should use the same data size,
34   // so the incorrect old approach of reading just 16 bits has been rewritten.
35 
36   //                                   Java
37   //                                   Thread.State   JDWP state
38   kTerminated = 66,                 // TERMINATED     TS_ZOMBIE    Thread.run has returned, but Thread* still around
39   kRunnable = 0,                    // RUNNABLE       TS_RUNNING   runnable
40   kObsoleteRunnable = 67,           // ---            ---          obsolete value
41   kTimedWaiting = 68,               // TIMED_WAITING  TS_WAIT      in Object.wait() with a timeout
42   kSleeping,                        // TIMED_WAITING  TS_SLEEPING  in Thread.sleep()
43   kBlocked,                         // BLOCKED        TS_MONITOR   blocked on a monitor
44   kWaiting,                         // WAITING        TS_WAIT      in Object.wait()
45   kWaitingForLockInflation,         // WAITING        TS_WAIT      blocked inflating a thin-lock
46   kWaitingForTaskProcessor,         // WAITING        TS_WAIT      blocked waiting for taskProcessor
47   kWaitingForGcToComplete,          // WAITING        TS_WAIT      blocked waiting for GC
48   kWaitingForCheckPointsToRun,      // WAITING        TS_WAIT      GC waiting for checkpoints to run
49   kWaitingPerformingGc,             // WAITING        TS_WAIT      performing GC
50   kWaitingForDebuggerSend,          // WAITING        TS_WAIT      blocked waiting for events to be sent
51   kWaitingForDebuggerToAttach,      // WAITING        TS_WAIT      blocked waiting for debugger to attach
52   kWaitingInMainDebuggerLoop,       // WAITING        TS_WAIT      blocking/reading/processing debugger events
53   kWaitingForDebuggerSuspension,    // WAITING        TS_WAIT      waiting for debugger suspend all
54   kWaitingForJniOnLoad,             // WAITING        TS_WAIT      waiting for execution of dlopen and JNI on load code
55   kWaitingForSignalCatcherOutput,   // WAITING        TS_WAIT      waiting for signal catcher IO to complete
56   kWaitingInMainSignalCatcherLoop,  // WAITING        TS_WAIT      blocking/reading/processing signals
57   kWaitingForDeoptimization,        // WAITING        TS_WAIT      waiting for deoptimization suspend all
58   kWaitingForMethodTracingStart,    // WAITING        TS_WAIT      waiting for method tracing to start
59   kWaitingForVisitObjects,          // WAITING        TS_WAIT      waiting for visiting objects
60   kWaitingForGetObjectsAllocated,   // WAITING        TS_WAIT      waiting for getting the number of allocated objects
61   kWaitingWeakGcRootRead,           // WAITING        TS_WAIT      waiting on the GC to read a weak root
62   kWaitingForGcThreadFlip,          // WAITING        TS_WAIT      waiting on the GC thread flip (CC collector) to finish
63   kNativeForAbort,                  // WAITING        TS_WAIT      checking other threads are not run on abort.
64   kStarting,                        // NEW            TS_WAIT      native thread started, not yet ready to run managed code
65   kNative,                          // RUNNABLE       TS_RUNNING   running in a JNI native method
66   kSuspended,                       // RUNNABLE       TS_RUNNING   suspended by GC or debugger
67   kInvalidState,                    // Used as error value; never stored.
68 };
69 EXPORT std::ostream& operator<<(std::ostream& os, ThreadState rhs);
70 
71 }  // namespace art
72 
73 #endif  // ART_RUNTIME_THREAD_STATE_H_
74