226 // stack and get_thread
227 set_stack_base(NULL);
228 set_stack_size(0);
229 set_self_raw_id(0);
230 set_lgrp_id(-1);
231 DEBUG_ONLY(clear_suspendible_thread();)
232
233 // allocated data structures
234 set_osthread(NULL);
235 set_resource_area(new (mtThread)ResourceArea());
236 DEBUG_ONLY(_current_resource_mark = NULL;)
237 set_handle_area(new (mtThread) HandleArea(NULL));
238 set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true));
239 set_active_handles(NULL);
240 set_free_handle_block(NULL);
241 set_last_handle_mark(NULL);
242
243 // This initial value ==> never claimed.
244 _oops_do_parity = 0;
245 _threads_hazard_ptr = NULL;
246 _nested_threads_hazard_ptr = NULL;
247 _nested_threads_hazard_ptr_cnt = 0;
248 _rcu_counter = 0;
249
250 // the handle mark links itself to last_handle_mark
251 new HandleMark(this);
252
253 // plain initialization
254 debug_only(_owned_locks = NULL;)
255 debug_only(_allow_allocation_count = 0;)
256 NOT_PRODUCT(_allow_safepoint_count = 0;)
257 NOT_PRODUCT(_skip_gcalot = false;)
258 _jvmti_env_iteration_count = 0;
259 set_allocated_bytes(0);
260 _vm_operation_started_count = 0;
261 _vm_operation_completed_count = 0;
262 _current_pending_monitor = NULL;
263 _current_pending_monitor_is_from_java = true;
264 _current_waiting_monitor = NULL;
265 _num_nested_signal = 0;
266 omFreeList = NULL;
864
865 void Thread::metadata_handles_do(void f(Metadata*)) {
866 // Only walk the Handles in Thread.
867 if (metadata_handles() != NULL) {
868 for (int i = 0; i< metadata_handles()->length(); i++) {
869 f(metadata_handles()->at(i));
870 }
871 }
872 }
873
874 void Thread::print_on(outputStream* st) const {
875 // get_priority assumes osthread initialized
876 if (osthread() != NULL) {
877 int os_prio;
878 if (os::get_native_priority(this, &os_prio) == OS_OK) {
879 st->print("os_prio=%d ", os_prio);
880 }
881 st->print("tid=" INTPTR_FORMAT " ", p2i(this));
882 osthread()->print_on(st);
883 }
884 if (_threads_hazard_ptr != NULL) {
885 st->print("_threads_hazard_ptr=" INTPTR_FORMAT, p2i(_threads_hazard_ptr));
886 }
887 if (_nested_threads_hazard_ptr != NULL) {
888 print_nested_threads_hazard_ptrs_on(st);
889 }
890 st->print(" ");
891 debug_only(if (WizardMode) print_owned_locks_on(st);)
892 }
893
894 void Thread::print_nested_threads_hazard_ptrs_on(outputStream* st) const {
895 assert(_nested_threads_hazard_ptr != NULL, "must be set to print");
896
897 if (EnableThreadSMRStatistics) {
898 st->print(", _nested_threads_hazard_ptr_cnt=%u", _nested_threads_hazard_ptr_cnt);
899 }
900 st->print(", _nested_threads_hazard_ptrs=");
901 for (NestedThreadsList* node = _nested_threads_hazard_ptr; node != NULL;
902 node = node->next()) {
903 if (node != _nested_threads_hazard_ptr) {
904 // First node does not need a comma-space separator.
905 st->print(", ");
906 }
907 st->print(INTPTR_FORMAT, p2i(node->t_list()));
908 }
909 }
910
911 // Thread::print_on_error() is called by fatal error handler. Don't use
912 // any lock or allocate memory.
913 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
914 assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
915
916 if (is_VM_thread()) { st->print("VMThread"); }
917 else if (is_GC_task_thread()) { st->print("GCTaskThread"); }
918 else if (is_Watcher_thread()) { st->print("WatcherThread"); }
919 else if (is_ConcurrentGC_thread()) { st->print("ConcurrentGCThread"); }
920 else { st->print("Thread"); }
921
922 if (is_Named_thread()) {
923 st->print(" \"%s\"", name());
924 }
925
926 st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]",
927 p2i(stack_end()), p2i(stack_base()));
928
929 if (osthread()) {
930 st->print(" [id=%d]", osthread()->thread_id());
931 }
932
933 if (_threads_hazard_ptr != NULL) {
934 st->print(" _threads_hazard_ptr=" INTPTR_FORMAT, p2i(_threads_hazard_ptr));
935 }
936 if (_nested_threads_hazard_ptr != NULL) {
937 print_nested_threads_hazard_ptrs_on(st);
938 }
939 }
940
941 void Thread::print_value_on(outputStream* st) const {
942 if (is_Named_thread()) {
943 st->print(" \"%s\" ", name());
944 }
945 st->print(INTPTR_FORMAT, p2i(this)); // print address
946 }
947
948 #ifdef ASSERT
949 void Thread::print_owned_locks_on(outputStream* st) const {
950 Monitor *cur = _owned_locks;
951 if (cur == NULL) {
952 st->print(" (no locks) ");
953 } else {
954 st->print_cr(" Locks owned:");
955 while (cur) {
956 cur->print_on(st);
957 cur = cur->next();
958 }
2978 st->print("%s", get_thread_name_string(buf, buflen));
2979 }
2980
2981 // Called by fatal error handler. The difference between this and
2982 // JavaThread::print() is that we can't grab lock or allocate memory.
2983 void JavaThread::print_on_error(outputStream* st, char *buf, int buflen) const {
2984 st->print("JavaThread \"%s\"", get_thread_name_string(buf, buflen));
2985 oop thread_obj = threadObj();
2986 if (thread_obj != NULL) {
2987 if (java_lang_Thread::is_daemon(thread_obj)) st->print(" daemon");
2988 }
2989 st->print(" [");
2990 st->print("%s", _get_thread_state_name(_thread_state));
2991 if (osthread()) {
2992 st->print(", id=%d", osthread()->thread_id());
2993 }
2994 st->print(", stack(" PTR_FORMAT "," PTR_FORMAT ")",
2995 p2i(stack_end()), p2i(stack_base()));
2996 st->print("]");
2997
2998 if (_threads_hazard_ptr != NULL) {
2999 st->print(" _threads_hazard_ptr=" INTPTR_FORMAT, p2i(_threads_hazard_ptr));
3000 }
3001 if (_nested_threads_hazard_ptr != NULL) {
3002 print_nested_threads_hazard_ptrs_on(st);
3003 }
3004 return;
3005 }
3006
3007 // Verification
3008
3009 static void frame_verify(frame* f, const RegisterMap *map) { f->verify(map); }
3010
3011 void JavaThread::verify() {
3012 // Verify oops in the thread.
3013 oops_do(&VerifyOopClosure::verify_oop, NULL);
3014
3015 // Verify the stack frames.
3016 frames_do(frame_verify);
3017 }
3018
3019 // CR 6300358 (sub-CR 2137150)
3020 // Most callers of this method assume that it can't return NULL but a
3021 // thread may not have a name whilst it is in the process of attaching to
3022 // the VM - see CR 6412693, and there are places where a JavaThread can be
3023 // seen prior to having it's threadObj set (eg JNI attaching threads and
|
226 // stack and get_thread
227 set_stack_base(NULL);
228 set_stack_size(0);
229 set_self_raw_id(0);
230 set_lgrp_id(-1);
231 DEBUG_ONLY(clear_suspendible_thread();)
232
233 // allocated data structures
234 set_osthread(NULL);
235 set_resource_area(new (mtThread)ResourceArea());
236 DEBUG_ONLY(_current_resource_mark = NULL;)
237 set_handle_area(new (mtThread) HandleArea(NULL));
238 set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true));
239 set_active_handles(NULL);
240 set_free_handle_block(NULL);
241 set_last_handle_mark(NULL);
242
243 // This initial value ==> never claimed.
244 _oops_do_parity = 0;
245 _threads_hazard_ptr = NULL;
246 _threads_list_ptr = NULL;
247 _nested_threads_hazard_ptr_cnt = 0;
248 _rcu_counter = 0;
249
250 // the handle mark links itself to last_handle_mark
251 new HandleMark(this);
252
253 // plain initialization
254 debug_only(_owned_locks = NULL;)
255 debug_only(_allow_allocation_count = 0;)
256 NOT_PRODUCT(_allow_safepoint_count = 0;)
257 NOT_PRODUCT(_skip_gcalot = false;)
258 _jvmti_env_iteration_count = 0;
259 set_allocated_bytes(0);
260 _vm_operation_started_count = 0;
261 _vm_operation_completed_count = 0;
262 _current_pending_monitor = NULL;
263 _current_pending_monitor_is_from_java = true;
264 _current_waiting_monitor = NULL;
265 _num_nested_signal = 0;
266 omFreeList = NULL;
864
865 void Thread::metadata_handles_do(void f(Metadata*)) {
866 // Only walk the Handles in Thread.
867 if (metadata_handles() != NULL) {
868 for (int i = 0; i< metadata_handles()->length(); i++) {
869 f(metadata_handles()->at(i));
870 }
871 }
872 }
873
874 void Thread::print_on(outputStream* st) const {
875 // get_priority assumes osthread initialized
876 if (osthread() != NULL) {
877 int os_prio;
878 if (os::get_native_priority(this, &os_prio) == OS_OK) {
879 st->print("os_prio=%d ", os_prio);
880 }
881 st->print("tid=" INTPTR_FORMAT " ", p2i(this));
882 osthread()->print_on(st);
883 }
884 ThreadsSMRSupport::print_info_on(this, st);
885 st->print(" ");
886 debug_only(if (WizardMode) print_owned_locks_on(st);)
887 }
888
889 // Thread::print_on_error() is called by fatal error handler. Don't use
890 // any lock or allocate memory.
891 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
892 assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
893
894 if (is_VM_thread()) { st->print("VMThread"); }
895 else if (is_GC_task_thread()) { st->print("GCTaskThread"); }
896 else if (is_Watcher_thread()) { st->print("WatcherThread"); }
897 else if (is_ConcurrentGC_thread()) { st->print("ConcurrentGCThread"); }
898 else { st->print("Thread"); }
899
900 if (is_Named_thread()) {
901 st->print(" \"%s\"", name());
902 }
903
904 st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]",
905 p2i(stack_end()), p2i(stack_base()));
906
907 if (osthread()) {
908 st->print(" [id=%d]", osthread()->thread_id());
909 }
910
911 ThreadsSMRSupport::print_info_on(this, st);
912 }
913
914 void Thread::print_value_on(outputStream* st) const {
915 if (is_Named_thread()) {
916 st->print(" \"%s\" ", name());
917 }
918 st->print(INTPTR_FORMAT, p2i(this)); // print address
919 }
920
921 #ifdef ASSERT
922 void Thread::print_owned_locks_on(outputStream* st) const {
923 Monitor *cur = _owned_locks;
924 if (cur == NULL) {
925 st->print(" (no locks) ");
926 } else {
927 st->print_cr(" Locks owned:");
928 while (cur) {
929 cur->print_on(st);
930 cur = cur->next();
931 }
2951 st->print("%s", get_thread_name_string(buf, buflen));
2952 }
2953
2954 // Called by fatal error handler. The difference between this and
2955 // JavaThread::print() is that we can't grab lock or allocate memory.
2956 void JavaThread::print_on_error(outputStream* st, char *buf, int buflen) const {
2957 st->print("JavaThread \"%s\"", get_thread_name_string(buf, buflen));
2958 oop thread_obj = threadObj();
2959 if (thread_obj != NULL) {
2960 if (java_lang_Thread::is_daemon(thread_obj)) st->print(" daemon");
2961 }
2962 st->print(" [");
2963 st->print("%s", _get_thread_state_name(_thread_state));
2964 if (osthread()) {
2965 st->print(", id=%d", osthread()->thread_id());
2966 }
2967 st->print(", stack(" PTR_FORMAT "," PTR_FORMAT ")",
2968 p2i(stack_end()), p2i(stack_base()));
2969 st->print("]");
2970
2971 ThreadsSMRSupport::print_info_on(this, st);
2972 return;
2973 }
2974
2975 // Verification
2976
2977 static void frame_verify(frame* f, const RegisterMap *map) { f->verify(map); }
2978
2979 void JavaThread::verify() {
2980 // Verify oops in the thread.
2981 oops_do(&VerifyOopClosure::verify_oop, NULL);
2982
2983 // Verify the stack frames.
2984 frames_do(frame_verify);
2985 }
2986
2987 // CR 6300358 (sub-CR 2137150)
2988 // Most callers of this method assume that it can't return NULL but a
2989 // thread may not have a name whilst it is in the process of attaching to
2990 // the VM - see CR 6412693, and there are places where a JavaThread can be
2991 // seen prior to having it's threadObj set (eg JNI attaching threads and
|