summaryrefslogtreecommitdiff
path: root/src/native/java_lang_Object.cc
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2013-01-07 17:35:41 -0800
committer Elliott Hughes <enh@google.com> 2013-01-08 11:06:02 -0800
commit4cd121ef0cb35fced70c7d9de378277be7a727d9 (patch)
treec786e70cfe50147749d9dd7494dd7112271c8f60 /src/native/java_lang_Object.cc
parent1a25aa432314bcf008c11e3514afc0b7aeb64d5c (diff)
Implement the Thread.sleep native method.
This makes returning TS_SLEEPING from JDWP simple and cheap, and makes the stack dumps for sleeping threads more easily understood by app developers (because there's no Object.wait magic going, and the thread state is "Sleeping" rather than "TimedWaiting"). Also make Object.wait() a native method in its own right, so every call into Monitor::Wait can explicitly pass the most appropriate ThreadState: kSleeping, kWaiting, or kTimedWaiting. Also add Thread.sleep and Object.wait(long, int) calls to the ThreadStress test. Change-Id: I49adb45dbcd669eba7cf3def45e6cbfc461a3254
Diffstat (limited to 'src/native/java_lang_Object.cc')
-rw-r--r--src/native/java_lang_Object.cc36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/native/java_lang_Object.cc b/src/native/java_lang_Object.cc
index bcea373365..f3c295e6dc 100644
--- a/src/native/java_lang_Object.cc
+++ b/src/native/java_lang_Object.cc
@@ -18,37 +18,49 @@
#include "object.h"
#include "scoped_thread_state_change.h"
+// TODO: better support for overloading.
+#undef NATIVE_METHOD
+#define NATIVE_METHOD(className, functionName, signature, identifier) \
+ { #functionName, signature, reinterpret_cast<void*>(className ## _ ## identifier) }
+
namespace art {
-static jobject Object_internalClone(JNIEnv* env, jobject javaThis) {
+static jobject Object_internalClone(JNIEnv* env, jobject java_this) {
ScopedObjectAccess soa(env);
- Object* o = soa.Decode<Object*>(javaThis);
+ Object* o = soa.Decode<Object*>(java_this);
return soa.AddLocalReference<jobject>(o->Clone(soa.Self()));
}
-static void Object_notify(JNIEnv* env, jobject javaThis) {
+static void Object_notify(JNIEnv* env, jobject java_this) {
ScopedObjectAccess soa(env);
- Object* o = soa.Decode<Object*>(javaThis);
+ Object* o = soa.Decode<Object*>(java_this);
o->Notify();
}
-static void Object_notifyAll(JNIEnv* env, jobject javaThis) {
+static void Object_notifyAll(JNIEnv* env, jobject java_this) {
ScopedObjectAccess soa(env);
- Object* o = soa.Decode<Object*>(javaThis);
+ Object* o = soa.Decode<Object*>(java_this);
o->NotifyAll();
}
-static void Object_wait(JNIEnv* env, jobject javaThis, jlong ms, jint ns) {
+static void Object_wait(JNIEnv* env, jobject java_this) {
+ ScopedObjectAccess soa(env);
+ Object* o = soa.Decode<Object*>(java_this);
+ o->Wait();
+}
+
+static void Object_waitJI(JNIEnv* env, jobject java_this, jlong ms, jint ns) {
ScopedObjectAccess soa(env);
- Object* o = soa.Decode<Object*>(javaThis);
+ Object* o = soa.Decode<Object*>(java_this);
o->Wait(ms, ns);
}
static JNINativeMethod gMethods[] = {
- NATIVE_METHOD(Object, internalClone, "()Ljava/lang/Object;"),
- NATIVE_METHOD(Object, notify, "()V"),
- NATIVE_METHOD(Object, notifyAll, "()V"),
- NATIVE_METHOD(Object, wait, "(JI)V"),
+ NATIVE_METHOD(Object, internalClone, "()Ljava/lang/Object;", internalClone),
+ NATIVE_METHOD(Object, notify, "()V", notify),
+ NATIVE_METHOD(Object, notifyAll, "()V", notifyAll),
+ NATIVE_METHOD(Object, wait, "()V", wait),
+ NATIVE_METHOD(Object, wait, "(JI)V", waitJI),
};
void register_java_lang_Object(JNIEnv* env) {