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