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 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 17 | #include "java_lang_Object.h" |
| 18 | |
Andreas Gampe | a14100c | 2017-04-24 15:09:56 -0700 | [diff] [blame] | 19 | #include "nativehelper/jni_macros.h" |
| 20 | |
Vladimir Marko | 3068d58 | 2019-05-28 16:39:29 +0100 | [diff] [blame] | 21 | #include "handle_scope-inl.h" |
Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 22 | #include "jni/jni_internal.h" |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 23 | #include "mirror/object-inl.h" |
Andreas Gampe | 87583b3 | 2017-05-25 11:22:18 -0700 | [diff] [blame] | 24 | #include "native_util.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 25 | #include "scoped_fast_native_object_access-inl.h" |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 26 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 27 | namespace art { |
| 28 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 29 | static jobject Object_internalClone(JNIEnv* env, jobject java_this) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 30 | ScopedFastNativeObjectAccess soa(env); |
Vladimir Marko | 3068d58 | 2019-05-28 16:39:29 +0100 | [diff] [blame] | 31 | StackHandleScope<1u> hs(soa.Self()); |
| 32 | Handle<mirror::Object> o = hs.NewHandle(soa.Decode<mirror::Object>(java_this)); |
| 33 | return soa.AddLocalReference<jobject>(mirror::Class::Clone(o, soa.Self())); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 36 | static void Object_notify(JNIEnv* env, jobject java_this) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 37 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 38 | soa.Decode<mirror::Object>(java_this)->Notify(soa.Self()); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 41 | static void Object_notifyAll(JNIEnv* env, jobject java_this) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 42 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 43 | soa.Decode<mirror::Object>(java_this)->NotifyAll(soa.Self()); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 46 | static void Object_waitJI(JNIEnv* env, jobject java_this, jlong ms, jint ns) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 47 | ScopedFastNativeObjectAccess soa(env); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 48 | soa.Decode<mirror::Object>(java_this)->Wait(soa.Self(), ms, ns); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Nicolas Geoffray | 6e311ac | 2017-02-27 11:46:03 +0000 | [diff] [blame] | 51 | static jint Object_identityHashCodeNative(JNIEnv* env, jclass, jobject javaObject) { |
| 52 | ScopedFastNativeObjectAccess soa(env); |
| 53 | ObjPtr<mirror::Object> o = soa.Decode<mirror::Object>(javaObject); |
| 54 | return static_cast<jint>(o->IdentityHashCode()); |
| 55 | } |
| 56 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 57 | static JNINativeMethod gMethods[] = { |
Igor Murashkin | 3b6f440 | 2017-02-16 16:13:17 -0800 | [diff] [blame] | 58 | FAST_NATIVE_METHOD(Object, internalClone, "()Ljava/lang/Object;"), |
| 59 | FAST_NATIVE_METHOD(Object, notify, "()V"), |
| 60 | FAST_NATIVE_METHOD(Object, notifyAll, "()V"), |
Igor Murashkin | 3b6f440 | 2017-02-16 16:13:17 -0800 | [diff] [blame] | 61 | OVERLOADED_FAST_NATIVE_METHOD(Object, wait, "(JI)V", waitJI), |
Nicolas Geoffray | 6e311ac | 2017-02-27 11:46:03 +0000 | [diff] [blame] | 62 | FAST_NATIVE_METHOD(Object, identityHashCodeNative, "(Ljava/lang/Object;)I"), |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 65 | void register_java_lang_Object(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 66 | REGISTER_NATIVE_METHODS("java/lang/Object"); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } // namespace art |