src/app/jdk/lib/jvm/os_genode.cpp
// This code is common to bsd and solaris and will be moved to a
// common place in dolphin.
//
// The passed in time value is either a relative time in nanoseconds
// or an absolute time in milliseconds. Either way it has to be unpacked
// into suitable seconds and nanoseconds components and stored in the
// given timespec structure.
// Given time is a 64-bit value and the time_t used in the timespec is only
// a signed-32-bit value (except on 64-bit Bsd) we have to watch for
// overflow if times way in the future are given. Further on Solaris versions
// prior to 10 there is a restriction (see cond_timedwait) that the specified
// number of seconds, in abstime, is less than current_time  + 100,000,000.
// As it will be 28 years before "now + 100000000" will overflow we can
// ignore overflow and just impose a hard-limit on seconds using the value
// of "now + 100,000,000". This places a limit on the timeout of about 3.17
// years from "now".
This code is common to bsd and solaris and will be moved to a
common place in dolphin.

The passed in time value is either a relative time in nanoseconds
or an absolute time in milliseconds. Either way it has to be unpacked
into suitable seconds and nanoseconds components and stored in the
given timespec structure.
Given time is a 64-bit value and the time_t used in the timespec is only
a signed-32-bit value (except on 64-bit Bsd) we have to watch for
overflow if times way in the future are given. Further on Solaris versions
prior to 10 there is a restriction  that the specified
number of seconds, in abstime, is less than current_time  + 100,000,000.
As it will be 28 years before "now + 100000000" will overflow we can
ignore overflow and just impose a hard-limit on seconds using the value
of "now + 100,000,000". This places a limit on the timeout of about 3.17
years from "now".
This code is common to bsd and solaris and will be moved to a common place in dolphin . The passed in time value is either a relative time in nanoseconds or an absolute time in milliseconds . Either way it has to be unpacked into suitable seconds and nanoseconds components and stored in the given timespec structure . Given time is a 64 - bit value and the time_t used in the timespec is only a signed - 32 - bit value ( except on 64 - bit Bsd ) we have to watch for overflow if times way in the future are given . Further on Solaris versions prior to 10 there is a restriction that the specified number of seconds in abstime is less than current_time + 100 000 000 . As it will be 28 years before " now + 100000000 " will overflow we can ignore overflow and just impose a hard - limit on seconds using the value of " now + 100 000 000 " . This places a limit on the timeout of about 3 . 17 years from " now " .
static void unpackTime(struct timespec* absTime, bool isAbsolute, jlong time) {
  assert(time > 0, "convertTime");
  struct timeval now;
  int status = gettimeofday(&now, NULL);
  assert(status == 0, "gettimeofday");
  time_t max_secs = now.tv_sec + MAX_SECS;
  if (isAbsolute) {
    jlong secs = time / 1000;
    if (secs > max_secs) {
      absTime->tv_sec = max_secs;
    } else {
      absTime->tv_sec = secs;
    }
    absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC;
  } else {
    jlong secs = time / NANOSECS_PER_SEC;
    if (secs >= MAX_SECS) {
      absTime->tv_sec = max_secs;
      absTime->tv_nsec = 0;
    } else {
      absTime->tv_sec = now.tv_sec + secs;
      absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000;
      if (absTime->tv_nsec >= NANOSECS_PER_SEC) {
        absTime->tv_nsec -= NANOSECS_PER_SEC;
        ++absTime->tv_sec; 
      }
    }
  }
  assert(absTime->tv_sec >= 0, "tv_sec < 0");
  assert(absTime->tv_sec <= max_secs, "tv_sec > max_secs");
  assert(absTime->tv_nsec >= 0, "tv_nsec < 0");
  assert(absTime->tv_nsec < NANOSECS_PER_SEC, "tv_nsec >= nanos_per_sec");
}
static void unpackTime ( struct timespec * absTime , bool isAbsolute , jlong time ) { assert ( time > 0 , " " ) ; struct timeval now ; int status = gettimeofday ( & now , NULL ) ; assert ( status == 0 , " " ) ; time_t max_secs = now . tv_sec + MAX_SECS ; if ( isAbsolute ) { jlong secs = time / 1000 ; if ( secs > max_secs ) { absTime -> tv_sec = max_secs ; } else { absTime -> tv_sec = secs ; } absTime -> tv_nsec = ( time % 1000 ) * NANOSECS_PER_MILLISEC ; } else { jlong secs = time / NANOSECS_PER_SEC ; if ( secs >= MAX_SECS ) { absTime -> tv_sec = max_secs ; absTime -> tv_nsec = 0 ; } else { absTime -> tv_sec = now . tv_sec + secs ; absTime -> tv_nsec = ( time % NANOSECS_PER_SEC ) + now . tv_usec * 1000 ; if ( absTime -> tv_nsec >= NANOSECS_PER_SEC ) { absTime -> tv_nsec -= NANOSECS_PER_SEC ; ++ absTime -> tv_sec ; } } } assert ( absTime -> tv_sec >= 0 , " " ) ; assert ( absTime -> tv_sec <= max_secs , " " ) ; assert ( absTime -> tv_nsec >= 0 , " " ) ; assert ( absTime -> tv_nsec < NANOSECS_PER_SEC , " " ) ; }
This code is common to bsd and solaris and will be moved to a
common place in dolphin.
This code is common to bsd and solaris and will be moved to a common place in dolphin .
// note: this must be <= max_secs