hotspot/src/share/vm/prims/jvm.cpp
changeset 28737 ca4b6a6e5cc8
parent 28731 f7339cba0a6a
child 28744 4283637ac96e
child 28947 2ea471384931
equal deleted inserted replaced
28736:33ab13e70aa0 28737:ca4b6a6e5cc8
   298 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
   298 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
   299   JVMWrapper("JVM_NanoTime");
   299   JVMWrapper("JVM_NanoTime");
   300   return os::javaTimeNanos();
   300   return os::javaTimeNanos();
   301 JVM_END
   301 JVM_END
   302 
   302 
       
   303 // The function below is actually exposed by sun.misc.VM and not
       
   304 // java.lang.System, but we choose to keep it here so that it stays next
       
   305 // to JVM_CurrentTimeMillis and JVM_NanoTime
       
   306 
       
   307 const jlong MAX_DIFF_SECS = 0x0100000000;   //  2^32
       
   308 const jlong MIN_DIFF_SECS = -MAX_DIFF_SECS; // -2^32
       
   309 
       
   310 JVM_LEAF(jlong, JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs))
       
   311   JVMWrapper("JVM_GetNanoTimeAdjustment");
       
   312   jlong seconds;
       
   313   jlong nanos;
       
   314 
       
   315   os::javaTimeSystemUTC(seconds, nanos);
       
   316 
       
   317   // We're going to verify that the result can fit in a long.
       
   318   // For that we need the difference in seconds between 'seconds'
       
   319   // and 'offset_secs' to be such that:
       
   320   //     |seconds - offset_secs| < (2^63/10^9)
       
   321   // We're going to approximate 10^9 ~< 2^30 (1000^3 ~< 1024^3)
       
   322   // which makes |seconds - offset_secs| < 2^33
       
   323   // and we will prefer +/- 2^32 as the maximum acceptable diff
       
   324   // as 2^32 has a more natural feel than 2^33...
       
   325   //
       
   326   // So if |seconds - offset_secs| >= 2^32 - we return a special
       
   327   // sentinel value (-1) which the caller should take as an
       
   328   // exception value indicating that the offset given to us is
       
   329   // too far from range of the current time - leading to too big
       
   330   // a nano adjustment. The caller is expected to recover by
       
   331   // computing a more accurate offset and calling this method
       
   332   // again. (For the record 2^32 secs is ~136 years, so that
       
   333   // should rarely happen)
       
   334   //
       
   335   jlong diff = seconds - offset_secs;
       
   336   if (diff >= MAX_DIFF_SECS || diff <= MIN_DIFF_SECS) {
       
   337      return -1; // sentinel value: the offset is too far off the target
       
   338   }
       
   339 
       
   340   // return the adjustment. If you compute a time by adding
       
   341   // this number of nanoseconds along with the number of seconds
       
   342   // in the offset you should get the current UTC time.
       
   343   return (diff * (jlong)1000000000) + nanos;
       
   344 JVM_END
   303 
   345 
   304 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
   346 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
   305                                jobject dst, jint dst_pos, jint length))
   347                                jobject dst, jint dst_pos, jint length))
   306   JVMWrapper("JVM_ArrayCopy");
   348   JVMWrapper("JVM_ArrayCopy");
   307   // Check if we have null pointers
   349   // Check if we have null pointers