diff options
Diffstat (limited to 'runtime/thread.h')
| -rw-r--r-- | runtime/thread.h | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/runtime/thread.h b/runtime/thread.h index a3ef9bc0a3..b609e723e9 100644 --- a/runtime/thread.h +++ b/runtime/thread.h @@ -158,6 +158,8 @@ class Thread { // Used to implement JNI AttachCurrentThread and AttachCurrentThreadAsDaemon calls. static Thread* Attach(const char* thread_name, bool as_daemon, jobject thread_group, bool create_peer); + // Attaches the calling native thread to the runtime, returning the new native peer. + static Thread* Attach(const char* thread_name, bool as_daemon, jobject thread_peer); // Reset internal state of child thread after fork. void InitAfterFork(); @@ -1140,6 +1142,14 @@ class Thread { return debug_disallow_read_barrier_; } + const void* GetCustomTLS() const { + return custom_tls_; + } + + void SetCustomTLS(const void* data) { + custom_tls_ = data; + } + // Returns true if the current thread is the jit sensitive thread. bool IsJitSensitiveThread() const { return this == jit_sensitive_thread_; @@ -1158,6 +1168,13 @@ class Thread { ~Thread() REQUIRES(!Locks::mutator_lock_, !Locks::thread_suspend_count_lock_); void Destroy(); + // Attaches the calling native thread to the runtime, returning the new native peer. + // Used to implement JNI AttachCurrentThread and AttachCurrentThreadAsDaemon calls. + template <typename PeerAction> + static Thread* Attach(const char* thread_name, + bool as_daemon, + PeerAction p); + void CreatePeer(const char* name, bool as_daemon, jobject thread_group); template<bool kTransactionActive> @@ -1537,13 +1554,9 @@ class Thread { // to avoid additional cost of a mutex and a condition variable, as used in art::Barrier. AtomicInteger* active_suspend_barriers[kMaxSuspendBarriers]; - // Entrypoint function pointers. - // TODO: move this to more of a global offset table model to avoid per-thread duplication. - JniEntryPoints jni_entrypoints; - QuickEntryPoints quick_entrypoints; - // Thread-local allocation pointer. Moved here to force alignment for thread_local_pos on ARM. uint8_t* thread_local_start; + // thread_local_pos and thread_local_end must be consecutive for ldrd and are 8 byte aligned for // potentially better performance. uint8_t* thread_local_pos; @@ -1551,6 +1564,11 @@ class Thread { size_t thread_local_objects; + // Entrypoint function pointers. + // TODO: move this to more of a global offset table model to avoid per-thread duplication. + JniEntryPoints jni_entrypoints; + QuickEntryPoints quick_entrypoints; + // Mterp jump table bases. void* mterp_current_ibase; void* mterp_default_ibase; @@ -1599,6 +1617,10 @@ class Thread { // Pending extra checkpoints if checkpoint_function_ is already used. std::list<Closure*> checkpoint_overflow_ GUARDED_BY(Locks::thread_suspend_count_lock_); + // Custom TLS field that can be used by plugins. + // TODO: Generalize once we have more plugins. + const void* custom_tls_; + // True if the thread is allowed to call back into java (for e.g. during class resolution). // By default this is true. bool can_call_into_java_; @@ -1691,6 +1713,14 @@ class ScopedTransitioningToRunnable : public ValueObject { Thread* const self_; }; +class ThreadLifecycleCallback { + public: + virtual ~ThreadLifecycleCallback() {} + + virtual void ThreadStart(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) = 0; + virtual void ThreadDeath(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) = 0; +}; + std::ostream& operator<<(std::ostream& os, const Thread& thread); std::ostream& operator<<(std::ostream& os, const StackedShadowFrameType& thread); |