blob: 9a2671c1678a87ba0c68f93bce17443fef1a370a [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"
Elliott Hugheseac76672012-05-24 21:56:51 -070019#include "jni_internal.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080020#include "mirror/field.h"
21#include "mirror/field-inl.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080022#include "object_utils.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070023#include "reflection.h"
Ian Rogers00f7d0e2012-07-19 15:28:27 -070024#include "scoped_thread_state_change.h"
Brian Carlstromf867b6f2011-09-16 12:17:25 -070025
Brian Carlstromf867b6f2011-09-16 12:17:25 -070026namespace art {
27
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028static bool GetFieldValue(const ScopedObjectAccess& soa, mirror::Object* o, mirror::Field* f,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070029 JValue& value, bool allow_references)
Ian Rogersb726dcb2012-09-05 08:57:23 -070030 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070031 DCHECK_EQ(value.GetJ(), 0LL);
Ian Rogers00f7d0e2012-07-19 15:28:27 -070032 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(f->GetDeclaringClass(),
33 true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -070034 return false;
35 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080036 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070037 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070038 value.SetZ(f->GetBoolean(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070039 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070040 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070041 value.SetB(f->GetByte(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070042 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070043 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070044 value.SetC(f->GetChar(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070045 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070046 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070047 value.SetD(f->GetDouble(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070048 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070049 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070050 value.SetF(f->GetFloat(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070051 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070052 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070053 value.SetI(f->GetInt(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070054 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070055 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070056 value.SetJ(f->GetLong(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070057 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070058 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070059 value.SetS(f->GetShort(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070060 return true;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070061 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -070062 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -070063 value.SetL(f->GetObject(o));
Elliott Hughes33203b52011-09-20 19:42:01 -070064 return true;
65 }
66 // Else break to report an error.
67 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070068 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -070069 // Never okay.
70 break;
71 }
Ian Rogers00f7d0e2012-07-19 15:28:27 -070072 soa.Self()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;",
Elliott Hughes33203b52011-09-20 19:42:01 -070073 "Not a primitive field: %s", PrettyField(f).c_str());
74 return false;
75}
76
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077static bool CheckReceiver(const ScopedObjectAccess& soa, jobject javaObj, mirror::Field* f,
78 mirror::Object*& o)
Ian Rogersb726dcb2012-09-05 08:57:23 -070079 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070080 if (f->IsStatic()) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -070081 o = f->GetDeclaringClass();
Elliott Hughesed1c1e32011-10-02 14:31:05 -070082 return true;
83 }
84
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085 o = soa.Decode<mirror::Object*>(javaObj);
86 mirror::Class* declaringClass = f->GetDeclaringClass();
Elliott Hugheseac76672012-05-24 21:56:51 -070087 if (!VerifyObjectInClass(o, declaringClass)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -070088 return false;
89 }
90 return true;
91}
92
Elliott Hughes0512f022012-03-15 22:10:52 -070093static jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070094 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
96 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070097 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080098 return NULL;
99 }
100
101 // Get the field's value, boxing if necessary.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700102 JValue value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700103 if (!GetFieldValue(soa, o, f, value, true)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800104 return NULL;
105 }
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800106 return
107 soa.AddLocalReference<jobject>(BoxPrimitive(FieldHelper(f).GetTypeAsPrimitiveType(), value));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800108}
109
Elliott Hughes0512f022012-03-15 22:10:52 -0700110static JValue GetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char dst_descriptor) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700111 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800112 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
113 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700114 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700115 return JValue();
Elliott Hughes33203b52011-09-20 19:42:01 -0700116 }
117
118 // Read the value.
Elliott Hughes1d878f32012-04-11 15:17:54 -0700119 JValue field_value;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700120 if (!GetFieldValue(soa, o, f, field_value, false)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700121 return JValue();
122 }
123
124 // Widen it if necessary (and possible).
125 JValue wide_value;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800126 mirror::Class* dst_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(dst_descriptor);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800127 if (!ConvertPrimitiveValue(FieldHelper(f).GetTypeAsPrimitiveType(), dst_type->GetPrimitiveType(),
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700128 field_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700129 return JValue();
130 }
131 return wide_value;
132}
133
Elliott Hughes0512f022012-03-15 22:10:52 -0700134static jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700135 return GetPrimitiveField(env, javaField, javaObj, 'Z').GetZ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700136}
137
Elliott Hughes0512f022012-03-15 22:10:52 -0700138static jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700139 return GetPrimitiveField(env, javaField, javaObj, 'B').GetB();
Elliott Hughes33203b52011-09-20 19:42:01 -0700140}
141
Elliott Hughes0512f022012-03-15 22:10:52 -0700142static jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700143 return GetPrimitiveField(env, javaField, javaObj, 'C').GetC();
Elliott Hughes33203b52011-09-20 19:42:01 -0700144}
145
Elliott Hughes0512f022012-03-15 22:10:52 -0700146static jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700147 return GetPrimitiveField(env, javaField, javaObj, 'D').GetD();
Elliott Hughes33203b52011-09-20 19:42:01 -0700148}
149
Elliott Hughes0512f022012-03-15 22:10:52 -0700150static jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700151 return GetPrimitiveField(env, javaField, javaObj, 'F').GetF();
Elliott Hughes33203b52011-09-20 19:42:01 -0700152}
153
Elliott Hughes0512f022012-03-15 22:10:52 -0700154static jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700155 return GetPrimitiveField(env, javaField, javaObj, 'I').GetI();
Elliott Hughes33203b52011-09-20 19:42:01 -0700156}
157
Elliott Hughes0512f022012-03-15 22:10:52 -0700158static jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700159 return GetPrimitiveField(env, javaField, javaObj, 'J').GetJ();
Elliott Hughes33203b52011-09-20 19:42:01 -0700160}
161
Elliott Hughes0512f022012-03-15 22:10:52 -0700162static jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700163 return GetPrimitiveField(env, javaField, javaObj, 'S').GetS();
Elliott Hughes33203b52011-09-20 19:42:01 -0700164}
165
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166static void SetFieldValue(mirror::Object* o, mirror::Field* f, const JValue& new_value,
167 bool allow_references)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700168 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700169 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(f->GetDeclaringClass(),
170 true, true)) {
Elliott Hughes923e8b82012-03-23 11:44:07 -0700171 return;
172 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800173 switch (FieldHelper(f).GetTypeAsPrimitiveType()) {
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700174 case Primitive::kPrimBoolean:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700175 f->SetBoolean(o, new_value.GetZ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700176 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700177 case Primitive::kPrimByte:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700178 f->SetByte(o, new_value.GetB());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700179 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700180 case Primitive::kPrimChar:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700181 f->SetChar(o, new_value.GetC());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700182 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700183 case Primitive::kPrimDouble:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700184 f->SetDouble(o, new_value.GetD());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700185 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700186 case Primitive::kPrimFloat:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700187 f->SetFloat(o, new_value.GetF());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700188 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700189 case Primitive::kPrimInt:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700190 f->SetInt(o, new_value.GetI());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700191 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700192 case Primitive::kPrimLong:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700193 f->SetLong(o, new_value.GetJ());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700194 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700195 case Primitive::kPrimShort:
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700196 f->SetShort(o, new_value.GetS());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700197 break;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700198 case Primitive::kPrimNot:
Elliott Hughes33203b52011-09-20 19:42:01 -0700199 if (allow_references) {
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700200 f->SetObject(o, new_value.GetL());
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700201 break;
Elliott Hughes33203b52011-09-20 19:42:01 -0700202 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700203 // Else fall through to report an error.
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700204 case Primitive::kPrimVoid:
Elliott Hughes33203b52011-09-20 19:42:01 -0700205 // Never okay.
Elliott Hughes5cb5ad22011-10-02 12:13:39 -0700206 Thread::Current()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;",
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700207 "Not a primitive field: %s", PrettyField(f).c_str());
208 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700209 }
Elliott Hughesfe6207f2011-09-26 17:24:06 -0700210
211 // Special handling for final fields on SMP systems.
212 // We need a store/store barrier here (JMM requirement).
213 if (f->IsFinal()) {
214 ANDROID_MEMBAR_STORE();
215 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700216}
217
Elliott Hughes0512f022012-03-15 22:10:52 -0700218static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700219 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800220 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800221
222 // Unbox the value, if necessary.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800223 mirror::Object* boxed_value = soa.Decode<mirror::Object*>(javaValue);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800224 JValue unboxed_value;
Elliott Hughesaaa5edc2012-05-16 15:54:30 -0700225 if (!UnboxPrimitiveForField(boxed_value, FieldHelper(f).GetType(), unboxed_value, f)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800226 return;
227 }
228
229 // Check that the receiver is non-null and an instance of the field's declaring class.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700231 if (!CheckReceiver(soa, javaObj, f, o)) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800232 return;
233 }
234
235 SetFieldValue(o, f, unboxed_value, true);
236}
237
Elliott Hughes0512f022012-03-15 22:10:52 -0700238static void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor,
239 const JValue& new_value) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700240 ScopedObjectAccess soa(env);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800241 mirror::Field* f = soa.DecodeField(env->FromReflectedField(javaField));
242 mirror::Object* o = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700243 if (!CheckReceiver(soa, javaObj, f, o)) {
Elliott Hughesed1c1e32011-10-02 14:31:05 -0700244 return;
Elliott Hughes33203b52011-09-20 19:42:01 -0700245 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800246 FieldHelper fh(f);
247 if (!fh.IsPrimitiveType()) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700248 soa.Self()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;",
Jesse Wilsonc129a6b2011-11-24 14:47:46 -0500249 "Not a primitive field: %s", PrettyField(f).c_str());
250 return;
251 }
Elliott Hughes33203b52011-09-20 19:42:01 -0700252
253 // Widen the value if necessary (and possible).
254 JValue wide_value;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255 mirror::Class* src_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(src_descriptor);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800256 if (!ConvertPrimitiveValue(src_type->GetPrimitiveType(), fh.GetTypeAsPrimitiveType(),
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700257 new_value, wide_value)) {
Elliott Hughes33203b52011-09-20 19:42:01 -0700258 return;
259 }
260
261 // Write the value.
262 SetFieldValue(o, f, wide_value, false);
263}
264
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700265static void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean z) {
266 JValue value;
267 value.SetZ(z);
268 SetPrimitiveField(env, javaField, javaObj, 'Z', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700269}
270
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700271static void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte b) {
272 JValue value;
273 value.SetB(b);
274 SetPrimitiveField(env, javaField, javaObj, 'B', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700275}
276
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700277static void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar c) {
278 JValue value;
279 value.SetC(c);
280 SetPrimitiveField(env, javaField, javaObj, 'C', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800281}
Elliott Hughes33203b52011-09-20 19:42:01 -0700282
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700283static void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble d) {
284 JValue value;
285 value.SetD(d);
286 SetPrimitiveField(env, javaField, javaObj, 'D', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800287}
Elliott Hughes33203b52011-09-20 19:42:01 -0700288
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700289static void Field_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat f) {
290 JValue value;
291 value.SetF(f);
292 SetPrimitiveField(env, javaField, javaObj, 'F', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800293}
294
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700295static void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint i) {
296 JValue value;
297 value.SetI(i);
298 SetPrimitiveField(env, javaField, javaObj, 'I', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800299}
300
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700301static void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong j) {
302 JValue value;
303 value.SetJ(j);
304 SetPrimitiveField(env, javaField, javaObj, 'J', value);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800305}
306
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700307static void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort s) {
308 JValue value;
309 value.SetS(s);
310 SetPrimitiveField(env, javaField, javaObj, 'S', value);
Elliott Hughes33203b52011-09-20 19:42:01 -0700311}
312
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700313static JNINativeMethod gMethods[] = {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800314 NATIVE_METHOD(Field, get, "(Ljava/lang/Object;)Ljava/lang/Object;"),
315 NATIVE_METHOD(Field, getBoolean, "(Ljava/lang/Object;)Z"),
316 NATIVE_METHOD(Field, getByte, "(Ljava/lang/Object;)B"),
317 NATIVE_METHOD(Field, getChar, "(Ljava/lang/Object;)C"),
318 NATIVE_METHOD(Field, getDouble, "(Ljava/lang/Object;)D"),
319 NATIVE_METHOD(Field, getFloat, "(Ljava/lang/Object;)F"),
320 NATIVE_METHOD(Field, getInt, "(Ljava/lang/Object;)I"),
321 NATIVE_METHOD(Field, getLong, "(Ljava/lang/Object;)J"),
322 NATIVE_METHOD(Field, getShort, "(Ljava/lang/Object;)S"),
323 NATIVE_METHOD(Field, set, "(Ljava/lang/Object;Ljava/lang/Object;)V"),
324 NATIVE_METHOD(Field, setBoolean, "(Ljava/lang/Object;Z)V"),
325 NATIVE_METHOD(Field, setByte, "(Ljava/lang/Object;B)V"),
326 NATIVE_METHOD(Field, setChar, "(Ljava/lang/Object;C)V"),
327 NATIVE_METHOD(Field, setDouble, "(Ljava/lang/Object;D)V"),
328 NATIVE_METHOD(Field, setFloat, "(Ljava/lang/Object;F)V"),
329 NATIVE_METHOD(Field, setInt, "(Ljava/lang/Object;I)V"),
330 NATIVE_METHOD(Field, setLong, "(Ljava/lang/Object;J)V"),
331 NATIVE_METHOD(Field, setShort, "(Ljava/lang/Object;S)V"),
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700332};
333
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700334void register_java_lang_reflect_Field(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700335 REGISTER_NATIVE_METHODS("java/lang/reflect/Field");
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700336}
337
338} // namespace art