aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/native/jni/java-lang
diff options
context:
space:
mode:
authorAndrew John Hughes <gandalf@gcc.gnu.org>2012-03-23 15:19:26 +0000
committerAndrew John Hughes <gandalf@gcc.gnu.org>2012-03-23 15:19:26 +0000
commit0563022a206294757effa44686727bffc4f7c2bd (patch)
treefebe3d4d4c0c994db223fee8e819bde6582494c9 /libjava/classpath/native/jni/java-lang
parent21669dfe20db0246ece395db5558a081a5c7088f (diff)
downloadgcc-0563022a206294757effa44686727bffc4f7c2bd.zip
gcc-0563022a206294757effa44686727bffc4f7c2bd.tar.gz
gcc-0563022a206294757effa44686727bffc4f7c2bd.tar.bz2
Merge GNU Classpath 0.99 into libjava.
From-SVN: r185741
Diffstat (limited to 'libjava/classpath/native/jni/java-lang')
-rw-r--r--libjava/classpath/native/jni/java-lang/java_lang_VMSystem.c52
1 files changed, 44 insertions, 8 deletions
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 <jcl.h>
+#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
/*
* 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