blob: 922fe00b29a87f6913c72f905f07406cc8f7e79a [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 Rogers4f6ad8a2013-03-18 15:27:28 -070019#include "dex_file-inl.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070020#include "jni_internal.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070021#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "mirror/field.h"
23#include "mirror/field-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
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030static bool GetFieldValue(const ScopedObjectAccess& soa, mirror::Object* o, mirror::Field* 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 Rogers00f7d0e2012-07-19 15:28:27 -070074 soa.Self()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;",
Elliott Hughes33203b52011-09-20 19:42:01 -070075 "Not a primitive field: %s", PrettyField(f).c_str());
76 return false;
77}
78
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079static bool CheckReceiver(const ScopedObjectAccess& soa, jobject javaObj, mirror::Field* f,
80 mirror::Object*& o)
Ian Rogersb726dcb2012-09-05 08:57:23 -070081 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070082 if (f->IsStatic()) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -070083 o = f->GetDeclaringClass();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070084 return true;
85 }
86
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087 o = soa.Decode<mirror::Object*>(javaObj);
88 mirror::Class* declaringClass = f->GetDeclaringClass();
Elliott Hugheseac76672012-05-24 21:56:51 -070089 if (!VerifyObjectInClass(o, declaringClass)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070090 return false;
91 }
92 return true;
93}
94
Elliott Hughes0512f022012-03-15 22:10:52 -070095static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070096 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080097 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
98 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070099 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800100 return NULL;
101 }
102
103 // Get the field's value, boxing if necessary.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700104 JValue value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700105 if (!GetFieldValue(soa, o, f, value, true)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800106 return NULL;
107 }
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800108 return
109 soa.AddLocalReference<jobject>(BoxPrimitive(FieldHelper(f).GetTypeAsPrimitiveType(), value));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800110}
111
Elliott Hughes0512f022012-03-15 22:10:52 -0700112static JValue GetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char dst_descriptor) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700113 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
115 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700116 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700117 return JValue();
Elliott Hughes33203b52011-09-20 19:42:01 -0700118 }
119
120 // Read the value.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700121 JValue field_value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700122 if (!GetFieldValue(soa, o, f, field_value, false)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700123 return JValue();
124 }
125
126 // Widen it if necessary (and possible).
127 JValue wide_value;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800128 mirror::Class* dst_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(dst_descriptor);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800129 if (!ConvertPrimitiveValue(FieldHelper(f).GetTypeAsPrimitiveType(), dst_type->GetPrimitiveType(),
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700130 field_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700131 return JValue();
132 }
133 return wide_value;
134}
135
Elliott Hughes0512f022012-03-15 22:10:52 -0700136static jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700137 return GetPrimitiveField(env, javaField, javaObj, 'Z').GetZ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700138}
139
Elliott Hughes0512f022012-03-15 22:10:52 -0700140static jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700141 return GetPrimitiveField(env, javaField, javaObj, 'B').GetB();
Elliott Hughes33203b52011-09-20 19:42:01 -0700142}
143
Elliott Hughes0512f022012-03-15 22:10:52 -0700144static jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700145 return GetPrimitiveField(env, javaField, javaObj, 'C').GetC();
Elliott Hughes33203b52011-09-20 19:42:01 -0700146}
147
Elliott Hughes0512f022012-03-15 22:10:52 -0700148static jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700149 return GetPrimitiveField(env, javaField, javaObj, 'D').GetD();
Elliott Hughes33203b52011-09-20 19:42:01 -0700150}
151
Elliott Hughes0512f022012-03-15 22:10:52 -0700152static jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700153 return GetPrimitiveField(env, javaField, javaObj, 'F').GetF();
Elliott Hughes33203b52011-09-20 19:42:01 -0700154}
155
Elliott Hughes0512f022012-03-15 22:10:52 -0700156static jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700157 return GetPrimitiveField(env, javaField, javaObj, 'I').GetI();
Elliott Hughes33203b52011-09-20 19:42:01 -0700158}
159
Elliott Hughes0512f022012-03-15 22:10:52 -0700160static jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700161 return GetPrimitiveField(env, javaField, javaObj, 'J').GetJ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700162}
163
Elliott Hughes0512f022012-03-15 22:10:52 -0700164static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700165 return GetPrimitiveField(env, javaField, javaObj, 'S').GetS();
Elliott Hughes33203b52011-09-20 19:42:01 -0700166}
167
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168static void SetFieldValue(mirror::Object* o, mirror::Field* f, const JValue& new_value,
169 bool allow_references)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700170 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700171 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(f->GetDeclaringClass(),
172 true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -0700173 return;
174 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800175 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700176 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700177 f->SetBoolean(o, new_value.GetZ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700178 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700179 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700180 f->SetByte(o, new_value.GetB());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700181 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700182 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700183 f->SetChar(o, new_value.GetC());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700184 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700185 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700186 f->SetDouble(o, new_value.GetD());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700187 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700188 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700189 f->SetFloat(o, new_value.GetF());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700190 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700191 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700192 f->SetInt(o, new_value.GetI());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700193 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700194 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700195 f->SetLong(o, new_value.GetJ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700196 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700197 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700198 f->SetShort(o, new_value.GetS());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700199 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700200 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -0700201 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700202 f->SetObject(o, new_value.GetL());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700203 break;
Elliott Hughes33203b52011-09-20 19:42:01 -0700204 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700205 // Else fall through to report an error.
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700206 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -0700207 // Never okay.
Elliott Hughes5cb5ad22011-10-02 12:13:39 -0700208 Thread::Current()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;",
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700209 "Not a primitive field: %s", PrettyField(f).c_str());
210 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700211 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700212
213 // Special handling for final fields on SMP systems.
214 // We need a store/store barrier here (JMM requirement).
215 if (f->IsFinal()) {
216 ANDROID_MEMBAR_STORE();
217 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700218}
219
Elliott Hughes0512f022012-03-15 22:10:52 -0700220static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700221 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800222 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800223
224 // Unbox the value, if necessary.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800226 JValue unboxed_value;
Elliott Hughesaaa5edc2012-05-16 15:54:30 -0700227 if (!UnboxPrimitiveForField(boxed_value, FieldHelper(f).GetType(), unboxed_value, f)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800228 return;
229 }
230
231 // Check that the receiver is non-null and an instance of the field's declaring class.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700233 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800234 return;
235 }
236
237 SetFieldValue(o, f, unboxed_value, true);
238}
239
Elliott Hughes0512f022012-03-15 22:10:52 -0700240static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor,
241 const JValue& new_value) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700242 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800243 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
244 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700245 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700246 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700247 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800248 FieldHelper fh(f);
249 if (!fh.IsPrimitiveType()) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700250 soa.Self()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;",
Jesse Wilsonc129a6b2011-11-24 14:47:46 -0500251 "Not a primitive field: %s", PrettyField(f).c_str());
252 return;
253 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700254
255 // Widen the value if necessary (and possible).
256 JValue wide_value;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800257 mirror::Class* src_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(src_descriptor);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800258 if (!ConvertPrimitiveValue(src_type->GetPrimitiveType(), fh.GetTypeAsPrimitiveType(),
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700259 new_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700260 return;
261 }
262
263 // Write the value.
264 SetFieldValue(o, f, wide_value, false);
265}
266
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700267static void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean z) {
268 JValue value;
269 value.SetZ(z);
270 SetPrimitiveField(env, javaField, javaObj, 'Z', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700271}
272
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700273static void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte b) {
274 JValue value;
275 value.SetB(b);
276 SetPrimitiveField(env, javaField, javaObj, 'B', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700277}
278
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700279static void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar c) {
280 JValue value;
281 value.SetC(c);
282 SetPrimitiveField(env, javaField, javaObj, 'C', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800283}
Elliott Hughes33203b52011-09-20 19:42:01 -0700284
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700285static void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble d) {
286 JValue value;
287 value.SetD(d);
288 SetPrimitiveField(env, javaField, javaObj, 'D', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800289}
Elliott Hughes33203b52011-09-20 19:42:01 -0700290
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700291static void Field_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat f) {
292 JValue value;
293 value.SetF(f);
294 SetPrimitiveField(env, javaField, javaObj, 'F', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800295}
296
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700297static void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint i) {
298 JValue value;
299 value.SetI(i);
300 SetPrimitiveField(env, javaField, javaObj, 'I', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800301}
302
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700303static void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong j) {
304 JValue value;
305 value.SetJ(j);
306 SetPrimitiveField(env, javaField, javaObj, 'J', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800307}
308
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700309static void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort s) {
310 JValue value;
311 value.SetS(s);
312 SetPrimitiveField(env, javaField, javaObj, 'S', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700313}
314
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700315static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800316 NATIVE_METHOD(Field, get, "(Ljava/lang/Object;)Ljava/lang/Object;"),
317 NATIVE_METHOD(Field, getBoolean, "(Ljava/lang/Object;)Z"),
318 NATIVE_METHOD(Field, getByte, "(Ljava/lang/Object;)B"),
319 NATIVE_METHOD(Field, getChar, "(Ljava/lang/Object;)C"),
320 NATIVE_METHOD(Field, getDouble, "(Ljava/lang/Object;)D"),
321 NATIVE_METHOD(Field, getFloat, "(Ljava/lang/Object;)F"),
322 NATIVE_METHOD(Field, getInt, "(Ljava/lang/Object;)I"),
323 NATIVE_METHOD(Field, getLong, "(Ljava/lang/Object;)J"),
324 NATIVE_METHOD(Field, getShort, "(Ljava/lang/Object;)S"),
325 NATIVE_METHOD(Field, set, "(Ljava/lang/Object;Ljava/lang/Object;)V"),
326 NATIVE_METHOD(Field, setBoolean, "(Ljava/lang/Object;Z)V"),
327 NATIVE_METHOD(Field, setByte, "(Ljava/lang/Object;B)V"),
328 NATIVE_METHOD(Field, setChar, "(Ljava/lang/Object;C)V"),
329 NATIVE_METHOD(Field, setDouble, "(Ljava/lang/Object;D)V"),
330 NATIVE_METHOD(Field, setFloat, "(Ljava/lang/Object;F)V"),
331 NATIVE_METHOD(Field, setInt, "(Ljava/lang/Object;I)V"),
332 NATIVE_METHOD(Field, setLong, "(Ljava/lang/Object;J)V"),
333 NATIVE_METHOD(Field, setShort, "(Ljava/lang/Object;S)V"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700334};
335
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700336void register_java_lang_reflect_Field(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700337 REGISTER_NATIVE_METHODS("java/lang/reflect/Field");
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700338}
339
340} // namespace art