blob: 48b58bf80727d73e74d83958844061c5399ce76a [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,
Ian Rogers62f05122014-03-21 11:21:29 -070031 mirror::ArtField* f, Primitive::Type field_type, bool allow_references,
32 JValue* value)
Ian Rogersb726dcb2012-09-05 08:57:23 -070033 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62f05122014-03-21 11:21:29 -070034 DCHECK_EQ(value->GetJ(), INT64_C(0));
Ian Rogers62f05122014-03-21 11:21:29 -070035 switch (field_type) {
36 case Primitive::kPrimBoolean:
37 value->SetZ(f->GetBoolean(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070038 return true;
Ian Rogers62f05122014-03-21 11:21:29 -070039 case Primitive::kPrimByte:
40 value->SetB(f->GetByte(o));
41 return true;
42 case Primitive::kPrimChar:
43 value->SetC(f->GetChar(o));
44 return true;
45 case Primitive::kPrimDouble:
46 value->SetD(f->GetDouble(o));
47 return true;
48 case Primitive::kPrimFloat:
49 value->SetF(f->GetFloat(o));
50 return true;
51 case Primitive::kPrimInt:
52 value->SetI(f->GetInt(o));
53 return true;
54 case Primitive::kPrimLong:
55 value->SetJ(f->GetLong(o));
56 return true;
57 case Primitive::kPrimShort:
58 value->SetS(f->GetShort(o));
59 return true;
60 case Primitive::kPrimNot:
61 if (allow_references) {
62 value->SetL(f->GetObject(o));
63 return true;
64 }
65 // Else break to report an error.
66 break;
67 case Primitive::kPrimVoid:
68 // Never okay.
69 break;
Elliott Hughes33203b52011-09-20 19:42:01 -070070 }
Ian Rogers62f05122014-03-21 11:21:29 -070071 ThrowIllegalArgumentException(nullptr, StringPrintf("Not a primitive field: %s",
72 PrettyField(f).c_str()).c_str());
Elliott Hughes33203b52011-09-20 19:42:01 -070073 return false;
74}
75
Ian Rogers1eb512d2013-10-18 15:42:20 -070076static bool CheckReceiver(const ScopedFastNativeObjectAccess& soa, jobject j_rcvr,
Ian Rogers62f05122014-03-21 11:21:29 -070077 mirror::ArtField* f, mirror::Object** class_or_rcvr)
Ian Rogersb726dcb2012-09-05 08:57:23 -070078 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62f05122014-03-21 11:21:29 -070079 soa.Self()->AssertThreadSuspensionIsAllowable();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070080 if (f->IsStatic()) {
Ian Rogers62f05122014-03-21 11:21:29 -070081 SirtRef<mirror::Class> sirt_klass(soa.Self(), f->GetDeclaringClass());
82 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(sirt_klass, true, true))) {
83 DCHECK(soa.Self()->IsExceptionPending());
84 *class_or_rcvr = nullptr;
85 return false;
86 }
87 *class_or_rcvr = sirt_klass.get();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070088 return true;
89 }
90
Ian Rogers62f05122014-03-21 11:21:29 -070091 *class_or_rcvr = soa.Decode<mirror::Object*>(j_rcvr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080092 mirror::Class* declaringClass = f->GetDeclaringClass();
Ian Rogers62f05122014-03-21 11:21:29 -070093 if (!VerifyObjectIsClass(*class_or_rcvr, declaringClass)) {
94 DCHECK(soa.Self()->IsExceptionPending());
95 *class_or_rcvr = nullptr;
Elliott Hughesed1c1e32011-10-02 14:31:05 -070096 return false;
97 }
98 return true;
99}
100
Elliott Hughes0512f022012-03-15 22:10:52 -0700101static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700102 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -0700103 CHECK(!kMovingFields) << "CheckReceiver may trigger thread suspension for initialization";
104 mirror::ArtField* f = mirror::ArtField::FromReflectedField(soa, javaField);
105 mirror::Object* o = nullptr;
106 if (!CheckReceiver(soa, javaObj, f, &o)) {
107 DCHECK(soa.Self()->IsExceptionPending());
108 return nullptr;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800109 }
Ian Rogers62f05122014-03-21 11:21:29 -0700110 // We now don't expect suspension unless an exception is thrown.
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800111 // Get the field's value, boxing if necessary.
Ian Rogers62f05122014-03-21 11:21:29 -0700112 Primitive::Type field_type = FieldHelper(f).GetTypeAsPrimitiveType();
Elliott Hughes1d878f32012-04-11 15:17:54 -0700113 JValue value;
Ian Rogers62f05122014-03-21 11:21:29 -0700114 if (!GetFieldValue(soa, o, f, field_type, true, &value)) {
115 DCHECK(soa.Self()->IsExceptionPending());
116 return nullptr;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800117 }
Ian Rogers62f05122014-03-21 11:21:29 -0700118 return soa.AddLocalReference<jobject>(BoxPrimitive(field_type, value));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800119}
120
Brian Carlstromea46f952013-07-30 01:26:50 -0700121static JValue GetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj,
122 char dst_descriptor) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700123 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -0700124 CHECK(!kMovingFields) << "CheckReceiver may trigger thread suspension for initialization";
125 mirror::ArtField* f = mirror::ArtField::FromReflectedField(soa, javaField);
126 mirror::Object* o = nullptr;
127 if (!CheckReceiver(soa, javaObj, f, &o)) {
128 DCHECK(soa.Self()->IsExceptionPending());
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700129 return JValue();
Elliott Hughes33203b52011-09-20 19:42:01 -0700130 }
Ian Rogers62f05122014-03-21 11:21:29 -0700131 // We now don't expect suspension unless an exception is thrown.
Elliott Hughes33203b52011-09-20 19:42:01 -0700132 // Read the value.
Ian Rogers62f05122014-03-21 11:21:29 -0700133 Primitive::Type field_type = FieldHelper(f).GetTypeAsPrimitiveType();
Elliott Hughes1d878f32012-04-11 15:17:54 -0700134 JValue field_value;
Ian Rogers62f05122014-03-21 11:21:29 -0700135 if (!GetFieldValue(soa, o, f, field_type, false, &field_value)) {
136 DCHECK(soa.Self()->IsExceptionPending());
Elliott Hughes33203b52011-09-20 19:42:01 -0700137 return JValue();
138 }
139
140 // Widen it if necessary (and possible).
141 JValue wide_value;
Ian Rogers62f05122014-03-21 11:21:29 -0700142 if (!ConvertPrimitiveValue(NULL, false, field_type, Primitive::GetType(dst_descriptor),
Ian Rogers84956ff2014-03-26 23:52:41 -0700143 field_value, &wide_value)) {
Ian Rogers62f05122014-03-21 11:21:29 -0700144 DCHECK(soa.Self()->IsExceptionPending());
Elliott Hughes33203b52011-09-20 19:42:01 -0700145 return JValue();
146 }
147 return wide_value;
148}
149
Elliott Hughes0512f022012-03-15 22:10:52 -0700150static jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700151 return GetPrimitiveField(env, javaField, javaObj, 'Z').GetZ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700152}
153
Elliott Hughes0512f022012-03-15 22:10:52 -0700154static jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700155 return GetPrimitiveField(env, javaField, javaObj, 'B').GetB();
Elliott Hughes33203b52011-09-20 19:42:01 -0700156}
157
Elliott Hughes0512f022012-03-15 22:10:52 -0700158static jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700159 return GetPrimitiveField(env, javaField, javaObj, 'C').GetC();
Elliott Hughes33203b52011-09-20 19:42:01 -0700160}
161
Elliott Hughes0512f022012-03-15 22:10:52 -0700162static jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700163 return GetPrimitiveField(env, javaField, javaObj, 'D').GetD();
Elliott Hughes33203b52011-09-20 19:42:01 -0700164}
165
Elliott Hughes0512f022012-03-15 22:10:52 -0700166static jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700167 return GetPrimitiveField(env, javaField, javaObj, 'F').GetF();
Elliott Hughes33203b52011-09-20 19:42:01 -0700168}
169
Elliott Hughes0512f022012-03-15 22:10:52 -0700170static jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700171 return GetPrimitiveField(env, javaField, javaObj, 'I').GetI();
Elliott Hughes33203b52011-09-20 19:42:01 -0700172}
173
Elliott Hughes0512f022012-03-15 22:10:52 -0700174static jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700175 return GetPrimitiveField(env, javaField, javaObj, 'J').GetJ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700176}
177
Elliott Hughes0512f022012-03-15 22:10:52 -0700178static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700179 return GetPrimitiveField(env, javaField, javaObj, 'S').GetS();
Elliott Hughes33203b52011-09-20 19:42:01 -0700180}
181
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800182static void SetFieldValue(ScopedFastNativeObjectAccess& soa, mirror::Object* o,
Ian Rogers62f05122014-03-21 11:21:29 -0700183 mirror::ArtField* f, Primitive::Type field_type, bool allow_references,
184 const JValue& new_value)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62f05122014-03-21 11:21:29 -0700186 DCHECK(f->GetDeclaringClass()->IsInitialized());
187 switch (field_type) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700188 case Primitive::kPrimBoolean:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100189 f->SetBoolean<false>(o, new_value.GetZ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700190 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700191 case Primitive::kPrimByte:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100192 f->SetByte<false>(o, new_value.GetB());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700193 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700194 case Primitive::kPrimChar:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100195 f->SetChar<false>(o, new_value.GetC());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700196 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700197 case Primitive::kPrimDouble:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100198 f->SetDouble<false>(o, new_value.GetD());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700199 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700200 case Primitive::kPrimFloat:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100201 f->SetFloat<false>(o, new_value.GetF());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700202 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700203 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100204 f->SetInt<false>(o, new_value.GetI());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700205 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700206 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100207 f->SetLong<false>(o, new_value.GetJ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700208 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700209 case Primitive::kPrimShort:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100210 f->SetShort<false>(o, new_value.GetS());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700211 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700212 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -0700213 if (allow_references) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100214 f->SetObject<false>(o, new_value.GetL());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700215 break;
Elliott Hughes33203b52011-09-20 19:42:01 -0700216 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700217 // Else fall through to report an error.
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700218 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -0700219 // Never okay.
Ian Rogers62f05122014-03-21 11:21:29 -0700220 ThrowIllegalArgumentException(nullptr, StringPrintf("Not a primitive field: %s",
221 PrettyField(f).c_str()).c_str());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700222 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700223 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700224}
225
Elliott Hughes0512f022012-03-15 22:10:52 -0700226static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700227 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -0700228 CHECK(!kMovingFields) << "CheckReceiver may trigger thread suspension for initialization";
229 mirror::ArtField* f = mirror::ArtField::FromReflectedField(soa, javaField);
230 // Check that the receiver is non-null and an instance of the field's declaring class.
231 mirror::Object* o = nullptr;
232 if (!CheckReceiver(soa, javaObj, f, &o)) {
233 DCHECK(soa.Self()->IsExceptionPending());
234 return;
235 }
236 Primitive::Type field_prim_type;
237 mirror::Class* field_type;
238 {
239 FieldHelper fh(f);
240 const char* field_type_desciptor = fh.GetTypeDescriptor();
241 field_prim_type = Primitive::GetType(field_type_desciptor[0]);
242 if (field_prim_type == Primitive::kPrimNot) {
243 SirtRef<mirror::Object> sirt_obj(soa.Self(), o);
244 // May cause resolution.
245 CHECK(!kMovingFields) << "Resolution may trigger thread suspension";
246 field_type = fh.GetType(true);
247 if (field_type == nullptr) {
248 DCHECK(soa.Self()->IsExceptionPending());
249 return;
250 }
251 } else {
252 field_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(field_type_desciptor[0]);
253 }
254 }
255 // We now don't expect suspension unless an exception is thrown.
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800256 // Unbox the value, if necessary.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800257 mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800258 JValue unboxed_value;
Ian Rogers84956ff2014-03-26 23:52:41 -0700259 if (!UnboxPrimitiveForField(boxed_value, field_type, f, &unboxed_value)) {
Ian Rogers62f05122014-03-21 11:21:29 -0700260 DCHECK(soa.Self()->IsExceptionPending());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800261 return;
262 }
Ian Rogers62f05122014-03-21 11:21:29 -0700263 SetFieldValue(soa, o, f, field_prim_type, true, unboxed_value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800264}
265
Elliott Hughes0512f022012-03-15 22:10:52 -0700266static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor,
267 const JValue& new_value) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700268 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -0700269 mirror::ArtField* f = mirror::ArtField::FromReflectedField(soa, javaField);
270 mirror::Object* o = nullptr;
271 if (!CheckReceiver(soa, javaObj, f, &o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700272 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700273 }
Ian Rogers62f05122014-03-21 11:21:29 -0700274 Primitive::Type field_type = FieldHelper(f).GetTypeAsPrimitiveType();
275 if (UNLIKELY(field_type == Primitive::kPrimNot)) {
276 ThrowIllegalArgumentException(nullptr, StringPrintf("Not a primitive field: %s",
277 PrettyField(f).c_str()).c_str());
Jesse Wilsonc129a6b2011-11-24 14:47:46 -0500278 return;
279 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700280
281 // Widen the value if necessary (and possible).
282 JValue wide_value;
Ian Rogers62f05122014-03-21 11:21:29 -0700283 if (!ConvertPrimitiveValue(nullptr, false, Primitive::GetType(src_descriptor),
Ian Rogers84956ff2014-03-26 23:52:41 -0700284 field_type, new_value, &wide_value)) {
Ian Rogers62f05122014-03-21 11:21:29 -0700285 DCHECK(soa.Self()->IsExceptionPending());
Elliott Hughes33203b52011-09-20 19:42:01 -0700286 return;
287 }
288
289 // Write the value.
Ian Rogers62f05122014-03-21 11:21:29 -0700290 SetFieldValue(soa, o, f, field_type, false, wide_value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700291}
292
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700293static void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean z) {
294 JValue value;
295 value.SetZ(z);
296 SetPrimitiveField(env, javaField, javaObj, 'Z', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700297}
298
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700299static void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte b) {
300 JValue value;
301 value.SetB(b);
302 SetPrimitiveField(env, javaField, javaObj, 'B', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700303}
304
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700305static void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar c) {
306 JValue value;
307 value.SetC(c);
308 SetPrimitiveField(env, javaField, javaObj, 'C', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800309}
Elliott Hughes33203b52011-09-20 19:42:01 -0700310
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700311static void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble d) {
312 JValue value;
313 value.SetD(d);
314 SetPrimitiveField(env, javaField, javaObj, 'D', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800315}
Elliott Hughes33203b52011-09-20 19:42:01 -0700316
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700317static void Field_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat f) {
318 JValue value;
319 value.SetF(f);
320 SetPrimitiveField(env, javaField, javaObj, 'F', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800321}
322
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700323static void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint i) {
324 JValue value;
325 value.SetI(i);
326 SetPrimitiveField(env, javaField, javaObj, 'I', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800327}
328
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700329static void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong j) {
330 JValue value;
331 value.SetJ(j);
332 SetPrimitiveField(env, javaField, javaObj, 'J', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800333}
334
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700335static void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort s) {
336 JValue value;
337 value.SetS(s);
338 SetPrimitiveField(env, javaField, javaObj, 'S', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700339}
340
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700341static JNINativeMethod gMethods[] = {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700342 NATIVE_METHOD(Field, get, "!(Ljava/lang/Object;)Ljava/lang/Object;"),
343 NATIVE_METHOD(Field, getBoolean, "!(Ljava/lang/Object;)Z"),
344 NATIVE_METHOD(Field, getByte, "!(Ljava/lang/Object;)B"),
345 NATIVE_METHOD(Field, getChar, "!(Ljava/lang/Object;)C"),
346 NATIVE_METHOD(Field, getDouble, "!(Ljava/lang/Object;)D"),
347 NATIVE_METHOD(Field, getFloat, "!(Ljava/lang/Object;)F"),
348 NATIVE_METHOD(Field, getInt, "!(Ljava/lang/Object;)I"),
349 NATIVE_METHOD(Field, getLong, "!(Ljava/lang/Object;)J"),
350 NATIVE_METHOD(Field, getShort, "!(Ljava/lang/Object;)S"),
351 NATIVE_METHOD(Field, set, "!(Ljava/lang/Object;Ljava/lang/Object;)V"),
352 NATIVE_METHOD(Field, setBoolean, "!(Ljava/lang/Object;Z)V"),
353 NATIVE_METHOD(Field, setByte, "!(Ljava/lang/Object;B)V"),
354 NATIVE_METHOD(Field, setChar, "!(Ljava/lang/Object;C)V"),
355 NATIVE_METHOD(Field, setDouble, "!(Ljava/lang/Object;D)V"),
356 NATIVE_METHOD(Field, setFloat, "!(Ljava/lang/Object;F)V"),
357 NATIVE_METHOD(Field, setInt, "!(Ljava/lang/Object;I)V"),
358 NATIVE_METHOD(Field, setLong, "!(Ljava/lang/Object;J)V"),
359 NATIVE_METHOD(Field, setShort, "!(Ljava/lang/Object;S)V"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700360};
361
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700362void register_java_lang_reflect_Field(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700363 REGISTER_NATIVE_METHODS("java/lang/reflect/Field");
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700364}
365
366} // namespace art