1bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes/*
2bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * Copyright (C) 2008 The Android Open Source Project
3bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes *
4bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
5bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * you may not use this file except in compliance with the License.
6bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * You may obtain a copy of the License at
7bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes *
8bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes *
10bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * Unless required by applicable law or agreed to in writing, software
11bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * See the License for the specific language governing permissions and
14bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes * limitations under the License.
15bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes */
16bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
17bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes#include "jni_internal.h"
1805f3057d6a4d23d712092ccd36a531590bff323bIan Rogers#include "mirror/object-inl.h"
1900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers#include "scoped_thread_state_change.h"
20bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
214cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes// TODO: better support for overloading.
224cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes#undef NATIVE_METHOD
234cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes#define NATIVE_METHOD(className, functionName, signature, identifier) \
244cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes    { #functionName, signature, reinterpret_cast<void*>(className ## _ ## identifier) }
254cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes
26bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughesnamespace art {
27bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
284cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughesstatic jobject Object_internalClone(JNIEnv* env, jobject java_this) {
2900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  ScopedObjectAccess soa(env);
302dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers  mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
3150b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers  return soa.AddLocalReference<jobject>(o->Clone(soa.Self()));
32bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes}
33bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
344cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughesstatic void Object_notify(JNIEnv* env, jobject java_this) {
3500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  ScopedObjectAccess soa(env);
362dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers  mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
3705f3057d6a4d23d712092ccd36a531590bff323bIan Rogers  o->Notify(soa.Self());
38bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes}
39bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
404cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughesstatic void Object_notifyAll(JNIEnv* env, jobject java_this) {
4100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  ScopedObjectAccess soa(env);
422dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers  mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
4305f3057d6a4d23d712092ccd36a531590bff323bIan Rogers  o->NotifyAll(soa.Self());
44bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes}
45bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
464cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughesstatic void Object_wait(JNIEnv* env, jobject java_this) {
474cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes  ScopedObjectAccess soa(env);
482dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers  mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
4905f3057d6a4d23d712092ccd36a531590bff323bIan Rogers  o->Wait(soa.Self());
504cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes}
514cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes
524cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughesstatic void Object_waitJI(JNIEnv* env, jobject java_this, jlong ms, jint ns) {
5300f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  ScopedObjectAccess soa(env);
542dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers  mirror::Object* o = soa.Decode<mirror::Object*>(java_this);
5505f3057d6a4d23d712092ccd36a531590bff323bIan Rogers  o->Wait(soa.Self(), ms, ns);
56bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes}
57bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
580512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughesstatic JNINativeMethod gMethods[] = {
594cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes  NATIVE_METHOD(Object, internalClone, "()Ljava/lang/Object;", internalClone),
604cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes  NATIVE_METHOD(Object, notify, "()V", notify),
614cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes  NATIVE_METHOD(Object, notifyAll, "()V", notifyAll),
624cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes  NATIVE_METHOD(Object, wait, "()V", wait),
634cd121ef0cb35fced70c7d9de378277be7a727d9Elliott Hughes  NATIVE_METHOD(Object, wait, "(JI)V", waitJI),
64bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes};
65bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
66bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughesvoid register_java_lang_Object(JNIEnv* env) {
67eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes  REGISTER_NATIVE_METHODS("java/lang/Object");
68bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes}
69bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
70bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes}  // namespace art
71