< prev index next >

src/hotspot/share/runtime/javaThread.cpp

Print this page

 471 
 472   _exception_oop(oop()),
 473   _exception_pc(0),
 474   _exception_handler_pc(0),
 475   _is_method_handle_return(0),
 476 
 477   _jni_active_critical(0),
 478   _pending_jni_exception_check_fn(nullptr),
 479   _depth_first_number(0),
 480 
 481   // JVMTI PopFrame support
 482   _popframe_condition(popframe_inactive),
 483   _frames_to_pop_failed_realloc(0),
 484 
 485   _cont_entry(nullptr),
 486   _cont_fastpath(0),
 487   _cont_fastpath_thread_state(1),
 488   _held_monitor_count(0),
 489   _jni_monitor_count(0),
 490 


 491   _handshake(this),
 492 
 493   _popframe_preserved_args(nullptr),
 494   _popframe_preserved_args_size(0),
 495 
 496   _jvmti_thread_state(nullptr),
 497   _interp_only_mode(0),
 498   _should_post_on_exceptions_flag(JNI_FALSE),
 499   _thread_stat(new ThreadStatistics()),
 500 
 501   _parker(),
 502 
 503   _class_to_be_initialized(nullptr),

 504 
 505   _SleepEvent(ParkEvent::Allocate(this)),
 506 
 507   _lock_stack(this) {
 508   set_jni_functions(jni_functions());
 509 
 510 #if INCLUDE_JVMCI
 511   assert(_jvmci._implicit_exception_pc == nullptr, "must be");
 512   if (JVMCICounterSize > 0) {
 513     resize_counters(0, (int) JVMCICounterSize);
 514   }
 515 #endif // INCLUDE_JVMCI
 516 
 517   // Setup safepoint state info for this thread
 518   ThreadSafepointState::create(this);
 519 
 520   SafepointMechanism::initialize_header(this);
 521 
 522   set_requires_cross_modify_fence(false);
 523 

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





 993   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread.
 994   // We call BarrierSet::barrier_set()->on_thread_detach() here so no touching of oops after this point.
 995   Threads::remove(this, daemon);
 996 
 997   if (log_is_enabled(Debug, os, thread, timer)) {
 998     _timer_exit_phase4.stop();
 999     log_debug(os, thread, timer)("name='%s'"
1000                                  ", exit-phase1=" JLONG_FORMAT
1001                                  ", exit-phase2=" JLONG_FORMAT
1002                                  ", exit-phase3=" JLONG_FORMAT
1003                                  ", exit-phase4=" JLONG_FORMAT,
1004                                  thread_name,
1005                                  _timer_exit_phase1.milliseconds(),
1006                                  _timer_exit_phase2.milliseconds(),
1007                                  _timer_exit_phase3.milliseconds(),
1008                                  _timer_exit_phase4.milliseconds());
1009     os::free(thread_name);
1010   }
1011 }
1012 

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



















1770 void JavaThread::print_stack_on(outputStream* st) {
1771   if (!has_last_Java_frame()) return;
1772 
1773   Thread* current_thread = Thread::current();
1774   ResourceMark rm(current_thread);
1775   HandleMark hm(current_thread);
1776 
1777   RegisterMap reg_map(this,
1778                       RegisterMap::UpdateMap::include,
1779                       RegisterMap::ProcessFrames::include,
1780                       RegisterMap::WalkContinuation::skip);
1781   vframe* start_vf = platform_thread_last_java_vframe(&reg_map);
1782   int count = 0;
1783   for (vframe* f = start_vf; f != nullptr; f = f->sender()) {
1784     if (f->is_java_frame()) {
1785       javaVFrame* jvf = javaVFrame::cast(f);
1786       java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci());
1787 
1788       // Print out lock information
1789       if (JavaMonitorsInStackTrace) {

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

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

1738   // Theads_lock is dropped somewhere in the caller since the JavaThread*
1739   // is already visible to JVM/TI via the ThreadsList.
1740   java_lang_Thread::release_set_thread(thread_oop(), this);
1741 }
1742 
1743 oop JavaThread::current_park_blocker() {
1744   // Support for JSR-166 locks
1745   oop thread_oop = threadObj();
1746   if (thread_oop != nullptr) {
1747     return java_lang_Thread::park_blocker(thread_oop);
1748   }
1749   return nullptr;
1750 }
1751 
1752 // Print current stack trace for checked JNI warnings and JNI fatal errors.
1753 // This is the external format, selecting the platform or vthread
1754 // as applicable, and allowing for a native-only stack.
1755 void JavaThread::print_jni_stack() {
1756   assert(this == JavaThread::current(), "Can't print stack of other threads");
1757   if (!has_last_Java_frame()) {
1758     print_native_stack_on(tty);














1759   } else {
1760     print_active_stack_on(tty);
1761   }
1762 }
1763 
1764 void JavaThread::print_native_stack_on(outputStream *st) {
1765   assert(this == JavaThread::current(), "Can't print stack of other threads");
1766   ResourceMark rm;
1767   char* buf = NEW_RESOURCE_ARRAY_RETURN_NULL(char, O_BUFLEN);
1768   if (buf == nullptr) {
1769     st->print_cr("Unable to print native stack - out of memory");
1770     return;
1771   }
1772   address lastpc = nullptr;
1773   if (os::platform_print_native_stack(st, 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(st, f, this, true /*print_source_info */,
1779                                 -1 /* max stack */, buf, O_BUFLEN);
1780   }
1781 }
1782 
1783 void JavaThread::print_stack_on(outputStream* st) {
1784   if (!has_last_Java_frame()) return;
1785 
1786   Thread* current_thread = Thread::current();
1787   ResourceMark rm(current_thread);
1788   HandleMark hm(current_thread);
1789 
1790   RegisterMap reg_map(this,
1791                       RegisterMap::UpdateMap::include,
1792                       RegisterMap::ProcessFrames::include,
1793                       RegisterMap::WalkContinuation::skip);
1794   vframe* start_vf = platform_thread_last_java_vframe(&reg_map);
1795   int count = 0;
1796   for (vframe* f = start_vf; f != nullptr; f = f->sender()) {
1797     if (f->is_java_frame()) {
1798       javaVFrame* jvf = javaVFrame::cast(f);
1799       java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci());
1800 
1801       // Print out lock information
1802       if (JavaMonitorsInStackTrace) {
< prev index next >