< prev index next >

src/hotspot/share/runtime/javaThread.cpp

Print this page

 462 
 463   _exception_oop(oop()),
 464   _exception_pc(0),
 465   _exception_handler_pc(0),
 466   _is_method_handle_return(0),
 467 
 468   _jni_active_critical(0),
 469   _pending_jni_exception_check_fn(nullptr),
 470   _depth_first_number(0),
 471 
 472   // JVMTI PopFrame support
 473   _popframe_condition(popframe_inactive),
 474   _frames_to_pop_failed_realloc(0),
 475 
 476   _cont_entry(nullptr),
 477   _cont_fastpath(0),
 478   _cont_fastpath_thread_state(1),
 479   _held_monitor_count(0),
 480   _jni_monitor_count(0),
 481 


 482   _handshake(this),
 483 
 484   _popframe_preserved_args(nullptr),
 485   _popframe_preserved_args_size(0),
 486 
 487   _jvmti_thread_state(nullptr),
 488   _interp_only_mode(0),
 489   _should_post_on_exceptions_flag(JNI_FALSE),
 490   _thread_stat(new ThreadStatistics()),
 491 
 492   _parker(),
 493 
 494   _class_to_be_initialized(nullptr),

 495 
 496   _SleepEvent(ParkEvent::Allocate(this)),
 497 
 498   _lock_stack(this) {
 499   set_jni_functions(jni_functions());
 500 
 501 #if INCLUDE_JVMCI
 502   assert(_jvmci._implicit_exception_pc == nullptr, "must be");
 503   if (JVMCICounterSize > 0) {
 504     resize_counters(0, (int) JVMCICounterSize);
 505   }
 506 #endif // INCLUDE_JVMCI
 507 
 508   // Setup safepoint state info for this thread
 509   ThreadSafepointState::create(this);
 510 
 511   SafepointMechanism::initialize_header(this);
 512 
 513   set_requires_cross_modify_fence(false);
 514 

 900   if (free_handle_block() != nullptr) {
 901     JNIHandleBlock* block = free_handle_block();
 902     set_free_handle_block(nullptr);
 903     JNIHandleBlock::release_block(block);
 904   }
 905 
 906   // These have to be removed while this is still a valid thread.
 907   _stack_overflow_state.remove_stack_guard_pages();
 908 
 909   if (UseTLAB) {
 910     tlab().retire();
 911   }
 912 
 913   if (JvmtiEnv::environments_might_exist()) {
 914     JvmtiExport::cleanup_thread(this);
 915   }
 916 
 917   // We need to cache the thread name for logging purposes below as once
 918   // we have called on_thread_detach this thread must not access any oops.
 919   char* thread_name = nullptr;
 920   if (log_is_enabled(Debug, os, thread, timer)) {
 921     ResourceMark rm(this);
 922     thread_name = os::strdup(name());
 923   }
 924 
 925   log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
 926     exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
 927     os::current_thread_id());
 928 
 929   if (log_is_enabled(Debug, os, thread, timer)) {
 930     _timer_exit_phase3.stop();
 931     _timer_exit_phase4.start();
 932   }
 933 
 934 #if INCLUDE_JVMCI
 935   if (JVMCICounterSize > 0) {
 936     if (jvmci_counters_include(this)) {
 937       for (int i = 0; i < JVMCICounterSize; i++) {
 938         _jvmci_old_thread_counters[i] += _jvmci_counters[i];
 939       }
 940     }
 941   }
 942 #endif // INCLUDE_JVMCI
 943 





 944   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread.
 945   // We call BarrierSet::barrier_set()->on_thread_detach() here so no touching of oops after this point.
 946   Threads::remove(this, daemon);
 947 
 948   if (log_is_enabled(Debug, os, thread, timer)) {
 949     _timer_exit_phase4.stop();
 950     log_debug(os, thread, timer)("name='%s'"
 951                                  ", exit-phase1=" JLONG_FORMAT
 952                                  ", exit-phase2=" JLONG_FORMAT
 953                                  ", exit-phase3=" JLONG_FORMAT
 954                                  ", exit-phase4=" JLONG_FORMAT,
 955                                  thread_name,
 956                                  _timer_exit_phase1.milliseconds(),
 957                                  _timer_exit_phase2.milliseconds(),
 958                                  _timer_exit_phase3.milliseconds(),
 959                                  _timer_exit_phase4.milliseconds());
 960     os::free(thread_name);
 961   }
 962 }
 963 

1697   // Theads_lock is dropped somewhere in the caller since the JavaThread*
1698   // is already visible to JVM/TI via the ThreadsList.
1699   java_lang_Thread::release_set_thread(thread_oop(), this);
1700 }
1701 
1702 oop JavaThread::current_park_blocker() {
1703   // Support for JSR-166 locks
1704   oop thread_oop = threadObj();
1705   if (thread_oop != nullptr) {
1706     return java_lang_Thread::park_blocker(thread_oop);
1707   }
1708   return nullptr;
1709 }
1710 
1711 // Print current stack trace for checked JNI warnings and JNI fatal errors.
1712 // This is the external format, selecting the platform or vthread
1713 // as applicable, and allowing for a native-only stack.
1714 void JavaThread::print_jni_stack() {
1715   assert(this == JavaThread::current(), "Can't print stack of other threads");
1716   if (!has_last_Java_frame()) {
1717     ResourceMark rm(this);
1718     char* buf = NEW_RESOURCE_ARRAY_RETURN_NULL(char, O_BUFLEN);
1719     if (buf == nullptr) {
1720       tty->print_cr("Unable to print native stack - out of memory");
1721       return;
1722     }
1723     address lastpc = nullptr;
1724     if (os::platform_print_native_stack(tty, nullptr, buf, O_BUFLEN, lastpc)) {
1725       // We have printed the native stack in platform-specific code,
1726       // so nothing else to do in this case.
1727     } else {
1728       frame f = os::current_frame();
1729       VMError::print_native_stack(tty, f, this, true /*print_source_info */,
1730                                   -1 /* max stack */, buf, O_BUFLEN);
1731     }
1732   } else {
1733     print_active_stack_on(tty);
1734   }
1735 }
1736 



















1737 void JavaThread::print_stack_on(outputStream* st) {
1738   if (!has_last_Java_frame()) return;
1739 
1740   Thread* current_thread = Thread::current();
1741   ResourceMark rm(current_thread);
1742   HandleMark hm(current_thread);
1743 
1744   RegisterMap reg_map(this,
1745                       RegisterMap::UpdateMap::include,
1746                       RegisterMap::ProcessFrames::include,
1747                       RegisterMap::WalkContinuation::skip);
1748   vframe* start_vf = platform_thread_last_java_vframe(&reg_map);
1749   int count = 0;
1750   for (vframe* f = start_vf; f != nullptr; f = f->sender()) {
1751     if (f->is_java_frame()) {
1752       javaVFrame* jvf = javaVFrame::cast(f);
1753       java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci());
1754 
1755       // Print out lock information
1756       if (JavaMonitorsInStackTrace) {

 462 
 463   _exception_oop(oop()),
 464   _exception_pc(0),
 465   _exception_handler_pc(0),
 466   _is_method_handle_return(0),
 467 
 468   _jni_active_critical(0),
 469   _pending_jni_exception_check_fn(nullptr),
 470   _depth_first_number(0),
 471 
 472   // JVMTI PopFrame support
 473   _popframe_condition(popframe_inactive),
 474   _frames_to_pop_failed_realloc(0),
 475 
 476   _cont_entry(nullptr),
 477   _cont_fastpath(0),
 478   _cont_fastpath_thread_state(1),
 479   _held_monitor_count(0),
 480   _jni_monitor_count(0),
 481 
 482   _can_call_java(true),
 483 
 484   _handshake(this),
 485 
 486   _popframe_preserved_args(nullptr),
 487   _popframe_preserved_args_size(0),
 488 
 489   _jvmti_thread_state(nullptr),
 490   _interp_only_mode(0),
 491   _should_post_on_exceptions_flag(JNI_FALSE),
 492   _thread_stat(new ThreadStatistics()),
 493 
 494   _parker(),
 495 
 496   _class_to_be_initialized(nullptr),
 497   _class_being_initialized(nullptr),
 498 
 499   _SleepEvent(ParkEvent::Allocate(this)),
 500 
 501   _lock_stack(this) {
 502   set_jni_functions(jni_functions());
 503 
 504 #if INCLUDE_JVMCI
 505   assert(_jvmci._implicit_exception_pc == nullptr, "must be");
 506   if (JVMCICounterSize > 0) {
 507     resize_counters(0, (int) JVMCICounterSize);
 508   }
 509 #endif // INCLUDE_JVMCI
 510 
 511   // Setup safepoint state info for this thread
 512   ThreadSafepointState::create(this);
 513 
 514   SafepointMechanism::initialize_header(this);
 515 
 516   set_requires_cross_modify_fence(false);
 517 

 903   if (free_handle_block() != nullptr) {
 904     JNIHandleBlock* block = free_handle_block();
 905     set_free_handle_block(nullptr);
 906     JNIHandleBlock::release_block(block);
 907   }
 908 
 909   // These have to be removed while this is still a valid thread.
 910   _stack_overflow_state.remove_stack_guard_pages();
 911 
 912   if (UseTLAB) {
 913     tlab().retire();
 914   }
 915 
 916   if (JvmtiEnv::environments_might_exist()) {
 917     JvmtiExport::cleanup_thread(this);
 918   }
 919 
 920   // We need to cache the thread name for logging purposes below as once
 921   // we have called on_thread_detach this thread must not access any oops.
 922   char* thread_name = nullptr;
 923   if (log_is_enabled(Debug, os, thread, timer) || (CountBytecodesPerThread && log_is_enabled(Info, init))) {
 924     ResourceMark rm(this);
 925     thread_name = os::strdup(name());
 926   }
 927 
 928   log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
 929     exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
 930     os::current_thread_id());
 931 
 932   if (log_is_enabled(Debug, os, thread, timer)) {
 933     _timer_exit_phase3.stop();
 934     _timer_exit_phase4.start();
 935   }
 936 
 937 #if INCLUDE_JVMCI
 938   if (JVMCICounterSize > 0) {
 939     if (jvmci_counters_include(this)) {
 940       for (int i = 0; i < JVMCICounterSize; i++) {
 941         _jvmci_old_thread_counters[i] += _jvmci_counters[i];
 942       }
 943     }
 944   }
 945 #endif // INCLUDE_JVMCI
 946 
 947   if (bc_counter_value() > 0) {
 948     log_info(init)("Thread '%s': " JLONG_FORMAT " bytecodes executed (during clinit: " JLONG_FORMAT ")",
 949                    thread_name, bc_counter_value(), clinit_bc_counter_value());
 950   }
 951 
 952   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread.
 953   // We call BarrierSet::barrier_set()->on_thread_detach() here so no touching of oops after this point.
 954   Threads::remove(this, daemon);
 955 
 956   if (log_is_enabled(Debug, os, thread, timer)) {
 957     _timer_exit_phase4.stop();
 958     log_debug(os, thread, timer)("name='%s'"
 959                                  ", exit-phase1=" JLONG_FORMAT
 960                                  ", exit-phase2=" JLONG_FORMAT
 961                                  ", exit-phase3=" JLONG_FORMAT
 962                                  ", exit-phase4=" JLONG_FORMAT,
 963                                  thread_name,
 964                                  _timer_exit_phase1.milliseconds(),
 965                                  _timer_exit_phase2.milliseconds(),
 966                                  _timer_exit_phase3.milliseconds(),
 967                                  _timer_exit_phase4.milliseconds());
 968     os::free(thread_name);
 969   }
 970 }
 971 

1705   // Theads_lock is dropped somewhere in the caller since the JavaThread*
1706   // is already visible to JVM/TI via the ThreadsList.
1707   java_lang_Thread::release_set_thread(thread_oop(), this);
1708 }
1709 
1710 oop JavaThread::current_park_blocker() {
1711   // Support for JSR-166 locks
1712   oop thread_oop = threadObj();
1713   if (thread_oop != nullptr) {
1714     return java_lang_Thread::park_blocker(thread_oop);
1715   }
1716   return nullptr;
1717 }
1718 
1719 // Print current stack trace for checked JNI warnings and JNI fatal errors.
1720 // This is the external format, selecting the platform or vthread
1721 // as applicable, and allowing for a native-only stack.
1722 void JavaThread::print_jni_stack() {
1723   assert(this == JavaThread::current(), "Can't print stack of other threads");
1724   if (!has_last_Java_frame()) {
1725     print_native_stack_on(tty);














1726   } else {
1727     print_active_stack_on(tty);
1728   }
1729 }
1730 
1731 void JavaThread::print_native_stack_on(outputStream *st) {
1732   assert(this == JavaThread::current(), "Can't print stack of other threads");
1733   ResourceMark rm;
1734   char* buf = NEW_RESOURCE_ARRAY_RETURN_NULL(char, O_BUFLEN);
1735   if (buf == nullptr) {
1736     st->print_cr("Unable to print native stack - out of memory");
1737     return;
1738   }
1739   address lastpc = nullptr;
1740   if (os::platform_print_native_stack(st, nullptr, buf, O_BUFLEN, lastpc)) {
1741     // We have printed the native stack in platform-specific code,
1742     // so nothing else to do in this case.
1743   } else {
1744     frame f = os::current_frame();
1745     VMError::print_native_stack(st, f, this, true /*print_source_info */,
1746                                 -1 /* max stack */, buf, O_BUFLEN);
1747   }
1748 }
1749 
1750 void JavaThread::print_stack_on(outputStream* st) {
1751   if (!has_last_Java_frame()) return;
1752 
1753   Thread* current_thread = Thread::current();
1754   ResourceMark rm(current_thread);
1755   HandleMark hm(current_thread);
1756 
1757   RegisterMap reg_map(this,
1758                       RegisterMap::UpdateMap::include,
1759                       RegisterMap::ProcessFrames::include,
1760                       RegisterMap::WalkContinuation::skip);
1761   vframe* start_vf = platform_thread_last_java_vframe(&reg_map);
1762   int count = 0;
1763   for (vframe* f = start_vf; f != nullptr; f = f->sender()) {
1764     if (f->is_java_frame()) {
1765       javaVFrame* jvf = javaVFrame::cast(f);
1766       java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci());
1767 
1768       // Print out lock information
1769       if (JavaMonitorsInStackTrace) {
< prev index next >