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