< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page




  97 // for enumerating dll libraries
  98 #include <vdmdbg.h>
  99 
 100 // for timer info max values which include all bits
 101 #define ALL_64_BITS CONST64(-1)
 102 
 103 // For DLL loading/load error detection
 104 // Values of PE COFF
 105 #define IMAGE_FILE_PTR_TO_SIGNATURE 0x3c
 106 #define IMAGE_FILE_SIGNATURE_LENGTH 4
 107 
 108 static HANDLE main_process;
 109 static HANDLE main_thread;
 110 static int    main_thread_id;
 111 
 112 static FILETIME process_creation_time;
 113 static FILETIME process_exit_time;
 114 static FILETIME process_user_time;
 115 static FILETIME process_kernel_time;
 116 
 117 #ifdef _M_IA64
 118   #define __CPU__ ia64
 119 #else
 120   #ifdef _M_AMD64
 121     #define __CPU__ amd64
 122   #else
 123     #define __CPU__ i486
 124   #endif
 125 #endif
 126 
 127 // save DLL module handle, used by GetModuleFileName
 128 
 129 HINSTANCE vm_lib_handle;
 130 
 131 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
 132   switch (reason) {
 133   case DLL_PROCESS_ATTACH:
 134     vm_lib_handle = hinst;
 135     if (ForceTimeHighResolution) {
 136       timeBeginPeriod(1L);
 137     }
 138     break;
 139   case DLL_PROCESS_DETACH:
 140     if (ForceTimeHighResolution) {
 141       timeEndPeriod(1L);
 142     }
 143     break;
 144   default:


 334 
 335 address os::current_stack_base() {
 336   MEMORY_BASIC_INFORMATION minfo;
 337   address stack_bottom;
 338   size_t stack_size;
 339 
 340   VirtualQuery(&minfo, &minfo, sizeof(minfo));
 341   stack_bottom =  (address)minfo.AllocationBase;
 342   stack_size = minfo.RegionSize;
 343 
 344   // Add up the sizes of all the regions with the same
 345   // AllocationBase.
 346   while (1) {
 347     VirtualQuery(stack_bottom+stack_size, &minfo, sizeof(minfo));
 348     if (stack_bottom == (address)minfo.AllocationBase) {
 349       stack_size += minfo.RegionSize;
 350     } else {
 351       break;
 352     }
 353   }
 354 
 355 #ifdef _M_IA64
 356   // IA64 has memory and register stacks
 357   //
 358   // This is the stack layout you get on NT/IA64 if you specify 1MB stack limit
 359   // at thread creation (1MB backing store growing upwards, 1MB memory stack
 360   // growing downwards, 2MB summed up)
 361   //
 362   // ...
 363   // ------- top of stack (high address) -----
 364   // |
 365   // |      1MB
 366   // |      Backing Store (Register Stack)
 367   // |
 368   // |         / \
 369   // |          |
 370   // |          |
 371   // |          |
 372   // ------------------------ stack base -----
 373   // |      1MB
 374   // |      Memory Stack
 375   // |
 376   // |          |
 377   // |          |
 378   // |          |
 379   // |         \ /
 380   // |
 381   // ----- bottom of stack (low address) -----
 382   // ...
 383 
 384   stack_size = stack_size / 2;
 385 #endif
 386   return stack_bottom + stack_size;
 387 }
 388 
 389 size_t os::current_stack_size() {
 390   size_t sz;
 391   MEMORY_BASIC_INFORMATION minfo;
 392   VirtualQuery(&minfo, &minfo, sizeof(minfo));
 393   sz = (size_t)os::current_stack_base() - (size_t)minfo.AllocationBase;
 394   return sz;
 395 }
 396 
 397 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
 398   const struct tm* time_struct_ptr = localtime(clock);
 399   if (time_struct_ptr != NULL) {
 400     *res = *time_struct_ptr;
 401     return res;
 402   }
 403   return NULL;
 404 }
 405 


1483      // that dll was built for
1484      (sizeof(lib_arch) != (os::read(fd, (void*)&lib_arch, sizeof(lib_arch))))
1485     );
1486 
1487   ::close(fd);
1488   if (failed_to_get_lib_arch) {
1489     // file i/o error - report os::lasterror(...) msg
1490     return NULL;
1491   }
1492 
1493   typedef struct {
1494     uint16_t arch_code;
1495     char* arch_name;
1496   } arch_t;
1497 
1498   static const arch_t arch_array[] = {
1499     {IMAGE_FILE_MACHINE_I386,      (char*)"IA 32"},
1500     {IMAGE_FILE_MACHINE_AMD64,     (char*)"AMD 64"},
1501     {IMAGE_FILE_MACHINE_IA64,      (char*)"IA 64"}
1502   };
1503 #if   (defined _M_IA64)
1504   static const uint16_t running_arch = IMAGE_FILE_MACHINE_IA64;
1505 #elif (defined _M_AMD64)
1506   static const uint16_t running_arch = IMAGE_FILE_MACHINE_AMD64;
1507 #elif (defined _M_IX86)
1508   static const uint16_t running_arch = IMAGE_FILE_MACHINE_I386;
1509 #else
1510   #error Method os::dll_load requires that one of following \
1511          is defined :_M_IA64,_M_AMD64 or _M_IX86
1512 #endif
1513 
1514 
1515   // Obtain a string for printf operation
1516   // lib_arch_str shall contain string what platform this .dll was built for
1517   // running_arch_str shall string contain what platform Hotspot was built for
1518   char *running_arch_str = NULL, *lib_arch_str = NULL;
1519   for (unsigned int i = 0; i < ARRAY_SIZE(arch_array); i++) {
1520     if (lib_arch == arch_array[i].arch_code) {
1521       lib_arch_str = arch_array[i].arch_name;
1522     }
1523     if (running_arch == arch_array[i].arch_code) {
1524       running_arch_str = arch_array[i].arch_name;
1525     }
1526   }
1527 
1528   assert(running_arch_str,
1529          "Didn't find running architecture code in arch_array");
1530 
1531   // If the architecture is right


2144         thread->java_suspend_self();
2145       }
2146     } while (threadIsSuspended);
2147   }
2148 }
2149 
2150 int os::signal_lookup() {
2151   return check_pending_signals(false);
2152 }
2153 
2154 int os::signal_wait() {
2155   return check_pending_signals(true);
2156 }
2157 
2158 // Implicit OS exception handling
2159 
2160 LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo,
2161                       address handler) {
2162     JavaThread* thread = (JavaThread*) Thread::current_or_null();
2163   // Save pc in thread
2164 #ifdef _M_IA64
2165   // Do not blow up if no thread info available.
2166   if (thread) {
2167     // Saving PRECISE pc (with slot information) in thread.
2168     uint64_t precise_pc = (uint64_t) exceptionInfo->ExceptionRecord->ExceptionAddress;
2169     // Convert precise PC into "Unix" format
2170     precise_pc = (precise_pc & 0xFFFFFFFFFFFFFFF0) | ((precise_pc & 0xF) >> 2);
2171     thread->set_saved_exception_pc((address)precise_pc);
2172   }
2173   // Set pc to handler
2174   exceptionInfo->ContextRecord->StIIP = (DWORD64)handler;
2175   // Clear out psr.ri (= Restart Instruction) in order to continue
2176   // at the beginning of the target bundle.
2177   exceptionInfo->ContextRecord->StIPSR &= 0xFFFFF9FFFFFFFFFF;
2178   assert(((DWORD64)handler & 0xF) == 0, "Target address must point to the beginning of a bundle!");
2179 #else
2180   #ifdef _M_AMD64
2181   // Do not blow up if no thread info available.
2182   if (thread) {
2183     thread->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Rip);
2184   }
2185   // Set pc to handler
2186   exceptionInfo->ContextRecord->Rip = (DWORD64)handler;
2187   #else
2188   // Do not blow up if no thread info available.
2189   if (thread) {
2190     thread->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Eip);
2191   }
2192   // Set pc to handler
2193   exceptionInfo->ContextRecord->Eip = (DWORD)(DWORD_PTR)handler;
2194   #endif
2195 #endif
2196 
2197   // Continue the execution
2198   return EXCEPTION_CONTINUE_EXECUTION;
2199 }
2200 
2201 
2202 // Used for PostMortemDump
2203 extern "C" void safepoints();
2204 extern "C" void find(int x);
2205 extern "C" void events();
2206 
2207 // According to Windows API documentation, an illegal instruction sequence should generate
2208 // the 0xC000001C exception code. However, real world experience shows that occasionnaly
2209 // the execution of an illegal instruction can generate the exception code 0xC000001E. This
2210 // seems to be an undocumented feature of Win NT 4.0 (and probably other Windows systems).
2211 
2212 #define EXCEPTION_ILLEGAL_INSTRUCTION_2 0xC000001E
2213 
2214 // From "Execution Protection in the Windows Operating System" draft 0.35
2215 // Once a system header becomes available, the "real" define should be
2216 // included or copied here.
2217 #define EXCEPTION_INFO_EXEC_VIOLATION 0x08
2218 
2219 // Handle NAT Bit consumption on IA64.
2220 #ifdef _M_IA64
2221   #define EXCEPTION_REG_NAT_CONSUMPTION    STATUS_REG_NAT_CONSUMPTION
2222 #endif
2223 
2224 // Windows Vista/2008 heap corruption check
2225 #define EXCEPTION_HEAP_CORRUPTION        0xC0000374
2226 
2227 // All Visual C++ exceptions thrown from code generated by the Microsoft Visual
2228 // C++ compiler contain this error code. Because this is a compiler-generated
2229 // error, the code is not listed in the Win32 API header files.
2230 // The code is actually a cryptic mnemonic device, with the initial "E"
2231 // standing for "exception" and the final 3 bytes (0x6D7363) representing the
2232 // ASCII values of "msc".
2233 
2234 #define EXCEPTION_UNCAUGHT_CXX_EXCEPTION    0xE06D7363
2235 
2236 #define def_excpt(val) { #val, (val) }
2237 
2238 static const struct { char* name; uint number; } exceptlabels[] = {
2239     def_excpt(EXCEPTION_ACCESS_VIOLATION),
2240     def_excpt(EXCEPTION_DATATYPE_MISALIGNMENT),
2241     def_excpt(EXCEPTION_BREAKPOINT),
2242     def_excpt(EXCEPTION_SINGLE_STEP),
2243     def_excpt(EXCEPTION_ARRAY_BOUNDS_EXCEEDED),
2244     def_excpt(EXCEPTION_FLT_DENORMAL_OPERAND),
2245     def_excpt(EXCEPTION_FLT_DIVIDE_BY_ZERO),
2246     def_excpt(EXCEPTION_FLT_INEXACT_RESULT),
2247     def_excpt(EXCEPTION_FLT_INVALID_OPERATION),
2248     def_excpt(EXCEPTION_FLT_OVERFLOW),
2249     def_excpt(EXCEPTION_FLT_STACK_CHECK),
2250     def_excpt(EXCEPTION_FLT_UNDERFLOW),
2251     def_excpt(EXCEPTION_INT_DIVIDE_BY_ZERO),
2252     def_excpt(EXCEPTION_INT_OVERFLOW),
2253     def_excpt(EXCEPTION_PRIV_INSTRUCTION),
2254     def_excpt(EXCEPTION_IN_PAGE_ERROR),
2255     def_excpt(EXCEPTION_ILLEGAL_INSTRUCTION),
2256     def_excpt(EXCEPTION_ILLEGAL_INSTRUCTION_2),
2257     def_excpt(EXCEPTION_NONCONTINUABLE_EXCEPTION),
2258     def_excpt(EXCEPTION_STACK_OVERFLOW),
2259     def_excpt(EXCEPTION_INVALID_DISPOSITION),
2260     def_excpt(EXCEPTION_GUARD_PAGE),
2261     def_excpt(EXCEPTION_INVALID_HANDLE),
2262     def_excpt(EXCEPTION_UNCAUGHT_CXX_EXCEPTION),
2263     def_excpt(EXCEPTION_HEAP_CORRUPTION)
2264 #ifdef _M_IA64
2265     , def_excpt(EXCEPTION_REG_NAT_CONSUMPTION)
2266 #endif
2267 };
2268 
2269 #undef def_excpt
2270 
2271 const char* os::exception_name(int exception_code, char *buf, size_t size) {
2272   uint code = static_cast<uint>(exception_code);
2273   for (uint i = 0; i < ARRAY_SIZE(exceptlabels); ++i) {
2274     if (exceptlabels[i].number == code) {
2275       jio_snprintf(buf, size, "%s", exceptlabels[i].name);
2276       return buf;
2277     }
2278   }
2279 
2280   return NULL;
2281 }
2282 
2283 //-----------------------------------------------------------------------------
2284 LONG Handle_IDiv_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) {
2285   // handle exception caused by idiv; should only happen for -MinInt/-1
2286   // (division by zero is handled explicitly)
2287 #ifdef _M_IA64
2288   assert(0, "Fix Handle_IDiv_Exception");
2289 #else
2290   #ifdef  _M_AMD64
2291   PCONTEXT ctx = exceptionInfo->ContextRecord;
2292   address pc = (address)ctx->Rip;
2293   assert(pc[0] >= Assembler::REX && pc[0] <= Assembler::REX_WRXB && pc[1] == 0xF7 || pc[0] == 0xF7, "not an idiv opcode");
2294   assert(pc[0] >= Assembler::REX && pc[0] <= Assembler::REX_WRXB && (pc[2] & ~0x7) == 0xF8 || (pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands");
2295   if (pc[0] == 0xF7) {
2296     // set correct result values and continue after idiv instruction
2297     ctx->Rip = (DWORD64)pc + 2;        // idiv reg, reg  is 2 bytes
2298   } else {
2299     ctx->Rip = (DWORD64)pc + 3;        // REX idiv reg, reg  is 3 bytes
2300   }
2301   // Do not set ctx->Rax as it already contains the correct value (either 32 or 64 bit, depending on the operation)
2302   // this is the case because the exception only happens for -MinValue/-1 and -MinValue is always in rax because of the
2303   // idiv opcode (0xF7).
2304   ctx->Rdx = (DWORD)0;             // remainder
2305   // Continue the execution
2306   #else
2307   PCONTEXT ctx = exceptionInfo->ContextRecord;
2308   address pc = (address)ctx->Eip;
2309   assert(pc[0] == 0xF7, "not an idiv opcode");
2310   assert((pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands");
2311   assert(ctx->Eax == min_jint, "unexpected idiv exception");
2312   // set correct result values and continue after idiv instruction
2313   ctx->Eip = (DWORD)pc + 2;        // idiv reg, reg  is 2 bytes
2314   ctx->Eax = (DWORD)min_jint;      // result
2315   ctx->Edx = (DWORD)0;             // remainder
2316   // Continue the execution
2317   #endif
2318 #endif
2319   return EXCEPTION_CONTINUE_EXECUTION;
2320 }
2321 
2322 //-----------------------------------------------------------------------------
2323 LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) {
2324   PCONTEXT ctx = exceptionInfo->ContextRecord;
2325 #ifndef  _WIN64
2326   // handle exception caused by native method modifying control word
2327   DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode;
2328 
2329   switch (exception_code) {
2330   case EXCEPTION_FLT_DENORMAL_OPERAND:
2331   case EXCEPTION_FLT_DIVIDE_BY_ZERO:
2332   case EXCEPTION_FLT_INEXACT_RESULT:
2333   case EXCEPTION_FLT_INVALID_OPERATION:
2334   case EXCEPTION_FLT_OVERFLOW:
2335   case EXCEPTION_FLT_STACK_CHECK:
2336   case EXCEPTION_FLT_UNDERFLOW:
2337     jint fp_control_word = (* (jint*) StubRoutines::addr_fpu_cntrl_wrd_std());
2338     if (fp_control_word != ctx->FloatSave.ControlWord) {


2395       return false;
2396     } else {
2397       *fr = os::fetch_frame_from_context((void*)exceptionInfo->ContextRecord);
2398       // in compiled code, the stack banging is performed just after the return pc
2399       // has been pushed on the stack
2400       *fr = frame(fr->sp() + 1, fr->fp(), (address)*(fr->sp()));
2401       if (!fr->is_java_frame()) {
2402         // See java_sender() comment above.
2403         *fr = fr->java_sender();
2404       }
2405     }
2406   }
2407   assert(fr->is_java_frame(), "Safety check");
2408   return true;
2409 }
2410 
2411 //-----------------------------------------------------------------------------
2412 LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
2413   if (InterceptOSException) return EXCEPTION_CONTINUE_SEARCH;
2414   DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode;
2415 #ifdef _M_IA64
2416   // On Itanium, we need the "precise pc", which has the slot number coded
2417   // into the least 4 bits: 0000=slot0, 0100=slot1, 1000=slot2 (Windows format).
2418   address pc = (address) exceptionInfo->ExceptionRecord->ExceptionAddress;
2419   // Convert the pc to "Unix format", which has the slot number coded
2420   // into the least 2 bits: 0000=slot0, 0001=slot1, 0010=slot2
2421   // This is needed for IA64 because "relocation" / "implicit null check" / "poll instruction"
2422   // information is saved in the Unix format.
2423   address pc_unix_format = (address) ((((uint64_t)pc) & 0xFFFFFFFFFFFFFFF0) | ((((uint64_t)pc) & 0xF) >> 2));
2424 #else
2425   #ifdef _M_AMD64
2426   address pc = (address) exceptionInfo->ContextRecord->Rip;
2427   #else
2428   address pc = (address) exceptionInfo->ContextRecord->Eip;
2429   #endif
2430 #endif
2431   Thread* t = Thread::current_or_null_safe();
2432 
2433   // Handle SafeFetch32 and SafeFetchN exceptions.
2434   if (StubRoutines::is_safefetch_fault(pc)) {
2435     return Handle_Exception(exceptionInfo, StubRoutines::continuation_for_safefetch_fault(pc));
2436   }
2437 
2438 #ifndef _WIN64
2439   // Execution protection violation - win32 running on AMD64 only
2440   // Handled first to avoid misdiagnosis as a "normal" access violation;
2441   // This is safe to do because we have a new/unique ExceptionInformation
2442   // code for this condition.
2443   if (exception_code == EXCEPTION_ACCESS_VIOLATION) {
2444     PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
2445     int exception_subcode = (int) exceptionRecord->ExceptionInformation[0];
2446     address addr = (address) exceptionRecord->ExceptionInformation[1];
2447 
2448     if (exception_subcode == EXCEPTION_INFO_EXEC_VIOLATION) {
2449       int page_size = os::vm_page_size();
2450 


2527       if (os::is_memory_serialize_page(thread, addr)) {
2528         // Block current thread until the memory serialize page permission restored.
2529         os::block_on_serialize_page_trap();
2530         return EXCEPTION_CONTINUE_EXECUTION;
2531       }
2532     }
2533   }
2534 
2535   if ((exception_code == EXCEPTION_ACCESS_VIOLATION) &&
2536       VM_Version::is_cpuinfo_segv_addr(pc)) {
2537     // Verify that OS save/restore AVX registers.
2538     return Handle_Exception(exceptionInfo, VM_Version::cpuinfo_cont_addr());
2539   }
2540 
2541   if (t != NULL && t->is_Java_thread()) {
2542     JavaThread* thread = (JavaThread*) t;
2543     bool in_java = thread->thread_state() == _thread_in_Java;
2544 
2545     // Handle potential stack overflows up front.
2546     if (exception_code == EXCEPTION_STACK_OVERFLOW) {
2547 #ifdef _M_IA64
2548       // Use guard page for register stack.
2549       PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
2550       address addr = (address) exceptionRecord->ExceptionInformation[1];
2551       // Check for a register stack overflow on Itanium
2552       if (thread->addr_inside_register_stack_red_zone(addr)) {
2553         // Fatal red zone violation happens if the Java program
2554         // catches a StackOverflow error and does so much processing
2555         // that it runs beyond the unprotected yellow guard zone. As
2556         // a result, we are out of here.
2557         fatal("ERROR: Unrecoverable stack overflow happened. JVM will exit.");
2558       } else if(thread->addr_inside_register_stack(addr)) {
2559         // Disable the yellow zone which sets the state that
2560         // we've got a stack overflow problem.
2561         if (thread->stack_yellow_reserved_zone_enabled()) {
2562           thread->disable_stack_yellow_reserved_zone();
2563         }
2564         // Give us some room to process the exception.
2565         thread->disable_register_stack_guard();
2566         // Tracing with +Verbose.
2567         if (Verbose) {
2568           tty->print_cr("SOF Compiled Register Stack overflow at " INTPTR_FORMAT " (SIGSEGV)", pc);
2569           tty->print_cr("Register Stack access at " INTPTR_FORMAT, addr);
2570           tty->print_cr("Register Stack base " INTPTR_FORMAT, thread->register_stack_base());
2571           tty->print_cr("Register Stack [" INTPTR_FORMAT "," INTPTR_FORMAT "]",
2572                         thread->register_stack_base(),
2573                         thread->register_stack_base() + thread->stack_size());
2574         }
2575 
2576         // Reguard the permanent register stack red zone just to be sure.
2577         // We saw Windows silently disabling this without telling us.
2578         thread->enable_register_stack_red_zone();
2579 
2580         return Handle_Exception(exceptionInfo,
2581                                 SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW));
2582       }
2583 #endif
2584       if (thread->stack_guards_enabled()) {
2585         if (in_java) {
2586           frame fr;
2587           PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
2588           address addr = (address) exceptionRecord->ExceptionInformation[1];
2589           if (os::win32::get_frame_at_stack_banging_point(thread, exceptionInfo, pc, &fr)) {
2590             assert(fr.is_java_frame(), "Must be a Java frame");
2591             SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
2592           }
2593         }
2594         // Yellow zone violation.  The o/s has unprotected the first yellow
2595         // zone page for us.  Note:  must call disable_stack_yellow_zone to
2596         // update the enabled status, even if the zone contains only one page.
2597         assert(thread->thread_state() != _thread_in_vm, "Undersized StackShadowPages");
2598         thread->disable_stack_yellow_reserved_zone();
2599         // If not in java code, return and hope for the best.
2600         return in_java
2601             ? Handle_Exception(exceptionInfo, SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW))
2602             :  EXCEPTION_CONTINUE_EXECUTION;
2603       } else {


2630             address stub = SharedRuntime::get_poll_stub(pc);
2631             return Handle_Exception(exceptionInfo, stub);
2632           }
2633         }
2634         {
2635 #ifdef _WIN64
2636           // If it's a legal stack address map the entire region in
2637           //
2638           PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
2639           address addr = (address) exceptionRecord->ExceptionInformation[1];
2640           if (addr > thread->stack_reserved_zone_base() && addr < thread->stack_base()) {
2641             addr = (address)((uintptr_t)addr &
2642                              (~((uintptr_t)os::vm_page_size() - (uintptr_t)1)));
2643             os::commit_memory((char *)addr, thread->stack_base() - addr,
2644                               !ExecMem);
2645             return EXCEPTION_CONTINUE_EXECUTION;
2646           } else
2647 #endif
2648           {
2649             // Null pointer exception.
2650 #ifdef _M_IA64
2651             // Process implicit null checks in compiled code. Note: Implicit null checks
2652             // can happen even if "ImplicitNullChecks" is disabled, e.g. in vtable stubs.
2653             if (CodeCache::contains((void*) pc_unix_format) && !MacroAssembler::needs_explicit_null_check((intptr_t) addr)) {
2654               CodeBlob *cb = CodeCache::find_blob_unsafe(pc_unix_format);
2655               // Handle implicit null check in UEP method entry
2656               if (cb && (cb->is_frame_complete_at(pc) ||
2657                          (cb->is_nmethod() && ((nmethod *)cb)->inlinecache_check_contains(pc)))) {
2658                 if (Verbose) {
2659                   intptr_t *bundle_start = (intptr_t*) ((intptr_t) pc_unix_format & 0xFFFFFFFFFFFFFFF0);
2660                   tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", pc_unix_format);
2661                   tty->print_cr("      to addr " INTPTR_FORMAT, addr);
2662                   tty->print_cr("      bundle is " INTPTR_FORMAT " (high), " INTPTR_FORMAT " (low)",
2663                                 *(bundle_start + 1), *bundle_start);
2664                 }
2665                 return Handle_Exception(exceptionInfo,
2666                                         SharedRuntime::continuation_for_implicit_exception(thread, pc_unix_format, SharedRuntime::IMPLICIT_NULL));
2667               }
2668             }
2669 
2670             // Implicit null checks were processed above.  Hence, we should not reach
2671             // here in the usual case => die!
2672             if (Verbose) tty->print_raw_cr("Access violation, possible null pointer exception");
2673             report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord,
2674                          exceptionInfo->ContextRecord);
2675             return EXCEPTION_CONTINUE_SEARCH;
2676 
2677 #else // !IA64
2678 
2679             if (!MacroAssembler::needs_explicit_null_check((intptr_t)addr)) {
2680               address stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
2681               if (stub != NULL) return Handle_Exception(exceptionInfo, stub);
2682             }
2683             report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord,
2684                          exceptionInfo->ContextRecord);
2685             return EXCEPTION_CONTINUE_SEARCH;
2686 #endif
2687           }
2688         }
2689       }
2690 
2691 #ifdef _WIN64
2692       // Special care for fast JNI field accessors.
2693       // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks
2694       // in and the heap gets shrunk before the field access.
2695       if (exception_code == EXCEPTION_ACCESS_VIOLATION) {
2696         address addr = JNI_FastGetField::find_slowcase_pc(pc);
2697         if (addr != (address)-1) {
2698           return Handle_Exception(exceptionInfo, addr);
2699         }
2700       }
2701 #endif
2702 
2703       // Stack overflow or null pointer exception in native code.
2704       report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord,
2705                    exceptionInfo->ContextRecord);
2706       return EXCEPTION_CONTINUE_SEARCH;
2707     } // /EXCEPTION_ACCESS_VIOLATION
2708     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2709 #if defined _M_IA64
2710     else if ((exception_code == EXCEPTION_ILLEGAL_INSTRUCTION ||
2711               exception_code == EXCEPTION_ILLEGAL_INSTRUCTION_2)) {
2712       M37 handle_wrong_method_break(0, NativeJump::HANDLE_WRONG_METHOD, PR0);
2713 
2714       // Compiled method patched to be non entrant? Following conditions must apply:
2715       // 1. must be first instruction in bundle
2716       // 2. must be a break instruction with appropriate code
2717       if ((((uint64_t) pc & 0x0F) == 0) &&
2718           (((IPF_Bundle*) pc)->get_slot0() == handle_wrong_method_break.bits())) {
2719         return Handle_Exception(exceptionInfo,
2720                                 (address)SharedRuntime::get_handle_wrong_method_stub());
2721       }
2722     } // /EXCEPTION_ILLEGAL_INSTRUCTION
2723 #endif
2724 
2725 
2726     if (in_java) {
2727       switch (exception_code) {
2728       case EXCEPTION_INT_DIVIDE_BY_ZERO:
2729         return Handle_Exception(exceptionInfo, SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO));
2730 
2731       case EXCEPTION_INT_OVERFLOW:
2732         return Handle_IDiv_Exception(exceptionInfo);
2733 
2734       } // switch
2735     }
2736     if (((thread->thread_state() == _thread_in_Java) ||
2737          (thread->thread_state() == _thread_in_native)) &&
2738          exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION) {
2739       LONG result=Handle_FLT_Exception(exceptionInfo);
2740       if (result==EXCEPTION_CONTINUE_EXECUTION) return result;
2741     }
2742   }
2743 
2744   if (exception_code != EXCEPTION_BREAKPOINT) {


3735   // and it being cleared here. It is critical - see 6535709 - that
3736   // we only clear the interrupt state, and reset the interrupt event,
3737   // if we are going to report that we were indeed interrupted - else
3738   // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
3739   // depending on the timing. By checking thread interrupt event to see
3740   // if the thread gets real interrupt thus prevent spurious wakeup.
3741   bool interrupted = osthread->interrupted() && (WaitForSingleObject(osthread->interrupt_event(), 0) == WAIT_OBJECT_0);
3742   if (interrupted && clear_interrupted) {
3743     osthread->set_interrupted(false);
3744     ResetEvent(osthread->interrupt_event());
3745   } // Otherwise leave the interrupted state alone
3746 
3747   return interrupted;
3748 }
3749 
3750 // Get's a pc (hint) for a running thread. Currently used only for profiling.
3751 ExtendedPC os::get_thread_pc(Thread* thread) {
3752   CONTEXT context;
3753   context.ContextFlags = CONTEXT_CONTROL;
3754   HANDLE handle = thread->osthread()->thread_handle();
3755 #ifdef _M_IA64
3756   assert(0, "Fix get_thread_pc");
3757   return ExtendedPC(NULL);
3758 #else
3759   if (GetThreadContext(handle, &context)) {
3760 #ifdef _M_AMD64
3761     return ExtendedPC((address) context.Rip);
3762 #else
3763     return ExtendedPC((address) context.Eip);
3764 #endif
3765   } else {
3766     return ExtendedPC(NULL);
3767   }
3768 #endif
3769 }
3770 
3771 // GetCurrentThreadId() returns DWORD
3772 intx os::current_thread_id()  { return GetCurrentThreadId(); }
3773 
3774 static int _initial_pid = 0;
3775 
3776 int os::current_process_id() {
3777   return (_initial_pid ? _initial_pid : _getpid());
3778 }
3779 
3780 int    os::win32::_vm_page_size              = 0;
3781 int    os::win32::_vm_allocation_granularity = 0;
3782 int    os::win32::_processor_type            = 0;
3783 // Processor level is not available on non-NT systems, use vm_version instead
3784 int    os::win32::_processor_level           = 0;
3785 julong os::win32::_physical_memory           = 0;
3786 size_t os::win32::_default_stack_size        = 0;
3787 
3788 intx          os::win32::_os_thread_limit    = 0;




  97 // for enumerating dll libraries
  98 #include <vdmdbg.h>
  99 
 100 // for timer info max values which include all bits
 101 #define ALL_64_BITS CONST64(-1)
 102 
 103 // For DLL loading/load error detection
 104 // Values of PE COFF
 105 #define IMAGE_FILE_PTR_TO_SIGNATURE 0x3c
 106 #define IMAGE_FILE_SIGNATURE_LENGTH 4
 107 
 108 static HANDLE main_process;
 109 static HANDLE main_thread;
 110 static int    main_thread_id;
 111 
 112 static FILETIME process_creation_time;
 113 static FILETIME process_exit_time;
 114 static FILETIME process_user_time;
 115 static FILETIME process_kernel_time;
 116 
 117 #ifdef _M_AMD64



 118   #define __CPU__ amd64
 119 #else
 120   #define __CPU__ i486

 121 #endif
 122 
 123 // save DLL module handle, used by GetModuleFileName
 124 
 125 HINSTANCE vm_lib_handle;
 126 
 127 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
 128   switch (reason) {
 129   case DLL_PROCESS_ATTACH:
 130     vm_lib_handle = hinst;
 131     if (ForceTimeHighResolution) {
 132       timeBeginPeriod(1L);
 133     }
 134     break;
 135   case DLL_PROCESS_DETACH:
 136     if (ForceTimeHighResolution) {
 137       timeEndPeriod(1L);
 138     }
 139     break;
 140   default:


 330 
 331 address os::current_stack_base() {
 332   MEMORY_BASIC_INFORMATION minfo;
 333   address stack_bottom;
 334   size_t stack_size;
 335 
 336   VirtualQuery(&minfo, &minfo, sizeof(minfo));
 337   stack_bottom =  (address)minfo.AllocationBase;
 338   stack_size = minfo.RegionSize;
 339 
 340   // Add up the sizes of all the regions with the same
 341   // AllocationBase.
 342   while (1) {
 343     VirtualQuery(stack_bottom+stack_size, &minfo, sizeof(minfo));
 344     if (stack_bottom == (address)minfo.AllocationBase) {
 345       stack_size += minfo.RegionSize;
 346     } else {
 347       break;
 348     }
 349   }
































 350   return stack_bottom + stack_size;
 351 }
 352 
 353 size_t os::current_stack_size() {
 354   size_t sz;
 355   MEMORY_BASIC_INFORMATION minfo;
 356   VirtualQuery(&minfo, &minfo, sizeof(minfo));
 357   sz = (size_t)os::current_stack_base() - (size_t)minfo.AllocationBase;
 358   return sz;
 359 }
 360 
 361 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
 362   const struct tm* time_struct_ptr = localtime(clock);
 363   if (time_struct_ptr != NULL) {
 364     *res = *time_struct_ptr;
 365     return res;
 366   }
 367   return NULL;
 368 }
 369 


1447      // that dll was built for
1448      (sizeof(lib_arch) != (os::read(fd, (void*)&lib_arch, sizeof(lib_arch))))
1449     );
1450 
1451   ::close(fd);
1452   if (failed_to_get_lib_arch) {
1453     // file i/o error - report os::lasterror(...) msg
1454     return NULL;
1455   }
1456 
1457   typedef struct {
1458     uint16_t arch_code;
1459     char* arch_name;
1460   } arch_t;
1461 
1462   static const arch_t arch_array[] = {
1463     {IMAGE_FILE_MACHINE_I386,      (char*)"IA 32"},
1464     {IMAGE_FILE_MACHINE_AMD64,     (char*)"AMD 64"},
1465     {IMAGE_FILE_MACHINE_IA64,      (char*)"IA 64"}
1466   };
1467 #if (defined _M_AMD64)


1468   static const uint16_t running_arch = IMAGE_FILE_MACHINE_AMD64;
1469 #elif (defined _M_IX86)
1470   static const uint16_t running_arch = IMAGE_FILE_MACHINE_I386;
1471 #else
1472   #error Method os::dll_load requires that one of following \
1473          is defined :_M_AMD64 or _M_IX86
1474 #endif
1475 
1476 
1477   // Obtain a string for printf operation
1478   // lib_arch_str shall contain string what platform this .dll was built for
1479   // running_arch_str shall string contain what platform Hotspot was built for
1480   char *running_arch_str = NULL, *lib_arch_str = NULL;
1481   for (unsigned int i = 0; i < ARRAY_SIZE(arch_array); i++) {
1482     if (lib_arch == arch_array[i].arch_code) {
1483       lib_arch_str = arch_array[i].arch_name;
1484     }
1485     if (running_arch == arch_array[i].arch_code) {
1486       running_arch_str = arch_array[i].arch_name;
1487     }
1488   }
1489 
1490   assert(running_arch_str,
1491          "Didn't find running architecture code in arch_array");
1492 
1493   // If the architecture is right


2106         thread->java_suspend_self();
2107       }
2108     } while (threadIsSuspended);
2109   }
2110 }
2111 
2112 int os::signal_lookup() {
2113   return check_pending_signals(false);
2114 }
2115 
2116 int os::signal_wait() {
2117   return check_pending_signals(true);
2118 }
2119 
2120 // Implicit OS exception handling
2121 
2122 LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo,
2123                       address handler) {
2124     JavaThread* thread = (JavaThread*) Thread::current_or_null();
2125   // Save pc in thread
















2126   #ifdef _M_AMD64
2127     // Do not blow up if no thread info available.
2128     if (thread) {
2129       thread->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Rip);
2130     }
2131     // Set pc to handler
2132     exceptionInfo->ContextRecord->Rip = (DWORD64)handler;
2133     #else
2134     // Do not blow up if no thread info available.
2135     if (thread) {
2136       thread->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Eip);
2137     }
2138     // Set pc to handler
2139     exceptionInfo->ContextRecord->Eip = (DWORD)(DWORD_PTR)handler;
2140   #endif

2141 
2142   // Continue the execution
2143   return EXCEPTION_CONTINUE_EXECUTION;
2144 }
2145 
2146 
2147 // Used for PostMortemDump
2148 extern "C" void safepoints();
2149 extern "C" void find(int x);
2150 extern "C" void events();
2151 
2152 // According to Windows API documentation, an illegal instruction sequence should generate
2153 // the 0xC000001C exception code. However, real world experience shows that occasionnaly
2154 // the execution of an illegal instruction can generate the exception code 0xC000001E. This
2155 // seems to be an undocumented feature of Win NT 4.0 (and probably other Windows systems).
2156 
2157 #define EXCEPTION_ILLEGAL_INSTRUCTION_2 0xC000001E
2158 
2159 // From "Execution Protection in the Windows Operating System" draft 0.35
2160 // Once a system header becomes available, the "real" define should be
2161 // included or copied here.
2162 #define EXCEPTION_INFO_EXEC_VIOLATION 0x08
2163 





2164 // Windows Vista/2008 heap corruption check
2165 #define EXCEPTION_HEAP_CORRUPTION        0xC0000374
2166 
2167 // All Visual C++ exceptions thrown from code generated by the Microsoft Visual
2168 // C++ compiler contain this error code. Because this is a compiler-generated
2169 // error, the code is not listed in the Win32 API header files.
2170 // The code is actually a cryptic mnemonic device, with the initial "E"
2171 // standing for "exception" and the final 3 bytes (0x6D7363) representing the
2172 // ASCII values of "msc".
2173 
2174 #define EXCEPTION_UNCAUGHT_CXX_EXCEPTION    0xE06D7363
2175 
2176 #define def_excpt(val) { #val, (val) }
2177 
2178 static const struct { char* name; uint number; } exceptlabels[] = {
2179     def_excpt(EXCEPTION_ACCESS_VIOLATION),
2180     def_excpt(EXCEPTION_DATATYPE_MISALIGNMENT),
2181     def_excpt(EXCEPTION_BREAKPOINT),
2182     def_excpt(EXCEPTION_SINGLE_STEP),
2183     def_excpt(EXCEPTION_ARRAY_BOUNDS_EXCEEDED),
2184     def_excpt(EXCEPTION_FLT_DENORMAL_OPERAND),
2185     def_excpt(EXCEPTION_FLT_DIVIDE_BY_ZERO),
2186     def_excpt(EXCEPTION_FLT_INEXACT_RESULT),
2187     def_excpt(EXCEPTION_FLT_INVALID_OPERATION),
2188     def_excpt(EXCEPTION_FLT_OVERFLOW),
2189     def_excpt(EXCEPTION_FLT_STACK_CHECK),
2190     def_excpt(EXCEPTION_FLT_UNDERFLOW),
2191     def_excpt(EXCEPTION_INT_DIVIDE_BY_ZERO),
2192     def_excpt(EXCEPTION_INT_OVERFLOW),
2193     def_excpt(EXCEPTION_PRIV_INSTRUCTION),
2194     def_excpt(EXCEPTION_IN_PAGE_ERROR),
2195     def_excpt(EXCEPTION_ILLEGAL_INSTRUCTION),
2196     def_excpt(EXCEPTION_ILLEGAL_INSTRUCTION_2),
2197     def_excpt(EXCEPTION_NONCONTINUABLE_EXCEPTION),
2198     def_excpt(EXCEPTION_STACK_OVERFLOW),
2199     def_excpt(EXCEPTION_INVALID_DISPOSITION),
2200     def_excpt(EXCEPTION_GUARD_PAGE),
2201     def_excpt(EXCEPTION_INVALID_HANDLE),
2202     def_excpt(EXCEPTION_UNCAUGHT_CXX_EXCEPTION),
2203     def_excpt(EXCEPTION_HEAP_CORRUPTION)



2204 };
2205 
2206 #undef def_excpt
2207 
2208 const char* os::exception_name(int exception_code, char *buf, size_t size) {
2209   uint code = static_cast<uint>(exception_code);
2210   for (uint i = 0; i < ARRAY_SIZE(exceptlabels); ++i) {
2211     if (exceptlabels[i].number == code) {
2212       jio_snprintf(buf, size, "%s", exceptlabels[i].name);
2213       return buf;
2214     }
2215   }
2216 
2217   return NULL;
2218 }
2219 
2220 //-----------------------------------------------------------------------------
2221 LONG Handle_IDiv_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) {
2222   // handle exception caused by idiv; should only happen for -MinInt/-1
2223   // (division by zero is handled explicitly)



2224   #ifdef  _M_AMD64
2225   PCONTEXT ctx = exceptionInfo->ContextRecord;
2226   address pc = (address)ctx->Rip;
2227   assert(pc[0] >= Assembler::REX && pc[0] <= Assembler::REX_WRXB && pc[1] == 0xF7 || pc[0] == 0xF7, "not an idiv opcode");
2228   assert(pc[0] >= Assembler::REX && pc[0] <= Assembler::REX_WRXB && (pc[2] & ~0x7) == 0xF8 || (pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands");
2229   if (pc[0] == 0xF7) {
2230     // set correct result values and continue after idiv instruction
2231     ctx->Rip = (DWORD64)pc + 2;        // idiv reg, reg  is 2 bytes
2232   } else {
2233     ctx->Rip = (DWORD64)pc + 3;        // REX idiv reg, reg  is 3 bytes
2234   }
2235   // Do not set ctx->Rax as it already contains the correct value (either 32 or 64 bit, depending on the operation)
2236   // this is the case because the exception only happens for -MinValue/-1 and -MinValue is always in rax because of the
2237   // idiv opcode (0xF7).
2238   ctx->Rdx = (DWORD)0;             // remainder
2239   // Continue the execution
2240   #else
2241   PCONTEXT ctx = exceptionInfo->ContextRecord;
2242   address pc = (address)ctx->Eip;
2243   assert(pc[0] == 0xF7, "not an idiv opcode");
2244   assert((pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands");
2245   assert(ctx->Eax == min_jint, "unexpected idiv exception");
2246   // set correct result values and continue after idiv instruction
2247   ctx->Eip = (DWORD)pc + 2;        // idiv reg, reg  is 2 bytes
2248   ctx->Eax = (DWORD)min_jint;      // result
2249   ctx->Edx = (DWORD)0;             // remainder
2250   // Continue the execution
2251   #endif

2252   return EXCEPTION_CONTINUE_EXECUTION;
2253 }
2254 
2255 //-----------------------------------------------------------------------------
2256 LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) {
2257   PCONTEXT ctx = exceptionInfo->ContextRecord;
2258 #ifndef  _WIN64
2259   // handle exception caused by native method modifying control word
2260   DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode;
2261 
2262   switch (exception_code) {
2263   case EXCEPTION_FLT_DENORMAL_OPERAND:
2264   case EXCEPTION_FLT_DIVIDE_BY_ZERO:
2265   case EXCEPTION_FLT_INEXACT_RESULT:
2266   case EXCEPTION_FLT_INVALID_OPERATION:
2267   case EXCEPTION_FLT_OVERFLOW:
2268   case EXCEPTION_FLT_STACK_CHECK:
2269   case EXCEPTION_FLT_UNDERFLOW:
2270     jint fp_control_word = (* (jint*) StubRoutines::addr_fpu_cntrl_wrd_std());
2271     if (fp_control_word != ctx->FloatSave.ControlWord) {


2328       return false;
2329     } else {
2330       *fr = os::fetch_frame_from_context((void*)exceptionInfo->ContextRecord);
2331       // in compiled code, the stack banging is performed just after the return pc
2332       // has been pushed on the stack
2333       *fr = frame(fr->sp() + 1, fr->fp(), (address)*(fr->sp()));
2334       if (!fr->is_java_frame()) {
2335         // See java_sender() comment above.
2336         *fr = fr->java_sender();
2337       }
2338     }
2339   }
2340   assert(fr->is_java_frame(), "Safety check");
2341   return true;
2342 }
2343 
2344 //-----------------------------------------------------------------------------
2345 LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
2346   if (InterceptOSException) return EXCEPTION_CONTINUE_SEARCH;
2347   DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode;










2348   #ifdef _M_AMD64
2349   address pc = (address) exceptionInfo->ContextRecord->Rip;
2350   #else
2351   address pc = (address) exceptionInfo->ContextRecord->Eip;
2352   #endif

2353   Thread* t = Thread::current_or_null_safe();
2354 
2355   // Handle SafeFetch32 and SafeFetchN exceptions.
2356   if (StubRoutines::is_safefetch_fault(pc)) {
2357     return Handle_Exception(exceptionInfo, StubRoutines::continuation_for_safefetch_fault(pc));
2358   }
2359 
2360 #ifndef _WIN64
2361   // Execution protection violation - win32 running on AMD64 only
2362   // Handled first to avoid misdiagnosis as a "normal" access violation;
2363   // This is safe to do because we have a new/unique ExceptionInformation
2364   // code for this condition.
2365   if (exception_code == EXCEPTION_ACCESS_VIOLATION) {
2366     PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
2367     int exception_subcode = (int) exceptionRecord->ExceptionInformation[0];
2368     address addr = (address) exceptionRecord->ExceptionInformation[1];
2369 
2370     if (exception_subcode == EXCEPTION_INFO_EXEC_VIOLATION) {
2371       int page_size = os::vm_page_size();
2372 


2449       if (os::is_memory_serialize_page(thread, addr)) {
2450         // Block current thread until the memory serialize page permission restored.
2451         os::block_on_serialize_page_trap();
2452         return EXCEPTION_CONTINUE_EXECUTION;
2453       }
2454     }
2455   }
2456 
2457   if ((exception_code == EXCEPTION_ACCESS_VIOLATION) &&
2458       VM_Version::is_cpuinfo_segv_addr(pc)) {
2459     // Verify that OS save/restore AVX registers.
2460     return Handle_Exception(exceptionInfo, VM_Version::cpuinfo_cont_addr());
2461   }
2462 
2463   if (t != NULL && t->is_Java_thread()) {
2464     JavaThread* thread = (JavaThread*) t;
2465     bool in_java = thread->thread_state() == _thread_in_Java;
2466 
2467     // Handle potential stack overflows up front.
2468     if (exception_code == EXCEPTION_STACK_OVERFLOW) {





































2469       if (thread->stack_guards_enabled()) {
2470         if (in_java) {
2471           frame fr;
2472           PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
2473           address addr = (address) exceptionRecord->ExceptionInformation[1];
2474           if (os::win32::get_frame_at_stack_banging_point(thread, exceptionInfo, pc, &fr)) {
2475             assert(fr.is_java_frame(), "Must be a Java frame");
2476             SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
2477           }
2478         }
2479         // Yellow zone violation.  The o/s has unprotected the first yellow
2480         // zone page for us.  Note:  must call disable_stack_yellow_zone to
2481         // update the enabled status, even if the zone contains only one page.
2482         assert(thread->thread_state() != _thread_in_vm, "Undersized StackShadowPages");
2483         thread->disable_stack_yellow_reserved_zone();
2484         // If not in java code, return and hope for the best.
2485         return in_java
2486             ? Handle_Exception(exceptionInfo, SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW))
2487             :  EXCEPTION_CONTINUE_EXECUTION;
2488       } else {


2515             address stub = SharedRuntime::get_poll_stub(pc);
2516             return Handle_Exception(exceptionInfo, stub);
2517           }
2518         }
2519         {
2520 #ifdef _WIN64
2521           // If it's a legal stack address map the entire region in
2522           //
2523           PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
2524           address addr = (address) exceptionRecord->ExceptionInformation[1];
2525           if (addr > thread->stack_reserved_zone_base() && addr < thread->stack_base()) {
2526             addr = (address)((uintptr_t)addr &
2527                              (~((uintptr_t)os::vm_page_size() - (uintptr_t)1)));
2528             os::commit_memory((char *)addr, thread->stack_base() - addr,
2529                               !ExecMem);
2530             return EXCEPTION_CONTINUE_EXECUTION;
2531           } else
2532 #endif
2533           {
2534             // Null pointer exception.





























2535             if (!MacroAssembler::needs_explicit_null_check((intptr_t)addr)) {
2536               address stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
2537               if (stub != NULL) return Handle_Exception(exceptionInfo, stub);
2538             }
2539             report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord,
2540                          exceptionInfo->ContextRecord);
2541             return EXCEPTION_CONTINUE_SEARCH;

2542           }
2543         }
2544       }
2545 
2546 #ifdef _WIN64
2547       // Special care for fast JNI field accessors.
2548       // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks
2549       // in and the heap gets shrunk before the field access.
2550       if (exception_code == EXCEPTION_ACCESS_VIOLATION) {
2551         address addr = JNI_FastGetField::find_slowcase_pc(pc);
2552         if (addr != (address)-1) {
2553           return Handle_Exception(exceptionInfo, addr);
2554         }
2555       }
2556 #endif
2557 
2558       // Stack overflow or null pointer exception in native code.
2559       report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord,
2560                    exceptionInfo->ContextRecord);
2561       return EXCEPTION_CONTINUE_SEARCH;
2562     } // /EXCEPTION_ACCESS_VIOLATION
2563     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
















2564 
2565     if (in_java) {
2566       switch (exception_code) {
2567       case EXCEPTION_INT_DIVIDE_BY_ZERO:
2568         return Handle_Exception(exceptionInfo, SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO));
2569 
2570       case EXCEPTION_INT_OVERFLOW:
2571         return Handle_IDiv_Exception(exceptionInfo);
2572 
2573       } // switch
2574     }
2575     if (((thread->thread_state() == _thread_in_Java) ||
2576          (thread->thread_state() == _thread_in_native)) &&
2577          exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION) {
2578       LONG result=Handle_FLT_Exception(exceptionInfo);
2579       if (result==EXCEPTION_CONTINUE_EXECUTION) return result;
2580     }
2581   }
2582 
2583   if (exception_code != EXCEPTION_BREAKPOINT) {


3574   // and it being cleared here. It is critical - see 6535709 - that
3575   // we only clear the interrupt state, and reset the interrupt event,
3576   // if we are going to report that we were indeed interrupted - else
3577   // an interrupt can be "lost", leading to spurious wakeups or lost wakeups
3578   // depending on the timing. By checking thread interrupt event to see
3579   // if the thread gets real interrupt thus prevent spurious wakeup.
3580   bool interrupted = osthread->interrupted() && (WaitForSingleObject(osthread->interrupt_event(), 0) == WAIT_OBJECT_0);
3581   if (interrupted && clear_interrupted) {
3582     osthread->set_interrupted(false);
3583     ResetEvent(osthread->interrupt_event());
3584   } // Otherwise leave the interrupted state alone
3585 
3586   return interrupted;
3587 }
3588 
3589 // Get's a pc (hint) for a running thread. Currently used only for profiling.
3590 ExtendedPC os::get_thread_pc(Thread* thread) {
3591   CONTEXT context;
3592   context.ContextFlags = CONTEXT_CONTROL;
3593   HANDLE handle = thread->osthread()->thread_handle();




3594   if (GetThreadContext(handle, &context)) {
3595     #ifdef _M_AMD64
3596       return ExtendedPC((address) context.Rip);
3597     #else
3598       return ExtendedPC((address) context.Eip);
3599     #endif
3600   } else {
3601     return ExtendedPC(NULL);
3602   }

3603 }
3604 
3605 // GetCurrentThreadId() returns DWORD
3606 intx os::current_thread_id()  { return GetCurrentThreadId(); }
3607 
3608 static int _initial_pid = 0;
3609 
3610 int os::current_process_id() {
3611   return (_initial_pid ? _initial_pid : _getpid());
3612 }
3613 
3614 int    os::win32::_vm_page_size              = 0;
3615 int    os::win32::_vm_allocation_granularity = 0;
3616 int    os::win32::_processor_type            = 0;
3617 // Processor level is not available on non-NT systems, use vm_version instead
3618 int    os::win32::_processor_level           = 0;
3619 julong os::win32::_physical_memory           = 0;
3620 size_t os::win32::_default_stack_size        = 0;
3621 
3622 intx          os::win32::_os_thread_limit    = 0;


< prev index next >