blob: 606e656f3c07aab4a94dcb937a0ef73739e210d9 [file] [log] [blame]
Mathieu Chartier78f7b4c2014-05-06 10:57:27 -07001/*
2 * Copyright (C) 2014 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_ref_Reference.h"
18
Andreas Gampea14100c2017-04-24 15:09:56 -070019#include "nativehelper/jni_macros.h"
20
Mathieu Chartier78f7b4c2014-05-06 10:57:27 -070021#include "gc/heap.h"
22#include "gc/reference_processor.h"
23#include "jni_internal.h"
24#include "mirror/object-inl.h"
25#include "mirror/reference-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070026#include "scoped_fast_native_object_access-inl.h"
Mathieu Chartier78f7b4c2014-05-06 10:57:27 -070027
28namespace art {
29
Mathieu Chartiercd48f2d2014-09-09 13:51:09 -070030static jobject Reference_getReferent(JNIEnv* env, jobject javaThis) {
Mathieu Chartier78f7b4c2014-05-06 10:57:27 -070031 ScopedFastNativeObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070032 ObjPtr<mirror::Reference> ref = soa.Decode<mirror::Reference>(javaThis);
Mathieu Chartier5d3f73a2016-10-14 14:28:47 -070033 ObjPtr<mirror::Object> const referent =
34 Runtime::Current()->GetHeap()->GetReferenceProcessor()->GetReferent(soa.Self(), ref);
Mathieu Chartier78f7b4c2014-05-06 10:57:27 -070035 return soa.AddLocalReference<jobject>(referent);
36}
37
Mathieu Chartier6f43e3a2016-12-14 14:12:17 -080038static void Reference_clearReferent(JNIEnv* env, jobject javaThis) {
Mathieu Chartierc9a70282016-12-13 14:44:33 -080039 ScopedFastNativeObjectAccess soa(env);
40 ObjPtr<mirror::Reference> ref = soa.Decode<mirror::Reference>(javaThis);
41 Runtime::Current()->GetHeap()->GetReferenceProcessor()->ClearReferent(ref);
42}
43
Mathieu Chartier78f7b4c2014-05-06 10:57:27 -070044static JNINativeMethod gMethods[] = {
Igor Murashkin3b6f4402017-02-16 16:13:17 -080045 FAST_NATIVE_METHOD(Reference, getReferent, "()Ljava/lang/Object;"),
46 FAST_NATIVE_METHOD(Reference, clearReferent, "()V"),
Mathieu Chartier78f7b4c2014-05-06 10:57:27 -070047};
48
49void register_java_lang_ref_Reference(JNIEnv* env) {
50 REGISTER_NATIVE_METHODS("java/lang/ref/Reference");
51}
52
53} // namespace art