JDK-6461933 : To adjust system boot time in nowMillisUTC() frequently
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-08-21
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other Other JDK 7
1.4.2_17-revFixed 1.4.2_18Fixed 5.0u18Fixed 7 b09Fixed
Related Reports
Relates :  
Relates :  
Description
NTP service is usually used to sychronize OS wall clock time in PCs on the network.
When NTP serviice runs and a user application runs long time, the diff. between the time gotten
 by System.currentTimeMillis()  and the time by InputEvent.getWhen()  becomes large.

nowMillisUTC()  in awt_Component.cpp statically  keeps the time of system boot 
calculated when the allication is launched. 
When the time in OS is adjusted by NTP service, the adjusted time is not reftected to
the above boot time in nowMillisUTC().


REQUEST :
  To adjust system boot time in nowMillisUTC() frequently.

  The "time" memeber of MSG structure is DWORD. nowMillisUTC() compares 
  the time with  SYSTEMTIME every 43.7 days. (in order to avoid the counter becomes "0"
   after 47.3 days.)
   This should be done, not once in 47.3 day, but everytime

Comments
SUGGESTED FIX The last webrev is in http://sa.sfbay.sun.com/projects/awt_data/dolphin/6461933/
06-02-2007

SUGGESTED FIX *** /tmp/geta24136 2006-12-15 13:31:49.000000000 +0300 --- awt_Component.cpp 2006-12-15 13:31:44.000000000 +0300 *************** *** 1759,1764 **** --- 1759,1768 ---- mr = WmPaste(); break; + case WM_TIMECHANGE: + nowMillisUTC(GetMessageTime(), TRUE); + break; + case WM_TIMER: mr = WmTimer(wParam); break; *************** *** 2285,2291 **** --- 2289,2300 ---- } return nowMillisUTC(event_offset); } + jlong nowMillisUTC(DWORD event_offset) { + return nowMillisUTC(event_offset, FALSE); + } + + jlong nowMillisUTC(DWORD event_offset, BOOL updateBootTime) { // All computations and stored values are in milliseconds. The Win32 // FILETIME structure is in 100s of nanoseconds, so the FT2INT64 macro // divides by 10^4. (10^7 / 10^4 = 10^3). *************** *** 2319,2325 **** SystemTimeToFileTime(&current_sys_time_1601, &current_file_time_1601); current_time_1601 = FT2INT64(current_file_time_1601); ! if ((current_time_1601 - boot_time_1601) > WRAP_TIME_MILLIS) { // Need to reset boot time DWORD since_boot_millis = GetTickCount(); boot_time_1601 = current_time_1601 - since_boot_millis; --- 2328,2334 ---- SystemTimeToFileTime(&current_sys_time_1601, &current_file_time_1601); current_time_1601 = FT2INT64(current_file_time_1601); ! if (((current_time_1601 - boot_time_1601) > WRAP_TIME_MILLIS) || updateBootTime) { // Need to reset boot time DWORD since_boot_millis = GetTickCount(); boot_time_1601 = current_time_1601 - since_boot_millis;
15-12-2006

EVALUATION Provided patch supposes a more frequent time update. Actually that doesn't needed so often. We may track the WM_TIMECHANGE message and adjust the boottime accordingly. In other words we may execute the same code if only NTP update just happened. I verified that mentioned event is heard by the Java application on NTP update. On WIndows XP(and further) there is a built-in NTP client. See DateTime->InternetTime->UpdateNow. I'm introducing one more function nowMillisUTC(offset, updateBootTime) that may update boottime if the second parameter is TRUE. This would only be called from WM_TIMECHANGE handler. All other calls will address the it with the FALSE value.
15-12-2006

EVALUATION According to the code we do following things: 1)get BootTime 2)get current system time 3)if (current system time - BootTime) >49.7 days then do (4) and (5) 4) get the time length passed since system boot by getTickCount() call 5) update BootTime accordingly 6)return BootTime+event_offset That happens usually just after the application starts and there is no problem with it. Now lets imagine that the first initialization had passed and after some time we get an NTP update. AWT itself updates the BootTime every 49.7 days after boot. NPT is also changing the BootTime value but AWT does nothing for that case because we think that there is not so much time had passed yet.
12-12-2006

EVALUATION Sounds reasonable. Should consider a performance impact as well.
21-08-2006