blob: 6667d511c2fce915b0cb2103037716fd96c502fc [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));
35 DCHECK(f->GetDeclaringClass()->IsInitialized());
36 switch (field_type) {
37 case Primitive::kPrimBoolean:
38 value->SetZ(f->GetBoolean(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070039 return true;
Ian Rogers62f05122014-03-21 11:21:29 -070040 case Primitive::kPrimByte:
41 value->SetB(f->GetByte(o));
42 return true;
43 case Primitive::kPrimChar:
44 value->SetC(f->GetChar(o));
45 return true;
46 case Primitive::kPrimDouble:
47 value->SetD(f->GetDouble(o));
48 return true;
49 case Primitive::kPrimFloat:
50 value->SetF(f->GetFloat(o));
51 return true;
52 case Primitive::kPrimInt:
53 value->SetI(f->GetInt(o));
54 return true;
55 case Primitive::kPrimLong:
56 value->SetJ(f->GetLong(o));
57 return true;
58 case Primitive::kPrimShort:
59 value->SetS(f->GetShort(o));
60 return true;
61 case Primitive::kPrimNot:
62 if (allow_references) {
63 value->SetL(f->GetObject(o));
64 return true;
65 }
66 // Else break to report an error.
67 break;
68 case Primitive::kPrimVoid:
69 // Never okay.
70 break;
Elliott Hughes33203b52011-09-20 19:42:01 -070071 }
Ian Rogers62f05122014-03-21 11:21:29 -070072 ThrowIllegalArgumentException(nullptr, StringPrintf("Not a primitive field: %s",
73 PrettyField(f).c_str()).c_str());
Elliott Hughes33203b52011-09-20 19:42:01 -070074 return false;
75}
76
Ian Rogers1eb512d2013-10-18 15:42:20 -070077static bool CheckReceiver(const ScopedFastNativeObjectAccess& soa, jobject j_rcvr,
Ian Rogers62f05122014-03-21 11:21:29 -070078 mirror::ArtField* f, mirror::Object** class_or_rcvr)
Ian Rogersb726dcb2012-09-05 08:57:23 -070079 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62f05122014-03-21 11:21:29 -070080 soa.Self()->AssertThreadSuspensionIsAllowable();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070081 if (f->IsStatic()) {
Ian Rogers62f05122014-03-21 11:21:29 -070082 SirtRef<mirror::Class> sirt_klass(soa.Self(), f->GetDeclaringClass());
83 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(sirt_klass, true, true))) {
84 DCHECK(soa.Self()->IsExceptionPending());
85 *class_or_rcvr = nullptr;
86 return false;
87 }
88 *class_or_rcvr = sirt_klass.get();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070089 return true;
90 }
91
Ian Rogers62f05122014-03-21 11:21:29 -070092 *class_or_rcvr = soa.Decode<mirror::Object*>(j_rcvr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093 mirror::Class* declaringClass = f->GetDeclaringClass();
Ian Rogers62f05122014-03-21 11:21:29 -070094 if (!VerifyObjectIsClass(*class_or_rcvr, declaringClass)) {
95 DCHECK(soa.Self()->IsExceptionPending());
96 *class_or_rcvr = nullptr;
Elliott Hughesed1c1e32011-10-02 14:31:05 -070097 return false;
98 }
99 return true;
100}
101
Elliott Hughes0512f022012-03-15 22:10:52 -0700102static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700103 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -0700104 CHECK(!kMovingFields) << "CheckReceiver may trigger thread suspension for initialization";
105 mirror::ArtField* f = mirror::ArtField::FromReflectedField(soa, javaField);
106 mirror::Object* o = nullptr;
107 if (!CheckReceiver(soa, javaObj, f, &o)) {
108 DCHECK(soa.Self()->IsExceptionPending());
109 return nullptr;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800110 }
Ian Rogers62f05122014-03-21 11:21:29 -0700111 // We now don't expect suspension unless an exception is thrown.
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800112 // Get the field's value, boxing if necessary.
Ian Rogers62f05122014-03-21 11:21:29 -0700113 Primitive::Type field_type = FieldHelper(f).GetTypeAsPrimitiveType();
Elliott Hughes1d878f32012-04-11 15:17:54 -0700114 JValue value;
Ian Rogers62f05122014-03-21 11:21:29 -0700115 if (!GetFieldValue(soa, o, f, field_type, true, &value)) {
116 DCHECK(soa.Self()->IsExceptionPending());
117 return nullptr;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800118 }
Ian Rogers62f05122014-03-21 11:21:29 -0700119 return soa.AddLocalReference<jobject>(BoxPrimitive(field_type, value));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800120}
121
Brian Carlstromea46f952013-07-30 01:26:50 -0700122static JValue GetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj,
123 char dst_descriptor) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700124 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -0700125 CHECK(!kMovingFields) << "CheckReceiver may trigger thread suspension for initialization";
126 mirror::ArtField* f = mirror::ArtField::FromReflectedField(soa, javaField);
127 mirror::Object* o = nullptr;
128 if (!CheckReceiver(soa, javaObj, f, &o)) {
129 DCHECK(soa.Self()->IsExceptionPending());
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700130 return JValue();
Elliott Hughes33203b52011-09-20 19:42:01 -0700131 }
Ian Rogers62f05122014-03-21 11:21:29 -0700132 // We now don't expect suspension unless an exception is thrown.
Elliott Hughes33203b52011-09-20 19:42:01 -0700133 // Read the value.
Ian Rogers62f05122014-03-21 11:21:29 -0700134 Primitive::Type field_type = FieldHelper(f).GetTypeAsPrimitiveType();
Elliott Hughes1d878f32012-04-11 15:17:54 -0700135 JValue field_value;
Ian Rogers62f05122014-03-21 11:21:29 -0700136 if (!GetFieldValue(soa, o, f, field_type, false, &field_value)) {
137 DCHECK(soa.Self()->IsExceptionPending());
Elliott Hughes33203b52011-09-20 19:42:01 -0700138 return JValue();
139 }
140
141 // Widen it if necessary (and possible).
142 JValue wide_value;
Ian Rogers62f05122014-03-21 11:21:29 -0700143 if (!ConvertPrimitiveValue(NULL, false, field_type, Primitive::GetType(dst_descriptor),
144 field_value, wide_value)) {
145 DCHECK(soa.Self()->IsExceptionPending());
Elliott Hughes33203b52011-09-20 19:42:01 -0700146 return JValue();
147 }
148 return wide_value;
149}
150
Elliott Hughes0512f022012-03-15 22:10:52 -0700151static jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700152 return GetPrimitiveField(env, javaField, javaObj, 'Z').GetZ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700153}
154
Elliott Hughes0512f022012-03-15 22:10:52 -0700155static jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700156 return GetPrimitiveField(env, javaField, javaObj, 'B').GetB();
Elliott Hughes33203b52011-09-20 19:42:01 -0700157}
158
Elliott Hughes0512f022012-03-15 22:10:52 -0700159static jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700160 return GetPrimitiveField(env, javaField, javaObj, 'C').GetC();
Elliott Hughes33203b52011-09-20 19:42:01 -0700161}
162
Elliott Hughes0512f022012-03-15 22:10:52 -0700163static jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700164 return GetPrimitiveField(env, javaField, javaObj, 'D').GetD();
Elliott Hughes33203b52011-09-20 19:42:01 -0700165}
166
Elliott Hughes0512f022012-03-15 22:10:52 -0700167static jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700168 return GetPrimitiveField(env, javaField, javaObj, 'F').GetF();
Elliott Hughes33203b52011-09-20 19:42:01 -0700169}
170
Elliott Hughes0512f022012-03-15 22:10:52 -0700171static jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700172 return GetPrimitiveField(env, javaField, javaObj, 'I').GetI();
Elliott Hughes33203b52011-09-20 19:42:01 -0700173}
174
Elliott Hughes0512f022012-03-15 22:10:52 -0700175static jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700176 return GetPrimitiveField(env, javaField, javaObj, 'J').GetJ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700177}
178
Elliott Hughes0512f022012-03-15 22:10:52 -0700179static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700180 return GetPrimitiveField(env, javaField, javaObj, 'S').GetS();
Elliott Hughes33203b52011-09-20 19:42:01 -0700181}
182
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800183static void SetFieldValue(ScopedFastNativeObjectAccess& soa, mirror::Object* o,
Ian Rogers62f05122014-03-21 11:21:29 -0700184 mirror::ArtField* f, Primitive::Type field_type, bool allow_references,
185 const JValue& new_value)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700186 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62f05122014-03-21 11:21:29 -0700187 DCHECK(f->GetDeclaringClass()->IsInitialized());
188 switch (field_type) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700189 case Primitive::kPrimBoolean:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100190 f->SetBoolean<false>(o, new_value.GetZ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700191 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700192 case Primitive::kPrimByte:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100193 f->SetByte<false>(o, new_value.GetB());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700194 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700195 case Primitive::kPrimChar:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100196 f->SetChar<false>(o, new_value.GetC());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700197 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700198 case Primitive::kPrimDouble:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100199 f->SetDouble<false>(o, new_value.GetD());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700200 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700201 case Primitive::kPrimFloat:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100202 f->SetFloat<false>(o, new_value.GetF());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700203 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700204 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100205 f->SetInt<false>(o, new_value.GetI());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700206 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700207 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100208 f->SetLong<false>(o, new_value.GetJ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700209 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700210 case Primitive::kPrimShort:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100211 f->SetShort<false>(o, new_value.GetS());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700212 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700213 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -0700214 if (allow_references) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100215 f->SetObject<false>(o, new_value.GetL());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700216 break;
Elliott Hughes33203b52011-09-20 19:42:01 -0700217 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700218 // Else fall through to report an error.
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700219 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -0700220 // Never okay.
Ian Rogers62f05122014-03-21 11:21:29 -0700221 ThrowIllegalArgumentException(nullptr, StringPrintf("Not a primitive field: %s",
222 PrettyField(f).c_str()).c_str());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700223 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700224 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700225}
226
Elliott Hughes0512f022012-03-15 22:10:52 -0700227static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700228 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -0700229 CHECK(!kMovingFields) << "CheckReceiver may trigger thread suspension for initialization";
230 mirror::ArtField* f = mirror::ArtField::FromReflectedField(soa, javaField);
231 // Check that the receiver is non-null and an instance of the field's declaring class.
232 mirror::Object* o = nullptr;
233 if (!CheckReceiver(soa, javaObj, f, &o)) {
234 DCHECK(soa.Self()->IsExceptionPending());
235 return;
236 }
237 Primitive::Type field_prim_type;
238 mirror::Class* field_type;
239 {
240 FieldHelper fh(f);
241 const char* field_type_desciptor = fh.GetTypeDescriptor();
242 field_prim_type = Primitive::GetType(field_type_desciptor[0]);
243 if (field_prim_type == Primitive::kPrimNot) {
244 SirtRef<mirror::Object> sirt_obj(soa.Self(), o);
245 // May cause resolution.
246 CHECK(!kMovingFields) << "Resolution may trigger thread suspension";
247 field_type = fh.GetType(true);
248 if (field_type == nullptr) {
249 DCHECK(soa.Self()->IsExceptionPending());
250 return;
251 }
252 } else {
253 field_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(field_type_desciptor[0]);
254 }
255 }
256 // We now don't expect suspension unless an exception is thrown.
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800257 // Unbox the value, if necessary.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800258 mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800259 JValue unboxed_value;
Ian Rogers62f05122014-03-21 11:21:29 -0700260 if (!UnboxPrimitiveForField(boxed_value, field_type, unboxed_value, f)) {
261 DCHECK(soa.Self()->IsExceptionPending());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800262 return;
263 }
Ian Rogers62f05122014-03-21 11:21:29 -0700264 SetFieldValue(soa, o, f, field_prim_type, true, unboxed_value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800265}
266
Elliott Hughes0512f022012-03-15 22:10:52 -0700267static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor,
268 const JValue& new_value) {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700269 ScopedFastNativeObjectAccess soa(env);
Ian Rogers62f05122014-03-21 11:21:29 -0700270 mirror::ArtField* f = mirror::ArtField::FromReflectedField(soa, javaField);
271 mirror::Object* o = nullptr;
272 if (!CheckReceiver(soa, javaObj, f, &o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700273 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700274 }
Ian Rogers62f05122014-03-21 11:21:29 -0700275 Primitive::Type field_type = FieldHelper(f).GetTypeAsPrimitiveType();
276 if (UNLIKELY(field_type == Primitive::kPrimNot)) {
277 ThrowIllegalArgumentException(nullptr, StringPrintf("Not a primitive field: %s",
278 PrettyField(f).c_str()).c_str());
Jesse Wilsonc129a6b2011-11-24 14:47:46 -0500279 return;
280 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700281
282 // Widen the value if necessary (and possible).
283 JValue wide_value;
Ian Rogers62f05122014-03-21 11:21:29 -0700284 if (!ConvertPrimitiveValue(nullptr, false, Primitive::GetType(src_descriptor),
285 field_type, new_value, wide_value)) {
286 DCHECK(soa.Self()->IsExceptionPending());
Elliott Hughes33203b52011-09-20 19:42:01 -0700287 return;
288 }
289
290 // Write the value.
Ian Rogers62f05122014-03-21 11:21:29 -0700291 SetFieldValue(soa, o, f, field_type, false, wide_value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700292}
293
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700294static void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean z) {
295 JValue value;
296 value.SetZ(z);
297 SetPrimitiveField(env, javaField, javaObj, 'Z', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700298}
299
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700300static void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte b) {
301 JValue value;
302 value.SetB(b);
303 SetPrimitiveField(env, javaField, javaObj, 'B', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700304}
305
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700306static void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar c) {
307 JValue value;
308 value.SetC(c);
309 SetPrimitiveField(env, javaField, javaObj, 'C', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800310}
Elliott Hughes33203b52011-09-20 19:42:01 -0700311
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700312static void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble d) {
313 JValue value;
314 value.SetD(d);
315 SetPrimitiveField(env, javaField, javaObj, 'D', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800316}
Elliott Hughes33203b52011-09-20 19:42:01 -0700317
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700318static void Field_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat f) {
319 JValue value;
320 value.SetF(f);
321 SetPrimitiveField(env, javaField, javaObj, 'F', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800322}
323
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700324static void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint i) {
325 JValue value;
326 value.SetI(i);
327 SetPrimitiveField(env, javaField, javaObj, 'I', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800328}
329
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700330static void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong j) {
331 JValue value;
332 value.SetJ(j);
333 SetPrimitiveField(env, javaField, javaObj, 'J', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800334}
335
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700336static void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort s) {
337 JValue value;
338 value.SetS(s);
339 SetPrimitiveField(env, javaField, javaObj, 'S', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700340}
341
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700342static JNINativeMethod gMethods[] = {
Ian Rogers1eb512d2013-10-18 15:42:20 -0700343 NATIVE_METHOD(Field, get, "!(Ljava/lang/Object;)Ljava/lang/Object;"),
344 NATIVE_METHOD(Field, getBoolean, "!(Ljava/lang/Object;)Z"),
345 NATIVE_METHOD(Field, getByte, "!(Ljava/lang/Object;)B"),
346 NATIVE_METHOD(Field, getChar, "!(Ljava/lang/Object;)C"),
347 NATIVE_METHOD(Field, getDouble, "!(Ljava/lang/Object;)D"),
348 NATIVE_METHOD(Field, getFloat, "!(Ljava/lang/Object;)F"),
349 NATIVE_METHOD(Field, getInt, "!(Ljava/lang/Object;)I"),
350 NATIVE_METHOD(Field, getLong, "!(Ljava/lang/Object;)J"),
351 NATIVE_METHOD(Field, getShort, "!(Ljava/lang/Object;)S"),
352 NATIVE_METHOD(Field, set, "!(Ljava/lang/Object;Ljava/lang/Object;)V"),
353 NATIVE_METHOD(Field, setBoolean, "!(Ljava/lang/Object;Z)V"),
354 NATIVE_METHOD(Field, setByte, "!(Ljava/lang/Object;B)V"),
355 NATIVE_METHOD(Field, setChar, "!(Ljava/lang/Object;C)V"),
356 NATIVE_METHOD(Field, setDouble, "!(Ljava/lang/Object;D)V"),
357 NATIVE_METHOD(Field, setFloat, "!(Ljava/lang/Object;F)V"),
358 NATIVE_METHOD(Field, setInt, "!(Ljava/lang/Object;I)V"),
359 NATIVE_METHOD(Field, setLong, "!(Ljava/lang/Object;J)V"),
360 NATIVE_METHOD(Field, setShort, "!(Ljava/lang/Object;S)V"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700361};
362
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700363void register_java_lang_reflect_Field(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700364 REGISTER_NATIVE_METHODS("java/lang/reflect/Field");
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700365}
366
367} // namespace art