diff options
author | Brian Carlstrom <bdc@google.com> | 2013-06-07 19:34:21 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-06-07 19:34:22 +0000 |
commit | 98ed9ca970a1b283bcfccbf3dbbd4d968458d452 (patch) | |
tree | 0ce9d5e03b521f832feec9ce13472cc4933c5aba /luni | |
parent | d1c6786d289258a054a57eaae6a0700b74fb0157 (diff) | |
parent | 22ccdd01e2fabc37d858be32291a854ff72f1840 (diff) | |
download | libcore-98ed9ca970a1b283bcfccbf3dbbd4d968458d452.zip libcore-98ed9ca970a1b283bcfccbf3dbbd4d968458d452.tar.gz libcore-98ed9ca970a1b283bcfccbf3dbbd4d968458d452.tar.bz2 |
Merge "Move System.currentTimeMillis, nanoTime, and mapLibraryName into the library."
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/native/java_lang_System.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
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 <limits.h> #include <stdlib.h> #include <string.h> +#include <sys/time.h> +#include <time.h> #include <unistd.h> 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;"), }; |