< prev index next >

hotspot/src/os/windows/vm/os_windows.cpp

Print this page


   1 /*
   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.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 822   FILETIME jot;
 823   if (!SystemTimeToFileTime(&java_origin, &jot)) {
 824     fatal(err_msg("Error = %d\nWindows error", GetLastError()));
 825   }
 826   _calculated_offset = jlong_from(jot.dwHighDateTime, jot.dwLowDateTime);
 827   _has_calculated_offset = 1;
 828   assert(_calculated_offset == _offset, "Calculated and constant time offsets must be equal");
 829   return _calculated_offset;
 830 }
 831 #else
 832 jlong offset() {
 833   return _offset;
 834 }
 835 #endif
 836 
 837 jlong windows_to_java_time(FILETIME wt) {
 838   jlong a = jlong_from(wt.dwHighDateTime, wt.dwLowDateTime);
 839   return (a - offset()) / 10000;
 840 }
 841 





 842 FILETIME java_to_windows_time(jlong l) {
 843   jlong a = (l * 10000) + offset();
 844   FILETIME result;
 845   result.dwHighDateTime = high(a);
 846   result.dwLowDateTime  = low(a);
 847   return result;
 848 }
 849 
 850 bool os::supports_vtime() { return true; }
 851 bool os::enable_vtime() { return false; }
 852 bool os::vtime_enabled() { return false; }
 853 
 854 double os::elapsedVTime() {
 855   FILETIME created;
 856   FILETIME exited;
 857   FILETIME kernel;
 858   FILETIME user;
 859   if (GetThreadTimes(GetCurrentThread(), &created, &exited, &kernel, &user) != 0) {
 860     // the resolution of windows_to_java_time() should be sufficient (ms)
 861     return (double) (windows_to_java_time(kernel) + windows_to_java_time(user)) / MILLIUNITS;
 862   } else {
 863     return elapsedTime();
 864   }
 865 }
 866 
 867 jlong os::javaTimeMillis() {
 868   if (UseFakeTimers) {
 869     return fake_time++;
 870   } else {
 871     FILETIME wt;
 872     GetSystemTimeAsFileTime(&wt);
 873     return windows_to_java_time(wt);
 874   }
 875 }
 876 









 877 jlong os::javaTimeNanos() {
 878   if (!win32::_has_performance_count) {
 879     return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do.
 880   } else {
 881     LARGE_INTEGER current_count;
 882     QueryPerformanceCounter(&current_count);
 883     double current = as_long(current_count);
 884     double freq = performance_frequency;
 885     jlong time = (jlong)((current/freq) * NANOSECS_PER_SEC);
 886     return time;
 887   }
 888 }
 889 
 890 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
 891   if (!win32::_has_performance_count) {
 892     // javaTimeMillis() doesn't have much percision,
 893     // but it is not going to wrap -- so all 64 bits
 894     info_ptr->max_value = ALL_64_BITS;
 895 
 896     // this is a wall clock timer, so may skip


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 822   FILETIME jot;
 823   if (!SystemTimeToFileTime(&java_origin, &jot)) {
 824     fatal(err_msg("Error = %d\nWindows error", GetLastError()));
 825   }
 826   _calculated_offset = jlong_from(jot.dwHighDateTime, jot.dwLowDateTime);
 827   _has_calculated_offset = 1;
 828   assert(_calculated_offset == _offset, "Calculated and constant time offsets must be equal");
 829   return _calculated_offset;
 830 }
 831 #else
 832 jlong offset() {
 833   return _offset;
 834 }
 835 #endif
 836 
 837 jlong windows_to_java_time(FILETIME wt) {
 838   jlong a = jlong_from(wt.dwHighDateTime, wt.dwLowDateTime);
 839   return (a - offset()) / 10000;
 840 }
 841 
 842 jlong windows_time_stamp(FILETIME wt) {
 843   jlong a = jlong_from(wt.dwHighDateTime, wt.dwLowDateTime);
 844   return (a - offset());
 845 }
 846 
 847 FILETIME java_to_windows_time(jlong l) {
 848   jlong a = (l * 10000) + offset();
 849   FILETIME result;
 850   result.dwHighDateTime = high(a);
 851   result.dwLowDateTime  = low(a);
 852   return result;
 853 }
 854 
 855 bool os::supports_vtime() { return true; }
 856 bool os::enable_vtime() { return false; }
 857 bool os::vtime_enabled() { return false; }
 858 
 859 double os::elapsedVTime() {
 860   FILETIME created;
 861   FILETIME exited;
 862   FILETIME kernel;
 863   FILETIME user;
 864   if (GetThreadTimes(GetCurrentThread(), &created, &exited, &kernel, &user) != 0) {
 865     // the resolution of windows_to_java_time() should be sufficient (ms)
 866     return (double) (windows_to_java_time(kernel) + windows_to_java_time(user)) / MILLIUNITS;
 867   } else {
 868     return elapsedTime();
 869   }
 870 }
 871 
 872 jlong os::javaTimeMillis() {
 873   if (UseFakeTimers) {
 874     return fake_time++;
 875   } else {
 876     FILETIME wt;
 877     GetSystemTimeAsFileTime(&wt);
 878     return windows_to_java_time(wt);
 879   }
 880 }
 881 
 882 void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
 883   FILETIME wt;
 884   GetSystemTimeAsFileTime(&wt);
 885   jlong ts = windows_time_stamp(wt); // 10th of micros
 886   jlong secs = jlong(ts / 10000000); // 10000 * 1000
 887   seconds = secs; 
 888   nanos = jlong(ts - (secs*10000000)) * 100;
 889 }
 890 
 891 jlong os::javaTimeNanos() {
 892   if (!win32::_has_performance_count) {
 893     return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do.
 894   } else {
 895     LARGE_INTEGER current_count;
 896     QueryPerformanceCounter(&current_count);
 897     double current = as_long(current_count);
 898     double freq = performance_frequency;
 899     jlong time = (jlong)((current/freq) * NANOSECS_PER_SEC);
 900     return time;
 901   }
 902 }
 903 
 904 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
 905   if (!win32::_has_performance_count) {
 906     // javaTimeMillis() doesn't have much percision,
 907     // but it is not going to wrap -- so all 64 bits
 908     info_ptr->max_value = ALL_64_BITS;
 909 
 910     // this is a wall clock timer, so may skip


< prev index next >