blob: 75d5f70bef773dcbfc4b4c16aaa334bb5f87bb43 [file] [log] [blame]
Elliott Hughesbf86d042011-08-31 17:53:14 -07001/*
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 Rogers2dd0e2c2013-01-24 12:42:14 -080018#include "mirror/object.h"
Ian Rogers00f7d0e2012-07-19 15:28:27 -070019#include "scoped_thread_state_change.h"
Elliott Hughesbf86d042011-08-31 17:53:14 -070020
Elliott Hughes4cd121e2013-01-07 17:35:41 -080021// 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 Hughesbf86d042011-08-31 17:53:14 -070026namespace art {
27
Elliott Hughes4cd121e2013-01-07 17:35:41 -080028static jobject Object_internalClone(JNIEnv* env, jobject java_this) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070029 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Ian Rogers50b35e22012-10-04 10:09:15 -070031 return soa.AddLocalReference<jobject>(o->Clone(soa.Self()));
Elliott Hughesbf86d042011-08-31 17:53:14 -070032}
33
Elliott Hughes4cd121e2013-01-07 17:35:41 -080034static void Object_notify(JNIEnv* env, jobject java_this) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070035 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Elliott Hughesbf86d042011-08-31 17:53:14 -070037 o->Notify();
38}
39
Elliott Hughes4cd121e2013-01-07 17:35:41 -080040static void Object_notifyAll(JNIEnv* env, jobject java_this) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070041 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Elliott Hughesbf86d042011-08-31 17:53:14 -070043 o->NotifyAll();
44}
45
Elliott Hughes4cd121e2013-01-07 17:35:41 -080046static void Object_wait(JNIEnv* env, jobject java_this) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070047 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Elliott Hughes4cd121e2013-01-07 17:35:41 -080049 o->Wait();
50}
51
52static void Object_waitJI(JNIEnv* env, jobject java_this, jlong ms, jint ns) {
53 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080054 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Elliott Hughesbf86d042011-08-31 17:53:14 -070055 o->Wait(ms, ns);
56}
57
Elliott Hughes0512f022012-03-15 22:10:52 -070058static JNINativeMethod gMethods[] = {
Elliott Hughes4cd121e2013-01-07 17:35:41 -080059 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 Hughesbf86d042011-08-31 17:53:14 -070064};
65
Elliott Hughesbf86d042011-08-31 17:53:14 -070066void register_java_lang_Object(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -070067 REGISTER_NATIVE_METHODS("java/lang/Object");
Elliott Hughesbf86d042011-08-31 17:53:14 -070068}
69
70} // namespace art