407 return NULL; |
407 return NULL; |
408 } |
408 } |
409 |
409 |
410 LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo); |
410 LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo); |
411 |
411 |
412 // Thread start routine for all new Java threads |
412 // Thread start routine for all newly created threads |
413 static unsigned __stdcall java_start(Thread* thread) { |
413 static unsigned __stdcall thread_native_entry(Thread* thread) { |
414 // Try to randomize the cache line index of hot stack frames. |
414 // Try to randomize the cache line index of hot stack frames. |
415 // This helps when threads of the same stack traces evict each other's |
415 // This helps when threads of the same stack traces evict each other's |
416 // cache lines. The threads can be either from the same JVM instance, or |
416 // cache lines. The threads can be either from the same JVM instance, or |
417 // from different JVM instances. The benefit is especially true for |
417 // from different JVM instances. The benefit is especially true for |
418 // processors with hyperthreading technology. |
418 // processors with hyperthreading technology. |
455 // One less thread is executing |
455 // One less thread is executing |
456 // When the VMThread gets here, the main thread may have already exited |
456 // When the VMThread gets here, the main thread may have already exited |
457 // which frees the CodeHeap containing the Atomic::add code |
457 // which frees the CodeHeap containing the Atomic::add code |
458 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) { |
458 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) { |
459 Atomic::dec_ptr((intptr_t*)&os::win32::_os_thread_count); |
459 Atomic::dec_ptr((intptr_t*)&os::win32::_os_thread_count); |
|
460 } |
|
461 |
|
462 // If a thread has not deleted itself ("delete this") as part of its |
|
463 // termination sequence, we have to ensure thread-local-storage is |
|
464 // cleared before we actually terminate. No threads should ever be |
|
465 // deleted asynchronously with respect to their termination. |
|
466 if (Thread::current_or_null_safe() != NULL) { |
|
467 assert(Thread::current_or_null_safe() == thread, "current thread is wrong"); |
|
468 thread->clear_thread_current(); |
460 } |
469 } |
461 |
470 |
462 // Thread must not return from exit_process_or_thread(), but if it does, |
471 // Thread must not return from exit_process_or_thread(), but if it does, |
463 // let it proceed to exit normally |
472 // let it proceed to exit normally |
464 return (unsigned)os::win32::exit_process_or_thread(os::win32::EPT_THREAD, res); |
473 return (unsigned)os::win32::exit_process_or_thread(os::win32::EPT_THREAD, res); |
629 |
638 |
630 const unsigned initflag = CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION; |
639 const unsigned initflag = CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION; |
631 HANDLE thread_handle = |
640 HANDLE thread_handle = |
632 (HANDLE)_beginthreadex(NULL, |
641 (HANDLE)_beginthreadex(NULL, |
633 (unsigned)stack_size, |
642 (unsigned)stack_size, |
634 (unsigned (__stdcall *)(void*)) java_start, |
643 (unsigned (__stdcall *)(void*)) thread_native_entry, |
635 thread, |
644 thread, |
636 initflag, |
645 initflag, |
637 &thread_id); |
646 &thread_id); |
638 |
647 |
639 char buf[64]; |
648 char buf[64]; |
668 |
677 |
669 |
678 |
670 // Free Win32 resources related to the OSThread |
679 // Free Win32 resources related to the OSThread |
671 void os::free_thread(OSThread* osthread) { |
680 void os::free_thread(OSThread* osthread) { |
672 assert(osthread != NULL, "osthread not set"); |
681 assert(osthread != NULL, "osthread not set"); |
|
682 |
|
683 // We are told to free resources of the argument thread, |
|
684 // but we can only really operate on the current thread. |
|
685 assert(Thread::current()->osthread() == osthread, |
|
686 "os::free_thread but not current thread"); |
|
687 |
673 CloseHandle(osthread->thread_handle()); |
688 CloseHandle(osthread->thread_handle()); |
674 CloseHandle(osthread->interrupt_event()); |
689 CloseHandle(osthread->interrupt_event()); |
675 delete osthread; |
690 delete osthread; |
676 } |
691 } |
677 |
692 |