< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page
rev 48401 : 8194482: Fix SIGSEGV in print_threads_compiling.


2929   if (has_last_Java_frame()) {
2930     // Traverse the execution stack
2931     for (StackFrameStream fst(this); !fst.is_done(); fst.next()) {
2932       fst.current()->nmethods_do(cf);
2933     }
2934   }
2935 }
2936 
2937 void JavaThread::metadata_do(void f(Metadata*)) {
2938   if (has_last_Java_frame()) {
2939     // Traverse the execution stack to call f() on the methods in the stack
2940     for (StackFrameStream fst(this); !fst.is_done(); fst.next()) {
2941       fst.current()->metadata_do(f);
2942     }
2943   } else if (is_Compiler_thread()) {
2944     // need to walk ciMetadata in current compile tasks to keep alive.
2945     CompilerThread* ct = (CompilerThread*)this;
2946     if (ct->env() != NULL) {
2947       ct->env()->metadata_do(f);
2948     }
2949     if (ct->task() != NULL) {
2950       ct->task()->metadata_do(f);

2951     }
2952   }
2953 }
2954 
2955 // Printing
2956 const char* _get_thread_state_name(JavaThreadState _thread_state) {
2957   switch (_thread_state) {
2958   case _thread_uninitialized:     return "_thread_uninitialized";
2959   case _thread_new:               return "_thread_new";
2960   case _thread_new_trans:         return "_thread_new_trans";
2961   case _thread_in_native:         return "_thread_in_native";
2962   case _thread_in_native_trans:   return "_thread_in_native_trans";
2963   case _thread_in_vm:             return "_thread_in_vm";
2964   case _thread_in_vm_trans:       return "_thread_in_vm_trans";
2965   case _thread_in_Java:           return "_thread_in_Java";
2966   case _thread_in_Java_trans:     return "_thread_in_Java_trans";
2967   case _thread_blocked:           return "_thread_blocked";
2968   case _thread_blocked_trans:     return "_thread_blocked_trans";
2969   default:                        return "unknown thread state";
2970   }


2984   st->print_raw("\"");
2985   st->print_raw(get_thread_name());
2986   st->print_raw("\" ");
2987   oop thread_oop = threadObj();
2988   if (thread_oop != NULL) {
2989     st->print("#" INT64_FORMAT " ", (int64_t)java_lang_Thread::thread_id(thread_oop));
2990     if (java_lang_Thread::is_daemon(thread_oop))  st->print("daemon ");
2991     st->print("prio=%d ", java_lang_Thread::priority(thread_oop));
2992   }
2993   Thread::print_on(st);
2994   // print guess for valid stack memory region (assume 4K pages); helps lock debugging
2995   st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
2996   if (thread_oop != NULL) {
2997     st->print_cr("   java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
2998   }
2999 #ifndef PRODUCT
3000   print_thread_state_on(st);
3001   _safepoint_state->print_on(st);
3002 #endif // PRODUCT
3003   if (is_Compiler_thread()) {
3004     CompilerThread* ct = (CompilerThread*)this;
3005     if (ct->task() != NULL) {
3006       st->print("   Compiling: ");
3007       ct->task()->print(st, NULL, true, false);
3008     } else {
3009       st->print("   No compile task");
3010     }
3011     st->cr();
3012   }
3013 }
3014 
3015 void JavaThread::print_name_on_error(outputStream* st, char *buf, int buflen) const {
3016   st->print("%s", get_thread_name_string(buf, buflen));
3017 }
3018 
3019 // Called by fatal error handler. The difference between this and
3020 // JavaThread::print() is that we can't grab lock or allocate memory.
3021 void JavaThread::print_on_error(outputStream* st, char *buf, int buflen) const {
3022   st->print("JavaThread \"%s\"", get_thread_name_string(buf, buflen));
3023   oop thread_obj = threadObj();
3024   if (thread_obj != NULL) {
3025     if (java_lang_Thread::is_daemon(thread_obj)) st->print(" daemon");
3026   }
3027   st->print(" [");


4695 
4696   PrintOnErrorClosure print_closure(st, current, buf, buflen, &found_current);
4697   Universe::heap()->gc_threads_do(&print_closure);
4698 
4699   if (!found_current) {
4700     st->cr();
4701     st->print("=>" PTR_FORMAT " (exited) ", p2i(current));
4702     current->print_on_error(st, buf, buflen);
4703     st->cr();
4704   }
4705   st->cr();
4706 
4707   st->print_cr("Threads with active compile tasks:");
4708   print_threads_compiling(st, buf, buflen);
4709 }
4710 
4711 void Threads::print_threads_compiling(outputStream* st, char* buf, int buflen) {
4712   ALL_JAVA_THREADS(thread) {
4713     if (thread->is_Compiler_thread()) {
4714       CompilerThread* ct = (CompilerThread*) thread;
4715       if (ct->task() != NULL) {






4716         thread->print_name_on_error(st, buf, buflen);
4717         ct->task()->print(st, NULL, true, true);
4718       }
4719     }
4720   }
4721 }
4722 
4723 
4724 // Internal SpinLock and Mutex
4725 // Based on ParkEvent
4726 
4727 // Ad-hoc mutual exclusion primitives: SpinLock and Mux
4728 //
4729 // We employ SpinLocks _only for low-contention, fixed-length
4730 // short-duration critical sections where we're concerned
4731 // about native mutex_t or HotSpot Mutex:: latency.
4732 // The mux construct provides a spin-then-block mutual exclusion
4733 // mechanism.
4734 //
4735 // Testing has shown that contention on the ListLock guarding gFreeList
4736 // is common.  If we implement ListLock as a simple SpinLock it's common
4737 // for the JVM to devolve to yielding with little progress.  This is true




2929   if (has_last_Java_frame()) {
2930     // Traverse the execution stack
2931     for (StackFrameStream fst(this); !fst.is_done(); fst.next()) {
2932       fst.current()->nmethods_do(cf);
2933     }
2934   }
2935 }
2936 
2937 void JavaThread::metadata_do(void f(Metadata*)) {
2938   if (has_last_Java_frame()) {
2939     // Traverse the execution stack to call f() on the methods in the stack
2940     for (StackFrameStream fst(this); !fst.is_done(); fst.next()) {
2941       fst.current()->metadata_do(f);
2942     }
2943   } else if (is_Compiler_thread()) {
2944     // need to walk ciMetadata in current compile tasks to keep alive.
2945     CompilerThread* ct = (CompilerThread*)this;
2946     if (ct->env() != NULL) {
2947       ct->env()->metadata_do(f);
2948     }
2949     CompileTask* task = ct->task();
2950     if (task != NULL) {
2951       task->metadata_do(f);
2952     }
2953   }
2954 }
2955 
2956 // Printing
2957 const char* _get_thread_state_name(JavaThreadState _thread_state) {
2958   switch (_thread_state) {
2959   case _thread_uninitialized:     return "_thread_uninitialized";
2960   case _thread_new:               return "_thread_new";
2961   case _thread_new_trans:         return "_thread_new_trans";
2962   case _thread_in_native:         return "_thread_in_native";
2963   case _thread_in_native_trans:   return "_thread_in_native_trans";
2964   case _thread_in_vm:             return "_thread_in_vm";
2965   case _thread_in_vm_trans:       return "_thread_in_vm_trans";
2966   case _thread_in_Java:           return "_thread_in_Java";
2967   case _thread_in_Java_trans:     return "_thread_in_Java_trans";
2968   case _thread_blocked:           return "_thread_blocked";
2969   case _thread_blocked_trans:     return "_thread_blocked_trans";
2970   default:                        return "unknown thread state";
2971   }


2985   st->print_raw("\"");
2986   st->print_raw(get_thread_name());
2987   st->print_raw("\" ");
2988   oop thread_oop = threadObj();
2989   if (thread_oop != NULL) {
2990     st->print("#" INT64_FORMAT " ", (int64_t)java_lang_Thread::thread_id(thread_oop));
2991     if (java_lang_Thread::is_daemon(thread_oop))  st->print("daemon ");
2992     st->print("prio=%d ", java_lang_Thread::priority(thread_oop));
2993   }
2994   Thread::print_on(st);
2995   // print guess for valid stack memory region (assume 4K pages); helps lock debugging
2996   st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
2997   if (thread_oop != NULL) {
2998     st->print_cr("   java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
2999   }
3000 #ifndef PRODUCT
3001   print_thread_state_on(st);
3002   _safepoint_state->print_on(st);
3003 #endif // PRODUCT
3004   if (is_Compiler_thread()) {
3005     CompileTask *task = ((CompilerThread*)this)->task();
3006     if (task != NULL) {
3007       st->print("   Compiling: ");
3008       task->print(st, NULL, true, false);
3009     } else {
3010       st->print("   No compile task");
3011     }
3012     st->cr();
3013   }
3014 }
3015 
3016 void JavaThread::print_name_on_error(outputStream* st, char *buf, int buflen) const {
3017   st->print("%s", get_thread_name_string(buf, buflen));
3018 }
3019 
3020 // Called by fatal error handler. The difference between this and
3021 // JavaThread::print() is that we can't grab lock or allocate memory.
3022 void JavaThread::print_on_error(outputStream* st, char *buf, int buflen) const {
3023   st->print("JavaThread \"%s\"", get_thread_name_string(buf, buflen));
3024   oop thread_obj = threadObj();
3025   if (thread_obj != NULL) {
3026     if (java_lang_Thread::is_daemon(thread_obj)) st->print(" daemon");
3027   }
3028   st->print(" [");


4696 
4697   PrintOnErrorClosure print_closure(st, current, buf, buflen, &found_current);
4698   Universe::heap()->gc_threads_do(&print_closure);
4699 
4700   if (!found_current) {
4701     st->cr();
4702     st->print("=>" PTR_FORMAT " (exited) ", p2i(current));
4703     current->print_on_error(st, buf, buflen);
4704     st->cr();
4705   }
4706   st->cr();
4707 
4708   st->print_cr("Threads with active compile tasks:");
4709   print_threads_compiling(st, buf, buflen);
4710 }
4711 
4712 void Threads::print_threads_compiling(outputStream* st, char* buf, int buflen) {
4713   ALL_JAVA_THREADS(thread) {
4714     if (thread->is_Compiler_thread()) {
4715       CompilerThread* ct = (CompilerThread*) thread;
4716 
4717       // Keep task in local variable for NULL check.
4718       // ct->_task might be set to NULL by concurring compiler thread
4719       // because it completed the compilation. The task is never freed,
4720       // though, just returned to a free list.
4721       CompileTask* task = ct->task();
4722       if (task != NULL) {
4723         thread->print_name_on_error(st, buf, buflen);
4724         task->print(st, NULL, true, true);
4725       }
4726     }
4727   }
4728 }
4729 
4730 
4731 // Internal SpinLock and Mutex
4732 // Based on ParkEvent
4733 
4734 // Ad-hoc mutual exclusion primitives: SpinLock and Mux
4735 //
4736 // We employ SpinLocks _only for low-contention, fixed-length
4737 // short-duration critical sections where we're concerned
4738 // about native mutex_t or HotSpot Mutex:: latency.
4739 // The mux construct provides a spin-then-block mutual exclusion
4740 // mechanism.
4741 //
4742 // Testing has shown that contention on the ListLock guarding gFreeList
4743 // is common.  If we implement ListLock as a simple SpinLock it's common
4744 // for the JVM to devolve to yielding with little progress.  This is true


< prev index next >