220
221
222 Thread::Thread() {
223 // stack and get_thread
224 set_stack_base(NULL);
225 set_stack_size(0);
226 set_self_raw_id(0);
227 set_lgrp_id(-1);
228 DEBUG_ONLY(clear_suspendible_thread();)
229
230 // allocated data structures
231 set_osthread(NULL);
232 set_resource_area(new (mtThread)ResourceArea());
233 DEBUG_ONLY(_current_resource_mark = NULL;)
234 set_handle_area(new (mtThread) HandleArea(NULL));
235 set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true));
236 set_active_handles(NULL);
237 set_free_handle_block(NULL);
238 set_last_handle_mark(NULL);
239
240 // This initial value ==> never claimed.
241 _oops_do_parity = 0;
242 _threads_hazard_ptr = NULL;
243 _threads_list_ptr = NULL;
244 _nested_threads_hazard_ptr_cnt = 0;
245 _rcu_counter = 0;
246
247 // the handle mark links itself to last_handle_mark
248 new HandleMark(this);
249
250 // plain initialization
251 debug_only(_owned_locks = NULL;)
252 debug_only(_allow_allocation_count = 0;)
253 NOT_PRODUCT(_allow_safepoint_count = 0;)
254 NOT_PRODUCT(_skip_gcalot = false;)
255 _jvmti_env_iteration_count = 0;
256 set_allocated_bytes(0);
257 _vm_operation_started_count = 0;
258 _vm_operation_completed_count = 0;
259 _current_pending_monitor = NULL;
859 ObjectSynchronizer::thread_local_used_oops_do(this, f);
860 }
861 }
862
863 void Thread::metadata_handles_do(void f(Metadata*)) {
864 // Only walk the Handles in Thread.
865 if (metadata_handles() != NULL) {
866 for (int i = 0; i< metadata_handles()->length(); i++) {
867 f(metadata_handles()->at(i));
868 }
869 }
870 }
871
872 void Thread::print_on(outputStream* st) const {
873 // get_priority assumes osthread initialized
874 if (osthread() != NULL) {
875 int os_prio;
876 if (os::get_native_priority(this, &os_prio) == OS_OK) {
877 st->print("os_prio=%d ", os_prio);
878 }
879 st->print("tid=" INTPTR_FORMAT " ", p2i(this));
880 osthread()->print_on(st);
881 }
882 ThreadsSMRSupport::print_info_on(this, st);
883 st->print(" ");
884 debug_only(if (WizardMode) print_owned_locks_on(st);)
885 }
886
887 // Thread::print_on_error() is called by fatal error handler. Don't use
888 // any lock or allocate memory.
889 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
890 assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
891
892 if (is_VM_thread()) { st->print("VMThread"); }
893 else if (is_GC_task_thread()) { st->print("GCTaskThread"); }
894 else if (is_Watcher_thread()) { st->print("WatcherThread"); }
895 else if (is_ConcurrentGC_thread()) { st->print("ConcurrentGCThread"); }
896 else { st->print("Thread"); }
897
898 if (is_Named_thread()) {
|
220
221
222 Thread::Thread() {
223 // stack and get_thread
224 set_stack_base(NULL);
225 set_stack_size(0);
226 set_self_raw_id(0);
227 set_lgrp_id(-1);
228 DEBUG_ONLY(clear_suspendible_thread();)
229
230 // allocated data structures
231 set_osthread(NULL);
232 set_resource_area(new (mtThread)ResourceArea());
233 DEBUG_ONLY(_current_resource_mark = NULL;)
234 set_handle_area(new (mtThread) HandleArea(NULL));
235 set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true));
236 set_active_handles(NULL);
237 set_free_handle_block(NULL);
238 set_last_handle_mark(NULL);
239
240 _statistic_info.setStartTime(os::javaTimeMillis());
241 _statistic_info.setDefineClassCount(0);
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;
862 ObjectSynchronizer::thread_local_used_oops_do(this, f);
863 }
864 }
865
866 void Thread::metadata_handles_do(void f(Metadata*)) {
867 // Only walk the Handles in Thread.
868 if (metadata_handles() != NULL) {
869 for (int i = 0; i< metadata_handles()->length(); i++) {
870 f(metadata_handles()->at(i));
871 }
872 }
873 }
874
875 void Thread::print_on(outputStream* st) const {
876 // get_priority assumes osthread initialized
877 if (osthread() != NULL) {
878 int os_prio;
879 if (os::get_native_priority(this, &os_prio) == OS_OK) {
880 st->print("os_prio=%d ", os_prio);
881 }
882
883 if (PrintExtendedThreadInfo && os::is_thread_cpu_time_supported()) {
884 st->print("cpu=%.2fms ",
885 os::thread_cpu_time(const_cast<Thread*>(this), true) / 1000000.0
886 );
887 st->print("elapsed=%.2fs ",
888 _statistic_info.getElepsedTime() / 1000.0);
889 }
890
891 if (PrintExtendedThreadInfo && is_Java_thread()) {
892 jlong allocated_bytes = const_cast<Thread*>(this)->cooked_allocated_bytes();
893 st->print("allocated=" JLONG_FORMAT "B ", allocated_bytes);
894 st->print("defined_classes=" INT64_FORMAT " ", _statistic_info.getDefineClassCount());
895 }
896
897 st->print("tid=" INTPTR_FORMAT " ", p2i(this));
898 osthread()->print_on(st);
899 }
900 ThreadsSMRSupport::print_info_on(this, st);
901 st->print(" ");
902 debug_only(if (WizardMode) print_owned_locks_on(st);)
903 }
904
905 // Thread::print_on_error() is called by fatal error handler. Don't use
906 // any lock or allocate memory.
907 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
908 assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
909
910 if (is_VM_thread()) { st->print("VMThread"); }
911 else if (is_GC_task_thread()) { st->print("GCTaskThread"); }
912 else if (is_Watcher_thread()) { st->print("WatcherThread"); }
913 else if (is_ConcurrentGC_thread()) { st->print("ConcurrentGCThread"); }
914 else { st->print("Thread"); }
915
916 if (is_Named_thread()) {
|