blob: d52bf0490bf3c479630cc21cfed4499d681af1c3 [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
Andreas Gampea14100c2017-04-24 15:09:56 -070019#include "nativehelper/jni_macros.h"
20
Elliott Hughesbf86d042011-08-31 17:53:14 -070021#include "jni_internal.h"
Ian Rogers05f30572013-02-20 12:13:11 -080022#include "mirror/object-inl.h"
Andreas Gampe87583b32017-05-25 11:22:18 -070023#include "native_util.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070024#include "scoped_fast_native_object_access-inl.h"
Elliott Hughesbf86d042011-08-31 17:53:14 -070025
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 Rogers1eb512d2013-10-18 15:42:20 -070029 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070030 ObjPtr<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 Rogers1eb512d2013-10-18 15:42:20 -070035 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070036 soa.Decode<mirror::Object>(java_this)->Notify(soa.Self());
Elliott Hughesbf86d042011-08-31 17:53:14 -070037}
38
Elliott Hughes4cd121e2013-01-07 17:35:41 -080039static void Object_notifyAll(JNIEnv* env, jobject java_this) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070040 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070041 soa.Decode<mirror::Object>(java_this)->NotifyAll(soa.Self());
Elliott Hughesbf86d042011-08-31 17:53:14 -070042}
43
Elliott Hughes4cd121e2013-01-07 17:35:41 -080044static void Object_wait(JNIEnv* env, jobject java_this) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070045 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070046 soa.Decode<mirror::Object>(java_this)->Wait(soa.Self());
Elliott Hughes4cd121e2013-01-07 17:35:41 -080047}
48
49static void Object_waitJI(JNIEnv* env, jobject java_this, jlong ms, jint ns) {
Ian Rogers1eb512d2013-10-18 15:42:20 -070050 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070051 soa.Decode<mirror::Object>(java_this)->Wait(soa.Self(), ms, ns);
Elliott Hughesbf86d042011-08-31 17:53:14 -070052}
53
Nicolas Geoffray6e311ac2017-02-27 11:46:03 +000054static jint Object_identityHashCodeNative(JNIEnv* env, jclass, jobject javaObject) {
55 ScopedFastNativeObjectAccess soa(env);
56 ObjPtr<mirror::Object> o = soa.Decode<mirror::Object>(javaObject);
57 return static_cast<jint>(o->IdentityHashCode());
58}
59
Elliott Hughes0512f022012-03-15 22:10:52 -070060static JNINativeMethod gMethods[] = {
Igor Murashkin3b6f4402017-02-16 16:13:17 -080061 FAST_NATIVE_METHOD(Object, internalClone, "()Ljava/lang/Object;"),
62 FAST_NATIVE_METHOD(Object, notify, "()V"),
63 FAST_NATIVE_METHOD(Object, notifyAll, "()V"),
64 OVERLOADED_FAST_NATIVE_METHOD(Object, wait, "()V", wait),
65 OVERLOADED_FAST_NATIVE_METHOD(Object, wait, "(JI)V", waitJI),
Nicolas Geoffray6e311ac2017-02-27 11:46:03 +000066 FAST_NATIVE_METHOD(Object, identityHashCodeNative, "(Ljava/lang/Object;)I"),
Elliott Hughesbf86d042011-08-31 17:53:14 -070067};
68
Elliott Hughesbf86d042011-08-31 17:53:14 -070069void register_java_lang_Object(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -070070 REGISTER_NATIVE_METHODS("java/lang/Object");
Elliott Hughesbf86d042011-08-31 17:53:14 -070071}
72
73} // namespace art