blob: b0daa916c6180be6447ffb79551ddfb46dda2f9d [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"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070022#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "mirror/field.h"
24#include "mirror/field-inl.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080025#include "object_utils.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070026#include "reflection.h"
Ian Rogers00f7d0e2012-07-19 15:28:27 -070027#include "scoped_thread_state_change.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070028
Brian Carlstromf867b6f2011-09-16 12:17:25 -070029namespace art {
30
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031static bool GetFieldValue(const ScopedObjectAccess& soa, mirror::Object* o, mirror::Field* f,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070032 JValue& value, bool allow_references)
Ian Rogersb726dcb2012-09-05 08:57:23 -070033 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070034 DCHECK_EQ(value.GetJ(), 0LL);
Ian Rogers00f7d0e2012-07-19 15:28:27 -070035 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(f->GetDeclaringClass(),
36 true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -070037 return false;
38 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080039 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070040 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070041 value.SetZ(f->GetBoolean(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070042 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070043 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070044 value.SetB(f->GetByte(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070045 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070046 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070047 value.SetC(f->GetChar(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070048 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070049 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070050 value.SetD(f->GetDouble(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070051 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070052 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070053 value.SetF(f->GetFloat(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070054 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070055 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070056 value.SetI(f->GetInt(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070057 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070058 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070059 value.SetJ(f->GetLong(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070060 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070061 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070062 value.SetS(f->GetShort(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070063 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070064 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -070065 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070066 value.SetL(f->GetObject(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070067 return true;
68 }
69 // Else break to report an error.
70 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070071 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -070072 // Never okay.
73 break;
74 }
Ian Rogers62d6c772013-02-27 08:32:07 -080075 ThrowIllegalArgumentException(NULL,
76 StringPrintf("Not a primitive field: %s",
77 PrettyField(f).c_str()).c_str());
Elliott Hughes33203b52011-09-20 19:42:01 -070078 return false;
79}
80
Ian Rogers62d6c772013-02-27 08:32:07 -080081static bool CheckReceiver(const ScopedObjectAccess& soa, jobject j_rcvr, mirror::Field* f,
82 mirror::Object*& class_or_rcvr)
Ian Rogersb726dcb2012-09-05 08:57:23 -070083 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070084 if (f->IsStatic()) {
Ian Rogers62d6c772013-02-27 08:32:07 -080085 class_or_rcvr = f->GetDeclaringClass();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070086 return true;
87 }
88
Ian Rogers62d6c772013-02-27 08:32:07 -080089 class_or_rcvr = soa.Decode<mirror::Object*>(j_rcvr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080090 mirror::Class* declaringClass = f->GetDeclaringClass();
Ian Rogers62d6c772013-02-27 08:32:07 -080091 if (!VerifyObjectInClass(class_or_rcvr, declaringClass)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070092 return false;
93 }
94 return true;
95}
96
Elliott Hughes0512f022012-03-15 22:10:52 -070097static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070098 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
100 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700101 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800102 return NULL;
103 }
104
105 // Get the field's value, boxing if necessary.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700106 JValue value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700107 if (!GetFieldValue(soa, o, f, value, true)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800108 return NULL;
109 }
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800110 return
111 soa.AddLocalReference<jobject>(BoxPrimitive(FieldHelper(f).GetTypeAsPrimitiveType(), value));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800112}
113
Elliott Hughes0512f022012-03-15 22:10:52 -0700114static JValue GetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char dst_descriptor) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700115 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800116 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
117 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;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800130 mirror::Class* dst_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(dst_descriptor);
Ian Rogers62d6c772013-02-27 08:32:07 -0800131 if (!ConvertPrimitiveValue(NULL, false, FieldHelper(f).GetTypeAsPrimitiveType(),
132 dst_type->GetPrimitiveType(), field_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700133 return JValue();
134 }
135 return wide_value;
136}
137
Elliott Hughes0512f022012-03-15 22:10:52 -0700138static jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700139 return GetPrimitiveField(env, javaField, javaObj, 'Z').GetZ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700140}
141
Elliott Hughes0512f022012-03-15 22:10:52 -0700142static jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700143 return GetPrimitiveField(env, javaField, javaObj, 'B').GetB();
Elliott Hughes33203b52011-09-20 19:42:01 -0700144}
145
Elliott Hughes0512f022012-03-15 22:10:52 -0700146static jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700147 return GetPrimitiveField(env, javaField, javaObj, 'C').GetC();
Elliott Hughes33203b52011-09-20 19:42:01 -0700148}
149
Elliott Hughes0512f022012-03-15 22:10:52 -0700150static jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700151 return GetPrimitiveField(env, javaField, javaObj, 'D').GetD();
Elliott Hughes33203b52011-09-20 19:42:01 -0700152}
153
Elliott Hughes0512f022012-03-15 22:10:52 -0700154static jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700155 return GetPrimitiveField(env, javaField, javaObj, 'F').GetF();
Elliott Hughes33203b52011-09-20 19:42:01 -0700156}
157
Elliott Hughes0512f022012-03-15 22:10:52 -0700158static jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700159 return GetPrimitiveField(env, javaField, javaObj, 'I').GetI();
Elliott Hughes33203b52011-09-20 19:42:01 -0700160}
161
Elliott Hughes0512f022012-03-15 22:10:52 -0700162static jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700163 return GetPrimitiveField(env, javaField, javaObj, 'J').GetJ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700164}
165
Elliott Hughes0512f022012-03-15 22:10:52 -0700166static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700167 return GetPrimitiveField(env, javaField, javaObj, 'S').GetS();
Elliott Hughes33203b52011-09-20 19:42:01 -0700168}
169
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170static void SetFieldValue(mirror::Object* o, mirror::Field* f, const JValue& new_value,
171 bool allow_references)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700172 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700173 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(f->GetDeclaringClass(),
174 true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -0700175 return;
176 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800177 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700178 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700179 f->SetBoolean(o, new_value.GetZ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700180 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700181 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700182 f->SetByte(o, new_value.GetB());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700183 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700184 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700185 f->SetChar(o, new_value.GetC());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700186 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700187 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700188 f->SetDouble(o, new_value.GetD());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700189 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700190 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700191 f->SetFloat(o, new_value.GetF());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700192 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700193 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700194 f->SetInt(o, new_value.GetI());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700195 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700196 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700197 f->SetLong(o, new_value.GetJ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700198 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700199 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700200 f->SetShort(o, new_value.GetS());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700201 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700202 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -0700203 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700204 f->SetObject(o, new_value.GetL());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700205 break;
Elliott Hughes33203b52011-09-20 19:42:01 -0700206 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700207 // Else fall through to report an error.
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700208 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -0700209 // Never okay.
Ian Rogers62d6c772013-02-27 08:32:07 -0800210 ThrowIllegalArgumentException(NULL, StringPrintf("Not a primitive field: %s",
211 PrettyField(f).c_str()).c_str());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700212 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700213 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700214
215 // Special handling for final fields on SMP systems.
216 // We need a store/store barrier here (JMM requirement).
217 if (f->IsFinal()) {
218 ANDROID_MEMBAR_STORE();
219 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700220}
221
Elliott Hughes0512f022012-03-15 22:10:52 -0700222static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700223 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800224 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800225
226 // Unbox the value, if necessary.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227 mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800228 JValue unboxed_value;
Elliott Hughesaaa5edc2012-05-16 15:54:30 -0700229 if (!UnboxPrimitiveForField(boxed_value, FieldHelper(f).GetType(), unboxed_value, f)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800230 return;
231 }
232
233 // Check that the receiver is non-null and an instance of the field's declaring class.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800234 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700235 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800236 return;
237 }
238
239 SetFieldValue(o, f, unboxed_value, true);
240}
241
Elliott Hughes0512f022012-03-15 22:10:52 -0700242static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor,
243 const JValue& new_value) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700244 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800245 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
246 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700247 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700248 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700249 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800250 FieldHelper fh(f);
251 if (!fh.IsPrimitiveType()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800252 ThrowIllegalArgumentException(NULL, StringPrintf("Not a primitive field: %s",
253 PrettyField(f).c_str()).c_str());
Jesse Wilsonc129a6b2011-11-24 14:47:46 -0500254 return;
255 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700256
257 // Widen the value if necessary (and possible).
258 JValue wide_value;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800259 mirror::Class* src_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(src_descriptor);
Ian Rogers62d6c772013-02-27 08:32:07 -0800260 if (!ConvertPrimitiveValue(NULL, false, src_type->GetPrimitiveType(), fh.GetTypeAsPrimitiveType(),
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700261 new_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700262 return;
263 }
264
265 // Write the value.
266 SetFieldValue(o, f, wide_value, false);
267}
268
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700269static void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean z) {
270 JValue value;
271 value.SetZ(z);
272 SetPrimitiveField(env, javaField, javaObj, 'Z', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700273}
274
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700275static void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte b) {
276 JValue value;
277 value.SetB(b);
278 SetPrimitiveField(env, javaField, javaObj, 'B', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700279}
280
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700281static void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar c) {
282 JValue value;
283 value.SetC(c);
284 SetPrimitiveField(env, javaField, javaObj, 'C', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800285}
Elliott Hughes33203b52011-09-20 19:42:01 -0700286
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700287static void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble d) {
288 JValue value;
289 value.SetD(d);
290 SetPrimitiveField(env, javaField, javaObj, 'D', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800291}
Elliott Hughes33203b52011-09-20 19:42:01 -0700292
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700293static void Field_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat f) {
294 JValue value;
295 value.SetF(f);
296 SetPrimitiveField(env, javaField, javaObj, 'F', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800297}
298
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700299static void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint i) {
300 JValue value;
301 value.SetI(i);
302 SetPrimitiveField(env, javaField, javaObj, 'I', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800303}
304
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700305static void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong j) {
306 JValue value;
307 value.SetJ(j);
308 SetPrimitiveField(env, javaField, javaObj, 'J', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800309}
310
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700311static void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort s) {
312 JValue value;
313 value.SetS(s);
314 SetPrimitiveField(env, javaField, javaObj, 'S', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700315}
316
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700317static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800318 NATIVE_METHOD(Field, get, "(Ljava/lang/Object;)Ljava/lang/Object;"),
319 NATIVE_METHOD(Field, getBoolean, "(Ljava/lang/Object;)Z"),
320 NATIVE_METHOD(Field, getByte, "(Ljava/lang/Object;)B"),
321 NATIVE_METHOD(Field, getChar, "(Ljava/lang/Object;)C"),
322 NATIVE_METHOD(Field, getDouble, "(Ljava/lang/Object;)D"),
323 NATIVE_METHOD(Field, getFloat, "(Ljava/lang/Object;)F"),
324 NATIVE_METHOD(Field, getInt, "(Ljava/lang/Object;)I"),
325 NATIVE_METHOD(Field, getLong, "(Ljava/lang/Object;)J"),
326 NATIVE_METHOD(Field, getShort, "(Ljava/lang/Object;)S"),
327 NATIVE_METHOD(Field, set, "(Ljava/lang/Object;Ljava/lang/Object;)V"),
328 NATIVE_METHOD(Field, setBoolean, "(Ljava/lang/Object;Z)V"),
329 NATIVE_METHOD(Field, setByte, "(Ljava/lang/Object;B)V"),
330 NATIVE_METHOD(Field, setChar, "(Ljava/lang/Object;C)V"),
331 NATIVE_METHOD(Field, setDouble, "(Ljava/lang/Object;D)V"),
332 NATIVE_METHOD(Field, setFloat, "(Ljava/lang/Object;F)V"),
333 NATIVE_METHOD(Field, setInt, "(Ljava/lang/Object;I)V"),
334 NATIVE_METHOD(Field, setLong, "(Ljava/lang/Object;J)V"),
335 NATIVE_METHOD(Field, setShort, "(Ljava/lang/Object;S)V"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700336};
337
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700338void register_java_lang_reflect_Field(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700339 REGISTER_NATIVE_METHODS("java/lang/reflect/Field");
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700340}
341
342} // namespace art