Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "jni_internal.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 18 | #include "mirror/object.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 19 | #include "scoped_thread_state_change.h" |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 20 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 21 | // TODO: better support for overloading. |
| 22 | #undef NATIVE_METHOD |
| 23 | #define NATIVE_METHOD(className, functionName, signature, identifier) \ |
| 24 | { #functionName, signature, reinterpret_cast<void*>(className ## _ ## identifier) } |
| 25 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 26 | namespace art { |
| 27 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 28 | static jobject Object_internalClone(JNIEnv* env, jobject java_this) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 29 | ScopedObjectAccess soa(env); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | mirror::Object* o = soa.Decode<mirror::Object*>(java_this); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 31 | return soa.AddLocalReference<jobject>(o->Clone(soa.Self())); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 34 | static void Object_notify(JNIEnv* env, jobject java_this) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 35 | ScopedObjectAccess soa(env); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | mirror::Object* o = soa.Decode<mirror::Object*>(java_this); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 37 | o->Notify(); |
| 38 | } |
| 39 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 40 | static void Object_notifyAll(JNIEnv* env, jobject java_this) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 41 | ScopedObjectAccess soa(env); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | mirror::Object* o = soa.Decode<mirror::Object*>(java_this); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 43 | o->NotifyAll(); |
| 44 | } |
| 45 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 46 | static void Object_wait(JNIEnv* env, jobject java_this) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 47 | ScopedObjectAccess soa(env); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 48 | mirror::Object* o = soa.Decode<mirror::Object*>(java_this); |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 49 | o->Wait(); |
| 50 | } |
| 51 | |
| 52 | static void Object_waitJI(JNIEnv* env, jobject java_this, jlong ms, jint ns) { |
| 53 | ScopedObjectAccess soa(env); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 54 | mirror::Object* o = soa.Decode<mirror::Object*>(java_this); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 55 | o->Wait(ms, ns); |
| 56 | } |
| 57 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 58 | static JNINativeMethod gMethods[] = { |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 59 | NATIVE_METHOD(Object, internalClone, "()Ljava/lang/Object;", internalClone), |
| 60 | NATIVE_METHOD(Object, notify, "()V", notify), |
| 61 | NATIVE_METHOD(Object, notifyAll, "()V", notifyAll), |
| 62 | NATIVE_METHOD(Object, wait, "()V", wait), |
| 63 | NATIVE_METHOD(Object, wait, "(JI)V", waitJI), |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 66 | void register_java_lang_Object(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 67 | REGISTER_NATIVE_METHODS("java/lang/Object"); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } // namespace art |