334 * NO LOCK should be taken inside ThreadCritical lock !!! 335 */ 336 void MemTracker::create_memory_record(address addr, MEMFLAGS flags, 337 size_t size, address pc, Thread* thread) { 338 if (!shutdown_in_progress()) { 339 // single thread, we just write records direct to global recorder,' 340 // with any lock 341 if (_state == NMT_bootstrapping_single_thread) { 342 assert(_main_thread_tid == os::current_thread_id(), "wrong thread"); 343 thread = NULL; 344 } else { 345 if (thread == NULL) { 346 // don't use Thread::current(), since it is possible that 347 // the calling thread has yet to attach to VM 'Thread', 348 // which will result assertion failure 349 thread = ThreadLocalStorage::thread(); 350 } 351 } 352 353 if (thread != NULL) { 354 #ifdef ASSERT 355 // cause assertion on stack base. This ensures that threads call 356 // Thread::record_stack_base_and_size() method, which will create 357 // thread native stack records. 358 thread->stack_base(); 359 #endif 360 // for a JavaThread, if it is running in native state, we need to transition it to 361 // VM state, so it can stop at safepoint. JavaThread running in VM state does not 362 // need lock to write records. 363 if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) { 364 if (((JavaThread*)thread)->thread_state() == _thread_in_native) { 365 ThreadInVMfromNative trans((JavaThread*)thread); 366 create_record_in_recorder(addr, flags, size, pc, thread); 367 } else { 368 create_record_in_recorder(addr, flags, size, pc, thread); 369 } 370 } else { 371 // other threads, such as worker and watcher threads, etc. need to 372 // take ThreadCritical to write to global recorder 373 ThreadCritical tc; 374 create_record_in_recorder(addr, flags, size, pc, NULL); 375 } 376 } else { 377 if (_state == NMT_bootstrapping_single_thread) { 378 // single thread, no lock needed 379 create_record_in_recorder(addr, flags, size, pc, NULL); | 334 * NO LOCK should be taken inside ThreadCritical lock !!! 335 */ 336 void MemTracker::create_memory_record(address addr, MEMFLAGS flags, 337 size_t size, address pc, Thread* thread) { 338 if (!shutdown_in_progress()) { 339 // single thread, we just write records direct to global recorder,' 340 // with any lock 341 if (_state == NMT_bootstrapping_single_thread) { 342 assert(_main_thread_tid == os::current_thread_id(), "wrong thread"); 343 thread = NULL; 344 } else { 345 if (thread == NULL) { 346 // don't use Thread::current(), since it is possible that 347 // the calling thread has yet to attach to VM 'Thread', 348 // which will result assertion failure 349 thread = ThreadLocalStorage::thread(); 350 } 351 } 352 353 if (thread != NULL) { 354 // for a JavaThread, if it is running in native state, we need to transition it to 355 // VM state, so it can stop at safepoint. JavaThread running in VM state does not 356 // need lock to write records. 357 if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) { 358 if (((JavaThread*)thread)->thread_state() == _thread_in_native) { 359 ThreadInVMfromNative trans((JavaThread*)thread); 360 create_record_in_recorder(addr, flags, size, pc, thread); 361 } else { 362 create_record_in_recorder(addr, flags, size, pc, thread); 363 } 364 } else { 365 // other threads, such as worker and watcher threads, etc. need to 366 // take ThreadCritical to write to global recorder 367 ThreadCritical tc; 368 create_record_in_recorder(addr, flags, size, pc, NULL); 369 } 370 } else { 371 if (_state == NMT_bootstrapping_single_thread) { 372 // single thread, no lock needed 373 create_record_in_recorder(addr, flags, size, pc, NULL); |