thread.hpp revision 3863
869N/A/*
869N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
869N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869N/A *
869N/A * This code is free software; you can redistribute it and/or modify it
869N/A * under the terms of the GNU General Public License version 2 only, as
869N/A * published by the Free Software Foundation.
869N/A *
869N/A * This code is distributed in the hope that it will be useful, but WITHOUT
869N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
869N/A * version 2 for more details (a copy is included in the LICENSE file that
869N/A * accompanied this code).
869N/A *
869N/A * You should have received a copy of the GNU General Public License version
869N/A * 2 along with this work; if not, write to the Free Software Foundation,
869N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
873N/A *
869N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
869N/A * or visit www.oracle.com if you need additional information or have any
869N/A * questions.
869N/A *
869N/A */
869N/A
869N/A#ifndef SHARE_VM_RUNTIME_THREAD_HPP
0N/A#define SHARE_VM_RUNTIME_THREAD_HPP
0N/A
0N/A#include "memory/allocation.hpp"
0N/A#include "memory/threadLocalAllocBuffer.hpp"
869N/A#include "oops/oop.hpp"
0N/A#include "prims/jni.h"
0N/A#include "prims/jvmtiExport.hpp"
0N/A#include "runtime/frame.hpp"
869N/A#include "runtime/javaFrameAnchor.hpp"
0N/A#include "runtime/jniHandles.hpp"
869N/A#include "runtime/mutexLocker.hpp"
0N/A#include "runtime/os.hpp"
869N/A#include "runtime/osThread.hpp"
869N/A#include "runtime/park.hpp"
869N/A#include "runtime/safepoint.hpp"
0N/A#include "runtime/stubRoutines.hpp"
869N/A#include "runtime/threadLocalStorage.hpp"
48N/A#include "runtime/unhandledOops.hpp"
869N/A#include "services/memRecorder.hpp"
0N/A#include "trace/tracing.hpp"
869N/A#include "utilities/exceptions.hpp"
716N/A#include "utilities/top.hpp"
869N/A#ifndef SERIALGC
0N/A#include "gc_implementation/g1/dirtyCardQueue.hpp"
0N/A#include "gc_implementation/g1/satbQueue.hpp"
869N/A#endif
868N/A#ifdef ZERO
983N/A#ifdef TARGET_ARCH_zero
1004N/A# include "stack_zero.hpp"
1007N/A#endif
869N/A#endif
869N/A
1004N/Aclass ThreadSafepointState;
0N/Aclass ThreadProfiler;
0N/A
869N/Aclass JvmtiThreadState;
868N/Aclass JvmtiGetLoadedClassesClosure;
0N/Aclass ThreadStatistics;
0N/Aclass ConcurrentLocksDump;
65N/Aclass ParkEvent;
869N/Aclass Parker;
868N/A
65N/Aclass ciEnv;
869N/Aclass CompileThread;
65N/Aclass CompileLog;
65N/Aclass CompileTask;
65N/Aclass CompileQueue;
65N/Aclass CompilerCounters;
65N/Aclass vframeArray;
65N/A
65N/Aclass DeoptResourceMark;
65N/Aclass jvmtiDeferredLocalVariableSet;
65N/A
65N/Aclass GCTaskQueue;
65N/Aclass ThreadClosure;
65N/Aclass IdealGraphPrinter;
65N/A
65N/Aclass WorkerThread;
65N/A
0N/A// Class hierarchy
869N/A// - Thread
868N/A// - NamedThread
0N/A// - VMThread
0N/A// - ConcurrentGCThread
0N/A// - WorkerThread
0N/A// - GangWorker
0N/A// - GCTaskThread
0N/A// - JavaThread
0N/A// - WatcherThread
869N/A
0N/Aclass Thread: public ThreadShadow {
0N/A friend class VMStructs;
869N/A private:
868N/A // Exception handling
0N/A // (Note: _pending_exception and friends are in ThreadShadow)
0N/A //oop _pending_exception; // pending exception for current thread
869N/A // const char* _exception_file; // file information for exception (debugging only)
0N/A // int _exception_line; // line information for exception (debugging only)
0N/A protected:
869N/A // Support for forcing alignment of thread objects for biased locking
868N/A void* _real_malloc_address;
869N/A public:
869N/A void* operator new(size_t size) { return allocate(size, true); }
868N/A void* operator new(size_t size, std::nothrow_t& nothrow_constant) { return allocate(size, false); }
868N/A void operator delete(void* p);
869N/A
869N/A protected:
0N/A static void* allocate(size_t size, bool throw_excpt, MEMFLAGS flags = mtThread);
0N/A private:
48N/A
869N/A // ***************************************************************
869N/A // Suspend and resume support
869N/A // ***************************************************************
868N/A //
869N/A // VM suspend/resume no longer exists - it was once used for various
868N/A // things including safepoints but was deprecated and finally removed
869N/A // in Java 7. Because VM suspension was considered "internal" Java-level
0N/A // suspension was considered "external", and this legacy naming scheme
0N/A // remains.
869N/A //
868N/A // External suspend/resume requests come from JVM_SuspendThread,
0N/A // JVM_ResumeThread, JVMTI SuspendThread, and finally JVMTI
0N/A // ResumeThread. External
848N/A // suspend requests cause _external_suspend to be set and external
848N/A // resume requests cause _external_suspend to be cleared.
848N/A // External suspend requests do not nest on top of other external
869N/A // suspend requests. The higher level APIs reject suspend requests
868N/A // for already suspended threads.
848N/A //
0N/A // The external_suspend
0N/A // flag is checked by has_special_runtime_exit_condition() and java thread
0N/A // will self-suspend when handle_special_runtime_exit_condition() is
869N/A // called. Most uses of the _thread_blocked state in JavaThreads are
0N/A // considered the same as being externally suspended; if the blocking
0N/A // condition lifts, the JavaThread will self-suspend. Other places
0N/A // where VM checks for external_suspend include:
868N/A // + mutex granting (do not enter monitors when thread is suspended)
868N/A // + state transitions from _thread_in_native
868N/A //
868N/A // In general, java_suspend() does not wait for an external suspend
869N/A // request to complete. When it returns, the only guarantee is that
868N/A // the _external_suspend field is true.
115N/A //
868N/A // wait_for_ext_suspend_completion() is used to wait for an external
868N/A // suspend request to complete. External suspend requests are usually
868N/A // followed by some other interface call that requires the thread to
868N/A // be quiescent, e.g., GetCallTrace(). By moving the "wait time" into
868N/A // the interface that requires quiescence, we give the JavaThread a
869N/A // chance to self-suspend before we need it to be quiescent. This
868N/A // improves overall suspend/query performance.
868N/A //
868N/A // _suspend_flags controls the behavior of java_ suspend/resume.
868N/A // It must be set under the protection of SR_lock. Read from the flag is
868N/A // OK without SR_lock as long as the value is only used as a hint.
868N/A // (e.g., check _external_suspend first without lock and then recheck
868N/A // inside SR_lock and finish the suspension)
869N/A //
868N/A // _suspend_flags is also overloaded for other "special conditions" so
868N/A // that a single check indicates whether any special action is needed
868N/A // eg. for async exceptions.
868N/A // -------------------------------------------------------------------
868N/A // Notes:
869N/A // 1. The suspend/resume logic no longer uses ThreadState in OSThread
868N/A // but we still update its value to keep other part of the system (mainly
868N/A // JVMTI) happy. ThreadState is legacy code (see notes in
868N/A // osThread.hpp).
868N/A //
868N/A // 2. It would be more natural if set_external_suspend() is private and
869N/A // part of java_suspend(), but that probably would affect the suspend/query
868N/A // performance. Need more investigation on this.
868N/A //
868N/A
868N/A // suspend/resume lock: used for self-suspend
868N/A Monitor* _SR_lock;
868N/A
868N/A protected:
869N/A enum SuspendFlags {
868N/A // NOTE: avoid using the sign-bit as cc generates different test code
868N/A // when the sign-bit is used, and sometimes incorrectly - see CR 6398077
868N/A
868N/A _external_suspend = 0x20000000U, // thread is asked to self suspend
868N/A _ext_suspended = 0x40000000U, // thread has self-suspended
868N/A _deopt_suspend = 0x10000000U, // thread needs to self suspend for deopt
868N/A
869N/A _has_async_exception = 0x00000001U, // there is a pending async exception
868N/A _critical_native_unlock = 0x00000002U // Must call back to unlock JNI critical lock
0N/A };
869N/A
0N/A // various suspension related flags - atomically updated
868N/A // overloaded for async exception checking in check_special_condition_for_native_trans.
869N/A volatile uint32_t _suspend_flags;
868N/A
0N/A private:
869N/A int _num_nested_signal;
0N/A
868N/A public:
869N/A void enter_signal_handler() { _num_nested_signal++; }
868N/A void leave_signal_handler() { _num_nested_signal--; }
868N/A bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
869N/A
0N/A private:
869N/A // Debug tracing
869N/A static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
868N/A
868N/A // Active_handles points to a block of handles
868N/A JNIHandleBlock* _active_handles;
868N/A
869N/A // One-element thread local free list
869N/A JNIHandleBlock* _free_handle_block;
869N/A
869N/A // Point to the last handle mark
869N/A HandleMark* _last_handle_mark;
869N/A
869N/A // The parity of the last strong_roots iteration in which this thread was
869N/A // claimed as a task.
869N/A jint _oops_do_parity;
869N/A
869N/A public:
869N/A void set_last_handle_mark(HandleMark* mark) { _last_handle_mark = mark; }
869N/A HandleMark* last_handle_mark() const { return _last_handle_mark; }
869N/A private:
869N/A
869N/A // debug support for checking if code does allow safepoints or not
869N/A // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on
869N/A // mutex, or blocking on an object synchronizer (Java locking).
869N/A // If !allow_safepoint(), then an assertion failure will happen in any of the above cases
869N/A // If !allow_allocation(), then an assertion failure will happen during allocation
869N/A // (Hence, !allow_safepoint() => !allow_allocation()).
869N/A //
869N/A // The two classes No_Safepoint_Verifier and No_Allocation_Verifier are used to set these counters.
869N/A //
869N/A NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
869N/A debug_only (int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
869N/A
869N/A // Used by SkipGCALot class.
869N/A NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
869N/A
869N/A // Record when GC is locked out via the GC_locker mechanism
869N/A CHECK_UNHANDLED_OOPS_ONLY(int _gc_locked_out_count;)
869N/A
869N/A friend class No_Alloc_Verifier;
869N/A friend class No_Safepoint_Verifier;
869N/A friend class Pause_No_Safepoint_Verifier;
869N/A friend class ThreadLocalStorage;
869N/A friend class GC_locker;
869N/A
869N/A ThreadLocalAllocBuffer _tlab; // Thread-local eden
869N/A jlong _allocated_bytes; // Cumulative number of bytes allocated on
869N/A // the Java heap
869N/A
869N/A TRACE_BUFFER _trace_buffer; // Thread-local buffer for tracing
869N/A
869N/A int _vm_operation_started_count; // VM_Operation support
869N/A int _vm_operation_completed_count; // VM_Operation support
869N/A
869N/A ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
869N/A // is waiting to lock
869N/A bool _current_pending_monitor_is_from_java; // locking is from Java code
869N/A
869N/A // ObjectMonitor on which this thread called Object.wait()
869N/A ObjectMonitor* _current_waiting_monitor;
869N/A
869N/A // Private thread-local objectmonitor list - a simple cache organized as a SLL.
869N/A public:
869N/A ObjectMonitor* omFreeList;
869N/A int omFreeCount; // length of omFreeList
869N/A int omFreeProvision; // reload chunk size
869N/A ObjectMonitor* omInUseList; // SLL to track monitors in circulation
869N/A int omInUseCount; // length of omInUseList
869N/A
0N/A#ifdef ASSERT
824N/A private:
869N/A bool _visited_for_critical_count;
868N/A
824N/A public:
824N/A void set_visited_for_critical_count(bool z) { _visited_for_critical_count = z; }
824N/A bool was_visited_for_critical_count() const { return _visited_for_critical_count; }
824N/A#endif
824N/A
869N/A public:
824N/A enum {
824N/A is_definitely_current_thread = true
869N/A };
869N/A
869N/A // Constructor
869N/A Thread();
869N/A virtual ~Thread();
869N/A
869N/A // initializtion
869N/A void initialize_thread_local_storage();
869N/A
869N/A // thread entry point
869N/A virtual void run();
869N/A
869N/A // Testers
869N/A virtual bool is_VM_thread() const { return false; }
869N/A virtual bool is_Java_thread() const { return false; }
869N/A virtual bool is_Compiler_thread() const { return false; }
869N/A virtual bool is_hidden_from_external_view() const { return false; }
869N/A virtual bool is_jvmti_agent_thread() const { return false; }
869N/A // True iff the thread can perform GC operations at a safepoint.
869N/A // Generally will be true only of VM thread and parallel GC WorkGang
869N/A // threads.
869N/A virtual bool is_GC_task_thread() const { return false; }
869N/A virtual bool is_Watcher_thread() const { return false; }
869N/A virtual bool is_ConcurrentGC_thread() const { return false; }
869N/A virtual bool is_Named_thread() const { return false; }
869N/A virtual bool is_Worker_thread() const { return false; }
869N/A
869N/A // Casts
869N/A virtual WorkerThread* as_Worker_thread() const { return NULL; }
849N/A
0N/A virtual char* name() const { return (char*)"Unknown thread"; }
869N/A
868N/A // Returns the current thread
0N/A static inline Thread* current();
0N/A
0N/A // Common thread operations
0N/A static void set_priority(Thread* thread, ThreadPriority priority);
0N/A static ThreadPriority get_priority(const Thread* const thread);
0N/A static void start(Thread* thread);
869N/A static void interrupt(Thread* thr);
869N/A static bool is_interrupted(Thread* thr, bool clear_interrupted);
869N/A
869N/A void set_native_thread_name(const char *name) {
869N/A assert(Thread::current() == this, "set_native_thread_name can only be called on the current thread");
869N/A os::set_native_thread_name(name);
869N/A }
869N/A
0N/A ObjectMonitor** omInUseList_addr() { return (ObjectMonitor **)&omInUseList; }
869N/A Monitor* SR_lock() const { return _SR_lock; }
0N/A
0N/A bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
869N/A
869N/A void set_suspend_flag(SuspendFlags f) {
869N/A assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
869N/A uint32_t flags;
869N/A do {
868N/A flags = _suspend_flags;
0N/A }
824N/A while (Atomic::cmpxchg((jint)(flags | f),
824N/A (volatile jint*)&_suspend_flags,
824N/A (jint)flags) != (jint)flags);
824N/A }
869N/A void clear_suspend_flag(SuspendFlags f) {
869N/A assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
869N/A uint32_t flags;
869N/A do {
869N/A flags = _suspend_flags;
869N/A }
869N/A while (Atomic::cmpxchg((jint)(flags & ~f),
869N/A (volatile jint*)&_suspend_flags,
869N/A (jint)flags) != (jint)flags);
868N/A }
824N/A
868N/A void set_has_async_exception() {
869N/A set_suspend_flag(_has_async_exception);
869N/A }
868N/A void clear_has_async_exception() {
869N/A clear_suspend_flag(_has_async_exception);
869N/A }
824N/A
824N/A bool do_critical_native_unlock() const { return (_suspend_flags & _critical_native_unlock) != 0; }
869N/A
869N/A void set_critical_native_unlock() {
869N/A set_suspend_flag(_critical_native_unlock);
869N/A }
869N/A void clear_critical_native_unlock() {
869N/A clear_suspend_flag(_critical_native_unlock);
869N/A }
869N/A
0N/A // Support for Unhandled Oop detection
869N/A#ifdef CHECK_UNHANDLED_OOPS
869N/A private:
869N/A UnhandledOops* _unhandled_oops;
0N/A public:
0N/A UnhandledOops* unhandled_oops() { return _unhandled_oops; }
869N/A // Mark oop safe for gc. It may be stack allocated but won't move.
0N/A void allow_unhandled_oop(oop *op) {
869N/A if (CheckUnhandledOops) unhandled_oops()->allow_unhandled_oop(op);
869N/A }
0N/A // Clear oops at safepoint so crashes point to unhandled oop violator
0N/A void clear_unhandled_oops() {
0N/A if (CheckUnhandledOops) unhandled_oops()->clear_unhandled_oops();
0N/A }
869N/A bool is_gc_locked_out() { return _gc_locked_out_count > 0; }
868N/A#endif // CHECK_UNHANDLED_OOPS
0N/A
0N/A#ifndef PRODUCT
0N/A bool skip_gcalot() { return _skip_gcalot; }
0N/A void set_skip_gcalot(bool v) { _skip_gcalot = v; }
0N/A#endif
869N/A
0N/A public:
0N/A // Installs a pending exception to be inserted later
0N/A static void send_async_exception(oop thread_oop, oop java_throwable);
0N/A
0N/A // Resource area
0N/A ResourceArea* resource_area() const { return _resource_area; }
46N/A void set_resource_area(ResourceArea* area) { _resource_area = area; }
869N/A
0N/A OSThread* osthread() const { return _osthread; }
0N/A void set_osthread(OSThread* thread) { _osthread = thread; }
46N/A
0N/A // JNI handle support
0N/A JNIHandleBlock* active_handles() const { return _active_handles; }
0N/A void set_active_handles(JNIHandleBlock* block) { _active_handles = block; }
0N/A JNIHandleBlock* free_handle_block() const { return _free_handle_block; }
869N/A void set_free_handle_block(JNIHandleBlock* block) { _free_handle_block = block; }
0N/A
0N/A // Internal handle support
0N/A HandleArea* handle_area() const { return _handle_area; }
0N/A void set_handle_area(HandleArea* area) { _handle_area = area; }
0N/A
0N/A // Thread-Local Allocation Buffer (TLAB) support
869N/A ThreadLocalAllocBuffer& tlab() { return _tlab; }
0N/A void initialize_tlab() {
0N/A if (UseTLAB) {
0N/A tlab().initialize();
756N/A }
869N/A }
868N/A
756N/A jlong allocated_bytes() { return _allocated_bytes; }
756N/A void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
988N/A void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
988N/A jlong cooked_allocated_bytes() {
988N/A jlong allocated_bytes = OrderAccess::load_acquire(&_allocated_bytes);
988N/A if (UseTLAB) {
988N/A size_t used_bytes = tlab().used_bytes();
988N/A if ((ssize_t)used_bytes > 0) {
988N/A // More-or-less valid tlab. The load_acquire above should ensure
756N/A // that the result of the add is <= the instantaneous value
756N/A return allocated_bytes + used_bytes;
756N/A }
869N/A }
756N/A return allocated_bytes;
869N/A }
756N/A
0N/A TRACE_BUFFER trace_buffer() { return _trace_buffer; }
869N/A void set_trace_buffer(TRACE_BUFFER buf) { _trace_buffer = buf; }
868N/A
0N/A // VM operation support
0N/A int vm_operation_ticket() { return ++_vm_operation_started_count; }
0N/A int vm_operation_completed_count() { return _vm_operation_completed_count; }
0N/A void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
0N/A
869N/A // For tracking the heavyweight monitor the thread is pending on.
869N/A ObjectMonitor* current_pending_monitor() {
0N/A return _current_pending_monitor;
0N/A }
0N/A void set_current_pending_monitor(ObjectMonitor* monitor) {
0N/A _current_pending_monitor = monitor;
824N/A }
869N/A void set_current_pending_monitor_is_from_java(bool from_java) {
868N/A _current_pending_monitor_is_from_java = from_java;
824N/A }
824N/A bool current_pending_monitor_is_from_java() {
824N/A return _current_pending_monitor_is_from_java;
869N/A }
868N/A
824N/A // For tracking the ObjectMonitor on which this thread called Object.wait()
869N/A ObjectMonitor* current_waiting_monitor() {
824N/A return _current_waiting_monitor;
869N/A }
869N/A void set_current_waiting_monitor(ObjectMonitor* monitor) {
869N/A _current_waiting_monitor = monitor;
869N/A }
869N/A
869N/A // GC support
869N/A // Apply "f->do_oop" to all root oops in "this".
869N/A // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames
869N/A virtual void oops_do(OopClosure* f, CodeBlobClosure* cf);
869N/A
869N/A // Handles the parallel case for the method below.
869N/Aprivate:
869N/A bool claim_oops_do_par_case(int collection_parity);
869N/Apublic:
869N/A // Requires that "collection_parity" is that of the current strong roots
868N/A // iteration. If "is_par" is false, sets the parity of "this" to
868N/A // "collection_parity", and returns "true". If "is_par" is true,
869N/A // uses an atomic instruction to set the current threads parity to
868N/A // "collection_parity", if it is not already. Returns "true" iff the
868N/A // calling thread does the update, this indicates that the calling thread
869N/A // has claimed the thread's stack as a root groop in the current
868N/A // collection.
824N/A bool claim_oops_do(bool is_par, int collection_parity) {
869N/A if (!is_par) {
824N/A _oops_do_parity = collection_parity;
0N/A return true;
869N/A } else {
868N/A return claim_oops_do_par_case(collection_parity);
0N/A }
0N/A }
0N/A
869N/A // Sweeper support
868N/A void nmethods_do(CodeBlobClosure* cf);
0N/A
869N/A // Used by fast lock support
869N/A virtual bool is_lock_owned(address adr) const;
868N/A
868N/A // Check if address is in the stack of the thread (not just for locks).
869N/A // Warning: the method can only be used on the running thread
869N/A bool is_in_stack(address adr) const;
0N/A
0N/A // Sets this thread as starting thread. Returns failure if thread
869N/A // creation fails due to lack of memory, too many threads etc.
869N/A bool set_as_starting_thread();
869N/A
869N/A protected:
869N/A // OS data associated with the thread
869N/A OSThread* _osthread; // Platform-specific thread information
869N/A
869N/A // Thread local resource area for temporary allocation within the VM
869N/A ResourceArea* _resource_area;
868N/A
869N/A // Thread local handle area for allocation of handles within the VM
869N/A HandleArea* _handle_area;
868N/A
869N/A // Support for stack overflow handling, get_thread, etc.
869N/A address _stack_base;
0N/A size_t _stack_size;
869N/A uintptr_t _self_raw_id; // used by get_thread (mutable)
0N/A int _lgrp_id;
0N/A
869N/A public:
868N/A // Stack overflow support
868N/A address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
869N/A
869N/A void set_stack_base(address base) { _stack_base = base; }
869N/A size_t stack_size() const { return _stack_size; }
869N/A void set_stack_size(size_t size) { _stack_size = size; }
868N/A void record_stack_base_and_size();
0N/A
0N/A bool on_local_stack(address adr) const {
0N/A /* QQQ this has knowledge of direction, ought to be a stack method */
0N/A return (_stack_base >= adr && adr >= (_stack_base - _stack_size));
869N/A }
0N/A
0N/A uintptr_t self_raw_id() { return _self_raw_id; }
0N/A void set_self_raw_id(uintptr_t value) { _self_raw_id = value; }
869N/A
869N/A int lgrp_id() const { return _lgrp_id; }
869N/A void set_lgrp_id(int value) { _lgrp_id = value; }
868N/A
0N/A // Printing
0N/A void print_on(outputStream* st) const;
0N/A void print() const { print_on(tty); }
0N/A virtual void print_on_error(outputStream* st, char* buf, int buflen) const;
869N/A
869N/A // Debug-only code
0N/A#ifdef ASSERT
869N/A private:
0N/A // Deadlock detection support for Mutex locks. List of locks own by thread.
0N/A Monitor* _owned_locks;
869N/A // Mutex::set_owner_implementation is the only place where _owned_locks is modified,
868N/A // thus the friendship
0N/A friend class Mutex;
0N/A friend class Monitor;
0N/A
0N/A public:
0N/A void print_owned_locks_on(outputStream* st) const;
869N/A void print_owned_locks() const { print_owned_locks_on(tty); }
868N/A Monitor* owned_locks() const { return _owned_locks; }
868N/A bool owns_locks() const { return owned_locks() != NULL; }
869N/A bool owns_locks_but_compiled_lock() const;
868N/A
868N/A // Deadlock detection
868N/A bool allow_allocation() { return _allow_allocation_count == 0; }
868N/A#endif
869N/A
0N/A void check_for_valid_safepoint_state(bool potential_vm_operation) PRODUCT_RETURN;
0N/A
869N/A private:
0N/A volatile int _jvmti_env_iteration_count;
0N/A
0N/A public:
0N/A void entering_jvmti_env_iteration() { ++_jvmti_env_iteration_count; }
869N/A void leaving_jvmti_env_iteration() { --_jvmti_env_iteration_count; }
0N/A bool is_inside_jvmti_env_iteration() { return _jvmti_env_iteration_count > 0; }
0N/A
869N/A // Code generation
0N/A static ByteSize exception_file_offset() { return byte_offset_of(Thread, _exception_file ); }
0N/A static ByteSize exception_line_offset() { return byte_offset_of(Thread, _exception_line ); }
0N/A static ByteSize active_handles_offset() { return byte_offset_of(Thread, _active_handles ); }
0N/A
869N/A static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base ); }
0N/A static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size ); }
0N/A
869N/A#define TLAB_FIELD_OFFSET(name) \
0N/A static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
0N/A
868N/A TLAB_FIELD_OFFSET(start)
868N/A TLAB_FIELD_OFFSET(end)
869N/A TLAB_FIELD_OFFSET(top)
869N/A TLAB_FIELD_OFFSET(pf_top)
869N/A TLAB_FIELD_OFFSET(size) // desired_size
0N/A TLAB_FIELD_OFFSET(refill_waste_limit)
868N/A TLAB_FIELD_OFFSET(number_of_refills)
869N/A TLAB_FIELD_OFFSET(fast_refill_waste)
868N/A TLAB_FIELD_OFFSET(slow_allocations)
868N/A
868N/A#undef TLAB_FIELD_OFFSET
0N/A
0N/A static ByteSize allocated_bytes_offset() { return byte_offset_of(Thread, _allocated_bytes ); }
869N/A
0N/A public:
0N/A volatile intptr_t _Stalled ;
0N/A volatile int _TypeTag ;
0N/A ParkEvent * _ParkEvent ; // for synchronized()
0N/A ParkEvent * _SleepEvent ; // for Thread.sleep
0N/A ParkEvent * _MutexEvent ; // for native internal Mutex/Monitor
0N/A ParkEvent * _MuxEvent ; // for low-level muxAcquire-muxRelease
869N/A int NativeSyncRecursion ; // diagnostic
869N/A
869N/A volatile int _OnTrap ; // Resume-at IP delta
869N/A jint _hashStateW ; // Marsaglia Shift-XOR thread-local RNG
869N/A jint _hashStateX ; // thread-specific hashCode generator state
869N/A jint _hashStateY ;
869N/A jint _hashStateZ ;
869N/A void * _schedctl ;
869N/A
869N/A intptr_t _ScratchA, _ScratchB ; // Scratch locations for fast-path sync code
869N/A static ByteSize ScratchA_offset() { return byte_offset_of(Thread, _ScratchA ); }
869N/A static ByteSize ScratchB_offset() { return byte_offset_of(Thread, _ScratchB ); }
869N/A
869N/A volatile jint rng [4] ; // RNG for spin loop
869N/A
869N/A // Low-level leaf-lock primitives used to implement synchronization
869N/A // and native monitor-mutex infrastructure.
0N/A // Not for general synchronization use.
868N/A static void SpinAcquire (volatile int * Lock, const char * Name) ;
0N/A static void SpinRelease (volatile int * Lock) ;
0N/A static void muxAcquire (volatile intptr_t * Lock, const char * Name) ;
869N/A static void muxAcquireW (volatile intptr_t * Lock, ParkEvent * ev) ;
0N/A static void muxRelease (volatile intptr_t * Lock) ;
0N/A};
869N/A
869N/A// Inline implementation of Thread::current()
869N/A// Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of
869N/A// startup.
869N/A// ThreadLocalStorage::thread is warm -- it's called > 16K times in the same
869N/A// period. This is inlined in thread_<os_family>.inline.hpp.
869N/A
869N/Ainline Thread* Thread::current() {
869N/A#ifdef ASSERT
869N/A// This function is very high traffic. Define PARANOID to enable expensive
869N/A// asserts.
869N/A#ifdef PARANOID
869N/A // Signal handler should call ThreadLocalStorage::get_thread_slow()
869N/A Thread* t = ThreadLocalStorage::get_thread_slow();
869N/A assert(t != NULL && !t->is_inside_signal_handler(),
869N/A "Don't use Thread::current() inside signal handler");
869N/A#endif
0N/A#endif
868N/A Thread* thread = ThreadLocalStorage::thread();
0N/A assert(thread != NULL, "just checking");
0N/A return thread;
869N/A}
0N/A
0N/A// Name support for threads. non-JavaThread subclasses with multiple
869N/A// uniquely named instances should derive from this.
0N/Aclass NamedThread: public Thread {
0N/A friend class VMStructs;
0N/A enum {
0N/A max_name_len = 64
0N/A };
0N/A private:
0N/A char* _name;
869N/A // log JavaThread being processed by oops_do
0N/A JavaThread* _processed_thread;
0N/A
0N/A public:
0N/A NamedThread();
869N/A ~NamedThread();
0N/A // May only be called once per thread.
0N/A void set_name(const char* format, ...);
869N/A virtual bool is_Named_thread() const { return true; }
0N/A virtual char* name() const { return _name == NULL ? (char*)"Unknown Thread" : _name; }
0N/A JavaThread *processed_thread() { return _processed_thread; }
0N/A void set_processed_thread(JavaThread *thread) { _processed_thread = thread; }
0N/A};
0N/A
0N/A// Worker threads are named and have an id of an assigned work.
0N/Aclass WorkerThread: public NamedThread {
869N/Aprivate:
868N/A uint _id;
869N/Apublic:
868N/A WorkerThread() : _id(0) { }
868N/A virtual bool is_Worker_thread() const { return true; }
869N/A
869N/A virtual WorkerThread* as_Worker_thread() const {
869N/A assert(is_Worker_thread(), "Dubious cast to WorkerThread*?");
868N/A return (WorkerThread*) this;
0N/A }
869N/A
0N/A void set_id(uint work_id) { _id = work_id; }
0N/A uint id() const { return _id; }
868N/A};
0N/A
0N/A// A single WatcherThread is used for simulating timer interrupts.
869N/Aclass WatcherThread: public Thread {
0N/A friend class VMStructs;
0N/A public:
0N/A virtual void run();
0N/A
0N/A private:
0N/A static WatcherThread* _watcher_thread;
0N/A
869N/A volatile static bool _should_terminate; // updated without holding lock
0N/A public:
0N/A enum SomeConstants {
0N/A delay_interval = 10 // interrupt delay in milliseconds
0N/A };
869N/A
0N/A // Constructor
0N/A WatcherThread();
869N/A
0N/A // Tester
0N/A bool is_Watcher_thread() const { return true; }
0N/A
0N/A // Printing
869N/A char* name() const { return (char*)"VM Periodic Task Thread"; }
0N/A void print_on(outputStream* st) const;
0N/A void print() const { print_on(tty); }
869N/A
0N/A // Returns the single instance of WatcherThread
0N/A static WatcherThread* watcher_thread() { return _watcher_thread; }
0N/A
0N/A // Create and start the single instance of WatcherThread, or stop it on shutdown
0N/A static void start();
869N/A static void stop();
0N/A};
0N/A
0N/A
0N/Aclass CompilerThread;
0N/A
0N/Atypedef void (*ThreadFunction)(JavaThread*, TRAPS);
869N/A
0N/Aclass JavaThread: public Thread {
0N/A friend class VMStructs;
869N/A private:
0N/A JavaThread* _next; // The next thread in the Threads list
869N/A oop _threadObj; // The Java level thread object
0N/A
0N/A#ifdef ASSERT
869N/A private:
869N/A int _java_call_counter;
869N/A
0N/A public:
0N/A int java_call_counter() { return _java_call_counter; }
869N/A void inc_java_call_counter() { _java_call_counter++; }
0N/A void dec_java_call_counter() {
0N/A assert(_java_call_counter > 0, "Invalid nesting of JavaCallWrapper");
869N/A _java_call_counter--;
869N/A }
869N/A private: // restore original namespace restriction
868N/A#endif // ifdef ASSERT
868N/A
868N/A#ifndef PRODUCT
0N/A public:
0N/A enum {
869N/A jump_ring_buffer_size = 16
868N/A };
868N/A private: // restore original namespace restriction
869N/A#endif
868N/A
868N/A JavaFrameAnchor _anchor; // Encapsulation of current java frame and it state
868N/A
868N/A ThreadFunction _entry_point;
869N/A
0N/A JNIEnv _jni_environment;
0N/A
869N/A // Deopt support
0N/A DeoptResourceMark* _deopt_mark; // Holds special ResourceMark for deoptimization
0N/A
0N/A intptr_t* _must_deopt_id; // id of frame that needs to be deopted once we
0N/A // transition out of native
869N/A nmethod* _deopt_nmethod; // nmethod that is currently being deoptimized
0N/A vframeArray* _vframe_array_head; // Holds the heap of the active vframeArrays
0N/A vframeArray* _vframe_array_last; // Holds last vFrameArray we popped
869N/A // Because deoptimization is lazy we must save jvmti requests to set locals
0N/A // in compiled frames until we deoptimize and we have an interpreter frame.
0N/A // This holds the pointer to array (yeah like there might be more than one) of
0N/A // description of compiled vframes that have locals that need to be updated.
0N/A GrowableArray<jvmtiDeferredLocalVariableSet*>* _deferred_locals_updates;
0N/A
0N/A // Handshake value for fixing 6243940. We need a place for the i2c
0N/A // adapter to store the callee methodOop. This value is NEVER live
869N/A // across a gc point so it does NOT have to be gc'd
0N/A // The handshake is open ended since we can't be certain that it will
0N/A // be NULLed. This is because we rarely ever see the race and end up
0N/A // in handle_wrong_method which is the backend of the handshake. See
0N/A // code in i2c adapters and handle_wrong_method.
869N/A
0N/A methodOop _callee_target;
0N/A
869N/A // Oop results of VM runtime calls
0N/A oop _vm_result; // Used to pass back an oop result into Java code, GC-preserved
0N/A oop _vm_result_2; // Used to pass back an oop result into Java code, GC-preserved
0N/A
0N/A // See ReduceInitialCardMarks: this holds the precise space interval of
869N/A // the most recent slow path allocation for which compiled code has
0N/A // elided card-marks for performance along the fast-path.
0N/A MemRegion _deferred_card_mark;
869N/A
0N/A MonitorChunk* _monitor_chunks; // Contains the off stack monitors
0N/A // allocated during deoptimization
0N/A // and by JNI_MonitorEnter/Exit
0N/A
869N/A // Async. requests support
0N/A enum AsyncRequests {
0N/A _no_async_condition = 0,
869N/A _async_exception,
0N/A _async_unsafe_access_error
0N/A };
0N/A AsyncRequests _special_runtime_exit_condition; // Enum indicating pending async. request
0N/A oop _pending_async_exception;
869N/A
0N/A // Safepoint support
0N/A public: // Expose _thread_state for SafeFetchInt()
869N/A volatile JavaThreadState _thread_state;
0N/A private:
0N/A ThreadSafepointState *_safepoint_state; // Holds information about a thread during a safepoint
0N/A address _saved_exception_pc; // Saved pc of instruction where last implicit exception happened
0N/A
0N/A // JavaThread termination support
0N/A enum TerminatedTypes {
0N/A _not_terminated = 0xDEAD - 2,
869N/A _thread_exiting, // JavaThread::exit() has been called for this thread
0N/A _thread_terminated, // JavaThread is removed from thread list
0N/A _vm_exited // JavaThread is still executing native code, but VM is terminated
0N/A // only VM_Exit can set _vm_exited
0N/A };
869N/A
0N/A // In general a JavaThread's _terminated field transitions as follows:
0N/A //
869N/A // _not_terminated => _thread_exiting => _thread_terminated
0N/A //
0N/A // _vm_exited is a special value to cover the case of a JavaThread
0N/A // executing native code after the VM itself is terminated.
0N/A volatile TerminatedTypes _terminated;
869N/A // suspend/resume support
0N/A volatile bool _suspend_equivalent; // Suspend equivalent condition
0N/A jint _in_deopt_handler; // count of deoptimization
869N/A // handlers thread is in
0N/A volatile bool _doing_unsafe_access; // Thread may fault due to unsafe access
0N/A bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was
0N/A // never locked) when throwing an exception. Used by interpreter only.
0N/A
869N/A // JNI attach states:
0N/A enum JNIAttachStates {
0N/A _not_attaching_via_jni = 1, // thread is not attaching via JNI
869N/A _attaching_via_jni, // thread is attaching via JNI
0N/A _attached_via_jni // thread has attached via JNI
0N/A };
0N/A
0N/A // A regular JavaThread's _jni_attach_state is _not_attaching_via_jni.
0N/A // A native thread that is attaching via JNI starts with a value
0N/A // of _attaching_via_jni and transitions to _attached_via_jni.
0N/A volatile JNIAttachStates _jni_attach_state;
869N/A
0N/A public:
0N/A // State of the stack guard pages for this thread.
0N/A enum StackGuardState {
0N/A stack_guard_unused, // not needed
869N/A stack_guard_yellow_disabled,// disabled (temporarily) after stack overflow
0N/A stack_guard_enabled // enabled
0N/A };
869N/A
0N/A private:
0N/A
0N/A StackGuardState _stack_guard_state;
0N/A
869N/A // Compiler exception handling (NOTE: The _exception_oop is *NOT* the same as _pending_exception. It is
0N/A // used to temp. parsing values into and out of the runtime system during exception handling for compiled
0N/A // code)
869N/A volatile oop _exception_oop; // Exception thrown in compiled code
0N/A volatile address _exception_pc; // PC where exception happened
0N/A volatile address _exception_handler_pc; // PC for handler of exception
0N/A volatile int _is_method_handle_return; // true (== 1) if the current exception PC is a MethodHandle call site.
0N/A
869N/A // support for compilation
0N/A bool _is_compiling; // is true if a compilation is active inthis thread (one compilation per thread possible)
0N/A
869N/A // support for JNI critical regions
0N/A jint _jni_active_critical; // count of entries into JNI critical region
0N/A
0N/A // For deadlock detection.
0N/A int _depth_first_number;
869N/A
0N/A // JVMTI PopFrame support
0N/A // This is set to popframe_pending to signal that top Java frame should be popped immediately
869N/A int _popframe_condition;
0N/A
0N/A#ifndef PRODUCT
0N/A int _jmp_ring_index;
0N/A struct {
869N/A // We use intptr_t instead of address so debugger doesn't try and display strings
0N/A intptr_t _target;
0N/A intptr_t _instruction;
869N/A const char* _file;
0N/A int _line;
0N/A } _jmp_ring[ jump_ring_buffer_size ];
0N/A#endif /* PRODUCT */
0N/A
0N/A#ifndef SERIALGC
0N/A // Support for G1 barriers
0N/A
869N/A ObjPtrQueue _satb_mark_queue; // Thread-local log for SATB barrier.
0N/A // Set of all such queues.
0N/A static SATBMarkQueueSet _satb_mark_queue_set;
869N/A
868N/A DirtyCardQueue _dirty_card_queue; // Thread-local log for dirty cards.
0N/A // Set of all such queues.
0N/A static DirtyCardQueueSet _dirty_card_queue_set;
0N/A
869N/A void flush_barrier_queues();
868N/A#endif // !SERIALGC
869N/A
0N/A friend class VMThread;
0N/A friend class ThreadWaitTransition;
0N/A friend class VM_Exit;
0N/A
869N/A void initialize(); // Initialized the instance variables
868N/A
869N/A public:
0N/A // Constructor
0N/A JavaThread(bool is_attaching_via_jni = false); // for main thread and JNI attached threads
0N/A JavaThread(ThreadFunction entry_point, size_t stack_size = 0);
0N/A ~JavaThread();
869N/A
868N/A#ifdef ASSERT
869N/A // verify this JavaThread hasn't be published in the Threads::list yet
0N/A void verify_not_published();
0N/A#endif
0N/A
0N/A //JNI functiontable getter/setter for JVMTI jni function table interception API.
869N/A void set_jni_functions(struct JNINativeInterface_* functionTable) {
868N/A _jni_environment.functions = functionTable;
0N/A }
0N/A struct JNINativeInterface_* get_jni_functions() {
0N/A return (struct JNINativeInterface_ *)_jni_environment.functions;
869N/A }
868N/A
0N/A // This function is called at thread creation to allow
869N/A // platform specific thread variables to be initialized.
0N/A void cache_global_variables();
869N/A
0N/A // Executes Shutdown.shutdown()
0N/A void invoke_shutdown_hooks();
869N/A
0N/A // Cleanup on thread exit
0N/A enum ExitType {
869N/A normal_exit,
868N/A jni_detach
0N/A };
0N/A void exit(bool destroy_vm, ExitType exit_type = normal_exit);
869N/A
868N/A void cleanup_failed_attach_current_thread();
869N/A
869N/A // Testers
869N/A virtual bool is_Java_thread() const { return true; }
869N/A
869N/A // compilation
868N/A void set_is_compiling(bool f) { _is_compiling = f; }
869N/A bool is_compiling() const { return _is_compiling; }
869N/A
869N/A // Thread chain operations
868N/A JavaThread* next() const { return _next; }
868N/A void set_next(JavaThread* p) { _next = p; }
868N/A
868N/A // Thread oop. threadObj() can be NULL for initial JavaThread
869N/A // (or for threads attached via JNI)
0N/A oop threadObj() const { return _threadObj; }
869N/A void set_threadObj(oop p) { _threadObj = p; }
869N/A
0N/A ThreadPriority java_priority() const; // Read from threadObj()
0N/A
869N/A // Prepare thread and add to priority queue. If a priority is
0N/A // not specified, use the priority of the thread object. Threads_lock
869N/A // must be held while this function is called.
868N/A void prepare(jobject jni_thread, ThreadPriority prio=NoPriority);
868N/A
869N/A void set_saved_exception_pc(address pc) { _saved_exception_pc = pc; }
0N/A address saved_exception_pc() { return _saved_exception_pc; }
245N/A
869N/A
868N/A ThreadFunction entry_point() const { return _entry_point; }
869N/A
869N/A // Allocates a new Java level thread object for this thread. thread_name may be NULL.
549N/A void allocate_threadObj(Handle thread_group, char* thread_name, bool daemon, TRAPS);
869N/A
245N/A // Last frame anchor routines
869N/A
245N/A JavaFrameAnchor* frame_anchor(void) { return &_anchor; }
245N/A
868N/A // last_Java_sp
869N/A bool has_last_Java_frame() const { return _anchor.has_last_Java_frame(); }
869N/A intptr_t* last_Java_sp() const { return _anchor.last_Java_sp(); }
869N/A
245N/A // last_Java_pc
245N/A
869N/A address last_Java_pc(void) { return _anchor.last_Java_pc(); }
869N/A
245N/A // Safepoint support
245N/A JavaThreadState thread_state() const { return _thread_state; }
869N/A void set_thread_state(JavaThreadState s) { _thread_state=s; }
869N/A ThreadSafepointState *safepoint_state() const { return _safepoint_state; }
245N/A void set_safepoint_state(ThreadSafepointState *state) { _safepoint_state = state; }
245N/A bool is_at_poll_safepoint() { return _safepoint_state->is_at_poll_safepoint(); }
245N/A
245N/A // thread has called JavaThread::exit() or is terminated
0N/A bool is_exiting() { return _terminated == _thread_exiting || is_terminated(); }
869N/A // thread is terminated (no longer on the threads list); we compare
868N/A // against the two non-terminated values so that a freed JavaThread
0N/A // will also be considered terminated.
0N/A bool is_terminated() { return _terminated != _not_terminated && _terminated != _thread_exiting; }
0N/A void set_terminated(TerminatedTypes t) { _terminated = t; }
0N/A // special for Threads::remove() which is static:
0N/A void set_terminated_value() { _terminated = _thread_terminated; }
869N/A void block_if_vm_exited();
0N/A
869N/A bool doing_unsafe_access() { return _doing_unsafe_access; }
0N/A void set_doing_unsafe_access(bool val) { _doing_unsafe_access = val; }
0N/A
0N/A bool do_not_unlock_if_synchronized() { return _do_not_unlock_if_synchronized; }
0N/A void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; }
869N/A
0N/A // native memory tracking
869N/A inline MemRecorder* get_recorder() const { return (MemRecorder*)_recorder; }
0N/A inline void set_recorder(MemRecorder* rc) { _recorder = (volatile MemRecorder*)rc; }
0N/A
0N/A private:
0N/A // per-thread memory recorder
869N/A volatile MemRecorder* _recorder;
0N/A
869N/A // Suspend/resume support for JavaThread
0N/A private:
0N/A void set_ext_suspended() { set_suspend_flag (_ext_suspended); }
0N/A void clear_ext_suspended() { clear_suspend_flag(_ext_suspended); }
0N/A
869N/A public:
0N/A void java_suspend();
869N/A void java_resume();
0N/A int java_suspend_self();
0N/A
0N/A void check_and_wait_while_suspended() {
0N/A assert(JavaThread::current() == this, "sanity check");
869N/A
0N/A bool do_self_suspend;
869N/A do {
0N/A // were we externally suspended while we were waiting?
0N/A do_self_suspend = handle_special_suspend_equivalent_condition();
0N/A if (do_self_suspend) {
0N/A // don't surprise the thread that suspended us by returning
869N/A java_suspend_self();
0N/A set_suspend_equivalent();
869N/A }
0N/A } while (do_self_suspend);
0N/A }
0N/A static void check_safepoint_and_suspend_for_native_trans(JavaThread *thread);
0N/A // Check for async exception in addition to safepoint and suspend request.
869N/A static void check_special_condition_for_native_trans(JavaThread *thread);
0N/A
869N/A // Same as check_special_condition_for_native_trans but finishes the
0N/A // transition into thread_in_Java mode so that it can potentially
0N/A // block.
0N/A static void check_special_condition_for_native_trans_and_transition(JavaThread *thread);
0N/A
869N/A bool is_ext_suspend_completed(bool called_by_wait, int delay, uint32_t *bits);
0N/A bool is_ext_suspend_completed_with_lock(uint32_t *bits) {
869N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A // Warning: is_ext_suspend_completed() may temporarily drop the
0N/A // SR_lock to allow the thread to reach a stable thread state if
0N/A // it is currently in a transient thread state.
0N/A return is_ext_suspend_completed(false /*!called_by_wait */,
869N/A SuspendRetryDelay, bits);
0N/A }
869N/A
0N/A // We cannot allow wait_for_ext_suspend_completion() to run forever or
0N/A // we could hang. SuspendRetryCount and SuspendRetryDelay are normally
869N/A // passed as the count and delay parameters. Experiments with specific
868N/A // calls to wait_for_ext_suspend_completion() can be done by passing
0N/A // other values in the code. Experiments with all calls can be done
0N/A // via the appropriate -XX options.
0N/A bool wait_for_ext_suspend_completion(int count, int delay, uint32_t *bits);
869N/A
868N/A void set_external_suspend() { set_suspend_flag (_external_suspend); }
0N/A void clear_external_suspend() { clear_suspend_flag(_external_suspend); }
869N/A
868N/A void set_deopt_suspend() { set_suspend_flag (_deopt_suspend); }
0N/A void clear_deopt_suspend() { clear_suspend_flag(_deopt_suspend); }
869N/A bool is_deopt_suspend() { return (_suspend_flags & _deopt_suspend) != 0; }
869N/A
0N/A bool is_external_suspend() const {
1017N/A return (_suspend_flags & _external_suspend) != 0;
1017N/A }
1017N/A // Whenever a thread transitions from native to vm/java it must suspend
1017N/A // if external|deopt suspend is present.
1017N/A bool is_suspend_after_native() const {
1017N/A return (_suspend_flags & (_external_suspend | _deopt_suspend) ) != 0;
1017N/A }
1017N/A
1017N/A // external suspend request is completed
0N/A bool is_ext_suspended() const {
869N/A return (_suspend_flags & _ext_suspended) != 0;
868N/A }
0N/A
0N/A bool is_external_suspend_with_lock() const {
0N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A return is_external_suspend();
0N/A }
869N/A
0N/A // Special method to handle a pending external suspend request
0N/A // when a suspend equivalent condition lifts.
0N/A bool handle_special_suspend_equivalent_condition() {
0N/A assert(is_suspend_equivalent(),
0N/A "should only be called in a suspend equivalence condition");
0N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A bool ret = is_external_suspend();
0N/A if (!ret) {
869N/A // not about to self-suspend so clear suspend equivalence
0N/A clear_suspend_equivalent();
0N/A }
0N/A // implied else:
0N/A // We have a pending external suspend request so we leave the
0N/A // suspend_equivalent flag set until java_suspend_self() sets
0N/A // the ext_suspended flag and clears the suspend_equivalent
0N/A // flag. This insures that wait_for_ext_suspend_completion()
0N/A // will return consistent values.
0N/A return ret;
869N/A }
0N/A
0N/A // utility methods to see if we are doing some kind of suspension
0N/A bool is_being_ext_suspended() const {
0N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A return is_ext_suspended() || is_external_suspend();
0N/A }
0N/A
869N/A bool is_suspend_equivalent() const { return _suspend_equivalent; }
0N/A
0N/A void set_suspend_equivalent() { _suspend_equivalent = true; };
0N/A void clear_suspend_equivalent() { _suspend_equivalent = false; };
0N/A
0N/A // Thread.stop support
0N/A void send_thread_stop(oop throwable);
869N/A AsyncRequests clear_special_runtime_exit_condition() {
868N/A AsyncRequests x = _special_runtime_exit_condition;
869N/A _special_runtime_exit_condition = _no_async_condition;
869N/A return x;
868N/A }
0N/A
0N/A // Are any async conditions present?
869N/A bool has_async_condition() { return (_special_runtime_exit_condition != _no_async_condition); }
869N/A
0N/A void check_and_handle_async_exceptions(bool check_unsafe_error = true);
0N/A
869N/A // these next two are also used for self-suspension and async exception support
868N/A void handle_special_runtime_exit_condition(bool check_asyncs = true);
869N/A
776N/A // Return true if JavaThread has an asynchronous condition or
776N/A // if external suspension is requested.
776N/A bool has_special_runtime_exit_condition() {
776N/A // We call is_external_suspend() last since external suspend should
776N/A // be less common. Because we don't use is_external_suspend_with_lock
776N/A // it is possible that we won't see an asynchronous external suspend
776N/A // request that has just gotten started, i.e., SR_lock grabbed but
776N/A // _external_suspend field change either not made yet or not visible
776N/A // yet. However, this is okay because the request is asynchronous and
776N/A // we will see the new flag value the next time through. It's also
776N/A // possible that the external suspend request is dropped after
776N/A // we have checked is_external_suspend(), we will recheck its value
776N/A // under SR_lock in java_suspend_self().
776N/A return (_special_runtime_exit_condition != _no_async_condition) ||
776N/A is_external_suspend() || is_deopt_suspend();
776N/A }
0N/A
0N/A void set_pending_unsafe_access_error() { _special_runtime_exit_condition = _async_unsafe_access_error; }
869N/A
868N/A void set_pending_async_exception(oop e) {
0N/A _pending_async_exception = e;
869N/A _special_runtime_exit_condition = _async_exception;
0N/A set_has_async_exception();
0N/A }
869N/A
868N/A // Fast-locking support
869N/A bool is_lock_owned(address adr) const;
0N/A
869N/A // Accessors for vframe array top
48N/A // The linked list of vframe arrays are sorted on sp. This means when we
96N/A // unpack the head must contain the vframe array to unpack.
549N/A void set_vframe_array_head(vframeArray* value) { _vframe_array_head = value; }
0N/A vframeArray* vframe_array_head() const { return _vframe_array_head; }
869N/A
868N/A // Side structure for defering update of java frame locals until deopt occurs
0N/A GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred_locals() const { return _deferred_locals_updates; }
869N/A void set_deferred_locals(GrowableArray<jvmtiDeferredLocalVariableSet *>* vf) { _deferred_locals_updates = vf; }
868N/A
0N/A // These only really exist to make debugging deopt problems simpler
0N/A
869N/A void set_vframe_array_last(vframeArray* value) { _vframe_array_last = value; }
868N/A vframeArray* vframe_array_last() const { return _vframe_array_last; }
0N/A
0N/A // The special resourceMark used during deoptimization
0N/A
869N/A void set_deopt_mark(DeoptResourceMark* value) { _deopt_mark = value; }
868N/A DeoptResourceMark* deopt_mark(void) { return _deopt_mark; }
869N/A
0N/A intptr_t* must_deopt_id() { return _must_deopt_id; }
0N/A void set_must_deopt_id(intptr_t* id) { _must_deopt_id = id; }
0N/A void clear_must_deopt_id() { _must_deopt_id = NULL; }
0N/A
869N/A void set_deopt_nmethod(nmethod* nm) { _deopt_nmethod = nm; }
868N/A nmethod* deopt_nmethod() { return _deopt_nmethod; }
0N/A
869N/A methodOop callee_target() const { return _callee_target; }
0N/A void set_callee_target (methodOop x) { _callee_target = x; }
0N/A
0N/A // Oop results of vm runtime calls
0N/A oop vm_result() const { return _vm_result; }
0N/A void set_vm_result (oop x) { _vm_result = x; }
869N/A
868N/A oop vm_result_2() const { return _vm_result_2; }
0N/A void set_vm_result_2 (oop x) { _vm_result_2 = x; }
869N/A
0N/A MemRegion deferred_card_mark() const { return _deferred_card_mark; }
0N/A void set_deferred_card_mark(MemRegion mr) { _deferred_card_mark = mr; }
0N/A
0N/A // Exception handling for compiled methods
0N/A oop exception_oop() const { return _exception_oop; }
869N/A address exception_pc() const { return _exception_pc; }
868N/A address exception_handler_pc() const { return _exception_handler_pc; }
0N/A bool is_method_handle_return() const { return _is_method_handle_return == 1; }
869N/A
869N/A void set_exception_oop(oop o) { _exception_oop = o; }
868N/A void set_exception_pc(address a) { _exception_pc = a; }
869N/A void set_exception_handler_pc(address a) { _exception_handler_pc = a; }
869N/A void set_is_method_handle_return(bool value) { _is_method_handle_return = value ? 1 : 0; }
868N/A
0N/A // Stack overflow support
0N/A inline size_t stack_available(address cur_sp);
869N/A address stack_yellow_zone_base()
0N/A { return (address)(stack_base() - (stack_size() - (stack_red_zone_size() + stack_yellow_zone_size()))); }
0N/A size_t stack_yellow_zone_size()
869N/A { return StackYellowPages * os::vm_page_size(); }
0N/A address stack_red_zone_base()
869N/A { return (address)(stack_base() - (stack_size() - stack_red_zone_size())); }
869N/A size_t stack_red_zone_size()
868N/A { return StackRedPages * os::vm_page_size(); }
0N/A bool in_stack_yellow_zone(address a)
0N/A { return (a <= stack_yellow_zone_base()) && (a >= stack_red_zone_base()); }
869N/A bool in_stack_red_zone(address a)
0N/A { return (a <= stack_red_zone_base()) && (a >= (address)((intptr_t)stack_base() - stack_size())); }
0N/A
869N/A void create_stack_guard_pages();
0N/A void remove_stack_guard_pages();
0N/A
0N/A void enable_stack_yellow_zone();
0N/A void disable_stack_yellow_zone();
0N/A void enable_stack_red_zone();
869N/A void disable_stack_red_zone();
868N/A
0N/A inline bool stack_yellow_zone_disabled();
0N/A inline bool stack_yellow_zone_enabled();
0N/A
869N/A // Attempt to reguard the stack after a stack overflow may have occurred.
868N/A // Returns true if (a) guard pages are not needed on this thread, (b) the
0N/A // pages are already guarded, or (c) the pages were successfully reguarded.
0N/A // Returns false if there is not enough stack space to reguard the pages, in
0N/A // which case the caller should unwind a frame and try again. The argument
0N/A // should be the caller's (approximate) sp.
0N/A bool reguard_stack(address cur_sp);
869N/A // Similar to above but see if current stackpoint is out of the guard area
0N/A // and reguard if possible.
0N/A bool reguard_stack(void);
0N/A
914N/A // Misc. accessors/mutators
914N/A void set_do_not_unlock(void) { _do_not_unlock_if_synchronized = true; }
914N/A void clr_do_not_unlock(void) { _do_not_unlock_if_synchronized = false; }
914N/A bool do_not_unlock(void) { return _do_not_unlock_if_synchronized; }
914N/A
914N/A#ifndef PRODUCT
914N/A void record_jump(address target, address instr, const char* file, int line);
0N/A#endif /* PRODUCT */
0N/A
0N/A // For assembly stub generation
869N/A static ByteSize threadObj_offset() { return byte_offset_of(JavaThread, _threadObj ); }
0N/A#ifndef PRODUCT
0N/A static ByteSize jmp_ring_index_offset() { return byte_offset_of(JavaThread, _jmp_ring_index ); }
0N/A static ByteSize jmp_ring_offset() { return byte_offset_of(JavaThread, _jmp_ring ); }
0N/A#endif /* PRODUCT */
0N/A static ByteSize jni_environment_offset() { return byte_offset_of(JavaThread, _jni_environment ); }
0N/A static ByteSize last_Java_sp_offset() {
869N/A return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
0N/A }
0N/A static ByteSize last_Java_pc_offset() {
0N/A return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
0N/A }
0N/A static ByteSize frame_anchor_offset() {
0N/A return byte_offset_of(JavaThread, _anchor);
869N/A }
0N/A static ByteSize callee_target_offset() { return byte_offset_of(JavaThread, _callee_target ); }
0N/A static ByteSize vm_result_offset() { return byte_offset_of(JavaThread, _vm_result ); }
0N/A static ByteSize vm_result_2_offset() { return byte_offset_of(JavaThread, _vm_result_2 ); }
0N/A static ByteSize thread_state_offset() { return byte_offset_of(JavaThread, _thread_state ); }
0N/A static ByteSize saved_exception_pc_offset() { return byte_offset_of(JavaThread, _saved_exception_pc ); }
0N/A static ByteSize osthread_offset() { return byte_offset_of(JavaThread, _osthread ); }
869N/A static ByteSize exception_oop_offset() { return byte_offset_of(JavaThread, _exception_oop ); }
0N/A static ByteSize exception_pc_offset() { return byte_offset_of(JavaThread, _exception_pc ); }
0N/A static ByteSize exception_handler_pc_offset() { return byte_offset_of(JavaThread, _exception_handler_pc); }
0N/A static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
0N/A static ByteSize stack_guard_state_offset() { return byte_offset_of(JavaThread, _stack_guard_state ); }
0N/A static ByteSize suspend_flags_offset() { return byte_offset_of(JavaThread, _suspend_flags ); }
0N/A
869N/A static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
0N/A static ByteSize should_post_on_exceptions_flag_offset() {
0N/A return byte_offset_of(JavaThread, _should_post_on_exceptions_flag);
0N/A }
0N/A
0N/A#ifndef SERIALGC
0N/A static ByteSize satb_mark_queue_offset() { return byte_offset_of(JavaThread, _satb_mark_queue); }
869N/A static ByteSize dirty_card_queue_offset() { return byte_offset_of(JavaThread, _dirty_card_queue); }
0N/A#endif // !SERIALGC
0N/A
0N/A // Returns the jni environment for this thread
0N/A JNIEnv* jni_environment() { return &_jni_environment; }
0N/A
0N/A static JavaThread* thread_from_jni_environment(JNIEnv* env) {
869N/A JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
0N/A // Only return NULL if thread is off the thread list; starting to
0N/A // exit should not return NULL.
0N/A if (thread_from_jni_env->is_terminated()) {
0N/A thread_from_jni_env->block_if_vm_exited();
0N/A return NULL;
0N/A } else {
869N/A return thread_from_jni_env;
0N/A }
0N/A }
0N/A
0N/A // JNI critical regions. These can nest.
0N/A bool in_critical() { return _jni_active_critical > 0; }
0N/A bool in_last_critical() { return _jni_active_critical == 1; }
869N/A void enter_critical() { assert(Thread::current() == this ||
0N/A Thread::current()->is_VM_thread() && SafepointSynchronize::is_synchronizing(),
0N/A "this must be current thread or synchronizing");
0N/A _jni_active_critical++; }
0N/A void exit_critical() { assert(Thread::current() == this,
0N/A "this must be current thread");
0N/A _jni_active_critical--;
869N/A assert(_jni_active_critical >= 0,
0N/A "JNI critical nesting problem?"); }
0N/A
0N/A // For deadlock detection
0N/A int depth_first_number() { return _depth_first_number; }
0N/A void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
869N/A
868N/A private:
869N/A void set_monitor_chunks(MonitorChunk* monitor_chunks) { _monitor_chunks = monitor_chunks; }
0N/A
0N/A public:
869N/A MonitorChunk* monitor_chunks() const { return _monitor_chunks; }
0N/A void add_monitor_chunk(MonitorChunk* chunk);
0N/A void remove_monitor_chunk(MonitorChunk* chunk);
0N/A bool in_deopt_handler() const { return _in_deopt_handler > 0; }
0N/A void inc_in_deopt_handler() { _in_deopt_handler++; }
869N/A void dec_in_deopt_handler() {
0N/A assert(_in_deopt_handler > 0, "mismatched deopt nesting");
0N/A if (_in_deopt_handler > 0) { // robustness
0N/A _in_deopt_handler--;
0N/A }
0N/A }
0N/A
869N/A private:
0N/A void set_entry_point(ThreadFunction entry_point) { _entry_point = entry_point; }
0N/A
0N/A public:
0N/A
0N/A // Frame iteration; calls the function f for all frames on the stack
0N/A void frames_do(void f(frame*, const RegisterMap*));
869N/A
0N/A // Memory operations
0N/A void oops_do(OopClosure* f, CodeBlobClosure* cf);
0N/A
0N/A // Sweeper operations
0N/A void nmethods_do(CodeBlobClosure* cf);
0N/A
869N/A // Memory management operations
0N/A void gc_epilogue();
0N/A void gc_prologue();
0N/A
0N/A // Misc. operations
0N/A char* name() const { return (char*)get_thread_name(); }
0N/A void print_on(outputStream* st) const;
869N/A void print() const { print_on(tty); }
0N/A void print_value();
0N/A void print_thread_state_on(outputStream* ) const PRODUCT_RETURN;
0N/A void print_thread_state() const PRODUCT_RETURN;
0N/A void print_on_error(outputStream* st, char* buf, int buflen) const;
0N/A void verify();
0N/A const char* get_thread_name() const;
869N/Aprivate:
0N/A // factor out low-level mechanics for use in both normal and error cases
0N/A const char* get_thread_name_string(char* buf = NULL, int buflen = 0) const;
0N/Apublic:
0N/A const char* get_threadgroup_name() const;
0N/A const char* get_parent_name() const;
0N/A
869N/A // Accessing frames
0N/A frame last_frame() {
0N/A _anchor.make_walkable(this);
0N/A return pd_last_frame();
0N/A }
0N/A javaVFrame* last_java_vframe(RegisterMap* reg_map);
0N/A
869N/A // Returns method at 'depth' java or native frames down the stack
0N/A // Used for security checks
0N/A klassOop security_get_caller_class(int depth);
0N/A
0N/A // Print stack trace in external format
0N/A void print_stack_on(outputStream* st);
0N/A void print_stack() { print_stack_on(tty); }
869N/A
0N/A // Print stack traces in various internal formats
0N/A void trace_stack() PRODUCT_RETURN;
0N/A void trace_stack_from(vframe* start_vf) PRODUCT_RETURN;
0N/A void trace_frames() PRODUCT_RETURN;
0N/A void trace_oops() PRODUCT_RETURN;
0N/A
869N/A // Print an annotated view of the stack frames
0N/A void print_frame_layout(int depth = 0, bool validate_only = false) NOT_DEBUG_RETURN;
0N/A void validate_frame_layout() {
0N/A print_frame_layout(0, true);
0N/A }
0N/A
0N/A // Returns the number of stack frames on the stack
869N/A int depth() const;
0N/A
0N/A // Function for testing deoptimization
0N/A void deoptimize();
0N/A void make_zombies();
0N/A
0N/A void deoptimized_wrt_marked_nmethods();
869N/A
0N/A // Profiling operation (see fprofile.cpp)
0N/A public:
0N/A bool profile_last_Java_frame(frame* fr);
0N/A
0N/A private:
0N/A ThreadProfiler* _thread_profiler;
869N/A private:
0N/A friend class FlatProfiler; // uses both [gs]et_thread_profiler.
0N/A friend class FlatProfilerTask; // uses get_thread_profiler.
0N/A friend class ThreadProfilerMark; // uses get_thread_profiler.
0N/A ThreadProfiler* get_thread_profiler() { return _thread_profiler; }
0N/A ThreadProfiler* set_thread_profiler(ThreadProfiler* tp) {
0N/A ThreadProfiler* result = _thread_profiler;
869N/A _thread_profiler = tp;
0N/A return result;
0N/A }
0N/A
0N/A // NMT (Native memory tracking) support.
0N/A // This flag helps NMT to determine if this JavaThread will be blocked
0N/A // at safepoint. If not, ThreadCritical is needed for writing memory records.
869N/A // JavaThread is only safepoint visible when it is in Threads' thread list,
0N/A // it is not visible until it is added to the list and becomes invisible
0N/A // once it is removed from the list.
0N/A public:
0N/A bool is_safepoint_visible() const { return _safepoint_visible; }
0N/A void set_safepoint_visible(bool visible) { _safepoint_visible = visible; }
0N/A private:
869N/A bool _safepoint_visible;
0N/A
0N/A // Static operations
0N/A public:
0N/A // Returns the running thread as a JavaThread
0N/A static inline JavaThread* current();
0N/A
869N/A // Returns the active Java thread. Do not use this if you know you are calling
0N/A // from a JavaThread, as it's slower than JavaThread::current. If called from
0N/A // the VMThread, it also returns the JavaThread that instigated the VMThread's
0N/A // operation. You may not want that either.
0N/A static JavaThread* active();
0N/A
0N/A inline CompilerThread* as_CompilerThread();
869N/A
0N/A public:
0N/A virtual void run();
0N/A void thread_main_inner();
0N/A
0N/A private:
0N/A // PRIVILEGED STACK
869N/A PrivilegedElement* _privileged_stack_top;
0N/A GrowableArray<oop>* _array_for_gc;
0N/A public:
0N/A
0N/A // Returns the privileged_stack information.
0N/A PrivilegedElement* privileged_stack_top() const { return _privileged_stack_top; }
0N/A void set_privileged_stack_top(PrivilegedElement *e) { _privileged_stack_top = e; }
869N/A void register_array_for_gc(GrowableArray<oop>* array) { _array_for_gc = array; }
0N/A
0N/A public:
0N/A // Thread local information maintained by JVMTI.
0N/A void set_jvmti_thread_state(JvmtiThreadState *value) { _jvmti_thread_state = value; }
0N/A // A JvmtiThreadState is lazily allocated. This jvmti_thread_state()
0N/A // getter is used to get this JavaThread's JvmtiThreadState if it has
869N/A // one which means NULL can be returned. JvmtiThreadState::state_for()
0N/A // is used to get the specified JavaThread's JvmtiThreadState if it has
0N/A // one or it allocates a new JvmtiThreadState for the JavaThread and
0N/A // returns it. JvmtiThreadState::state_for() will return NULL only if
0N/A // the specified JavaThread is exiting.
0N/A JvmtiThreadState *jvmti_thread_state() const { return _jvmti_thread_state; }
0N/A static ByteSize jvmti_thread_state_offset() { return byte_offset_of(JavaThread, _jvmti_thread_state); }
869N/A void set_jvmti_get_loaded_classes_closure(JvmtiGetLoadedClassesClosure* value) { _jvmti_get_loaded_classes_closure = value; }
0N/A JvmtiGetLoadedClassesClosure* get_jvmti_get_loaded_classes_closure() const { return _jvmti_get_loaded_classes_closure; }
0N/A
0N/A // JVMTI PopFrame support
0N/A // Setting and clearing popframe_condition
0N/A // All of these enumerated values are bits. popframe_pending
0N/A // indicates that a PopFrame() has been requested and not yet been
869N/A // completed. popframe_processing indicates that that PopFrame() is in
0N/A // the process of being completed. popframe_force_deopt_reexecution_bit
0N/A // indicates that special handling is required when returning to a
0N/A // deoptimized caller.
0N/A enum PopCondition {
0N/A popframe_inactive = 0x00,
0N/A popframe_pending_bit = 0x01,
869N/A popframe_processing_bit = 0x02,
0N/A popframe_force_deopt_reexecution_bit = 0x04
0N/A };
0N/A PopCondition popframe_condition() { return (PopCondition) _popframe_condition; }
0N/A void set_popframe_condition(PopCondition c) { _popframe_condition = c; }
0N/A void set_popframe_condition_bit(PopCondition c) { _popframe_condition |= c; }
0N/A void clear_popframe_condition() { _popframe_condition = popframe_inactive; }
869N/A static ByteSize popframe_condition_offset() { return byte_offset_of(JavaThread, _popframe_condition); }
0N/A bool has_pending_popframe() { return (popframe_condition() & popframe_pending_bit) != 0; }
0N/A bool popframe_forcing_deopt_reexecution() { return (popframe_condition() & popframe_force_deopt_reexecution_bit) != 0; }
0N/A void clear_popframe_forcing_deopt_reexecution() { _popframe_condition &= ~popframe_force_deopt_reexecution_bit; }
0N/A#ifdef CC_INTERP
0N/A bool pop_frame_pending(void) { return ((_popframe_condition & popframe_pending_bit) != 0); }
0N/A void clr_pop_frame_pending(void) { _popframe_condition = popframe_inactive; }
869N/A bool pop_frame_in_process(void) { return ((_popframe_condition & popframe_processing_bit) != 0); }
0N/A void set_pop_frame_in_process(void) { _popframe_condition |= popframe_processing_bit; }
0N/A void clr_pop_frame_in_process(void) { _popframe_condition &= ~popframe_processing_bit; }
0N/A#endif
0N/A
0N/A private:
0N/A // Saved incoming arguments to popped frame.
869N/A // Used only when popped interpreted frame returns to deoptimized frame.
0N/A void* _popframe_preserved_args;
0N/A int _popframe_preserved_args_size;
0N/A
0N/A public:
0N/A void popframe_preserve_args(ByteSize size_in_bytes, void* start);
0N/A void* popframe_preserved_args();
869N/A ByteSize popframe_preserved_args_size();
0N/A WordSize popframe_preserved_args_size_in_words();
0N/A void popframe_free_preserved_args();
0N/A
0N/A
0N/A private:
0N/A JvmtiThreadState *_jvmti_thread_state;
869N/A JvmtiGetLoadedClassesClosure* _jvmti_get_loaded_classes_closure;
0N/A
0N/A // Used by the interpreter in fullspeed mode for frame pop, method
0N/A // entry, method exit and single stepping support. This field is
0N/A // only set to non-zero by the VM_EnterInterpOnlyMode VM operation.
0N/A // It can be set to zero asynchronously (i.e., without a VM operation
0N/A // or a lock) so we have to be very careful.
869N/A int _interp_only_mode;
869N/A
0N/A public:
0N/A // used by the interpreter for fullspeed debugging support (see above)
0N/A static ByteSize interp_only_mode_offset() { return byte_offset_of(JavaThread, _interp_only_mode); }
0N/A bool is_interp_only_mode() { return (_interp_only_mode != 0); }
0N/A int get_interp_only_mode() { return _interp_only_mode; }
0N/A void increment_interp_only_mode() { ++_interp_only_mode; }
0N/A void decrement_interp_only_mode() { --_interp_only_mode; }
869N/A
0N/A // support for cached flag that indicates whether exceptions need to be posted for this thread
0N/A // if this is false, we can avoid deoptimizing when events are thrown
0N/A // this gets set to reflect whether jvmtiExport::post_exception_throw would actually do anything
0N/A private:
0N/A int _should_post_on_exceptions_flag;
0N/A
869N/A public:
0N/A int should_post_on_exceptions_flag() { return _should_post_on_exceptions_flag; }
0N/A void set_should_post_on_exceptions_flag(int val) { _should_post_on_exceptions_flag = val; }
869N/A
869N/A private:
869N/A ThreadStatistics *_thread_stat;
869N/A
869N/A public:
869N/A ThreadStatistics* get_thread_stat() const { return _thread_stat; }
869N/A
868N/A // Return a blocker object for which this thread is blocked parking.
868N/A oop current_park_blocker();
868N/A
868N/A private:
869N/A static size_t _stack_size_at_create;
868N/A
868N/A public:
0N/A static inline size_t stack_size_at_create(void) {
0N/A return _stack_size_at_create;
0N/A }
0N/A static inline void set_stack_size_at_create(size_t value) {
869N/A _stack_size_at_create = value;
0N/A }
0N/A
0N/A#ifndef SERIALGC
824N/A // SATB marking queue support
869N/A ObjPtrQueue& satb_mark_queue() { return _satb_mark_queue; }
868N/A static SATBMarkQueueSet& satb_mark_queue_set() {
824N/A return _satb_mark_queue_set;
824N/A }
824N/A
869N/A // Dirty card queue support
868N/A DirtyCardQueue& dirty_card_queue() { return _dirty_card_queue; }
869N/A static DirtyCardQueueSet& dirty_card_queue_set() {
869N/A return _dirty_card_queue_set;
868N/A }
824N/A#endif // !SERIALGC
824N/A
869N/A // This method initializes the SATB and dirty card queues before a
868N/A // JavaThread is added to the Java thread list. Right now, we don't
824N/A // have to do anything to the dirty card queue (it should have been
869N/A // activated when the thread was created), but we have to activate
868N/A // the SATB queue if the thread is created while a marking cycle is
869N/A // in progress. The activation / de-activation of the SATB queues at
868N/A // the beginning / end of a marking cycle is done during safepoints
869N/A // so we have to make sure this method is called outside one to be
824N/A // able to safely read the active field of the SATB queue set. Right
824N/A // now, it is called just before the thread is added to the Java
869N/A // thread list in the Threads::add() method. That method is holding
868N/A // the Threads_lock which ensures we are outside a safepoint. We
824N/A // cannot do the obvious and set the active field of the SATB queue
869N/A // when the thread is created given that, in some cases, safepoints
869N/A // might happen between the JavaThread constructor being called and the
868N/A // thread being added to the Java thread list (an example of this is
868N/A // when the structure for the DestroyJavaVM thread is created).
849N/A#ifndef SERIALGC
824N/A void initialize_queues();
0N/A#else // !SERIALGC
869N/A void initialize_queues() { }
868N/A#endif // !SERIALGC
0N/A
0N/A // Machine dependent stuff
0N/A#ifdef TARGET_OS_ARCH_linux_x86
0N/A# include "thread_linux_x86.hpp"
0N/A#endif
869N/A#ifdef TARGET_OS_ARCH_linux_sparc
0N/A# include "thread_linux_sparc.hpp"
0N/A#endif
869N/A#ifdef TARGET_OS_ARCH_linux_zero
869N/A# include "thread_linux_zero.hpp"
0N/A#endif
#ifdef TARGET_OS_ARCH_solaris_x86
# include "thread_solaris_x86.hpp"
#endif
#ifdef TARGET_OS_ARCH_solaris_sparc
# include "thread_solaris_sparc.hpp"
#endif
#ifdef TARGET_OS_ARCH_windows_x86
# include "thread_windows_x86.hpp"
#endif
#ifdef TARGET_OS_ARCH_linux_arm
# include "thread_linux_arm.hpp"
#endif
#ifdef TARGET_OS_ARCH_linux_ppc
# include "thread_linux_ppc.hpp"
#endif
#ifdef TARGET_OS_ARCH_bsd_x86
# include "thread_bsd_x86.hpp"
#endif
#ifdef TARGET_OS_ARCH_bsd_zero
# include "thread_bsd_zero.hpp"
#endif
public:
void set_blocked_on_compilation(bool value) {
_blocked_on_compilation = value;
}
bool blocked_on_compilation() {
return _blocked_on_compilation;
}
protected:
bool _blocked_on_compilation;
// JSR166 per-thread parker
private:
Parker* _parker;
public:
Parker* parker() { return _parker; }
// Biased locking support
private:
GrowableArray<MonitorInfo*>* _cached_monitor_info;
public:
GrowableArray<MonitorInfo*>* cached_monitor_info() { return _cached_monitor_info; }
void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; }
// clearing/querying jni attach status
bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; }
bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; }
void set_done_attaching_via_jni() { _jni_attach_state = _attached_via_jni; OrderAccess::fence(); }
private:
// This field is used to determine if a thread has claimed
// a par_id: it is -1 if the thread has not claimed a par_id;
// otherwise its value is the par_id that has been claimed.
int _claimed_par_id;
public:
int get_claimed_par_id() { return _claimed_par_id; }
void set_claimed_par_id(int id) { _claimed_par_id = id;}
};
// Inline implementation of JavaThread::current
inline JavaThread* JavaThread::current() {
Thread* thread = ThreadLocalStorage::thread();
assert(thread != NULL && thread->is_Java_thread(), "just checking");
return (JavaThread*)thread;
}
inline CompilerThread* JavaThread::as_CompilerThread() {
assert(is_Compiler_thread(), "just checking");
return (CompilerThread*)this;
}
inline bool JavaThread::stack_yellow_zone_disabled() {
return _stack_guard_state == stack_guard_yellow_disabled;
}
inline bool JavaThread::stack_yellow_zone_enabled() {
#ifdef ASSERT
if (os::uses_stack_guard_pages()) {
assert(_stack_guard_state != stack_guard_unused, "guard pages must be in use");
}
#endif
return _stack_guard_state == stack_guard_enabled;
}
inline size_t JavaThread::stack_available(address cur_sp) {
// This code assumes java stacks grow down
address low_addr; // Limit on the address for deepest stack depth
if ( _stack_guard_state == stack_guard_unused) {
low_addr = stack_base() - stack_size();
} else {
low_addr = stack_yellow_zone_base();
}
return cur_sp > low_addr ? cur_sp - low_addr : 0;
}
// A thread used for Compilation.
class CompilerThread : public JavaThread {
friend class VMStructs;
private:
CompilerCounters* _counters;
ciEnv* _env;
CompileLog* _log;
CompileTask* _task;
CompileQueue* _queue;
BufferBlob* _buffer_blob;
nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
public:
static CompilerThread* current();
CompilerThread(CompileQueue* queue, CompilerCounters* counters);
bool is_Compiler_thread() const { return true; }
// Hide this compiler thread from external view.
bool is_hidden_from_external_view() const { return true; }
CompileQueue* queue() { return _queue; }
CompilerCounters* counters() { return _counters; }
// Get/set the thread's compilation environment.
ciEnv* env() { return _env; }
void set_env(ciEnv* env) { _env = env; }
BufferBlob* get_buffer_blob() { return _buffer_blob; }
void set_buffer_blob(BufferBlob* b) { _buffer_blob = b; };
// Get/set the thread's logging information
CompileLog* log() { return _log; }
void init_log(CompileLog* log) {
// Set once, for good.
assert(_log == NULL, "set only once");
_log = log;
}
// GC support
// Apply "f->do_oop" to all root oops in "this".
// Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames
void oops_do(OopClosure* f, CodeBlobClosure* cf);
#ifndef PRODUCT
private:
IdealGraphPrinter *_ideal_graph_printer;
public:
IdealGraphPrinter *ideal_graph_printer() { return _ideal_graph_printer; }
void set_ideal_graph_printer(IdealGraphPrinter *n) { _ideal_graph_printer = n; }
#endif
// Get/set the thread's current task
CompileTask* task() { return _task; }
void set_task(CompileTask* task) { _task = task; }
// Track the nmethod currently being scanned by the sweeper
void set_scanned_nmethod(nmethod* nm) {
assert(_scanned_nmethod == NULL || nm == NULL, "should reset to NULL before writing a new value");
_scanned_nmethod = nm;
}
};
inline CompilerThread* CompilerThread::current() {
return JavaThread::current()->as_CompilerThread();
}
// The active thread queue. It also keeps track of the current used
// thread priorities.
class Threads: AllStatic {
friend class VMStructs;
private:
static JavaThread* _thread_list;
static int _number_of_threads;
static int _number_of_non_daemon_threads;
static int _return_code;
public:
// Thread management
// force_daemon is a concession to JNI, where we may need to add a
// thread to the thread list before allocating its thread object
static void add(JavaThread* p, bool force_daemon = false);
static void remove(JavaThread* p);
static bool includes(JavaThread* p);
static JavaThread* first() { return _thread_list; }
static void threads_do(ThreadClosure* tc);
// Initializes the vm and creates the vm thread
static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
static void convert_vm_init_libraries_to_agents();
static void create_vm_init_libraries();
static void create_vm_init_agents();
static void shutdown_vm_agents();
static bool destroy_vm();
// Supported VM versions via JNI
// Includes JNI_VERSION_1_1
static jboolean is_supported_jni_version_including_1_1(jint version);
// Does not include JNI_VERSION_1_1
static jboolean is_supported_jni_version(jint version);
// Garbage collection
static void follow_other_roots(void f(oop*));
// Apply "f->do_oop" to all root oops in all threads.
// This version may only be called by sequential code.
static void oops_do(OopClosure* f, CodeBlobClosure* cf);
// This version may be called by sequential or parallel code.
static void possibly_parallel_oops_do(OopClosure* f, CodeBlobClosure* cf);
// This creates a list of GCTasks, one per thread.
static void create_thread_roots_tasks(GCTaskQueue* q);
// This creates a list of GCTasks, one per thread, for marking objects.
static void create_thread_roots_marking_tasks(GCTaskQueue* q);
// Apply "f->do_oop" to roots in all threads that
// are part of compiled frames
static void compiled_frame_oops_do(OopClosure* f, CodeBlobClosure* cf);
static void convert_hcode_pointers();
static void restore_hcode_pointers();
// Sweeper
static void nmethods_do(CodeBlobClosure* cf);
static void gc_epilogue();
static void gc_prologue();
// Verification
static void verify();
static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks);
static void print(bool print_stacks, bool internal_format) {
// this function is only used by debug.cpp
print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */);
}
static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
// Get Java threads that are waiting to enter a monitor. If doLock
// is true, then Threads_lock is grabbed as needed. Otherwise, the
// VM needs to be at a safepoint.
static GrowableArray<JavaThread*>* get_pending_threads(int count,
address monitor, bool doLock);
// Get owning Java thread from the monitor's owner field. If doLock
// is true, then Threads_lock is grabbed as needed. Otherwise, the
// VM needs to be at a safepoint.
static JavaThread *owning_thread_from_monitor_owner(address owner,
bool doLock);
// Number of threads on the active threads list
static int number_of_threads() { return _number_of_threads; }
// Number of non-daemon threads on the active threads list
static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; }
// Deoptimizes all frames tied to marked nmethods
static void deoptimized_wrt_marked_nmethods();
};
// Thread iterator
class ThreadClosure: public StackObj {
public:
virtual void do_thread(Thread* thread) = 0;
};
class SignalHandlerMark: public StackObj {
private:
Thread* _thread;
public:
SignalHandlerMark(Thread* t) {
_thread = t;
if (_thread) _thread->enter_signal_handler();
}
~SignalHandlerMark() {
if (_thread) _thread->leave_signal_handler();
_thread = NULL;
}
};
#endif // SHARE_VM_RUNTIME_THREAD_HPP