< prev index next >

src/hotspot/share/runtime/javaThread.cpp

Print this page

 480   _exception_oop(oop()),
 481   _exception_pc(nullptr),
 482   _exception_handler_pc(nullptr),
 483   _is_method_handle_return(0),
 484 
 485   _jni_active_critical(0),
 486   _pending_jni_exception_check_fn(nullptr),
 487   _depth_first_number(0),
 488 
 489   // JVMTI PopFrame support
 490   _popframe_condition(popframe_inactive),
 491   _frames_to_pop_failed_realloc(0),
 492 
 493   _cont_entry(nullptr),
 494   _cont_fastpath(nullptr),
 495   _cont_fastpath_thread_state(1),
 496   _held_monitor_count(0),
 497   _jni_monitor_count(0),
 498   _unlocked_inflated_monitor(nullptr),
 499 


 500   _preempt_alternate_return(nullptr),
 501   _preemption_cancelled(false),
 502   _pending_interrupted_exception(false),
 503 
 504   _handshake(this),
 505 
 506   _popframe_preserved_args(nullptr),
 507   _popframe_preserved_args_size(0),
 508 
 509   _jvmti_thread_state(nullptr),
 510   _interp_only_mode(0),
 511   _should_post_on_exceptions_flag(JNI_FALSE),
 512   _thread_stat(new ThreadStatistics()),
 513 
 514   _parker(),
 515 
 516   _class_to_be_initialized(nullptr),
 517   _class_being_initialized(nullptr),
 518 
 519   _SleepEvent(ParkEvent::Allocate(this)),

 961   if (free_handle_block() != nullptr) {
 962     JNIHandleBlock* block = free_handle_block();
 963     set_free_handle_block(nullptr);
 964     JNIHandleBlock::release_block(block);
 965   }
 966 
 967   // These have to be removed while this is still a valid thread.
 968   _stack_overflow_state.remove_stack_guard_pages();
 969 
 970   if (UseTLAB) {
 971     tlab().retire();
 972   }
 973 
 974   if (JvmtiEnv::environments_might_exist()) {
 975     JvmtiExport::cleanup_thread(this);
 976   }
 977 
 978   // We need to cache the thread name for logging purposes below as once
 979   // we have called on_thread_detach this thread must not access any oops.
 980   char* thread_name = nullptr;
 981   if (log_is_enabled(Debug, os, thread, timer)) {
 982     ResourceMark rm(this);
 983     thread_name = os::strdup(name());
 984   }
 985 
 986   if (log_is_enabled(Info, os, thread)) {
 987     ResourceMark rm(this);
 988     log_info(os, thread)("JavaThread %s (name: \"%s\", tid: " UINTX_FORMAT ").",
 989                          exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
 990                          name(), os::current_thread_id());
 991   }
 992 
 993   if (log_is_enabled(Debug, os, thread, timer)) {
 994     _timer_exit_phase3.stop();
 995     _timer_exit_phase4.start();
 996   }
 997 
 998 #if INCLUDE_JVMCI
 999   if (JVMCICounterSize > 0) {
1000     if (jvmci_counters_include(this)) {
1001       for (int i = 0; i < JVMCICounterSize; i++) {
1002         _jvmci_old_thread_counters[i] += _jvmci_counters[i];
1003       }
1004     }
1005   }
1006 #endif // INCLUDE_JVMCI
1007 





1008   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread.
1009   // We call BarrierSet::barrier_set()->on_thread_detach() here so no touching of oops after this point.
1010   Threads::remove(this, daemon);
1011 
1012   if (log_is_enabled(Debug, os, thread, timer)) {
1013     _timer_exit_phase4.stop();
1014     log_debug(os, thread, timer)("name='%s'"
1015                                  ", exit-phase1=" JLONG_FORMAT
1016                                  ", exit-phase2=" JLONG_FORMAT
1017                                  ", exit-phase3=" JLONG_FORMAT
1018                                  ", exit-phase4=" JLONG_FORMAT,
1019                                  thread_name,
1020                                  _timer_exit_phase1.milliseconds(),
1021                                  _timer_exit_phase2.milliseconds(),
1022                                  _timer_exit_phase3.milliseconds(),
1023                                  _timer_exit_phase4.milliseconds());
1024     os::free(thread_name);
1025   }
1026 }
1027 

1746   // Theads_lock is dropped somewhere in the caller since the JavaThread*
1747   // is already visible to JVM/TI via the ThreadsList.
1748   java_lang_Thread::release_set_thread(thread_oop(), this);
1749 }
1750 
1751 oop JavaThread::current_park_blocker() {
1752   // Support for JSR-166 locks
1753   oop thread_oop = threadObj();
1754   if (thread_oop != nullptr) {
1755     return java_lang_Thread::park_blocker(thread_oop);
1756   }
1757   return nullptr;
1758 }
1759 
1760 // Print current stack trace for checked JNI warnings and JNI fatal errors.
1761 // This is the external format, selecting the platform or vthread
1762 // as applicable, and allowing for a native-only stack.
1763 void JavaThread::print_jni_stack() {
1764   assert(this == JavaThread::current(), "Can't print stack of other threads");
1765   if (!has_last_Java_frame()) {
1766     ResourceMark rm(this);
1767     char* buf = NEW_RESOURCE_ARRAY_RETURN_NULL(char, O_BUFLEN);
1768     if (buf == nullptr) {
1769       tty->print_cr("Unable to print native stack - out of memory");
1770       return;
1771     }
1772     address lastpc = nullptr;
1773     if (os::platform_print_native_stack(tty, nullptr, buf, O_BUFLEN, lastpc)) {
1774       // We have printed the native stack in platform-specific code,
1775       // so nothing else to do in this case.
1776     } else {
1777       frame f = os::current_frame();
1778       VMError::print_native_stack(tty, f, this, true /*print_source_info */,
1779                                   -1 /* max stack */, buf, O_BUFLEN);
1780     }
1781   } else {
1782     print_active_stack_on(tty);
1783   }
1784 }
1785 



















1786 void JavaThread::print_stack_on(outputStream* st) {
1787   if (!has_last_Java_frame()) return;
1788 
1789   Thread* current_thread = Thread::current();
1790   ResourceMark rm(current_thread);
1791   HandleMark hm(current_thread);
1792 
1793   RegisterMap reg_map(this,
1794                       RegisterMap::UpdateMap::include,
1795                       RegisterMap::ProcessFrames::include,
1796                       RegisterMap::WalkContinuation::skip);
1797   vframe* start_vf = platform_thread_last_java_vframe(&reg_map);
1798   int count = 0;
1799   for (vframe* f = start_vf; f != nullptr; f = f->sender()) {
1800     if (f->is_java_frame()) {
1801       javaVFrame* jvf = javaVFrame::cast(f);
1802       java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci());
1803 
1804       // Print out lock information
1805       if (JavaMonitorsInStackTrace) {

2344       ResourceMark rm(this);
2345       jio_snprintf(reason, sizeof reason, "Waited for initialization of %s by another thread",
2346                    class_to_be_initialized()->external_name());
2347       event->set_pinnedReason(reason);
2348     } else if (class_being_initialized() != nullptr) {
2349       ResourceMark rm(this);
2350       jio_snprintf(reason, sizeof(reason), "VM call to %s.<clinit> on stack",
2351                    class_being_initialized()->external_name());
2352       event->set_pinnedReason(reason);
2353     } else if (result == freeze_pinned_native) {
2354       event->set_pinnedReason("Native or VM frame on stack");
2355     } else {
2356       jio_snprintf(reason, sizeof(reason), "Freeze or preempt failed (%d)", result);
2357       event->set_pinnedReason(reason);
2358     }
2359     event->set_blockingOperation(op);
2360     event->set_carrierThread(JFR_JVM_THREAD_ID(this));
2361     event->commit();
2362   }
2363 }
2364 #endif

 480   _exception_oop(oop()),
 481   _exception_pc(nullptr),
 482   _exception_handler_pc(nullptr),
 483   _is_method_handle_return(0),
 484 
 485   _jni_active_critical(0),
 486   _pending_jni_exception_check_fn(nullptr),
 487   _depth_first_number(0),
 488 
 489   // JVMTI PopFrame support
 490   _popframe_condition(popframe_inactive),
 491   _frames_to_pop_failed_realloc(0),
 492 
 493   _cont_entry(nullptr),
 494   _cont_fastpath(nullptr),
 495   _cont_fastpath_thread_state(1),
 496   _held_monitor_count(0),
 497   _jni_monitor_count(0),
 498   _unlocked_inflated_monitor(nullptr),
 499 
 500   _can_call_java(true),
 501 
 502   _preempt_alternate_return(nullptr),
 503   _preemption_cancelled(false),
 504   _pending_interrupted_exception(false),
 505 
 506   _handshake(this),
 507 
 508   _popframe_preserved_args(nullptr),
 509   _popframe_preserved_args_size(0),
 510 
 511   _jvmti_thread_state(nullptr),
 512   _interp_only_mode(0),
 513   _should_post_on_exceptions_flag(JNI_FALSE),
 514   _thread_stat(new ThreadStatistics()),
 515 
 516   _parker(),
 517 
 518   _class_to_be_initialized(nullptr),
 519   _class_being_initialized(nullptr),
 520 
 521   _SleepEvent(ParkEvent::Allocate(this)),

 963   if (free_handle_block() != nullptr) {
 964     JNIHandleBlock* block = free_handle_block();
 965     set_free_handle_block(nullptr);
 966     JNIHandleBlock::release_block(block);
 967   }
 968 
 969   // These have to be removed while this is still a valid thread.
 970   _stack_overflow_state.remove_stack_guard_pages();
 971 
 972   if (UseTLAB) {
 973     tlab().retire();
 974   }
 975 
 976   if (JvmtiEnv::environments_might_exist()) {
 977     JvmtiExport::cleanup_thread(this);
 978   }
 979 
 980   // We need to cache the thread name for logging purposes below as once
 981   // we have called on_thread_detach this thread must not access any oops.
 982   char* thread_name = nullptr;
 983   if (log_is_enabled(Debug, os, thread, timer) || (CountBytecodesPerThread && log_is_enabled(Info, init))) {
 984     ResourceMark rm(this);
 985     thread_name = os::strdup(name());
 986   }
 987 
 988   if (log_is_enabled(Info, os, thread)) {
 989     ResourceMark rm(this);
 990     log_info(os, thread)("JavaThread %s (name: \"%s\", tid: " UINTX_FORMAT ").",
 991                          exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
 992                          name(), os::current_thread_id());
 993   }
 994 
 995   if (log_is_enabled(Debug, os, thread, timer)) {
 996     _timer_exit_phase3.stop();
 997     _timer_exit_phase4.start();
 998   }
 999 
1000 #if INCLUDE_JVMCI
1001   if (JVMCICounterSize > 0) {
1002     if (jvmci_counters_include(this)) {
1003       for (int i = 0; i < JVMCICounterSize; i++) {
1004         _jvmci_old_thread_counters[i] += _jvmci_counters[i];
1005       }
1006     }
1007   }
1008 #endif // INCLUDE_JVMCI
1009 
1010   if (bc_counter_value() > 0) {
1011     log_info(init)("Thread '%s': " JLONG_FORMAT " bytecodes executed (during clinit: " JLONG_FORMAT ")",
1012                    thread_name, bc_counter_value(), clinit_bc_counter_value());
1013   }
1014 
1015   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread.
1016   // We call BarrierSet::barrier_set()->on_thread_detach() here so no touching of oops after this point.
1017   Threads::remove(this, daemon);
1018 
1019   if (log_is_enabled(Debug, os, thread, timer)) {
1020     _timer_exit_phase4.stop();
1021     log_debug(os, thread, timer)("name='%s'"
1022                                  ", exit-phase1=" JLONG_FORMAT
1023                                  ", exit-phase2=" JLONG_FORMAT
1024                                  ", exit-phase3=" JLONG_FORMAT
1025                                  ", exit-phase4=" JLONG_FORMAT,
1026                                  thread_name,
1027                                  _timer_exit_phase1.milliseconds(),
1028                                  _timer_exit_phase2.milliseconds(),
1029                                  _timer_exit_phase3.milliseconds(),
1030                                  _timer_exit_phase4.milliseconds());
1031     os::free(thread_name);
1032   }
1033 }
1034 

1753   // Theads_lock is dropped somewhere in the caller since the JavaThread*
1754   // is already visible to JVM/TI via the ThreadsList.
1755   java_lang_Thread::release_set_thread(thread_oop(), this);
1756 }
1757 
1758 oop JavaThread::current_park_blocker() {
1759   // Support for JSR-166 locks
1760   oop thread_oop = threadObj();
1761   if (thread_oop != nullptr) {
1762     return java_lang_Thread::park_blocker(thread_oop);
1763   }
1764   return nullptr;
1765 }
1766 
1767 // Print current stack trace for checked JNI warnings and JNI fatal errors.
1768 // This is the external format, selecting the platform or vthread
1769 // as applicable, and allowing for a native-only stack.
1770 void JavaThread::print_jni_stack() {
1771   assert(this == JavaThread::current(), "Can't print stack of other threads");
1772   if (!has_last_Java_frame()) {
1773     print_native_stack_on(tty);














1774   } else {
1775     print_active_stack_on(tty);
1776   }
1777 }
1778 
1779 void JavaThread::print_native_stack_on(outputStream *st) {
1780   assert(this == JavaThread::current(), "Can't print stack of other threads");
1781   ResourceMark rm;
1782   char* buf = NEW_RESOURCE_ARRAY_RETURN_NULL(char, O_BUFLEN);
1783   if (buf == nullptr) {
1784     st->print_cr("Unable to print native stack - out of memory");
1785     return;
1786   }
1787   address lastpc = nullptr;
1788   if (os::platform_print_native_stack(st, nullptr, buf, O_BUFLEN, lastpc)) {
1789     // We have printed the native stack in platform-specific code,
1790     // so nothing else to do in this case.
1791   } else {
1792     frame f = os::current_frame();
1793     VMError::print_native_stack(st, f, this, true /*print_source_info */,
1794                                 -1 /* max stack */, buf, O_BUFLEN);
1795   }
1796 }
1797 
1798 void JavaThread::print_stack_on(outputStream* st) {
1799   if (!has_last_Java_frame()) return;
1800 
1801   Thread* current_thread = Thread::current();
1802   ResourceMark rm(current_thread);
1803   HandleMark hm(current_thread);
1804 
1805   RegisterMap reg_map(this,
1806                       RegisterMap::UpdateMap::include,
1807                       RegisterMap::ProcessFrames::include,
1808                       RegisterMap::WalkContinuation::skip);
1809   vframe* start_vf = platform_thread_last_java_vframe(&reg_map);
1810   int count = 0;
1811   for (vframe* f = start_vf; f != nullptr; f = f->sender()) {
1812     if (f->is_java_frame()) {
1813       javaVFrame* jvf = javaVFrame::cast(f);
1814       java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci());
1815 
1816       // Print out lock information
1817       if (JavaMonitorsInStackTrace) {

2356       ResourceMark rm(this);
2357       jio_snprintf(reason, sizeof reason, "Waited for initialization of %s by another thread",
2358                    class_to_be_initialized()->external_name());
2359       event->set_pinnedReason(reason);
2360     } else if (class_being_initialized() != nullptr) {
2361       ResourceMark rm(this);
2362       jio_snprintf(reason, sizeof(reason), "VM call to %s.<clinit> on stack",
2363                    class_being_initialized()->external_name());
2364       event->set_pinnedReason(reason);
2365     } else if (result == freeze_pinned_native) {
2366       event->set_pinnedReason("Native or VM frame on stack");
2367     } else {
2368       jio_snprintf(reason, sizeof(reason), "Freeze or preempt failed (%d)", result);
2369       event->set_pinnedReason(reason);
2370     }
2371     event->set_blockingOperation(op);
2372     event->set_carrierThread(JFR_JVM_THREAD_ID(this));
2373     event->commit();
2374   }
2375 }
2376 #endif
< prev index next >