blob: 49cacdf156fd1494c5a705fd111ef0d29b12f5a9 [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
Andreas Gampe277ccbd2014-11-03 21:36:10 -080017#include "java_lang_Object.h"
18
Elliott Hughesbf86d042011-08-31 17:53:14 -070019#include "jni_internal.h"
Ian Rogers05f30572013-02-20 12:13:11 -080020#include "mirror/object-inl.h"
Ian Rogers1eb512d2013-10-18 15:42:20 -070021#include "scoped_fast_native_object_access.h"
Elliott Hughesbf86d042011-08-31 17:53:14 -070022
Elliott Hughes4cd121e2013-01-07 17:35:41 -080023// TODO: better support for overloading.
24#undef NATIVE_METHOD
25#define NATIVE_METHOD(className, functionName, signature, identifier) \
26 { #functionName, signature, reinterpret_cast<void*>(className ## _ ## identifier) }
27
Elliott Hughesbf86d042011-08-31 17:53:14 -070028namespace art {
29
Elliott Hughes4cd121e2013-01-07 17:35:41 -080030static jobject Object_internalClone(JNIEnv* env, jobject java_this) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070031 ScopedFastNativeObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Ian Rogers50b35e22012-10-04 10:09:15 -070033 return soa.AddLocalReference<jobject>(o->Clone(soa.Self()));
Elliott Hughesbf86d042011-08-31 17:53:14 -070034}
35
Elliott Hughes4cd121e2013-01-07 17:35:41 -080036static void Object_notify(JNIEnv* env, jobject java_this) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070037 ScopedFastNativeObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Ian Rogers05f30572013-02-20 12:13:11 -080039 o->Notify(soa.Self());
Elliott Hughesbf86d042011-08-31 17:53:14 -070040}
41
Elliott Hughes4cd121e2013-01-07 17:35:41 -080042static void Object_notifyAll(JNIEnv* env, jobject java_this) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070043 ScopedFastNativeObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Ian Rogers05f30572013-02-20 12:13:11 -080045 o->NotifyAll(soa.Self());
Elliott Hughesbf86d042011-08-31 17:53:14 -070046}
47
Elliott Hughes4cd121e2013-01-07 17:35:41 -080048static void Object_wait(JNIEnv* env, jobject java_this) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070049 ScopedFastNativeObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Ian Rogers05f30572013-02-20 12:13:11 -080051 o->Wait(soa.Self());
Elliott Hughes4cd121e2013-01-07 17:35:41 -080052}
53
54static void Object_waitJI(JNIEnv* env, jobject java_this, jlong ms, jint ns) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070055 ScopedFastNativeObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080056 mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
Ian Rogers05f30572013-02-20 12:13:11 -080057 o->Wait(soa.Self(), ms, ns);
Elliott Hughesbf86d042011-08-31 17:53:14 -070058}
59
Elliott Hughes0512f022012-03-15 22:10:52 -070060static JNINativeMethod gMethods[] = {
Ian Rogers1eb512d2013-10-18 15:42:20 -070061 NATIVE_METHOD(Object, internalClone, "!()Ljava/lang/Object;", internalClone),
62 NATIVE_METHOD(Object, notify, "!()V", notify),
63 NATIVE_METHOD(Object, notifyAll, "!()V", notifyAll),
64 NATIVE_METHOD(Object, wait, "!()V", wait),
65 NATIVE_METHOD(Object, wait, "!(JI)V", waitJI),
Elliott Hughesbf86d042011-08-31 17:53:14 -070066};
67
Elliott Hughesbf86d042011-08-31 17:53:14 -070068void register_java_lang_Object(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -070069 REGISTER_NATIVE_METHODS("java/lang/Object");
Elliott Hughesbf86d042011-08-31 17:53:14 -070070}
71
72} // namespace art