Brian Carlstrom | f867b6f | 2011-09-16 12:17:25 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | #include "jni_internal.h" |
| 18 | #include "class_linker.h" |
| 19 | #include "object.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 20 | #include "object_utils.h" |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 21 | #include "reflection.h" |
Brian Carlstrom | f867b6f | 2011-09-16 12:17:25 -0700 | [diff] [blame] | 22 | |
| 23 | #include "JniConstants.h" // Last to avoid problems with LOG redefinition. |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | namespace { |
| 28 | |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 29 | bool GetFieldValue(Object* o, Field* f, JValue& value, bool allow_references) { |
Brian Carlstrom | b82b687 | 2011-10-26 17:18:07 -0700 | [diff] [blame] | 30 | ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 31 | switch (FieldHelper(f).GetTypeAsPrimitiveType()) { |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 32 | case Primitive::kPrimBoolean: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 33 | value.z = f->GetBoolean(o); |
| 34 | return true; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 35 | case Primitive::kPrimByte: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 36 | value.b = f->GetByte(o); |
| 37 | return true; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 38 | case Primitive::kPrimChar: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 39 | value.c = f->GetChar(o); |
| 40 | return true; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 41 | case Primitive::kPrimDouble: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 42 | value.d = f->GetDouble(o); |
| 43 | return true; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 44 | case Primitive::kPrimFloat: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 45 | value.f = f->GetFloat(o); |
| 46 | return true; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 47 | case Primitive::kPrimInt: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 48 | value.i = f->GetInt(o); |
| 49 | return true; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 50 | case Primitive::kPrimLong: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 51 | value.j = f->GetLong(o); |
| 52 | return true; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 53 | case Primitive::kPrimShort: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 54 | value.s = f->GetShort(o); |
| 55 | return true; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 56 | case Primitive::kPrimNot: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 57 | if (allow_references) { |
| 58 | value.l = f->GetObject(o); |
| 59 | return true; |
| 60 | } |
| 61 | // Else break to report an error. |
| 62 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 63 | case Primitive::kPrimVoid: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 64 | // Never okay. |
| 65 | break; |
| 66 | } |
Elliott Hughes | 5cb5ad2 | 2011-10-02 12:13:39 -0700 | [diff] [blame] | 67 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;", |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 68 | "Not a primitive field: %s", PrettyField(f).c_str()); |
| 69 | return false; |
| 70 | } |
| 71 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 72 | bool CheckReceiver(JNIEnv* env, jobject javaObj, Field* f, Object*& o) { |
Elliott Hughes | ed1c1e3 | 2011-10-02 14:31:05 -0700 | [diff] [blame] | 73 | if (f->IsStatic()) { |
| 74 | o = NULL; |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | o = Decode<Object*>(env, javaObj); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 79 | Class* declaringClass = f->GetDeclaringClass(); |
Elliott Hughes | ed1c1e3 | 2011-10-02 14:31:05 -0700 | [diff] [blame] | 80 | if (!VerifyObjectInClass(env, o, declaringClass)) { |
| 81 | return false; |
| 82 | } |
| 83 | return true; |
| 84 | } |
| 85 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 86 | jobject Field_get(JNIEnv* env, jobject javaField, jobject javaObj) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 87 | Field* f = DecodeField(env->FromReflectedField(javaField)); |
Elliott Hughes | ed1c1e3 | 2011-10-02 14:31:05 -0700 | [diff] [blame] | 88 | Object* o = NULL; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 89 | if (!CheckReceiver(env, javaObj, f, o)) { |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | // Get the field's value, boxing if necessary. |
| 94 | JValue value; |
| 95 | if (!GetFieldValue(o, f, value, true)) { |
| 96 | return NULL; |
| 97 | } |
| 98 | BoxPrimitive(env, FieldHelper(f).GetTypeAsPrimitiveType(), value); |
| 99 | |
| 100 | return AddLocalReference<jobject>(env, value.l); |
| 101 | } |
| 102 | |
| 103 | JValue GetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char dst_descriptor) { |
| 104 | Field* f = DecodeField(env->FromReflectedField(javaField)); |
| 105 | Object* o = NULL; |
| 106 | if (!CheckReceiver(env, javaObj, f, o)) { |
Elliott Hughes | ed1c1e3 | 2011-10-02 14:31:05 -0700 | [diff] [blame] | 107 | return JValue(); |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | // Read the value. |
| 111 | JValue field_value; |
| 112 | if (!GetFieldValue(o, f, field_value, false)) { |
| 113 | return JValue(); |
| 114 | } |
| 115 | |
| 116 | // Widen it if necessary (and possible). |
| 117 | JValue wide_value; |
Elliott Hughes | 582a7d1 | 2011-10-10 18:38:42 -0700 | [diff] [blame] | 118 | Class* dst_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(dst_descriptor); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 119 | if (!ConvertPrimitiveValue(FieldHelper(f).GetTypeAsPrimitiveType(), dst_type->GetPrimitiveType(), |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 120 | field_value, wide_value)) { |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 121 | return JValue(); |
| 122 | } |
| 123 | return wide_value; |
| 124 | } |
| 125 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 126 | jboolean Field_getBoolean(JNIEnv* env, jobject javaField, jobject javaObj) { |
| 127 | return GetPrimitiveField(env, javaField, javaObj, 'Z').z; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 130 | jbyte Field_getByte(JNIEnv* env, jobject javaField, jobject javaObj) { |
| 131 | return GetPrimitiveField(env, javaField, javaObj, 'B').b; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 134 | jchar Field_getChar(JNIEnv* env, jobject javaField, jobject javaObj) { |
| 135 | return GetPrimitiveField(env, javaField, javaObj, 'C').c; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 138 | jdouble Field_getDouble(JNIEnv* env, jobject javaField, jobject javaObj) { |
| 139 | return GetPrimitiveField(env, javaField, javaObj, 'D').d; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 142 | jfloat Field_getFloat(JNIEnv* env, jobject javaField, jobject javaObj) { |
| 143 | return GetPrimitiveField(env, javaField, javaObj, 'F').f; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 146 | jint Field_getInt(JNIEnv* env, jobject javaField, jobject javaObj) { |
| 147 | return GetPrimitiveField(env, javaField, javaObj, 'I').i; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 150 | jlong Field_getLong(JNIEnv* env, jobject javaField, jobject javaObj) { |
| 151 | return GetPrimitiveField(env, javaField, javaObj, 'J').j; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 154 | jshort Field_getShort(JNIEnv* env, jobject javaField, jobject javaObj) { |
| 155 | return GetPrimitiveField(env, javaField, javaObj, 'S').s; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | void SetFieldValue(Object* o, Field* f, const JValue& new_value, bool allow_references) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 159 | switch (FieldHelper(f).GetTypeAsPrimitiveType()) { |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 160 | case Primitive::kPrimBoolean: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 161 | f->SetBoolean(o, new_value.z); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 162 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 163 | case Primitive::kPrimByte: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 164 | f->SetByte(o, new_value.b); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 165 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 166 | case Primitive::kPrimChar: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 167 | f->SetChar(o, new_value.c); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 168 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 169 | case Primitive::kPrimDouble: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 170 | f->SetDouble(o, new_value.d); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 171 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 172 | case Primitive::kPrimFloat: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 173 | f->SetFloat(o, new_value.f); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 174 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 175 | case Primitive::kPrimInt: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 176 | f->SetInt(o, new_value.i); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 177 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 178 | case Primitive::kPrimLong: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 179 | f->SetLong(o, new_value.j); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 180 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 181 | case Primitive::kPrimShort: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 182 | f->SetShort(o, new_value.s); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 183 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 184 | case Primitive::kPrimNot: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 185 | if (allow_references) { |
| 186 | f->SetObject(o, new_value.l); |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 187 | break; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 188 | } |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 189 | // Else fall through to report an error. |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 190 | case Primitive::kPrimVoid: |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 191 | // Never okay. |
Elliott Hughes | 5cb5ad2 | 2011-10-02 12:13:39 -0700 | [diff] [blame] | 192 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;", |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 193 | "Not a primitive field: %s", PrettyField(f).c_str()); |
| 194 | return; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 195 | } |
Elliott Hughes | fe6207f | 2011-09-26 17:24:06 -0700 | [diff] [blame] | 196 | |
| 197 | // Special handling for final fields on SMP systems. |
| 198 | // We need a store/store barrier here (JMM requirement). |
| 199 | if (f->IsFinal()) { |
| 200 | ANDROID_MEMBAR_STORE(); |
| 201 | } |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 204 | void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject javaValue) { |
| 205 | ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); |
| 206 | Field* f = DecodeField(env->FromReflectedField(javaField)); |
| 207 | |
| 208 | // Unbox the value, if necessary. |
| 209 | Object* boxed_value = Decode<Object*>(env, javaValue); |
| 210 | JValue unboxed_value; |
| 211 | if (!UnboxPrimitive(env, boxed_value, FieldHelper(f).GetType(), unboxed_value)) { |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | // Check that the receiver is non-null and an instance of the field's declaring class. |
| 216 | Object* o = NULL; |
| 217 | if (!CheckReceiver(env, javaObj, f, o)) { |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | SetFieldValue(o, f, unboxed_value, true); |
| 222 | } |
| 223 | |
| 224 | void SetPrimitiveField(JNIEnv* env, jobject javaField, jobject javaObj, char src_descriptor, |
| 225 | const JValue& new_value) { |
Brian Carlstrom | b82b687 | 2011-10-26 17:18:07 -0700 | [diff] [blame] | 226 | ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable); |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 227 | Field* f = DecodeField(env->FromReflectedField(javaField)); |
Elliott Hughes | ed1c1e3 | 2011-10-02 14:31:05 -0700 | [diff] [blame] | 228 | Object* o = NULL; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 229 | if (!CheckReceiver(env, javaObj, f, o)) { |
Elliott Hughes | ed1c1e3 | 2011-10-02 14:31:05 -0700 | [diff] [blame] | 230 | return; |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 231 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 232 | FieldHelper fh(f); |
| 233 | if (!fh.IsPrimitiveType()) { |
Jesse Wilson | c129a6b | 2011-11-24 14:47:46 -0500 | [diff] [blame] | 234 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;", |
| 235 | "Not a primitive field: %s", PrettyField(f).c_str()); |
| 236 | return; |
| 237 | } |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 238 | |
| 239 | // Widen the value if necessary (and possible). |
| 240 | JValue wide_value; |
Elliott Hughes | 582a7d1 | 2011-10-10 18:38:42 -0700 | [diff] [blame] | 241 | Class* src_type = Runtime::Current()->GetClassLinker()->FindPrimitiveClass(src_descriptor); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 242 | if (!ConvertPrimitiveValue(src_type->GetPrimitiveType(), fh.GetTypeAsPrimitiveType(), |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 243 | new_value, wide_value)) { |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 244 | return; |
| 245 | } |
| 246 | |
| 247 | // Write the value. |
| 248 | SetFieldValue(o, f, wide_value, false); |
| 249 | } |
| 250 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 251 | void Field_setBoolean(JNIEnv* env, jobject javaField, jobject javaObj, jboolean value) { |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 252 | JValue v = { 0 }; |
| 253 | v.z = value; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 254 | SetPrimitiveField(env, javaField, javaObj, 'Z', v); |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 257 | void Field_setByte(JNIEnv* env, jobject javaField, jobject javaObj, jbyte value) { |
| 258 | JValue v = { 0 }; |
| 259 | v.b = value; |
| 260 | SetPrimitiveField(env, javaField, javaObj, 'B', v); |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 263 | void Field_setChar(JNIEnv* env, jobject javaField, jobject javaObj, jchar value) { |
| 264 | JValue v = { 0 }; |
| 265 | v.c = value; |
| 266 | SetPrimitiveField(env, javaField, javaObj, 'C', v); |
| 267 | } |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 268 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 269 | void Field_setDouble(JNIEnv* env, jobject javaField, jobject javaObj, jdouble value) { |
| 270 | JValue v = { 0 }; |
| 271 | v.d = value; |
| 272 | SetPrimitiveField(env, javaField, javaObj, 'D', v); |
| 273 | } |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 274 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 275 | void Field_setFloat(JNIEnv* env, jobject javaField, jobject javaObj, jfloat value) { |
| 276 | JValue v = { 0 }; |
| 277 | v.f = value; |
| 278 | SetPrimitiveField(env, javaField, javaObj, 'F', v); |
| 279 | } |
| 280 | |
| 281 | void Field_setInt(JNIEnv* env, jobject javaField, jobject javaObj, jint value) { |
| 282 | JValue v = { 0 }; |
| 283 | v.i = value; |
| 284 | SetPrimitiveField(env, javaField, javaObj, 'I', v); |
| 285 | } |
| 286 | |
| 287 | void Field_setLong(JNIEnv* env, jobject javaField, jobject javaObj, jlong value) { |
| 288 | JValue v = { 0 }; |
| 289 | v.j = value; |
| 290 | SetPrimitiveField(env, javaField, javaObj, 'J', v); |
| 291 | } |
| 292 | |
| 293 | void Field_setShort(JNIEnv* env, jobject javaField, jobject javaObj, jshort value) { |
| 294 | JValue v = { 0 }; |
| 295 | v.s = value; |
| 296 | SetPrimitiveField(env, javaField, javaObj, 'S', v); |
Elliott Hughes | 33203b5 | 2011-09-20 19:42:01 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Brian Carlstrom | f867b6f | 2011-09-16 12:17:25 -0700 | [diff] [blame] | 299 | static JNINativeMethod gMethods[] = { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 300 | NATIVE_METHOD(Field, get, "(Ljava/lang/Object;)Ljava/lang/Object;"), |
| 301 | NATIVE_METHOD(Field, getBoolean, "(Ljava/lang/Object;)Z"), |
| 302 | NATIVE_METHOD(Field, getByte, "(Ljava/lang/Object;)B"), |
| 303 | NATIVE_METHOD(Field, getChar, "(Ljava/lang/Object;)C"), |
| 304 | NATIVE_METHOD(Field, getDouble, "(Ljava/lang/Object;)D"), |
| 305 | NATIVE_METHOD(Field, getFloat, "(Ljava/lang/Object;)F"), |
| 306 | NATIVE_METHOD(Field, getInt, "(Ljava/lang/Object;)I"), |
| 307 | NATIVE_METHOD(Field, getLong, "(Ljava/lang/Object;)J"), |
| 308 | NATIVE_METHOD(Field, getShort, "(Ljava/lang/Object;)S"), |
| 309 | NATIVE_METHOD(Field, set, "(Ljava/lang/Object;Ljava/lang/Object;)V"), |
| 310 | NATIVE_METHOD(Field, setBoolean, "(Ljava/lang/Object;Z)V"), |
| 311 | NATIVE_METHOD(Field, setByte, "(Ljava/lang/Object;B)V"), |
| 312 | NATIVE_METHOD(Field, setChar, "(Ljava/lang/Object;C)V"), |
| 313 | NATIVE_METHOD(Field, setDouble, "(Ljava/lang/Object;D)V"), |
| 314 | NATIVE_METHOD(Field, setFloat, "(Ljava/lang/Object;F)V"), |
| 315 | NATIVE_METHOD(Field, setInt, "(Ljava/lang/Object;I)V"), |
| 316 | NATIVE_METHOD(Field, setLong, "(Ljava/lang/Object;J)V"), |
| 317 | NATIVE_METHOD(Field, setShort, "(Ljava/lang/Object;S)V"), |
Brian Carlstrom | f867b6f | 2011-09-16 12:17:25 -0700 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | } // namespace |
| 321 | |
| 322 | void register_java_lang_reflect_Field(JNIEnv* env) { |
Brian Carlstrom | f867b6f | 2011-09-16 12:17:25 -0700 | [diff] [blame] | 323 | jniRegisterNativeMethods(env, "java/lang/reflect/Field", gMethods, NELEM(gMethods)); |
| 324 | } |
| 325 | |
| 326 | } // namespace art |