417 // processors with hyperthreading technology. |
417 // processors with hyperthreading technology. |
418 static int counter = 0; |
418 static int counter = 0; |
419 int pid = os::current_process_id(); |
419 int pid = os::current_process_id(); |
420 _alloca(((pid ^ counter++) & 7) * 128); |
420 _alloca(((pid ^ counter++) & 7) * 128); |
421 |
421 |
|
422 thread->initialize_thread_current(); |
|
423 |
422 OSThread* osthr = thread->osthread(); |
424 OSThread* osthr = thread->osthread(); |
423 assert(osthr->get_state() == RUNNABLE, "invalid os thread state"); |
425 assert(osthr->get_state() == RUNNABLE, "invalid os thread state"); |
424 |
426 |
425 if (UseNUMA) { |
427 if (UseNUMA) { |
426 int lgrp_id = os::numa_get_group_id(); |
428 int lgrp_id = os::numa_get_group_id(); |
2144 |
2146 |
2145 // Implicit OS exception handling |
2147 // Implicit OS exception handling |
2146 |
2148 |
2147 LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo, |
2149 LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo, |
2148 address handler) { |
2150 address handler) { |
2149 JavaThread* thread = JavaThread::current(); |
2151 JavaThread* thread = (JavaThread*) Thread::current_or_null(); |
2150 // Save pc in thread |
2152 // Save pc in thread |
2151 #ifdef _M_IA64 |
2153 #ifdef _M_IA64 |
2152 // Do not blow up if no thread info available. |
2154 // Do not blow up if no thread info available. |
2153 if (thread) { |
2155 if (thread) { |
2154 // Saving PRECISE pc (with slot information) in thread. |
2156 // Saving PRECISE pc (with slot information) in thread. |
2382 address pc = (address) exceptionInfo->ContextRecord->Rip; |
2384 address pc = (address) exceptionInfo->ContextRecord->Rip; |
2383 #else |
2385 #else |
2384 address pc = (address) exceptionInfo->ContextRecord->Eip; |
2386 address pc = (address) exceptionInfo->ContextRecord->Eip; |
2385 #endif |
2387 #endif |
2386 #endif |
2388 #endif |
2387 Thread* t = ThreadLocalStorage::get_thread_slow(); // slow & steady |
2389 Thread* t = Thread::current_or_null_safe(); |
2388 |
2390 |
2389 // Handle SafeFetch32 and SafeFetchN exceptions. |
2391 // Handle SafeFetch32 and SafeFetchN exceptions. |
2390 if (StubRoutines::is_safefetch_fault(pc)) { |
2392 if (StubRoutines::is_safefetch_fault(pc)) { |
2391 return Handle_Exception(exceptionInfo, StubRoutines::continuation_for_safefetch_fault(pc)); |
2393 return Handle_Exception(exceptionInfo, StubRoutines::continuation_for_safefetch_fault(pc)); |
2392 } |
2394 } |
4009 int result = MessageBox(NULL, message, title, |
4011 int result = MessageBox(NULL, message, title, |
4010 MB_YESNO | MB_ICONERROR | MB_SYSTEMMODAL | MB_DEFAULT_DESKTOP_ONLY); |
4012 MB_YESNO | MB_ICONERROR | MB_SYSTEMMODAL | MB_DEFAULT_DESKTOP_ONLY); |
4011 return result == IDYES; |
4013 return result == IDYES; |
4012 } |
4014 } |
4013 |
4015 |
4014 int os::allocate_thread_local_storage() { |
|
4015 return TlsAlloc(); |
|
4016 } |
|
4017 |
|
4018 |
|
4019 void os::free_thread_local_storage(int index) { |
|
4020 TlsFree(index); |
|
4021 } |
|
4022 |
|
4023 |
|
4024 void os::thread_local_storage_at_put(int index, void* value) { |
|
4025 TlsSetValue(index, value); |
|
4026 assert(thread_local_storage_at(index) == value, "Just checking"); |
|
4027 } |
|
4028 |
|
4029 |
|
4030 void* os::thread_local_storage_at(int index) { |
|
4031 return TlsGetValue(index); |
|
4032 } |
|
4033 |
|
4034 |
|
4035 #ifndef PRODUCT |
4016 #ifndef PRODUCT |
4036 #ifndef _WIN64 |
4017 #ifndef _WIN64 |
4037 // Helpers to check whether NX protection is enabled |
4018 // Helpers to check whether NX protection is enabled |
4038 int nx_exception_filter(_EXCEPTION_POINTERS *pex) { |
4019 int nx_exception_filter(_EXCEPTION_POINTERS *pex) { |
4039 if (pex->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && |
4020 if (pex->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && |
4077 if (!DuplicateHandle(main_process, GetCurrentThread(), main_process, |
4058 if (!DuplicateHandle(main_process, GetCurrentThread(), main_process, |
4078 &main_thread, THREAD_ALL_ACCESS, false, 0)) { |
4059 &main_thread, THREAD_ALL_ACCESS, false, 0)) { |
4079 fatal("DuplicateHandle failed\n"); |
4060 fatal("DuplicateHandle failed\n"); |
4080 } |
4061 } |
4081 main_thread_id = (int) GetCurrentThreadId(); |
4062 main_thread_id = (int) GetCurrentThreadId(); |
|
4063 |
|
4064 // initialize fast thread access - only used for 32-bit |
|
4065 win32::initialize_thread_ptr_offset(); |
4082 } |
4066 } |
4083 |
4067 |
4084 // To install functions for atexit processing |
4068 // To install functions for atexit processing |
4085 extern "C" { |
4069 extern "C" { |
4086 static void perfMemory_exit_helper() { |
4070 static void perfMemory_exit_helper() { |
5175 if (time == 0) { // Wait for the minimal time unit if zero |
5159 if (time == 0) { // Wait for the minimal time unit if zero |
5176 time = 1; |
5160 time = 1; |
5177 } |
5161 } |
5178 } |
5162 } |
5179 |
5163 |
5180 JavaThread* thread = (JavaThread*)(Thread::current()); |
5164 JavaThread* thread = JavaThread::current(); |
5181 assert(thread->is_Java_thread(), "Must be JavaThread"); |
|
5182 JavaThread *jt = (JavaThread *)thread; |
|
5183 |
5165 |
5184 // Don't wait if interrupted or already triggered |
5166 // Don't wait if interrupted or already triggered |
5185 if (Thread::is_interrupted(thread, false) || |
5167 if (Thread::is_interrupted(thread, false) || |
5186 WaitForSingleObject(_ParkEvent, 0) == WAIT_OBJECT_0) { |
5168 WaitForSingleObject(_ParkEvent, 0) == WAIT_OBJECT_0) { |
5187 ResetEvent(_ParkEvent); |
5169 ResetEvent(_ParkEvent); |
5188 return; |
5170 return; |
5189 } else { |
5171 } else { |
5190 ThreadBlockInVM tbivm(jt); |
5172 ThreadBlockInVM tbivm(thread); |
5191 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */); |
5173 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */); |
5192 jt->set_suspend_equivalent(); |
5174 thread->set_suspend_equivalent(); |
5193 |
5175 |
5194 WaitForSingleObject(_ParkEvent, time); |
5176 WaitForSingleObject(_ParkEvent, time); |
5195 ResetEvent(_ParkEvent); |
5177 ResetEvent(_ParkEvent); |
5196 |
5178 |
5197 // If externally suspended while waiting, re-suspend |
5179 // If externally suspended while waiting, re-suspend |
5198 if (jt->handle_special_suspend_equivalent_condition()) { |
5180 if (thread->handle_special_suspend_equivalent_condition()) { |
5199 jt->java_suspend_self(); |
5181 thread->java_suspend_self(); |
5200 } |
5182 } |
5201 } |
5183 } |
5202 } |
5184 } |
5203 |
5185 |
5204 void Parker::unpark() { |
5186 void Parker::unpark() { |
5297 |
5279 |
5298 LONG WINAPI os::win32::serialize_fault_filter(struct _EXCEPTION_POINTERS* e) { |
5280 LONG WINAPI os::win32::serialize_fault_filter(struct _EXCEPTION_POINTERS* e) { |
5299 DWORD exception_code = e->ExceptionRecord->ExceptionCode; |
5281 DWORD exception_code = e->ExceptionRecord->ExceptionCode; |
5300 |
5282 |
5301 if (exception_code == EXCEPTION_ACCESS_VIOLATION) { |
5283 if (exception_code == EXCEPTION_ACCESS_VIOLATION) { |
5302 JavaThread* thread = (JavaThread*)ThreadLocalStorage::get_thread_slow(); |
5284 JavaThread* thread = JavaThread::current(); |
5303 PEXCEPTION_RECORD exceptionRecord = e->ExceptionRecord; |
5285 PEXCEPTION_RECORD exceptionRecord = e->ExceptionRecord; |
5304 address addr = (address) exceptionRecord->ExceptionInformation[1]; |
5286 address addr = (address) exceptionRecord->ExceptionInformation[1]; |
5305 |
5287 |
5306 if (os::is_memory_serialize_page(thread, addr)) { |
5288 if (os::is_memory_serialize_page(thread, addr)) { |
5307 return EXCEPTION_CONTINUE_EXECUTION; |
5289 return EXCEPTION_CONTINUE_EXECUTION; |
6064 if(!strcmp(name, siglabels[i].name)) |
6046 if(!strcmp(name, siglabels[i].name)) |
6065 return siglabels[i].number; |
6047 return siglabels[i].number; |
6066 return -1; |
6048 return -1; |
6067 } |
6049 } |
6068 |
6050 |
|
6051 // Fast current thread access |
|
6052 |
|
6053 int os::win32::_thread_ptr_offset = 0; |
|
6054 |
|
6055 static void call_wrapper_dummy() {} |
|
6056 |
|
6057 // We need to call the os_exception_wrapper once so that it sets |
|
6058 // up the offset from FS of the thread pointer. |
|
6059 void os::win32::initialize_thread_ptr_offset() { |
|
6060 os::os_exception_wrapper((java_call_t)call_wrapper_dummy, |
|
6061 NULL, NULL, NULL, NULL); |
|
6062 } |