comparison src/os/windows/vm/os_windows.cpp @ 14518:d8041d695d19

Merged with jdk9/dev/hotspot changeset 3812c088b945
author twisti
date Tue, 11 Mar 2014 18:45:59 -0700
parents 359f7e70ae7f 6c9332549827
children b51e29501f30 4ca6dc0799b6
comparison
equal deleted inserted replaced
14141:f97c5ec83832 14518:d8041d695d19
1 /* 1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
164 // For Windows at the moment does nothing 164 // For Windows at the moment does nothing
165 void os::run_periodic_checks() { 165 void os::run_periodic_checks() {
166 return; 166 return;
167 } 167 }
168 168
169 #ifndef _WIN64
170 // previous UnhandledExceptionFilter, if there is one 169 // previous UnhandledExceptionFilter, if there is one
171 static LPTOP_LEVEL_EXCEPTION_FILTER prev_uef_handler = NULL; 170 static LPTOP_LEVEL_EXCEPTION_FILTER prev_uef_handler = NULL;
172 171
173 LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo); 172 LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo);
174 #endif
175 void os::init_system_properties_values() { 173 void os::init_system_properties_values() {
176 /* sysclasspath, java_home, dll_dir */ 174 /* sysclasspath, java_home, dll_dir */
177 { 175 {
178 char *home_path; 176 char *home_path;
179 char *dll_path; 177 char *dll_path;
628 CloseHandle(osthread->thread_handle()); 626 CloseHandle(osthread->thread_handle());
629 CloseHandle(osthread->interrupt_event()); 627 CloseHandle(osthread->interrupt_event());
630 delete osthread; 628 delete osthread;
631 } 629 }
632 630
633
634 static int has_performance_count = 0;
635 static jlong first_filetime; 631 static jlong first_filetime;
636 static jlong initial_performance_count; 632 static jlong initial_performance_count;
637 static jlong performance_frequency; 633 static jlong performance_frequency;
638 634
639 635
645 } 641 }
646 642
647 643
648 jlong os::elapsed_counter() { 644 jlong os::elapsed_counter() {
649 LARGE_INTEGER count; 645 LARGE_INTEGER count;
650 if (has_performance_count) { 646 if (win32::_has_performance_count) {
651 QueryPerformanceCounter(&count); 647 QueryPerformanceCounter(&count);
652 return as_long(count) - initial_performance_count; 648 return as_long(count) - initial_performance_count;
653 } else { 649 } else {
654 FILETIME wt; 650 FILETIME wt;
655 GetSystemTimeAsFileTime(&wt); 651 GetSystemTimeAsFileTime(&wt);
657 } 653 }
658 } 654 }
659 655
660 656
661 jlong os::elapsed_frequency() { 657 jlong os::elapsed_frequency() {
662 if (has_performance_count) { 658 if (win32::_has_performance_count) {
663 return performance_frequency; 659 return performance_frequency;
664 } else { 660 } else {
665 // the FILETIME time is the number of 100-nanosecond intervals since January 1,1601. 661 // the FILETIME time is the number of 100-nanosecond intervals since January 1,1601.
666 return 10000000; 662 return 10000000;
667 } 663 }
736 bool os::bind_to_processor(uint processor_id) { 732 bool os::bind_to_processor(uint processor_id) {
737 // Not yet implemented. 733 // Not yet implemented.
738 return false; 734 return false;
739 } 735 }
740 736
741 static void initialize_performance_counter() { 737 void os::win32::initialize_performance_counter() {
742 LARGE_INTEGER count; 738 LARGE_INTEGER count;
743 if (QueryPerformanceFrequency(&count)) { 739 if (QueryPerformanceFrequency(&count)) {
744 has_performance_count = 1; 740 win32::_has_performance_count = 1;
745 performance_frequency = as_long(count); 741 performance_frequency = as_long(count);
746 QueryPerformanceCounter(&count); 742 QueryPerformanceCounter(&count);
747 initial_performance_count = as_long(count); 743 initial_performance_count = as_long(count);
748 } else { 744 } else {
749 has_performance_count = 0; 745 win32::_has_performance_count = 0;
750 FILETIME wt; 746 FILETIME wt;
751 GetSystemTimeAsFileTime(&wt); 747 GetSystemTimeAsFileTime(&wt);
752 first_filetime = jlong_from(wt.dwHighDateTime, wt.dwLowDateTime); 748 first_filetime = jlong_from(wt.dwHighDateTime, wt.dwLowDateTime);
753 } 749 }
754 } 750 }
839 return windows_to_java_time(wt); 835 return windows_to_java_time(wt);
840 } 836 }
841 } 837 }
842 838
843 jlong os::javaTimeNanos() { 839 jlong os::javaTimeNanos() {
844 if (!has_performance_count) { 840 if (!win32::_has_performance_count) {
845 return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do. 841 return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do.
846 } else { 842 } else {
847 LARGE_INTEGER current_count; 843 LARGE_INTEGER current_count;
848 QueryPerformanceCounter(&current_count); 844 QueryPerformanceCounter(&current_count);
849 double current = as_long(current_count); 845 double current = as_long(current_count);
852 return time; 848 return time;
853 } 849 }
854 } 850 }
855 851
856 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { 852 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
857 if (!has_performance_count) { 853 if (!win32::_has_performance_count) {
858 // javaTimeMillis() doesn't have much percision, 854 // javaTimeMillis() doesn't have much percision,
859 // but it is not going to wrap -- so all 64 bits 855 // but it is not going to wrap -- so all 64 bits
860 info_ptr->max_value = ALL_64_BITS; 856 info_ptr->max_value = ALL_64_BITS;
861 857
862 // this is a wall clock timer, so may skip 858 // this is a wall clock timer, so may skip
1810 strcpy(buf, saved_jvm_path); 1806 strcpy(buf, saved_jvm_path);
1811 return; 1807 return;
1812 } 1808 }
1813 1809
1814 buf[0] = '\0'; 1810 buf[0] = '\0';
1815 if (Arguments::created_by_gamma_launcher()) { 1811 if (Arguments::sun_java_launcher_is_altjvm()) {
1816 // Support for the gamma launcher. Check for an 1812 // Support for the java launcher's '-XXaltjvm=<path>' option. Check
1817 // JAVA_HOME environment variable 1813 // for a JAVA_HOME environment variable and fix up the path so it
1818 // and fix up the path so it looks like 1814 // looks like jvm.dll is installed there (append a fake suffix
1819 // libjvm.so is installed there (append a fake suffix 1815 // hotspot/jvm.dll).
1820 // hotspot/libjvm.so). 1816 char* java_home_var = ::getenv("JAVA_HOME");
1821 char* java_home_var = ::getenv("JAVA_HOME"); 1817 if (java_home_var != NULL && java_home_var[0] != 0) {
1822 if (java_home_var != NULL && java_home_var[0] != 0) { 1818 strncpy(buf, java_home_var, buflen);
1823 1819
1824 strncpy(buf, java_home_var, buflen); 1820 // determine if this is a legacy image or modules image
1825 1821 // modules image doesn't have "jre" subdirectory
1826 // determine if this is a legacy image or modules image 1822 size_t len = strlen(buf);
1827 // modules image doesn't have "jre" subdirectory 1823 char* jrebin_p = buf + len;
1828 size_t len = strlen(buf); 1824 jio_snprintf(jrebin_p, buflen-len, "\\jre\\bin\\");
1829 char* jrebin_p = buf + len; 1825 if (0 != _access(buf, 0)) {
1830 jio_snprintf(jrebin_p, buflen-len, "\\jre\\bin\\"); 1826 jio_snprintf(jrebin_p, buflen-len, "\\bin\\");
1831 if (0 != _access(buf, 0)) { 1827 }
1832 jio_snprintf(jrebin_p, buflen-len, "\\bin\\"); 1828 len = strlen(buf);
1833 } 1829 jio_snprintf(buf + len, buflen-len, "hotspot\\jvm.dll");
1834 len = strlen(buf); 1830 }
1835 jio_snprintf(buf + len, buflen-len, "hotspot\\jvm.dll"); 1831 }
1836 } 1832
1837 } 1833 if (buf[0] == '\0') {
1838 1834 GetModuleFileName(vm_lib_handle, buf, buflen);
1839 if(buf[0] == '\0') {
1840 GetModuleFileName(vm_lib_handle, buf, buflen);
1841 } 1835 }
1842 strcpy(saved_jvm_path, buf); 1836 strcpy(saved_jvm_path, buf);
1843 } 1837 }
1844 1838
1845 1839
2251 // Continue the execution 2245 // Continue the execution
2252 #endif 2246 #endif
2253 return EXCEPTION_CONTINUE_EXECUTION; 2247 return EXCEPTION_CONTINUE_EXECUTION;
2254 } 2248 }
2255 2249
2256 #ifndef _WIN64
2257 //----------------------------------------------------------------------------- 2250 //-----------------------------------------------------------------------------
2258 LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) { 2251 LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) {
2252 PCONTEXT ctx = exceptionInfo->ContextRecord;
2253 #ifndef _WIN64
2259 // handle exception caused by native method modifying control word 2254 // handle exception caused by native method modifying control word
2260 PCONTEXT ctx = exceptionInfo->ContextRecord;
2261 DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode; 2255 DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode;
2262 2256
2263 switch (exception_code) { 2257 switch (exception_code) {
2264 case EXCEPTION_FLT_DENORMAL_OPERAND: 2258 case EXCEPTION_FLT_DENORMAL_OPERAND:
2265 case EXCEPTION_FLT_DIVIDE_BY_ZERO: 2259 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
2281 if (prev_uef_handler != NULL) { 2275 if (prev_uef_handler != NULL) {
2282 // We didn't handle this exception so pass it to the previous 2276 // We didn't handle this exception so pass it to the previous
2283 // UnhandledExceptionFilter. 2277 // UnhandledExceptionFilter.
2284 return (prev_uef_handler)(exceptionInfo); 2278 return (prev_uef_handler)(exceptionInfo);
2285 } 2279 }
2286 2280 #else // !_WIN64
2287 return EXCEPTION_CONTINUE_SEARCH;
2288 }
2289 #else //_WIN64
2290 /* 2281 /*
2291 On Windows, the mxcsr control bits are non-volatile across calls 2282 On Windows, the mxcsr control bits are non-volatile across calls
2292 See also CR 6192333 2283 See also CR 6192333
2293 If EXCEPTION_FLT_* happened after some native method modified 2284 */
2294 mxcsr - it is not a jvm fault.
2295 However should we decide to restore of mxcsr after a faulty
2296 native method we can uncomment following code
2297 jint MxCsr = INITIAL_MXCSR; 2285 jint MxCsr = INITIAL_MXCSR;
2298 // we can't use StubRoutines::addr_mxcsr_std() 2286 // we can't use StubRoutines::addr_mxcsr_std()
2299 // because in Win64 mxcsr is not saved there 2287 // because in Win64 mxcsr is not saved there
2300 if (MxCsr != ctx->MxCsr) { 2288 if (MxCsr != ctx->MxCsr) {
2301 ctx->MxCsr = MxCsr; 2289 ctx->MxCsr = MxCsr;
2302 return EXCEPTION_CONTINUE_EXECUTION; 2290 return EXCEPTION_CONTINUE_EXECUTION;
2303 } 2291 }
2304 2292 #endif // !_WIN64
2305 */ 2293
2306 #endif //_WIN64 2294 return EXCEPTION_CONTINUE_SEARCH;
2307 2295 }
2308 2296
2309 // Fatal error reporting is single threaded so we can make this a 2297 // Fatal error reporting is single threaded so we can make this a
2310 // static and preallocated. If it's more than MAX_PATH silently ignore 2298 // static and preallocated. If it's more than MAX_PATH silently ignore
2311 // it. 2299 // it.
2312 static char saved_error_file[MAX_PATH] = {0}; 2300 static char saved_error_file[MAX_PATH] = {0};
2651 case EXCEPTION_INT_OVERFLOW: 2639 case EXCEPTION_INT_OVERFLOW:
2652 return Handle_IDiv_Exception(exceptionInfo); 2640 return Handle_IDiv_Exception(exceptionInfo);
2653 2641
2654 } // switch 2642 } // switch
2655 } 2643 }
2656 #ifndef _WIN64
2657 if (((thread->thread_state() == _thread_in_Java) || 2644 if (((thread->thread_state() == _thread_in_Java) ||
2658 (thread->thread_state() == _thread_in_native)) && 2645 (thread->thread_state() == _thread_in_native)) &&
2659 exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION) 2646 exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION)
2660 { 2647 {
2661 LONG result=Handle_FLT_Exception(exceptionInfo); 2648 LONG result=Handle_FLT_Exception(exceptionInfo);
2662 if (result==EXCEPTION_CONTINUE_EXECUTION) return result; 2649 if (result==EXCEPTION_CONTINUE_EXECUTION) return result;
2663 } 2650 }
2664 #endif //_WIN64
2665 } 2651 }
2666 2652
2667 if (exception_code != EXCEPTION_BREAKPOINT) { 2653 if (exception_code != EXCEPTION_BREAKPOINT) {
2668 report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord, 2654 report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord,
2669 exceptionInfo->ContextRecord); 2655 exceptionInfo->ContextRecord);
3507 result = OS_TIMEOUT; 3493 result = OS_TIMEOUT;
3508 } 3494 }
3509 return result; 3495 return result;
3510 } 3496 }
3511 3497
3498 //
3499 // Short sleep, direct OS call.
3500 //
3501 // ms = 0, means allow others (if any) to run.
3502 //
3503 void os::naked_short_sleep(jlong ms) {
3504 assert(ms < 1000, "Un-interruptable sleep, short time use only");
3505 Sleep(ms);
3506 }
3507
3512 // Sleep forever; naked call to OS-specific sleep; use with CAUTION 3508 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
3513 void os::infinite_sleep() { 3509 void os::infinite_sleep() {
3514 while (true) { // sleep forever ... 3510 while (true) { // sleep forever ...
3515 Sleep(100000); // ... 100 seconds at a time 3511 Sleep(100000); // ... 100 seconds at a time
3516 } 3512 }
3694 volatile intx os::win32::_os_thread_count = 0; 3690 volatile intx os::win32::_os_thread_count = 0;
3695 3691
3696 bool os::win32::_is_nt = false; 3692 bool os::win32::_is_nt = false;
3697 bool os::win32::_is_windows_2003 = false; 3693 bool os::win32::_is_windows_2003 = false;
3698 bool os::win32::_is_windows_server = false; 3694 bool os::win32::_is_windows_server = false;
3695
3696 bool os::win32::_has_performance_count = 0;
3699 3697
3700 void os::win32::initialize_system_info() { 3698 void os::win32::initialize_system_info() {
3701 SYSTEM_INFO si; 3699 SYSTEM_INFO si;
3702 GetSystemInfo(&si); 3700 GetSystemInfo(&si);
3703 _vm_page_size = si.dwPageSize; 3701 _vm_page_size = si.dwPageSize;