From 22ccdd01e2fabc37d858be32291a854ff72f1840 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 31 Aug 2011 10:28:27 -0700 Subject: Move System.currentTimeMillis, nanoTime, and mapLibraryName into the library. (cherry-picked from commit 37d6cc06f62b2029663137a1b8c18242152c1e97) Change-Id: I3b3aa3f508b9c6f43b27022cd8bc9aa82e630e01 --- luni/src/main/native/java_lang_System.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'luni') diff --git a/luni/src/main/native/java_lang_System.cpp b/luni/src/main/native/java_lang_System.cpp index 8cfd070..0686310 100644 --- a/luni/src/main/native/java_lang_System.cpp +++ b/luni/src/main/native/java_lang_System.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include static void System_log(JNIEnv* env, jclass, jchar type, jstring javaMessage, jthrowable exception) { @@ -83,8 +85,36 @@ static jobjectArray System_specialProperties(JNIEnv* env, jclass) { return toStringArray(env, properties); } +static jlong System_currentTimeMillis(JNIEnv*, jclass) { + timeval now; + gettimeofday(&now, NULL); + jlong when = now.tv_sec * 1000LL + now.tv_usec / 1000; + return when; +} + +static jlong System_nanoTime(JNIEnv*, jclass) { + timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return now.tv_sec * 1000000000LL + now.tv_nsec; +} + +static jstring System_mapLibraryName(JNIEnv* env, jclass, jstring javaName) { + ScopedUtfChars name(env, javaName); + if (name.c_str() == NULL) { + return NULL; + } + char* mappedName = NULL; + asprintf(&mappedName, OS_SHARED_LIB_FORMAT_STR, name.c_str()); + jstring result = env->NewStringUTF(mappedName); + free(mappedName); + return result; +} + static JNINativeMethod gMethods[] = { + NATIVE_METHOD(System, currentTimeMillis, "()J"), NATIVE_METHOD(System, log, "(CLjava/lang/String;Ljava/lang/Throwable;)V"), + NATIVE_METHOD(System, mapLibraryName, "(Ljava/lang/String;)Ljava/lang/String;"), + NATIVE_METHOD(System, nanoTime, "()J"), NATIVE_METHOD(System, setFieldImpl, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V"), NATIVE_METHOD(System, specialProperties, "()[Ljava/lang/String;"), }; -- cgit v1.1