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
944 if (free_handle_block() != nullptr) {
945 JNIHandleBlock* block = free_handle_block();
946 set_free_handle_block(nullptr);
947 JNIHandleBlock::release_block(block);
948 }
949
950 // These have to be removed while this is still a valid thread.
951 _stack_overflow_state.remove_stack_guard_pages();
952
953 if (UseTLAB) {
954 tlab().retire();
955 }
956
957 if (JvmtiEnv::environments_might_exist()) {
958 JvmtiExport::cleanup_thread(this);
959 }
960
961 // We need to cache the thread name for logging purposes below as once
962 // we have called on_thread_detach this thread must not access any oops.
963 char* thread_name = nullptr;
964 if (log_is_enabled(Debug, os, thread, timer)) {
965 ResourceMark rm(this);
966 thread_name = os::strdup(name());
967 }
968
969 if (log_is_enabled(Info, os, thread)) {
970 ResourceMark rm(this);
971 log_info(os, thread)("JavaThread %s (name: \"%s\", tid: " UINTX_FORMAT ").",
972 exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
973 name(), os::current_thread_id());
974 }
975
976 if (log_is_enabled(Debug, os, thread, timer)) {
977 _timer_exit_phase3.stop();
978 _timer_exit_phase4.start();
979 }
980
981 #if INCLUDE_JVMCI
982 if (JVMCICounterSize > 0) {
983 if (jvmci_counters_include(this)) {
984 for (int i = 0; i < JVMCICounterSize; i++) {
985 _jvmci_old_thread_counters[i] += _jvmci_counters[i];
986 }
987 }
988 }
989 #endif // INCLUDE_JVMCI
990
991 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread.
992 // We call BarrierSet::barrier_set()->on_thread_detach() here so no touching of oops after this point.
993 Threads::remove(this, daemon);
994
995 if (log_is_enabled(Debug, os, thread, timer)) {
996 _timer_exit_phase4.stop();
997 log_debug(os, thread, timer)("name='%s'"
998 ", exit-phase1=" JLONG_FORMAT
999 ", exit-phase2=" JLONG_FORMAT
1000 ", exit-phase3=" JLONG_FORMAT
1001 ", exit-phase4=" JLONG_FORMAT,
1002 thread_name,
1003 _timer_exit_phase1.milliseconds(),
1004 _timer_exit_phase2.milliseconds(),
1005 _timer_exit_phase3.milliseconds(),
1006 _timer_exit_phase4.milliseconds());
1007 os::free(thread_name);
1008 }
1009 }
1010
1728 // Theads_lock is dropped somewhere in the caller since the JavaThread*
1729 // is already visible to JVM/TI via the ThreadsList.
1730 java_lang_Thread::release_set_thread(thread_oop(), this);
1731 }
1732
1733 oop JavaThread::current_park_blocker() {
1734 // Support for JSR-166 locks
1735 oop thread_oop = threadObj();
1736 if (thread_oop != nullptr) {
1737 return java_lang_Thread::park_blocker(thread_oop);
1738 }
1739 return nullptr;
1740 }
1741
1742 // Print current stack trace for checked JNI warnings and JNI fatal errors.
1743 // This is the external format, selecting the platform or vthread
1744 // as applicable, and allowing for a native-only stack.
1745 void JavaThread::print_jni_stack() {
1746 assert(this == JavaThread::current(), "Can't print stack of other threads");
1747 if (!has_last_Java_frame()) {
1748 ResourceMark rm(this);
1749 char* buf = NEW_RESOURCE_ARRAY_RETURN_NULL(char, O_BUFLEN);
1750 if (buf == nullptr) {
1751 tty->print_cr("Unable to print native stack - out of memory");
1752 return;
1753 }
1754 address lastpc = nullptr;
1755 if (os::platform_print_native_stack(tty, nullptr, buf, O_BUFLEN, lastpc)) {
1756 // We have printed the native stack in platform-specific code,
1757 // so nothing else to do in this case.
1758 } else {
1759 frame f = os::current_frame();
1760 VMError::print_native_stack(tty, f, this, true /*print_source_info */,
1761 -1 /* max stack */, buf, O_BUFLEN);
1762 }
1763 } else {
1764 print_active_stack_on(tty);
1765 }
1766 }
1767
1768 void JavaThread::print_stack_on(outputStream* st) {
1769 if (!has_last_Java_frame()) return;
1770
1771 Thread* current_thread = Thread::current();
1772 ResourceMark rm(current_thread);
1773 HandleMark hm(current_thread);
1774
1775 RegisterMap reg_map(this,
1776 RegisterMap::UpdateMap::include,
1777 RegisterMap::ProcessFrames::include,
1778 RegisterMap::WalkContinuation::skip);
1779 vframe* start_vf = platform_thread_last_java_vframe(®_map);
1780 int count = 0;
1781 for (vframe* f = start_vf; f != nullptr; f = f->sender()) {
1782 if (f->is_java_frame()) {
1783 javaVFrame* jvf = javaVFrame::cast(f);
1784 java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci());
1785
1786 // Print out lock information
1787 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
947 if (free_handle_block() != nullptr) {
948 JNIHandleBlock* block = free_handle_block();
949 set_free_handle_block(nullptr);
950 JNIHandleBlock::release_block(block);
951 }
952
953 // These have to be removed while this is still a valid thread.
954 _stack_overflow_state.remove_stack_guard_pages();
955
956 if (UseTLAB) {
957 tlab().retire();
958 }
959
960 if (JvmtiEnv::environments_might_exist()) {
961 JvmtiExport::cleanup_thread(this);
962 }
963
964 // We need to cache the thread name for logging purposes below as once
965 // we have called on_thread_detach this thread must not access any oops.
966 char* thread_name = nullptr;
967 if (log_is_enabled(Debug, os, thread, timer) || (CountBytecodesPerThread && log_is_enabled(Info, init))) {
968 ResourceMark rm(this);
969 thread_name = os::strdup(name());
970 }
971
972 if (log_is_enabled(Info, os, thread)) {
973 ResourceMark rm(this);
974 log_info(os, thread)("JavaThread %s (name: \"%s\", tid: " UINTX_FORMAT ").",
975 exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
976 name(), os::current_thread_id());
977 }
978
979 if (log_is_enabled(Debug, os, thread, timer)) {
980 _timer_exit_phase3.stop();
981 _timer_exit_phase4.start();
982 }
983
984 #if INCLUDE_JVMCI
985 if (JVMCICounterSize > 0) {
986 if (jvmci_counters_include(this)) {
987 for (int i = 0; i < JVMCICounterSize; i++) {
988 _jvmci_old_thread_counters[i] += _jvmci_counters[i];
989 }
990 }
991 }
992 #endif // INCLUDE_JVMCI
993
994 if (bc_counter_value() > 0) {
995 log_info(init)("Thread '%s': " JLONG_FORMAT " bytecodes executed (during clinit: " JLONG_FORMAT ")",
996 thread_name, bc_counter_value(), clinit_bc_counter_value());
997 }
998
999 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread.
1000 // We call BarrierSet::barrier_set()->on_thread_detach() here so no touching of oops after this point.
1001 Threads::remove(this, daemon);
1002
1003 if (log_is_enabled(Debug, os, thread, timer)) {
1004 _timer_exit_phase4.stop();
1005 log_debug(os, thread, timer)("name='%s'"
1006 ", exit-phase1=" JLONG_FORMAT
1007 ", exit-phase2=" JLONG_FORMAT
1008 ", exit-phase3=" JLONG_FORMAT
1009 ", exit-phase4=" JLONG_FORMAT,
1010 thread_name,
1011 _timer_exit_phase1.milliseconds(),
1012 _timer_exit_phase2.milliseconds(),
1013 _timer_exit_phase3.milliseconds(),
1014 _timer_exit_phase4.milliseconds());
1015 os::free(thread_name);
1016 }
1017 }
1018
1736 // Theads_lock is dropped somewhere in the caller since the JavaThread*
1737 // is already visible to JVM/TI via the ThreadsList.
1738 java_lang_Thread::release_set_thread(thread_oop(), this);
1739 }
1740
1741 oop JavaThread::current_park_blocker() {
1742 // Support for JSR-166 locks
1743 oop thread_oop = threadObj();
1744 if (thread_oop != nullptr) {
1745 return java_lang_Thread::park_blocker(thread_oop);
1746 }
1747 return nullptr;
1748 }
1749
1750 // Print current stack trace for checked JNI warnings and JNI fatal errors.
1751 // This is the external format, selecting the platform or vthread
1752 // as applicable, and allowing for a native-only stack.
1753 void JavaThread::print_jni_stack() {
1754 assert(this == JavaThread::current(), "Can't print stack of other threads");
1755 if (!has_last_Java_frame()) {
1756 print_native_stack_on(tty);
1757 } else {
1758 print_active_stack_on(tty);
1759 }
1760 }
1761
1762 void JavaThread::print_native_stack_on(outputStream *st) {
1763 assert(this == JavaThread::current(), "Can't print stack of other threads");
1764 ResourceMark rm;
1765 char* buf = NEW_RESOURCE_ARRAY_RETURN_NULL(char, O_BUFLEN);
1766 if (buf == nullptr) {
1767 st->print_cr("Unable to print native stack - out of memory");
1768 return;
1769 }
1770 address lastpc = nullptr;
1771 if (os::platform_print_native_stack(st, nullptr, buf, O_BUFLEN, lastpc)) {
1772 // We have printed the native stack in platform-specific code,
1773 // so nothing else to do in this case.
1774 } else {
1775 frame f = os::current_frame();
1776 VMError::print_native_stack(st, f, this, true /*print_source_info */,
1777 -1 /* max stack */, buf, O_BUFLEN);
1778 }
1779 }
1780
1781 void JavaThread::print_stack_on(outputStream* st) {
1782 if (!has_last_Java_frame()) return;
1783
1784 Thread* current_thread = Thread::current();
1785 ResourceMark rm(current_thread);
1786 HandleMark hm(current_thread);
1787
1788 RegisterMap reg_map(this,
1789 RegisterMap::UpdateMap::include,
1790 RegisterMap::ProcessFrames::include,
1791 RegisterMap::WalkContinuation::skip);
1792 vframe* start_vf = platform_thread_last_java_vframe(®_map);
1793 int count = 0;
1794 for (vframe* f = start_vf; f != nullptr; f = f->sender()) {
1795 if (f->is_java_frame()) {
1796 javaVFrame* jvf = javaVFrame::cast(f);
1797 java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci());
1798
1799 // Print out lock information
1800 if (JavaMonitorsInStackTrace) {
|