blob: 00f89b65eaa5ee9ccd0deb85a1f6359092e708b1 [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 Rogers00f7d0e2012-07-19 15:28:27 -070026#include "scoped_thread_state_change.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070027
Brian Carlstromf867b6f2011-09-16 12:17:25 -070028namespace art {
29
Brian Carlstromea46f952013-07-30 01:26:50 -070030static bool GetFieldValue(const ScopedObjectAccess& soa, mirror::Object* o, mirror::ArtField* f,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070031 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);
Ian Rogers00f7d0e2012-07-19 15:28:27 -070034 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(f->GetDeclaringClass(),
35 true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -070036 return false;
37 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080038 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070039 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070040 value.SetZ(f->GetBoolean(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070041 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070042 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070043 value.SetB(f->GetByte(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070044 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070045 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070046 value.SetC(f->GetChar(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070047 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070048 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070049 value.SetD(f->GetDouble(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070050 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070051 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070052 value.SetF(f->GetFloat(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070053 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070054 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070055 value.SetI(f->GetInt(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070056 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070057 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070058 value.SetJ(f->GetLong(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070059 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070060 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070061 value.SetS(f->GetShort(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070062 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070063 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -070064 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070065 value.SetL(f->GetObject(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070066 return true;
67 }
68 // Else break to report an error.
69 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070070 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -070071 // Never okay.
72 break;
73 }
Ian Rogers62d6c772013-02-27 08:32:07 -080074 ThrowIllegalArgumentException(NULL,
75 StringPrintf("Not a primitive field: %s",
76 PrettyField(f).c_str()).c_str());
Elliott Hughes33203b52011-09-20 19:42:01 -070077 return false;
78}
79
Brian Carlstromea46f952013-07-30 01:26:50 -070080static bool CheckReceiver(const ScopedObjectAccess& soa, jobject j_rcvr, mirror::ArtField* f,
Ian Rogers62d6c772013-02-27 08:32:07 -080081 mirror::Object*& class_or_rcvr)
Ian Rogersb726dcb2012-09-05 08:57:23 -070082 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070083 if (f->IsStatic()) {
Ian Rogers62d6c772013-02-27 08:32:07 -080084 class_or_rcvr = f->GetDeclaringClass();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070085 return true;
86 }
87
Ian Rogers62d6c772013-02-27 08:32:07 -080088 class_or_rcvr = soa.Decode<mirror::Object*>(j_rcvr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089 mirror::Class* declaringClass = f->GetDeclaringClass();
Ian Rogers62d6c772013-02-27 08:32:07 -080090 if (!VerifyObjectInClass(class_or_rcvr, declaringClass)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070091 return false;
92 }
93 return true;
94}
95
Elliott Hughes0512f022012-03-15 22:10:52 -070096static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070097 ScopedObjectAccess soa(env);
Brian Carlstromea46f952013-07-30 01:26:50 -070098 mirror::ArtField* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700100 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800101 return NULL;
102 }
103
104 // Get the field's value, boxing if necessary.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700105 JValue value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700106 if (!GetFieldValue(soa, o, f, value, true)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800107 return NULL;
108 }
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800109 return
110 soa.AddLocalReference<jobject>(BoxPrimitive(FieldHelper(f).GetTypeAsPrimitiveType(), value));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800111}
112
Brian Carlstromea46f952013-07-30 01:26:50 -0700113static JValue GetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj,
114 char dst_descriptor) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700115 ScopedObjectAccess soa(env);
Brian Carlstromea46f952013-07-30 01:26:50 -0700116 mirror::ArtField* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800117 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700118 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700119 return JValue();
Elliott Hughes33203b52011-09-20 19:42:01 -0700120 }
121
122 // Read the value.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700123 JValue field_value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700124 if (!GetFieldValue(soa, o, f, field_value, false)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700125 return JValue();
126 }
127
128 // Widen it if necessary (and possible).
129 JValue wide_value;
Brian Carlstromea46f952013-07-30 01:26:50 -0700130 mirror::Class* dst_type =
131 Runtime::Current()->GetClassLinker()->FindPrimitiveClass(dst_descriptor);
Ian Rogers62d6c772013-02-27 08:32:07 -0800132 if (!ConvertPrimitiveValue(NULL, false, FieldHelper(f).GetTypeAsPrimitiveType(),
133 dst_type->GetPrimitiveType(), field_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700134 return JValue();
135 }
136 return wide_value;
137}
138
Elliott Hughes0512f022012-03-15 22:10:52 -0700139static jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700140 return GetPrimitiveField(env, javaField, javaObj, 'Z').GetZ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700141}
142
Elliott Hughes0512f022012-03-15 22:10:52 -0700143static jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700144 return GetPrimitiveField(env, javaField, javaObj, 'B').GetB();
Elliott Hughes33203b52011-09-20 19:42:01 -0700145}
146
Elliott Hughes0512f022012-03-15 22:10:52 -0700147static jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700148 return GetPrimitiveField(env, javaField, javaObj, 'C').GetC();
Elliott Hughes33203b52011-09-20 19:42:01 -0700149}
150
Elliott Hughes0512f022012-03-15 22:10:52 -0700151static jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700152 return GetPrimitiveField(env, javaField, javaObj, 'D').GetD();
Elliott Hughes33203b52011-09-20 19:42:01 -0700153}
154
Elliott Hughes0512f022012-03-15 22:10:52 -0700155static jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700156 return GetPrimitiveField(env, javaField, javaObj, 'F').GetF();
Elliott Hughes33203b52011-09-20 19:42:01 -0700157}
158
Elliott Hughes0512f022012-03-15 22:10:52 -0700159static jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700160 return GetPrimitiveField(env, javaField, javaObj, 'I').GetI();
Elliott Hughes33203b52011-09-20 19:42:01 -0700161}
162
Elliott Hughes0512f022012-03-15 22:10:52 -0700163static jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700164 return GetPrimitiveField(env, javaField, javaObj, 'J').GetJ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700165}
166
Elliott Hughes0512f022012-03-15 22:10:52 -0700167static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700168 return GetPrimitiveField(env, javaField, javaObj, 'S').GetS();
Elliott Hughes33203b52011-09-20 19:42:01 -0700169}
170
Brian Carlstromea46f952013-07-30 01:26:50 -0700171static void SetFieldValue(mirror::Object* o, mirror::ArtField* f, const JValue& new_value,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 bool allow_references)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700173 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700174 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(f->GetDeclaringClass(),
175 true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -0700176 return;
177 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800178 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700179 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700180 f->SetBoolean(o, new_value.GetZ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700181 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700182 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700183 f->SetByte(o, new_value.GetB());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700184 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700185 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700186 f->SetChar(o, new_value.GetC());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700187 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700188 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700189 f->SetDouble(o, new_value.GetD());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700190 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700191 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700192 f->SetFloat(o, new_value.GetF());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700193 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700194 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700195 f->SetInt(o, new_value.GetI());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700196 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700197 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700198 f->SetLong(o, new_value.GetJ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700199 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700200 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700201 f->SetShort(o, new_value.GetS());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700202 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700203 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -0700204 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700205 f->SetObject(o, new_value.GetL());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700206 break;
Elliott Hughes33203b52011-09-20 19:42:01 -0700207 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700208 // Else fall through to report an error.
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700209 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -0700210 // Never okay.
Ian Rogers62d6c772013-02-27 08:32:07 -0800211 ThrowIllegalArgumentException(NULL, StringPrintf("Not a primitive field: %s",
212 PrettyField(f).c_str()).c_str());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700213 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700214 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700215
216 // Special handling for final fields on SMP systems.
217 // We need a store/store barrier here (JMM requirement).
218 if (f->IsFinal()) {
219 ANDROID_MEMBAR_STORE();
220 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700221}
222
Elliott Hughes0512f022012-03-15 22:10:52 -0700223static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700224 ScopedObjectAccess soa(env);
Brian Carlstromea46f952013-07-30 01:26:50 -0700225 mirror::ArtField* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800226
227 // Unbox the value, if necessary.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800228 mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800229 JValue unboxed_value;
Elliott Hughesaaa5edc2012-05-16 15:54:30 -0700230 if (!UnboxPrimitiveForField(boxed_value, FieldHelper(f).GetType(), unboxed_value, f)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800231 return;
232 }
233
234 // Check that the receiver is non-null and an instance of the field's declaring class.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800235 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700236 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800237 return;
238 }
239
240 SetFieldValue(o, f, unboxed_value, true);
241}
242
Elliott Hughes0512f022012-03-15 22:10:52 -0700243static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor,
244 const JValue& new_value) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700245 ScopedObjectAccess soa(env);
Brian Carlstromea46f952013-07-30 01:26:50 -0700246 mirror::ArtField* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800247 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700248 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700249 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700250 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800251 FieldHelper fh(f);
252 if (!fh.IsPrimitiveType()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800253 ThrowIllegalArgumentException(NULL, StringPrintf("Not a primitive field: %s",
254 PrettyField(f).c_str()).c_str());
Jesse Wilsonc129a6b2011-11-24 14:47:46 -0500255 return;
256 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700257
258 // Widen the value if necessary (and possible).
259 JValue wide_value;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260 mirror::Class* src_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(src_descriptor);
Ian Rogers62d6c772013-02-27 08:32:07 -0800261 if (!ConvertPrimitiveValue(NULL, false, src_type->GetPrimitiveType(), fh.GetTypeAsPrimitiveType(),
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700262 new_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700263 return;
264 }
265
266 // Write the value.
267 SetFieldValue(o, f, wide_value, false);
268}
269
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700270static void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean z) {
271 JValue value;
272 value.SetZ(z);
273 SetPrimitiveField(env, javaField, javaObj, 'Z', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700274}
275
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700276static void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte b) {
277 JValue value;
278 value.SetB(b);
279 SetPrimitiveField(env, javaField, javaObj, 'B', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700280}
281
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700282static void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar c) {
283 JValue value;
284 value.SetC(c);
285 SetPrimitiveField(env, javaField, javaObj, 'C', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800286}
Elliott Hughes33203b52011-09-20 19:42:01 -0700287
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700288static void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble d) {
289 JValue value;
290 value.SetD(d);
291 SetPrimitiveField(env, javaField, javaObj, 'D', 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_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat f) {
295 JValue value;
296 value.SetF(f);
297 SetPrimitiveField(env, javaField, javaObj, 'F', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800298}
299
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700300static void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint i) {
301 JValue value;
302 value.SetI(i);
303 SetPrimitiveField(env, javaField, javaObj, 'I', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800304}
305
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700306static void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong j) {
307 JValue value;
308 value.SetJ(j);
309 SetPrimitiveField(env, javaField, javaObj, 'J', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800310}
311
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700312static void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort s) {
313 JValue value;
314 value.SetS(s);
315 SetPrimitiveField(env, javaField, javaObj, 'S', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700316}
317
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700318static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800319 NATIVE_METHOD(Field, get, "(Ljava/lang/Object;)Ljava/lang/Object;"),
320 NATIVE_METHOD(Field, getBoolean, "(Ljava/lang/Object;)Z"),
321 NATIVE_METHOD(Field, getByte, "(Ljava/lang/Object;)B"),
322 NATIVE_METHOD(Field, getChar, "(Ljava/lang/Object;)C"),
323 NATIVE_METHOD(Field, getDouble, "(Ljava/lang/Object;)D"),
324 NATIVE_METHOD(Field, getFloat, "(Ljava/lang/Object;)F"),
325 NATIVE_METHOD(Field, getInt, "(Ljava/lang/Object;)I"),
326 NATIVE_METHOD(Field, getLong, "(Ljava/lang/Object;)J"),
327 NATIVE_METHOD(Field, getShort, "(Ljava/lang/Object;)S"),
328 NATIVE_METHOD(Field, set, "(Ljava/lang/Object;Ljava/lang/Object;)V"),
329 NATIVE_METHOD(Field, setBoolean, "(Ljava/lang/Object;Z)V"),
330 NATIVE_METHOD(Field, setByte, "(Ljava/lang/Object;B)V"),
331 NATIVE_METHOD(Field, setChar, "(Ljava/lang/Object;C)V"),
332 NATIVE_METHOD(Field, setDouble, "(Ljava/lang/Object;D)V"),
333 NATIVE_METHOD(Field, setFloat, "(Ljava/lang/Object;F)V"),
334 NATIVE_METHOD(Field, setInt, "(Ljava/lang/Object;I)V"),
335 NATIVE_METHOD(Field, setLong, "(Ljava/lang/Object;J)V"),
336 NATIVE_METHOD(Field, setShort, "(Ljava/lang/Object;S)V"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700337};
338
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700339void register_java_lang_reflect_Field(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700340 REGISTER_NATIVE_METHODS("java/lang/reflect/Field");
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700341}
342
343} // namespace art