blob: 553aeb8f12a83dbb08d164d252f409ada504c3c2 [file] [log] [blame]
Brian Carlstromf867b6f2011-09-16 12:17:25 -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
Brian Carlstromf867b6f2011-09-16 12:17:25 -070017#include "class_linker.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080018#include "class_linker-inl.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080019#include "common_throws.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070020#include "dex_file-inl.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070021#include "jni_internal.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070022#include "mirror/art_field-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070023#include "mirror/class-inl.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080024#include "object_utils.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070025#include "reflection.h"
Ian Rogers1eb512d2013-10-18 15:42:20 -070026#include "scoped_fast_native_object_access.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070027
Brian Carlstromf867b6f2011-09-16 12:17:25 -070028namespace art {
29
Ian Rogers1eb512d2013-10-18 15:42:20 -070030static bool GetFieldValue(const ScopedFastNativeObjectAccess& soa, mirror::Object* o,
31 mirror::ArtField* f, JValue& value, bool allow_references)
Ian Rogersb726dcb2012-09-05 08:57:23 -070032 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070033 DCHECK_EQ(value.GetJ(), 0LL);
Mathieu Chartierc528dba2013-11-26 12:00:11 -080034 CHECK(!kMovingFields);
35 SirtRef<mirror::Object> sirt_obj(soa.Self(), o);
36 SirtRef<mirror::Class> sirt_klass(soa.Self(), f->GetDeclaringClass());
37 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(sirt_klass, true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -070038 return false;
39 }
Mathieu Chartierc528dba2013-11-26 12:00:11 -080040 o = sirt_obj.get();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080041 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070042 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070043 value.SetZ(f->GetBoolean(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070044 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070045 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070046 value.SetB(f->GetByte(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070047 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070048 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070049 value.SetC(f->GetChar(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070050 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070051 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070052 value.SetD(f->GetDouble(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070053 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070054 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070055 value.SetF(f->GetFloat(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070056 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070057 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070058 value.SetI(f->GetInt(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070059 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070060 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070061 value.SetJ(f->GetLong(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070062 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070063 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070064 value.SetS(f->GetShort(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070065 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070066 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -070067 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070068 value.SetL(f->GetObject(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070069 return true;
70 }
71 // Else break to report an error.
72 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070073 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -070074 // Never okay.
75 break;
76 }
Ian Rogers62d6c772013-02-27 08:32:07 -080077 ThrowIllegalArgumentException(NULL,
78 StringPrintf("Not a primitive field: %s",
79 PrettyField(f).c_str()).c_str());
Elliott Hughes33203b52011-09-20 19:42:01 -070080 return false;
81}
82
Ian Rogers1eb512d2013-10-18 15:42:20 -070083static bool CheckReceiver(const ScopedFastNativeObjectAccess& soa, jobject j_rcvr,
84 mirror::ArtField* f, mirror::Object*& class_or_rcvr)
Ian Rogersb726dcb2012-09-05 08:57:23 -070085 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070086 if (f->IsStatic()) {
Ian Rogers62d6c772013-02-27 08:32:07 -080087 class_or_rcvr = f->GetDeclaringClass();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070088 return true;
89 }
90
Ian Rogers62d6c772013-02-27 08:32:07 -080091 class_or_rcvr = soa.Decode<mirror::Object*>(j_rcvr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080092 mirror::Class* declaringClass = f->GetDeclaringClass();
Ian Rogers62d6c772013-02-27 08:32:07 -080093 if (!VerifyObjectInClass(class_or_rcvr, declaringClass)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070094 return false;
95 }
96 return true;
97}
98
Elliott Hughes0512f022012-03-15 22:10:52 -070099static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700100 ScopedFastNativeObjectAccess soa(env);
Brian Carlstromea46f952013-07-30 01:26:50 -0700101 mirror::ArtField* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800102 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700103 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800104 return NULL;
105 }
106
107 // Get the field's value, boxing if necessary.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700108 JValue value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700109 if (!GetFieldValue(soa, o, f, value, true)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800110 return NULL;
111 }
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800112 return
113 soa.AddLocalReference<jobject>(BoxPrimitive(FieldHelper(f).GetTypeAsPrimitiveType(), value));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800114}
115
Brian Carlstromea46f952013-07-30 01:26:50 -0700116static JValue GetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj,
117 char dst_descriptor) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700118 ScopedFastNativeObjectAccess soa(env);
Brian Carlstromea46f952013-07-30 01:26:50 -0700119 mirror::ArtField* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700121 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700122 return JValue();
Elliott Hughes33203b52011-09-20 19:42:01 -0700123 }
124
125 // Read the value.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700126 JValue field_value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700127 if (!GetFieldValue(soa, o, f, field_value, false)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700128 return JValue();
129 }
130
131 // Widen it if necessary (and possible).
132 JValue wide_value;
Brian Carlstromea46f952013-07-30 01:26:50 -0700133 mirror::Class* dst_type =
134 Runtime::Current()->GetClassLinker()->FindPrimitiveClass(dst_descriptor);
Ian Rogers62d6c772013-02-27 08:32:07 -0800135 if (!ConvertPrimitiveValue(NULL, false, FieldHelper(f).GetTypeAsPrimitiveType(),
136 dst_type->GetPrimitiveType(), field_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700137 return JValue();
138 }
139 return wide_value;
140}
141
Elliott Hughes0512f022012-03-15 22:10:52 -0700142static jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700143 return GetPrimitiveField(env, javaField, javaObj, 'Z').GetZ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700144}
145
Elliott Hughes0512f022012-03-15 22:10:52 -0700146static jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700147 return GetPrimitiveField(env, javaField, javaObj, 'B').GetB();
Elliott Hughes33203b52011-09-20 19:42:01 -0700148}
149
Elliott Hughes0512f022012-03-15 22:10:52 -0700150static jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700151 return GetPrimitiveField(env, javaField, javaObj, 'C').GetC();
Elliott Hughes33203b52011-09-20 19:42:01 -0700152}
153
Elliott Hughes0512f022012-03-15 22:10:52 -0700154static jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700155 return GetPrimitiveField(env, javaField, javaObj, 'D').GetD();
Elliott Hughes33203b52011-09-20 19:42:01 -0700156}
157
Elliott Hughes0512f022012-03-15 22:10:52 -0700158static jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700159 return GetPrimitiveField(env, javaField, javaObj, 'F').GetF();
Elliott Hughes33203b52011-09-20 19:42:01 -0700160}
161
Elliott Hughes0512f022012-03-15 22:10:52 -0700162static jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700163 return GetPrimitiveField(env, javaField, javaObj, 'I').GetI();
Elliott Hughes33203b52011-09-20 19:42:01 -0700164}
165
Elliott Hughes0512f022012-03-15 22:10:52 -0700166static jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700167 return GetPrimitiveField(env, javaField, javaObj, 'J').GetJ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700168}
169
Elliott Hughes0512f022012-03-15 22:10:52 -0700170static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700171 return GetPrimitiveField(env, javaField, javaObj, 'S').GetS();
Elliott Hughes33203b52011-09-20 19:42:01 -0700172}
173
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800174static void SetFieldValue(ScopedFastNativeObjectAccess& soa, mirror::Object* o,
175 mirror::ArtField* f, const JValue& new_value, bool allow_references)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700176 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800177 CHECK(!kMovingFields);
178 SirtRef<mirror::Object> sirt_obj(soa.Self(), o);
179 SirtRef<mirror::Class> sirt_klass(soa.Self(), f->GetDeclaringClass());
180 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(sirt_klass, true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -0700181 return;
182 }
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800183 o = sirt_obj.get();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800184 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700185 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700186 f->SetBoolean(o, new_value.GetZ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700187 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700188 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700189 f->SetByte(o, new_value.GetB());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700190 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700191 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700192 f->SetChar(o, new_value.GetC());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700193 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700194 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700195 f->SetDouble(o, new_value.GetD());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700196 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700197 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700198 f->SetFloat(o, new_value.GetF());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700199 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700200 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700201 f->SetInt(o, new_value.GetI());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700202 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700203 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700204 f->SetLong(o, new_value.GetJ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700205 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700206 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700207 f->SetShort(o, new_value.GetS());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700208 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700209 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -0700210 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700211 f->SetObject(o, new_value.GetL());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700212 break;
Elliott Hughes33203b52011-09-20 19:42:01 -0700213 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700214 // Else fall through to report an error.
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700215 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -0700216 // Never okay.
Ian Rogers62d6c772013-02-27 08:32:07 -0800217 ThrowIllegalArgumentException(NULL, StringPrintf("Not a primitive field: %s",
218 PrettyField(f).c_str()).c_str());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700219 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700220 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700221
222 // Special handling for final fields on SMP systems.
223 // We need a store/store barrier here (JMM requirement).
224 if (f->IsFinal()) {
225 ANDROID_MEMBAR_STORE();
226 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700227}
228
Elliott Hughes0512f022012-03-15 22:10:52 -0700229static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700230 ScopedFastNativeObjectAccess soa(env);
Brian Carlstromea46f952013-07-30 01:26:50 -0700231 mirror::ArtField* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800232
233 // Unbox the value, if necessary.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800234 mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800235 JValue unboxed_value;
Elliott Hughesaaa5edc2012-05-16 15:54:30 -0700236 if (!UnboxPrimitiveForField(boxed_value, FieldHelper(f).GetType(), unboxed_value, f)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800237 return;
238 }
239
240 // Check that the receiver is non-null and an instance of the field's declaring class.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800241 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700242 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800243 return;
244 }
245
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800246 SetFieldValue(soa, o, f, unboxed_value, true);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800247}
248
Elliott Hughes0512f022012-03-15 22:10:52 -0700249static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor,
250 const JValue& new_value) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700251 ScopedFastNativeObjectAccess soa(env);
Brian Carlstromea46f952013-07-30 01:26:50 -0700252 mirror::ArtField* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800253 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700254 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700255 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700256 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800257 FieldHelper fh(f);
258 if (!fh.IsPrimitiveType()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800259 ThrowIllegalArgumentException(NULL, StringPrintf("Not a primitive field: %s",
260 PrettyField(f).c_str()).c_str());
Jesse Wilsonc129a6b2011-11-24 14:47:46 -0500261 return;
262 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700263
264 // Widen the value if necessary (and possible).
265 JValue wide_value;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800266 mirror::Class* src_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(src_descriptor);
Ian Rogers62d6c772013-02-27 08:32:07 -0800267 if (!ConvertPrimitiveValue(NULL, false, src_type->GetPrimitiveType(), fh.GetTypeAsPrimitiveType(),
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700268 new_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700269 return;
270 }
271
272 // Write the value.
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800273 SetFieldValue(soa, o, f, wide_value, false);
Elliott Hughes33203b52011-09-20 19:42:01 -0700274}
275
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700276static void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean z) {
277 JValue value;
278 value.SetZ(z);
279 SetPrimitiveField(env, javaField, javaObj, 'Z', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700280}
281
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700282static void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte b) {
283 JValue value;
284 value.SetB(b);
285 SetPrimitiveField(env, javaField, javaObj, 'B', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700286}
287
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700288static void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar c) {
289 JValue value;
290 value.SetC(c);
291 SetPrimitiveField(env, javaField, javaObj, 'C', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800292}
Elliott Hughes33203b52011-09-20 19:42:01 -0700293
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700294static void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble d) {
295 JValue value;
296 value.SetD(d);
297 SetPrimitiveField(env, javaField, javaObj, 'D', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800298}
Elliott Hughes33203b52011-09-20 19:42:01 -0700299
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700300static void Field_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat f) {
301 JValue value;
302 value.SetF(f);
303 SetPrimitiveField(env, javaField, javaObj, 'F', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800304}
305
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700306static void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint i) {
307 JValue value;
308 value.SetI(i);
309 SetPrimitiveField(env, javaField, javaObj, 'I', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800310}
311
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700312static void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong j) {
313 JValue value;
314 value.SetJ(j);
315 SetPrimitiveField(env, javaField, javaObj, 'J', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800316}
317
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700318static void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort s) {
319 JValue value;
320 value.SetS(s);
321 SetPrimitiveField(env, javaField, javaObj, 'S', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700322}
323
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700324static JNINativeMethod gMethods[] = {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700325 NATIVE_METHOD(Field, get, "!(Ljava/lang/Object;)Ljava/lang/Object;"),
326 NATIVE_METHOD(Field, getBoolean, "!(Ljava/lang/Object;)Z"),
327 NATIVE_METHOD(Field, getByte, "!(Ljava/lang/Object;)B"),
328 NATIVE_METHOD(Field, getChar, "!(Ljava/lang/Object;)C"),
329 NATIVE_METHOD(Field, getDouble, "!(Ljava/lang/Object;)D"),
330 NATIVE_METHOD(Field, getFloat, "!(Ljava/lang/Object;)F"),
331 NATIVE_METHOD(Field, getInt, "!(Ljava/lang/Object;)I"),
332 NATIVE_METHOD(Field, getLong, "!(Ljava/lang/Object;)J"),
333 NATIVE_METHOD(Field, getShort, "!(Ljava/lang/Object;)S"),
334 NATIVE_METHOD(Field, set, "!(Ljava/lang/Object;Ljava/lang/Object;)V"),
335 NATIVE_METHOD(Field, setBoolean, "!(Ljava/lang/Object;Z)V"),
336 NATIVE_METHOD(Field, setByte, "!(Ljava/lang/Object;B)V"),
337 NATIVE_METHOD(Field, setChar, "!(Ljava/lang/Object;C)V"),
338 NATIVE_METHOD(Field, setDouble, "!(Ljava/lang/Object;D)V"),
339 NATIVE_METHOD(Field, setFloat, "!(Ljava/lang/Object;F)V"),
340 NATIVE_METHOD(Field, setInt, "!(Ljava/lang/Object;I)V"),
341 NATIVE_METHOD(Field, setLong, "!(Ljava/lang/Object;J)V"),
342 NATIVE_METHOD(Field, setShort, "!(Ljava/lang/Object;S)V"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700343};
344
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700345void register_java_lang_reflect_Field(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700346 REGISTER_NATIVE_METHODS("java/lang/reflect/Field");
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700347}
348
349} // namespace art