319 // set up any platform-specific state. 320 os::initialize_thread(this); 321 322 // Set stack limits after thread is initialized. 323 if (is_Java_thread()) { 324 ((JavaThread*) this)->set_stack_overflow_limit(); 325 ((JavaThread*) this)->set_reserved_stack_activation(stack_base()); 326 } 327 #if INCLUDE_NMT 328 // record thread's native stack, stack grows downward 329 MemTracker::record_thread_stack(stack_end(), stack_size()); 330 #endif // INCLUDE_NMT 331 log_debug(os, thread)("Thread " UINTX_FORMAT " stack dimensions: " 332 PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT "k).", 333 os::current_thread_id(), p2i(stack_base() - stack_size()), 334 p2i(stack_base()), stack_size()/1024); 335 } 336 337 338 Thread::~Thread() { 339 // Reclaim the objectmonitors from the omFreeList of the moribund thread. 340 ObjectSynchronizer::omFlush(this); 341 342 EVENT_THREAD_DESTRUCT(this); 343 344 // stack_base can be NULL if the thread is never started or exited before 345 // record_stack_base_and_size called. Although, we would like to ensure 346 // that all started threads do call record_stack_base_and_size(), there is 347 // not proper way to enforce that. 348 #if INCLUDE_NMT 349 if (_stack_base != NULL) { 350 MemTracker::release_thread_stack(stack_end(), stack_size()); 351 #ifdef ASSERT 352 set_stack_base(NULL); 353 #endif 354 } 355 #endif // INCLUDE_NMT 356 357 // deallocate data structures 358 delete resource_area(); 359 // since the handle marks are using the handle area, we have to deallocated the root 360 // handle mark before deallocating the thread's handle area, 361 assert(last_handle_mark() != NULL, "check we have an element"); 4234 p->initialize_queues(); 4235 p->set_next(_thread_list); 4236 _thread_list = p; 4237 _number_of_threads++; 4238 oop threadObj = p->threadObj(); 4239 bool daemon = true; 4240 // Bootstrapping problem: threadObj can be null for initial 4241 // JavaThread (or for threads attached via JNI) 4242 if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) { 4243 _number_of_non_daemon_threads++; 4244 daemon = false; 4245 } 4246 4247 ThreadService::add_thread(p, daemon); 4248 4249 // Possible GC point. 4250 Events::log(p, "Thread added: " INTPTR_FORMAT, p2i(p)); 4251 } 4252 4253 void Threads::remove(JavaThread* p) { 4254 // Extra scope needed for Thread_lock, so we can check 4255 // that we do not remove thread without safepoint code notice 4256 { MutexLocker ml(Threads_lock); 4257 4258 assert(includes(p), "p must be present"); 4259 4260 JavaThread* current = _thread_list; 4261 JavaThread* prev = NULL; 4262 4263 while (current != p) { 4264 prev = current; 4265 current = current->next(); 4266 } 4267 4268 if (prev) { 4269 prev->set_next(current->next()); 4270 } else { 4271 _thread_list = p->next(); 4272 } 4273 _number_of_threads--; | 319 // set up any platform-specific state. 320 os::initialize_thread(this); 321 322 // Set stack limits after thread is initialized. 323 if (is_Java_thread()) { 324 ((JavaThread*) this)->set_stack_overflow_limit(); 325 ((JavaThread*) this)->set_reserved_stack_activation(stack_base()); 326 } 327 #if INCLUDE_NMT 328 // record thread's native stack, stack grows downward 329 MemTracker::record_thread_stack(stack_end(), stack_size()); 330 #endif // INCLUDE_NMT 331 log_debug(os, thread)("Thread " UINTX_FORMAT " stack dimensions: " 332 PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT "k).", 333 os::current_thread_id(), p2i(stack_base() - stack_size()), 334 p2i(stack_base()), stack_size()/1024); 335 } 336 337 338 Thread::~Thread() { 339 EVENT_THREAD_DESTRUCT(this); 340 341 // stack_base can be NULL if the thread is never started or exited before 342 // record_stack_base_and_size called. Although, we would like to ensure 343 // that all started threads do call record_stack_base_and_size(), there is 344 // not proper way to enforce that. 345 #if INCLUDE_NMT 346 if (_stack_base != NULL) { 347 MemTracker::release_thread_stack(stack_end(), stack_size()); 348 #ifdef ASSERT 349 set_stack_base(NULL); 350 #endif 351 } 352 #endif // INCLUDE_NMT 353 354 // deallocate data structures 355 delete resource_area(); 356 // since the handle marks are using the handle area, we have to deallocated the root 357 // handle mark before deallocating the thread's handle area, 358 assert(last_handle_mark() != NULL, "check we have an element"); 4231 p->initialize_queues(); 4232 p->set_next(_thread_list); 4233 _thread_list = p; 4234 _number_of_threads++; 4235 oop threadObj = p->threadObj(); 4236 bool daemon = true; 4237 // Bootstrapping problem: threadObj can be null for initial 4238 // JavaThread (or for threads attached via JNI) 4239 if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) { 4240 _number_of_non_daemon_threads++; 4241 daemon = false; 4242 } 4243 4244 ThreadService::add_thread(p, daemon); 4245 4246 // Possible GC point. 4247 Events::log(p, "Thread added: " INTPTR_FORMAT, p2i(p)); 4248 } 4249 4250 void Threads::remove(JavaThread* p) { 4251 4252 // Reclaim the objectmonitors from the omFreeList of the moribund thread. 4253 ObjectSynchronizer::omFlush(p); 4254 4255 // Extra scope needed for Thread_lock, so we can check 4256 // that we do not remove thread without safepoint code notice 4257 { MutexLocker ml(Threads_lock); 4258 4259 assert(includes(p), "p must be present"); 4260 4261 JavaThread* current = _thread_list; 4262 JavaThread* prev = NULL; 4263 4264 while (current != p) { 4265 prev = current; 4266 current = current->next(); 4267 } 4268 4269 if (prev) { 4270 prev->set_next(current->next()); 4271 } else { 4272 _thread_list = p->next(); 4273 } 4274 _number_of_threads--; |