From 0563022a206294757effa44686727bffc4f7c2bd Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Fri, 23 Mar 2012 15:19:26 +0000 Subject: Merge GNU Classpath 0.99 into libjava. From-SVN: r185741 --- .../native/jni/java-lang/java_lang_VMSystem.c | 52 ++++++++++++++++++---- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'libjava/classpath/native/jni/java-lang') diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c b/libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c index d203227..f623857 100644 --- a/libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c +++ b/libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c @@ -39,8 +39,12 @@ exception statement from your version. */ #include +#include #include #include +#include +#include +#include /* * Class: java_lang_VMSystem @@ -111,6 +115,22 @@ Java_java_lang_VMSystem_setErr (JNIEnv * env, (*env)->SetStaticObjectField (env, cls, field, obj); } +static jlong currentTimeMicros(JNIEnv * env) +{ + /* Note: this implementation copied directly from Japhar's, by Chris Toshok. */ + jlong result; + struct timeval tp; + + if (gettimeofday (&tp, NULL) == -1) + (*env)->FatalError (env, "gettimeofday call failed."); + + result = (jlong) tp.tv_sec; + result *= (jlong)1000000L; + result += (jlong)tp.tv_usec; + + return result; +} + /* * Class: java_lang_VMSystem * Method: nanoTime @@ -118,22 +138,38 @@ Java_java_lang_VMSystem_setErr (JNIEnv * env, */ JNIEXPORT jlong JNICALL Java_java_lang_VMSystem_nanoTime - (JNIEnv * env __attribute__ ((__unused__)), + (JNIEnv * env, jclass thisClass __attribute__ ((__unused__))) { - /* Note: this implementation copied directly from Japhar's, by Chris Toshok. */ +#if defined(HAVE_CLOCK_GETTIME) && defined(_POSIX_MONOTONIC_CLOCK) jlong result; - struct timeval tp; + struct timespec tp; - if (gettimeofday (&tp, NULL) == -1) - (*env)->FatalError (env, "gettimeofday call failed."); + if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) { + return currentTimeMicros(env) * (jlong)1000; + } result = (jlong) tp.tv_sec; - result *= (jlong)1000000L; - result += (jlong)tp.tv_usec; - result *= (jlong)1000; + result *= (jlong)1000000000L; + result += (jlong)tp.tv_nsec; return result; +#else + return currentTimeMicros(env) * (jlong)1000; +#endif +} + +/* + * Class: java_lang_VMSystem + * Method: currentTimeMillis + * Signature: ()J + */ +JNIEXPORT jlong JNICALL +Java_java_lang_VMSystem_currentTimeMillis + (JNIEnv * env, + jclass thisClass __attribute__ ((__unused__))) +{ + return currentTimeMicros(env) / (jlong)1000L; } JNIEXPORT jstring JNICALL -- cgit v1.1