< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page

  72 #include "oops/verifyOopClosure.hpp"
  73 #include "prims/jvm_misc.hpp"
  74 #include "prims/jvmtiDeferredUpdates.hpp"
  75 #include "prims/jvmtiExport.hpp"
  76 #include "prims/jvmtiThreadState.hpp"
  77 #include "runtime/arguments.hpp"
  78 #include "runtime/atomic.hpp"
  79 #include "runtime/biasedLocking.hpp"
  80 #include "runtime/fieldDescriptor.inline.hpp"
  81 #include "runtime/flags/jvmFlagLimit.hpp"
  82 #include "runtime/deoptimization.hpp"
  83 #include "runtime/frame.inline.hpp"
  84 #include "runtime/handles.inline.hpp"
  85 #include "runtime/handshake.hpp"
  86 #include "runtime/init.hpp"
  87 #include "runtime/interfaceSupport.inline.hpp"
  88 #include "runtime/java.hpp"
  89 #include "runtime/javaCalls.hpp"
  90 #include "runtime/jniHandles.inline.hpp"
  91 #include "runtime/jniPeriodicChecker.hpp"

  92 #include "runtime/monitorDeflationThread.hpp"
  93 #include "runtime/mutexLocker.hpp"
  94 #include "runtime/nonJavaThread.hpp"
  95 #include "runtime/objectMonitor.hpp"
  96 #include "runtime/orderAccess.hpp"
  97 #include "runtime/osThread.hpp"
  98 #include "runtime/prefetch.inline.hpp"
  99 #include "runtime/safepoint.hpp"
 100 #include "runtime/safepointMechanism.inline.hpp"
 101 #include "runtime/safepointVerifiers.hpp"
 102 #include "runtime/serviceThread.hpp"
 103 #include "runtime/sharedRuntime.hpp"
 104 #include "runtime/stackFrameStream.inline.hpp"
 105 #include "runtime/stackWatermarkSet.hpp"
 106 #include "runtime/statSampler.hpp"
 107 #include "runtime/task.hpp"
 108 #include "runtime/thread.inline.hpp"
 109 #include "runtime/threadCritical.hpp"
 110 #include "runtime/threadSMR.inline.hpp"
 111 #include "runtime/threadStatisticalInfo.hpp"
 112 #include "runtime/threadWXSetters.inline.hpp"
 113 #include "runtime/timer.hpp"
 114 #include "runtime/timerTrace.hpp"
 115 #include "runtime/trimNativeHeap.hpp"
 116 #include "runtime/vframe.inline.hpp"
 117 #include "runtime/vframeArray.hpp"
 118 #include "runtime/vframe_hp.hpp"
 119 #include "runtime/vmThread.hpp"
 120 #include "runtime/vmOperations.hpp"
 121 #include "runtime/vm_version.hpp"
 122 #include "services/attachListener.hpp"
 123 #include "services/management.hpp"
 124 #include "services/memTracker.hpp"
 125 #include "services/threadService.hpp"

 132 #include "utilities/preserveException.hpp"
 133 #include "utilities/spinYield.hpp"
 134 #include "utilities/vmError.hpp"
 135 #if INCLUDE_JVMCI
 136 #include "jvmci/jvmci.hpp"
 137 #include "jvmci/jvmciEnv.hpp"
 138 #endif
 139 #ifdef COMPILER1
 140 #include "c1/c1_Compiler.hpp"
 141 #endif
 142 #ifdef COMPILER2
 143 #include "opto/c2compiler.hpp"
 144 #include "opto/idealGraphPrinter.hpp"
 145 #endif
 146 #if INCLUDE_RTM_OPT
 147 #include "runtime/rtmLocking.hpp"
 148 #endif
 149 #if INCLUDE_JFR
 150 #include "jfr/jfr.hpp"
 151 #endif



 152 
 153 // Initialization after module runtime initialization
 154 void universe_post_module_init();  // must happen after call_initPhase2
 155 
 156 #ifdef DTRACE_ENABLED
 157 
 158 // Only bother with this argument setup if dtrace is available
 159 
 160   #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_START
 161   #define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_STOP
 162 
 163   #define DTRACE_THREAD_PROBE(probe, javathread)                           \
 164     {                                                                      \
 165       ResourceMark rm(this);                                               \
 166       int len = 0;                                                         \
 167       const char* name = (javathread)->get_thread_name();                  \
 168       len = strlen(name);                                                  \
 169       HOTSPOT_THREAD_PROBE_##probe(/* probe = start, stop */               \
 170         (char *) name, len,                                                \
 171         java_lang_Thread::thread_id((javathread)->threadObj()),            \

 688 void Thread::print_owned_locks_on(outputStream* st) const {
 689   Mutex* cur = _owned_locks;
 690   if (cur == NULL) {
 691     st->print(" (no locks) ");
 692   } else {
 693     st->print_cr(" Locks owned:");
 694     while (cur) {
 695       cur->print_on(st);
 696       cur = cur->next();
 697     }
 698   }
 699 }
 700 #endif // ASSERT
 701 
 702 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter
 703 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being
 704 // used for compilation in the future. If that change is made, the need for these methods
 705 // should be revisited, and they should be removed if possible.
 706 
 707 bool Thread::is_lock_owned(address adr) const {

 708   return is_in_full_stack(adr);
 709 }
 710 
 711 bool Thread::set_as_starting_thread() {
 712   assert(_starting_thread == NULL, "already initialized: "
 713          "_starting_thread=" INTPTR_FORMAT, p2i(_starting_thread));
 714   // NOTE: this must be called inside the main thread.
 715   DEBUG_ONLY(_starting_thread = this;)
 716   return os::create_main_thread(this->as_Java_thread());
 717 }
 718 
 719 static void initialize_class(Symbol* class_name, TRAPS) {
 720   Klass* klass = SystemDictionary::resolve_or_fail(class_name, true, CHECK);
 721   InstanceKlass::cast(klass)->initialize(CHECK);
 722 }
 723 
 724 
 725 // Creates the initial ThreadGroup
 726 static Handle create_initial_thread_group(TRAPS) {
 727   Handle system_instance = JavaCalls::construct_new_instance(

1077 
1078   // JVMTI PopFrame support
1079   _popframe_condition(popframe_inactive),
1080   _frames_to_pop_failed_realloc(0),
1081 
1082   _handshake(this),
1083 
1084   _popframe_preserved_args(nullptr),
1085   _popframe_preserved_args_size(0),
1086 
1087   _jvmti_thread_state(nullptr),
1088   _interp_only_mode(0),
1089   _should_post_on_exceptions_flag(JNI_FALSE),
1090   _thread_stat(new ThreadStatistics()),
1091 
1092   _parker(),
1093   _cached_monitor_info(nullptr),
1094 
1095   _class_to_be_initialized(nullptr),
1096 
1097   _SleepEvent(ParkEvent::Allocate(this))
1098 {

1099   set_jni_functions(jni_functions());
1100 
1101 #if INCLUDE_JVMCI
1102   assert(_jvmci._implicit_exception_pc == nullptr, "must be");
1103   if (JVMCICounterSize > 0) {
1104     resize_counters(0, (int) JVMCICounterSize);
1105   }
1106 #endif // INCLUDE_JVMCI
1107 
1108   // Setup safepoint state info for this thread
1109   ThreadSafepointState::create(this);
1110 
1111   SafepointMechanism::initialize_header(this);
1112 
1113   set_requires_cross_modify_fence(false);
1114 
1115   pd_initialize();
1116   assert(deferred_card_mark().is_empty(), "Default MemRegion ctor");
1117 }
1118 

1556     tlab().retire();
1557   }
1558 
1559   Threads::remove(this, is_daemon);
1560   this->smr_delete();
1561 }
1562 
1563 JavaThread* JavaThread::active() {
1564   Thread* thread = Thread::current();
1565   if (thread->is_Java_thread()) {
1566     return thread->as_Java_thread();
1567   } else {
1568     assert(thread->is_VM_thread(), "this must be a vm thread");
1569     VM_Operation* op = ((VMThread*) thread)->vm_operation();
1570     JavaThread *ret = op == NULL ? NULL : op->calling_thread()->as_Java_thread();
1571     return ret;
1572   }
1573 }
1574 
1575 bool JavaThread::is_lock_owned(address adr) const {
1576   if (Thread::is_lock_owned(adr)) return true;

1577 
1578   for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) {
1579     if (chunk->contains(adr)) return true;
1580   }
1581 
1582   return false;
1583 }
1584 
1585 oop JavaThread::exception_oop() const {
1586   return Atomic::load(&_exception_oop);
1587 }
1588 
1589 void JavaThread::set_exception_oop(oop o) {
1590   Atomic::store(&_exception_oop, o);
1591 }
1592 
1593 void JavaThread::add_monitor_chunk(MonitorChunk* chunk) {
1594   chunk->set_next(monitor_chunks());
1595   set_monitor_chunks(chunk);
1596 }

2006   // written
2007   GrowableArray<jvmtiDeferredLocalVariableSet*>* list = JvmtiDeferredUpdates::deferred_locals(this);
2008   if (list != NULL) {
2009     for (int i = 0; i < list->length(); i++) {
2010       list->at(i)->oops_do(f);
2011     }
2012   }
2013 
2014   // Traverse instance variables at the end since the GC may be moving things
2015   // around using this function
2016   f->do_oop((oop*) &_vm_result);
2017   f->do_oop((oop*) &_exception_oop);
2018   f->do_oop((oop*) &_pending_async_exception);
2019 #if INCLUDE_JVMCI
2020   f->do_oop((oop*) &_jvmci_reserved_oop0);
2021 #endif
2022 
2023   if (jvmti_thread_state() != NULL) {
2024     jvmti_thread_state()->oops_do(f, cf);
2025   }




2026 }
2027 
2028 void JavaThread::oops_do_frames(OopClosure* f, CodeBlobClosure* cf) {
2029   if (!has_last_Java_frame()) {
2030     return;
2031   }
2032   // Finish any pending lazy GC activity for the frames
2033   StackWatermarkSet::finish_processing(this, NULL /* context */, StackWatermarkKind::gc);
2034   // Traverse the execution stack
2035   for (StackFrameStream fst(this, true /* update */, false /* process_frames */); !fst.is_done(); fst.next()) {
2036     fst.current()->oops_do(f, cf, fst.register_map());
2037   }
2038 }
2039 
2040 #ifdef ASSERT
2041 void JavaThread::verify_states_for_handshake() {
2042   // This checks that the thread has a correct frame state during a handshake.
2043   verify_frame_info();
2044 }
2045 #endif

2834   // Initialize assert poison page mechanism.
2835   if (ShowRegistersOnAssert) {
2836     initialize_assert_poison();
2837   }
2838 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2839 
2840   SafepointMechanism::initialize();
2841 
2842   jint adjust_after_os_result = Arguments::adjust_after_os();
2843   if (adjust_after_os_result != JNI_OK) return adjust_after_os_result;
2844 
2845   // Initialize output stream logging
2846   ostream_init_log();
2847 
2848   // Convert -Xrun to -agentlib: if there is no JVM_OnLoad
2849   // Must be before create_vm_init_agents()
2850   if (Arguments::init_libraries_at_startup()) {
2851     convert_vm_init_libraries_to_agents();
2852   }
2853 







2854   // Launch -agentlib/-agentpath and converted -Xrun agents
2855   if (Arguments::init_agents_at_startup()) {
2856     create_vm_init_agents();
2857   }
2858 
2859   // Initialize Threads state
2860   _number_of_threads = 0;
2861   _number_of_non_daemon_threads = 0;
2862 
2863   // Initialize global data structures and create system classes in heap
2864   vm_init_globals();
2865 
2866 #if INCLUDE_JVMCI
2867   if (JVMCICounterSize > 0) {
2868     JavaThread::_jvmci_old_thread_counters = NEW_C_HEAP_ARRAY(jlong, JVMCICounterSize, mtJVMCI);
2869     memset(JavaThread::_jvmci_old_thread_counters, 0, sizeof(jlong) * JVMCICounterSize);
2870   } else {
2871     JavaThread::_jvmci_old_thread_counters = NULL;
2872   }
2873 #endif // INCLUDE_JVMCI

3723 
3724   int i = 0;
3725   DO_JAVA_THREADS(t_list, p) {
3726     if (!p->can_call_java()) continue;
3727 
3728     // The first stage of async deflation does not affect any field
3729     // used by this comparison so the ObjectMonitor* is usable here.
3730     address pending = (address)p->current_pending_monitor();
3731     if (pending == monitor) {             // found a match
3732       if (i < count) result->append(p);   // save the first count matches
3733       i++;
3734     }
3735   }
3736 
3737   return result;
3738 }
3739 
3740 
3741 JavaThread *Threads::owning_thread_from_monitor_owner(ThreadsList * t_list,
3742                                                       address owner) {

3743   // NULL owner means not locked so we can skip the search
3744   if (owner == NULL) return NULL;
3745 
3746   DO_JAVA_THREADS(t_list, p) {
3747     // first, see if owner is the address of a Java thread
3748     if (owner == (address)p) return p;
3749   }
3750 
3751   // Cannot assert on lack of success here since this function may be
3752   // used by code that is trying to report useful problem information
3753   // like deadlock detection.
3754   if (UseHeavyMonitors) return NULL;
3755 
3756   // If we didn't find a matching Java thread and we didn't force use of
3757   // heavyweight monitors, then the owner is the stack address of the
3758   // Lock Word in the owning Java thread's stack.
3759   //
3760   JavaThread* the_owner = NULL;
3761   DO_JAVA_THREADS(t_list, q) {
3762     if (q->is_lock_owned(owner)) {
3763       the_owner = q;
3764       break;
3765     }
3766   }
3767 
3768   // cannot assert on lack of success here; see above comment
3769   return the_owner;
3770 }
3771 































3772 class PrintOnClosure : public ThreadClosure {
3773 private:
3774   outputStream* _st;
3775 
3776 public:
3777   PrintOnClosure(outputStream* st) :
3778       _st(st) {}
3779 
3780   virtual void do_thread(Thread* thread) {
3781     if (thread != NULL) {
3782       thread->print_on(_st);
3783       _st->cr();
3784     }
3785   }
3786 };
3787 
3788 // Threads::print_on() is called at safepoint by VM_PrintThreads operation.
3789 void Threads::print_on(outputStream* st, bool print_stacks,
3790                        bool internal_format, bool print_concurrent_locks,
3791                        bool print_extended_info) {

  72 #include "oops/verifyOopClosure.hpp"
  73 #include "prims/jvm_misc.hpp"
  74 #include "prims/jvmtiDeferredUpdates.hpp"
  75 #include "prims/jvmtiExport.hpp"
  76 #include "prims/jvmtiThreadState.hpp"
  77 #include "runtime/arguments.hpp"
  78 #include "runtime/atomic.hpp"
  79 #include "runtime/biasedLocking.hpp"
  80 #include "runtime/fieldDescriptor.inline.hpp"
  81 #include "runtime/flags/jvmFlagLimit.hpp"
  82 #include "runtime/deoptimization.hpp"
  83 #include "runtime/frame.inline.hpp"
  84 #include "runtime/handles.inline.hpp"
  85 #include "runtime/handshake.hpp"
  86 #include "runtime/init.hpp"
  87 #include "runtime/interfaceSupport.inline.hpp"
  88 #include "runtime/java.hpp"
  89 #include "runtime/javaCalls.hpp"
  90 #include "runtime/jniHandles.inline.hpp"
  91 #include "runtime/jniPeriodicChecker.hpp"
  92 #include "runtime/lockStack.inline.hpp"
  93 #include "runtime/monitorDeflationThread.hpp"
  94 #include "runtime/mutexLocker.hpp"
  95 #include "runtime/nonJavaThread.hpp"
  96 #include "runtime/objectMonitor.inline.hpp"
  97 #include "runtime/orderAccess.hpp"
  98 #include "runtime/osThread.hpp"
  99 #include "runtime/prefetch.inline.hpp"
 100 #include "runtime/safepoint.hpp"
 101 #include "runtime/safepointMechanism.inline.hpp"
 102 #include "runtime/safepointVerifiers.hpp"
 103 #include "runtime/serviceThread.hpp"
 104 #include "runtime/sharedRuntime.hpp"
 105 #include "runtime/stackFrameStream.inline.hpp"
 106 #include "runtime/stackWatermarkSet.inline.hpp"
 107 #include "runtime/statSampler.hpp"
 108 #include "runtime/task.hpp"
 109 #include "runtime/thread.inline.hpp"
 110 #include "runtime/threadCritical.hpp"
 111 #include "runtime/threadSMR.inline.hpp"
 112 #include "runtime/threadStatisticalInfo.hpp"
 113 #include "runtime/threadWXSetters.inline.hpp"
 114 #include "runtime/timer.hpp"
 115 #include "runtime/timerTrace.hpp"
 116 #include "runtime/trimNativeHeap.hpp"
 117 #include "runtime/vframe.inline.hpp"
 118 #include "runtime/vframeArray.hpp"
 119 #include "runtime/vframe_hp.hpp"
 120 #include "runtime/vmThread.hpp"
 121 #include "runtime/vmOperations.hpp"
 122 #include "runtime/vm_version.hpp"
 123 #include "services/attachListener.hpp"
 124 #include "services/management.hpp"
 125 #include "services/memTracker.hpp"
 126 #include "services/threadService.hpp"

 133 #include "utilities/preserveException.hpp"
 134 #include "utilities/spinYield.hpp"
 135 #include "utilities/vmError.hpp"
 136 #if INCLUDE_JVMCI
 137 #include "jvmci/jvmci.hpp"
 138 #include "jvmci/jvmciEnv.hpp"
 139 #endif
 140 #ifdef COMPILER1
 141 #include "c1/c1_Compiler.hpp"
 142 #endif
 143 #ifdef COMPILER2
 144 #include "opto/c2compiler.hpp"
 145 #include "opto/idealGraphPrinter.hpp"
 146 #endif
 147 #if INCLUDE_RTM_OPT
 148 #include "runtime/rtmLocking.hpp"
 149 #endif
 150 #if INCLUDE_JFR
 151 #include "jfr/jfr.hpp"
 152 #endif
 153 #if INCLUDE_VM_STRUCTS
 154 #include "runtime/vmStructs.hpp"
 155 #endif
 156 
 157 // Initialization after module runtime initialization
 158 void universe_post_module_init();  // must happen after call_initPhase2
 159 
 160 #ifdef DTRACE_ENABLED
 161 
 162 // Only bother with this argument setup if dtrace is available
 163 
 164   #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_START
 165   #define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_STOP
 166 
 167   #define DTRACE_THREAD_PROBE(probe, javathread)                           \
 168     {                                                                      \
 169       ResourceMark rm(this);                                               \
 170       int len = 0;                                                         \
 171       const char* name = (javathread)->get_thread_name();                  \
 172       len = strlen(name);                                                  \
 173       HOTSPOT_THREAD_PROBE_##probe(/* probe = start, stop */               \
 174         (char *) name, len,                                                \
 175         java_lang_Thread::thread_id((javathread)->threadObj()),            \

 692 void Thread::print_owned_locks_on(outputStream* st) const {
 693   Mutex* cur = _owned_locks;
 694   if (cur == NULL) {
 695     st->print(" (no locks) ");
 696   } else {
 697     st->print_cr(" Locks owned:");
 698     while (cur) {
 699       cur->print_on(st);
 700       cur = cur->next();
 701     }
 702   }
 703 }
 704 #endif // ASSERT
 705 
 706 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter
 707 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being
 708 // used for compilation in the future. If that change is made, the need for these methods
 709 // should be revisited, and they should be removed if possible.
 710 
 711 bool Thread::is_lock_owned(address adr) const {
 712   assert(LockingMode != LM_LIGHTWEIGHT, "should not be called with new lightweight locking");
 713   return is_in_full_stack(adr);
 714 }
 715 
 716 bool Thread::set_as_starting_thread() {
 717   assert(_starting_thread == NULL, "already initialized: "
 718          "_starting_thread=" INTPTR_FORMAT, p2i(_starting_thread));
 719   // NOTE: this must be called inside the main thread.
 720   DEBUG_ONLY(_starting_thread = this;)
 721   return os::create_main_thread(this->as_Java_thread());
 722 }
 723 
 724 static void initialize_class(Symbol* class_name, TRAPS) {
 725   Klass* klass = SystemDictionary::resolve_or_fail(class_name, true, CHECK);
 726   InstanceKlass::cast(klass)->initialize(CHECK);
 727 }
 728 
 729 
 730 // Creates the initial ThreadGroup
 731 static Handle create_initial_thread_group(TRAPS) {
 732   Handle system_instance = JavaCalls::construct_new_instance(

1082 
1083   // JVMTI PopFrame support
1084   _popframe_condition(popframe_inactive),
1085   _frames_to_pop_failed_realloc(0),
1086 
1087   _handshake(this),
1088 
1089   _popframe_preserved_args(nullptr),
1090   _popframe_preserved_args_size(0),
1091 
1092   _jvmti_thread_state(nullptr),
1093   _interp_only_mode(0),
1094   _should_post_on_exceptions_flag(JNI_FALSE),
1095   _thread_stat(new ThreadStatistics()),
1096 
1097   _parker(),
1098   _cached_monitor_info(nullptr),
1099 
1100   _class_to_be_initialized(nullptr),
1101 
1102   _SleepEvent(ParkEvent::Allocate(this)),
1103 
1104   _lock_stack(this) {
1105   set_jni_functions(jni_functions());
1106 
1107 #if INCLUDE_JVMCI
1108   assert(_jvmci._implicit_exception_pc == nullptr, "must be");
1109   if (JVMCICounterSize > 0) {
1110     resize_counters(0, (int) JVMCICounterSize);
1111   }
1112 #endif // INCLUDE_JVMCI
1113 
1114   // Setup safepoint state info for this thread
1115   ThreadSafepointState::create(this);
1116 
1117   SafepointMechanism::initialize_header(this);
1118 
1119   set_requires_cross_modify_fence(false);
1120 
1121   pd_initialize();
1122   assert(deferred_card_mark().is_empty(), "Default MemRegion ctor");
1123 }
1124 

1562     tlab().retire();
1563   }
1564 
1565   Threads::remove(this, is_daemon);
1566   this->smr_delete();
1567 }
1568 
1569 JavaThread* JavaThread::active() {
1570   Thread* thread = Thread::current();
1571   if (thread->is_Java_thread()) {
1572     return thread->as_Java_thread();
1573   } else {
1574     assert(thread->is_VM_thread(), "this must be a vm thread");
1575     VM_Operation* op = ((VMThread*) thread)->vm_operation();
1576     JavaThread *ret = op == NULL ? NULL : op->calling_thread()->as_Java_thread();
1577     return ret;
1578   }
1579 }
1580 
1581 bool JavaThread::is_lock_owned(address adr) const {
1582   assert(LockingMode != LM_LIGHTWEIGHT, "should not be called with new lightweight locking");
1583  if (Thread::is_lock_owned(adr)) return true;
1584 
1585   for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) {
1586     if (chunk->contains(adr)) return true;
1587   }
1588 
1589   return false;
1590 }
1591 
1592 oop JavaThread::exception_oop() const {
1593   return Atomic::load(&_exception_oop);
1594 }
1595 
1596 void JavaThread::set_exception_oop(oop o) {
1597   Atomic::store(&_exception_oop, o);
1598 }
1599 
1600 void JavaThread::add_monitor_chunk(MonitorChunk* chunk) {
1601   chunk->set_next(monitor_chunks());
1602   set_monitor_chunks(chunk);
1603 }

2013   // written
2014   GrowableArray<jvmtiDeferredLocalVariableSet*>* list = JvmtiDeferredUpdates::deferred_locals(this);
2015   if (list != NULL) {
2016     for (int i = 0; i < list->length(); i++) {
2017       list->at(i)->oops_do(f);
2018     }
2019   }
2020 
2021   // Traverse instance variables at the end since the GC may be moving things
2022   // around using this function
2023   f->do_oop((oop*) &_vm_result);
2024   f->do_oop((oop*) &_exception_oop);
2025   f->do_oop((oop*) &_pending_async_exception);
2026 #if INCLUDE_JVMCI
2027   f->do_oop((oop*) &_jvmci_reserved_oop0);
2028 #endif
2029 
2030   if (jvmti_thread_state() != NULL) {
2031     jvmti_thread_state()->oops_do(f, cf);
2032   }
2033 
2034   if (LockingMode == LM_LIGHTWEIGHT) {
2035     lock_stack().oops_do(f);
2036   }
2037 }
2038 
2039 void JavaThread::oops_do_frames(OopClosure* f, CodeBlobClosure* cf) {
2040   if (!has_last_Java_frame()) {
2041     return;
2042   }
2043   // Finish any pending lazy GC activity for the frames
2044   StackWatermarkSet::finish_processing(this, NULL /* context */, StackWatermarkKind::gc);
2045   // Traverse the execution stack
2046   for (StackFrameStream fst(this, true /* update */, false /* process_frames */); !fst.is_done(); fst.next()) {
2047     fst.current()->oops_do(f, cf, fst.register_map());
2048   }
2049 }
2050 
2051 #ifdef ASSERT
2052 void JavaThread::verify_states_for_handshake() {
2053   // This checks that the thread has a correct frame state during a handshake.
2054   verify_frame_info();
2055 }
2056 #endif

2845   // Initialize assert poison page mechanism.
2846   if (ShowRegistersOnAssert) {
2847     initialize_assert_poison();
2848   }
2849 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2850 
2851   SafepointMechanism::initialize();
2852 
2853   jint adjust_after_os_result = Arguments::adjust_after_os();
2854   if (adjust_after_os_result != JNI_OK) return adjust_after_os_result;
2855 
2856   // Initialize output stream logging
2857   ostream_init_log();
2858 
2859   // Convert -Xrun to -agentlib: if there is no JVM_OnLoad
2860   // Must be before create_vm_init_agents()
2861   if (Arguments::init_libraries_at_startup()) {
2862     convert_vm_init_libraries_to_agents();
2863   }
2864 
2865   // Should happen before any agent attaches and pokes into vmStructs
2866 #if INCLUDE_VM_STRUCTS
2867   if (UseCompactObjectHeaders) {
2868     VMStructs::compact_headers_overrides();
2869   }
2870 #endif
2871 
2872   // Launch -agentlib/-agentpath and converted -Xrun agents
2873   if (Arguments::init_agents_at_startup()) {
2874     create_vm_init_agents();
2875   }
2876 
2877   // Initialize Threads state
2878   _number_of_threads = 0;
2879   _number_of_non_daemon_threads = 0;
2880 
2881   // Initialize global data structures and create system classes in heap
2882   vm_init_globals();
2883 
2884 #if INCLUDE_JVMCI
2885   if (JVMCICounterSize > 0) {
2886     JavaThread::_jvmci_old_thread_counters = NEW_C_HEAP_ARRAY(jlong, JVMCICounterSize, mtJVMCI);
2887     memset(JavaThread::_jvmci_old_thread_counters, 0, sizeof(jlong) * JVMCICounterSize);
2888   } else {
2889     JavaThread::_jvmci_old_thread_counters = NULL;
2890   }
2891 #endif // INCLUDE_JVMCI

3741 
3742   int i = 0;
3743   DO_JAVA_THREADS(t_list, p) {
3744     if (!p->can_call_java()) continue;
3745 
3746     // The first stage of async deflation does not affect any field
3747     // used by this comparison so the ObjectMonitor* is usable here.
3748     address pending = (address)p->current_pending_monitor();
3749     if (pending == monitor) {             // found a match
3750       if (i < count) result->append(p);   // save the first count matches
3751       i++;
3752     }
3753   }
3754 
3755   return result;
3756 }
3757 
3758 
3759 JavaThread *Threads::owning_thread_from_monitor_owner(ThreadsList * t_list,
3760                                                       address owner) {
3761   assert(LockingMode != LM_LIGHTWEIGHT, "Not with new lightweight locking");
3762   // NULL owner means not locked so we can skip the search
3763   if (owner == NULL) return NULL;
3764 
3765   DO_JAVA_THREADS(t_list, p) {
3766     // first, see if owner is the address of a Java thread
3767     if (owner == (address)p) return p;
3768   }
3769 
3770   // Cannot assert on lack of success here since this function may be
3771   // used by code that is trying to report useful problem information
3772   // like deadlock detection.
3773   if (UseHeavyMonitors) return NULL;
3774 
3775   // If we didn't find a matching Java thread and we didn't force use of
3776   // heavyweight monitors, then the owner is the stack address of the
3777   // Lock Word in the owning Java thread's stack.
3778   //
3779   JavaThread* the_owner = NULL;
3780   DO_JAVA_THREADS(t_list, q) {
3781     if (q->is_lock_owned(owner)) {
3782       the_owner = q;
3783       break;
3784     }
3785   }
3786 
3787   // cannot assert on lack of success here; see above comment
3788   return the_owner;
3789 }
3790 
3791 JavaThread* Threads::owning_thread_from_object(ThreadsList * t_list, oop obj) {
3792   assert(LockingMode == LM_LIGHTWEIGHT, "Only with new lightweight locking");
3793   DO_JAVA_THREADS(t_list, q) {
3794     // Need to start processing before accessing oops in the thread.
3795     StackWatermark* watermark = StackWatermarkSet::get(q, StackWatermarkKind::gc);
3796     if (watermark != nullptr) {
3797       watermark->start_processing();
3798     }
3799 
3800     if (q->lock_stack().contains(obj)) {
3801       return q;
3802     }
3803   }
3804   return NULL;
3805 }
3806 
3807 JavaThread* Threads::owning_thread_from_monitor(ThreadsList* t_list, ObjectMonitor* monitor) {
3808   if (LockingMode == LM_LIGHTWEIGHT) {
3809     if (monitor->is_owner_anonymous()) {
3810       return owning_thread_from_object(t_list, monitor->object());
3811     } else {
3812       Thread* owner = reinterpret_cast<Thread*>(monitor->owner());
3813       assert(owner == NULL || owner->is_Java_thread(), "only JavaThreads own monitors");
3814       return reinterpret_cast<JavaThread*>(owner);
3815     }
3816   } else {
3817     address owner = (address)monitor->owner();
3818     return owning_thread_from_monitor_owner(t_list, owner);
3819   }
3820 }
3821 
3822 class PrintOnClosure : public ThreadClosure {
3823 private:
3824   outputStream* _st;
3825 
3826 public:
3827   PrintOnClosure(outputStream* st) :
3828       _st(st) {}
3829 
3830   virtual void do_thread(Thread* thread) {
3831     if (thread != NULL) {
3832       thread->print_on(_st);
3833       _st->cr();
3834     }
3835   }
3836 };
3837 
3838 // Threads::print_on() is called at safepoint by VM_PrintThreads operation.
3839 void Threads::print_on(outputStream* st, bool print_stacks,
3840                        bool internal_format, bool print_concurrent_locks,
3841                        bool print_extended_info) {
< prev index next >