Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 17 | #include "reflection-inl.h" |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 18 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method-inl.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 21 | #include "base/enums.h" |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 22 | #include "class_linker.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 23 | #include "common_throws.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 24 | #include "dex/dex_file-inl.h" |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 25 | #include "indirect_reference_table-inl.h" |
Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 26 | #include "jni/java_vm_ext.h" |
| 27 | #include "jni/jni_internal.h" |
Andreas Gampe | c5b7564 | 2018-05-16 15:12:11 -0700 | [diff] [blame^] | 28 | #include "jvalue-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 30 | #include "mirror/executable.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 31 | #include "mirror/object_array-inl.h" |
Andreas Gampe | 373a9b5 | 2017-10-18 09:01:57 -0700 | [diff] [blame] | 32 | #include "nativehelper/scoped_local_ref.h" |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 33 | #include "nth_caller_visitor.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 34 | #include "scoped_thread_state_change-inl.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 35 | #include "stack_reference.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 36 | #include "well_known_classes.h" |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 37 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 38 | namespace art { |
Ian Rogers | 9e937be | 2018-02-15 17:06:58 -0800 | [diff] [blame] | 39 | namespace { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 40 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 41 | using android::base::StringPrintf; |
| 42 | |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 43 | class ArgArray { |
| 44 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 45 | ArgArray(const char* shorty, uint32_t shorty_len) |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 46 | : shorty_(shorty), shorty_len_(shorty_len), num_bytes_(0) { |
| 47 | size_t num_slots = shorty_len + 1; // +1 in case of receiver. |
| 48 | if (LIKELY((num_slots * 2) < kSmallArgArraySize)) { |
| 49 | // We can trivially use the small arg array. |
| 50 | arg_array_ = small_arg_array_; |
| 51 | } else { |
| 52 | // Analyze shorty to see if we need the large arg array. |
| 53 | for (size_t i = 1; i < shorty_len; ++i) { |
| 54 | char c = shorty[i]; |
| 55 | if (c == 'J' || c == 'D') { |
| 56 | num_slots++; |
| 57 | } |
| 58 | } |
| 59 | if (num_slots <= kSmallArgArraySize) { |
| 60 | arg_array_ = small_arg_array_; |
| 61 | } else { |
| 62 | large_arg_array_.reset(new uint32_t[num_slots]); |
| 63 | arg_array_ = large_arg_array_.get(); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | uint32_t* GetArray() { |
| 69 | return arg_array_; |
| 70 | } |
| 71 | |
| 72 | uint32_t GetNumBytes() { |
| 73 | return num_bytes_; |
| 74 | } |
| 75 | |
| 76 | void Append(uint32_t value) { |
| 77 | arg_array_[num_bytes_ / 4] = value; |
| 78 | num_bytes_ += 4; |
| 79 | } |
| 80 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 81 | void Append(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 82 | Append(StackReference<mirror::Object>::FromMirrorPtr(obj.Ptr()).AsVRegValue()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void AppendWide(uint64_t value) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 86 | arg_array_[num_bytes_ / 4] = value; |
| 87 | arg_array_[(num_bytes_ / 4) + 1] = value >> 32; |
| 88 | num_bytes_ += 8; |
| 89 | } |
| 90 | |
| 91 | void AppendFloat(float value) { |
| 92 | jvalue jv; |
| 93 | jv.f = value; |
| 94 | Append(jv.i); |
| 95 | } |
| 96 | |
| 97 | void AppendDouble(double value) { |
| 98 | jvalue jv; |
| 99 | jv.d = value; |
| 100 | AppendWide(jv.j); |
| 101 | } |
| 102 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 103 | void BuildArgArrayFromVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 104 | ObjPtr<mirror::Object> receiver, |
| 105 | va_list ap) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 106 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 107 | // Set receiver if non-null (method is not static) |
| 108 | if (receiver != nullptr) { |
| 109 | Append(receiver); |
| 110 | } |
| 111 | for (size_t i = 1; i < shorty_len_; ++i) { |
| 112 | switch (shorty_[i]) { |
| 113 | case 'Z': |
| 114 | case 'B': |
| 115 | case 'C': |
| 116 | case 'S': |
| 117 | case 'I': |
| 118 | Append(va_arg(ap, jint)); |
| 119 | break; |
| 120 | case 'F': |
| 121 | AppendFloat(va_arg(ap, jdouble)); |
| 122 | break; |
| 123 | case 'L': |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 124 | Append(soa.Decode<mirror::Object>(va_arg(ap, jobject))); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 125 | break; |
| 126 | case 'D': |
| 127 | AppendDouble(va_arg(ap, jdouble)); |
| 128 | break; |
| 129 | case 'J': |
| 130 | AppendWide(va_arg(ap, jlong)); |
| 131 | break; |
| 132 | #ifndef NDEBUG |
| 133 | default: |
| 134 | LOG(FATAL) << "Unexpected shorty character: " << shorty_[i]; |
| 135 | #endif |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 140 | void BuildArgArrayFromJValues(const ScopedObjectAccessAlreadyRunnable& soa, |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 141 | ObjPtr<mirror::Object> receiver, jvalue* args) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 142 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 143 | // Set receiver if non-null (method is not static) |
| 144 | if (receiver != nullptr) { |
| 145 | Append(receiver); |
| 146 | } |
| 147 | for (size_t i = 1, args_offset = 0; i < shorty_len_; ++i, ++args_offset) { |
| 148 | switch (shorty_[i]) { |
| 149 | case 'Z': |
| 150 | Append(args[args_offset].z); |
| 151 | break; |
| 152 | case 'B': |
| 153 | Append(args[args_offset].b); |
| 154 | break; |
| 155 | case 'C': |
| 156 | Append(args[args_offset].c); |
| 157 | break; |
| 158 | case 'S': |
| 159 | Append(args[args_offset].s); |
| 160 | break; |
| 161 | case 'I': |
Ian Rogers | 9e937be | 2018-02-15 17:06:58 -0800 | [diff] [blame] | 162 | FALLTHROUGH_INTENDED; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 163 | case 'F': |
| 164 | Append(args[args_offset].i); |
| 165 | break; |
| 166 | case 'L': |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 167 | Append(soa.Decode<mirror::Object>(args[args_offset].l)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 168 | break; |
| 169 | case 'D': |
Ian Rogers | 9e937be | 2018-02-15 17:06:58 -0800 | [diff] [blame] | 170 | FALLTHROUGH_INTENDED; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 171 | case 'J': |
| 172 | AppendWide(args[args_offset].j); |
| 173 | break; |
| 174 | #ifndef NDEBUG |
| 175 | default: |
| 176 | LOG(FATAL) << "Unexpected shorty character: " << shorty_[i]; |
| 177 | #endif |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | void BuildArgArrayFromFrame(ShadowFrame* shadow_frame, uint32_t arg_offset) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 183 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 184 | // Set receiver if non-null (method is not static) |
| 185 | size_t cur_arg = arg_offset; |
| 186 | if (!shadow_frame->GetMethod()->IsStatic()) { |
| 187 | Append(shadow_frame->GetVReg(cur_arg)); |
| 188 | cur_arg++; |
| 189 | } |
| 190 | for (size_t i = 1; i < shorty_len_; ++i) { |
| 191 | switch (shorty_[i]) { |
| 192 | case 'Z': |
| 193 | case 'B': |
| 194 | case 'C': |
| 195 | case 'S': |
| 196 | case 'I': |
| 197 | case 'F': |
| 198 | case 'L': |
| 199 | Append(shadow_frame->GetVReg(cur_arg)); |
| 200 | cur_arg++; |
| 201 | break; |
| 202 | case 'D': |
| 203 | case 'J': |
| 204 | AppendWide(shadow_frame->GetVRegLong(cur_arg)); |
| 205 | cur_arg++; |
| 206 | cur_arg++; |
| 207 | break; |
| 208 | #ifndef NDEBUG |
| 209 | default: |
| 210 | LOG(FATAL) << "Unexpected shorty character: " << shorty_[i]; |
| 211 | #endif |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | static void ThrowIllegalPrimitiveArgumentException(const char* expected, |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 217 | const char* found_descriptor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 218 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 219 | ThrowIllegalArgumentException( |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 220 | StringPrintf("Invalid primitive conversion from %s to %s", expected, |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 221 | PrettyDescriptor(found_descriptor).c_str()).c_str()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 224 | bool BuildArgArrayFromObjectArray(ObjPtr<mirror::Object> receiver, |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 225 | ObjPtr<mirror::ObjectArray<mirror::Object>> raw_args, |
| 226 | ArtMethod* m, |
| 227 | Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 228 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 229 | const DexFile::TypeList* classes = m->GetParameterTypeList(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 230 | // Set receiver if non-null (method is not static) |
| 231 | if (receiver != nullptr) { |
| 232 | Append(receiver); |
| 233 | } |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 234 | StackHandleScope<2> hs(self); |
| 235 | MutableHandle<mirror::Object> arg(hs.NewHandle<mirror::Object>(nullptr)); |
| 236 | Handle<mirror::ObjectArray<mirror::Object>> args( |
| 237 | hs.NewHandle<mirror::ObjectArray<mirror::Object>>(raw_args)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 238 | for (size_t i = 1, args_offset = 0; i < shorty_len_; ++i, ++args_offset) { |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 239 | arg.Assign(args->Get(args_offset)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 240 | if (((shorty_[i] == 'L') && (arg != nullptr)) || |
| 241 | ((arg == nullptr && shorty_[i] != 'L'))) { |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 242 | // TODO: The method's parameter's type must have been previously resolved, yet |
| 243 | // we've seen cases where it's not b/34440020. |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 244 | ObjPtr<mirror::Class> dst_class( |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 245 | m->ResolveClassFromTypeIndex(classes->GetTypeItem(args_offset).type_idx_)); |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 246 | if (dst_class.Ptr() == nullptr) { |
| 247 | CHECK(self->IsExceptionPending()); |
| 248 | return false; |
| 249 | } |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 250 | if (UNLIKELY(arg == nullptr || !arg->InstanceOf(dst_class))) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 251 | ThrowIllegalArgumentException( |
Ian Rogers | 11e4c03 | 2014-03-14 12:00:39 -0700 | [diff] [blame] | 252 | StringPrintf("method %s argument %zd has type %s, got %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 253 | m->PrettyMethod(false).c_str(), |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 254 | args_offset + 1, // Humans don't count from 0. |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 255 | mirror::Class::PrettyDescriptor(dst_class).c_str(), |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 256 | mirror::Object::PrettyTypeOf(arg.Get()).c_str()).c_str()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 257 | return false; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | #define DO_FIRST_ARG(match_descriptor, get_fn, append) { \ |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 262 | if (LIKELY(arg != nullptr && \ |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 263 | arg->GetClass()->DescriptorEquals(match_descriptor))) { \ |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 264 | ArtField* primitive_field = arg->GetClass()->GetInstanceField(0); \ |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 265 | append(primitive_field-> get_fn(arg.Get())); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 266 | |
| 267 | #define DO_ARG(match_descriptor, get_fn, append) \ |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 268 | } else if (LIKELY(arg != nullptr && \ |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 269 | arg->GetClass<>()->DescriptorEquals(match_descriptor))) { \ |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 270 | ArtField* primitive_field = arg->GetClass()->GetInstanceField(0); \ |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 271 | append(primitive_field-> get_fn(arg.Get())); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 272 | |
| 273 | #define DO_FAIL(expected) \ |
| 274 | } else { \ |
| 275 | if (arg->GetClass<>()->IsPrimitive()) { \ |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 276 | std::string temp; \ |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 277 | ThrowIllegalPrimitiveArgumentException(expected, \ |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 278 | arg->GetClass<>()->GetDescriptor(&temp)); \ |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 279 | } else { \ |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 280 | ThrowIllegalArgumentException(\ |
Ian Rogers | 11e4c03 | 2014-03-14 12:00:39 -0700 | [diff] [blame] | 281 | StringPrintf("method %s argument %zd has type %s, got %s", \ |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 282 | ArtMethod::PrettyMethod(m, false).c_str(), \ |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 283 | args_offset + 1, \ |
| 284 | expected, \ |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 285 | mirror::Object::PrettyTypeOf(arg.Get()).c_str()).c_str()); \ |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 286 | } \ |
| 287 | return false; \ |
| 288 | } } |
| 289 | |
| 290 | switch (shorty_[i]) { |
| 291 | case 'L': |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 292 | Append(arg.Get()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 293 | break; |
| 294 | case 'Z': |
| 295 | DO_FIRST_ARG("Ljava/lang/Boolean;", GetBoolean, Append) |
| 296 | DO_FAIL("boolean") |
| 297 | break; |
| 298 | case 'B': |
| 299 | DO_FIRST_ARG("Ljava/lang/Byte;", GetByte, Append) |
| 300 | DO_FAIL("byte") |
| 301 | break; |
| 302 | case 'C': |
| 303 | DO_FIRST_ARG("Ljava/lang/Character;", GetChar, Append) |
| 304 | DO_FAIL("char") |
| 305 | break; |
| 306 | case 'S': |
| 307 | DO_FIRST_ARG("Ljava/lang/Short;", GetShort, Append) |
| 308 | DO_ARG("Ljava/lang/Byte;", GetByte, Append) |
| 309 | DO_FAIL("short") |
| 310 | break; |
| 311 | case 'I': |
| 312 | DO_FIRST_ARG("Ljava/lang/Integer;", GetInt, Append) |
| 313 | DO_ARG("Ljava/lang/Character;", GetChar, Append) |
| 314 | DO_ARG("Ljava/lang/Short;", GetShort, Append) |
| 315 | DO_ARG("Ljava/lang/Byte;", GetByte, Append) |
| 316 | DO_FAIL("int") |
| 317 | break; |
| 318 | case 'J': |
| 319 | DO_FIRST_ARG("Ljava/lang/Long;", GetLong, AppendWide) |
| 320 | DO_ARG("Ljava/lang/Integer;", GetInt, AppendWide) |
| 321 | DO_ARG("Ljava/lang/Character;", GetChar, AppendWide) |
| 322 | DO_ARG("Ljava/lang/Short;", GetShort, AppendWide) |
| 323 | DO_ARG("Ljava/lang/Byte;", GetByte, AppendWide) |
| 324 | DO_FAIL("long") |
| 325 | break; |
| 326 | case 'F': |
| 327 | DO_FIRST_ARG("Ljava/lang/Float;", GetFloat, AppendFloat) |
| 328 | DO_ARG("Ljava/lang/Long;", GetLong, AppendFloat) |
| 329 | DO_ARG("Ljava/lang/Integer;", GetInt, AppendFloat) |
| 330 | DO_ARG("Ljava/lang/Character;", GetChar, AppendFloat) |
| 331 | DO_ARG("Ljava/lang/Short;", GetShort, AppendFloat) |
| 332 | DO_ARG("Ljava/lang/Byte;", GetByte, AppendFloat) |
| 333 | DO_FAIL("float") |
| 334 | break; |
| 335 | case 'D': |
| 336 | DO_FIRST_ARG("Ljava/lang/Double;", GetDouble, AppendDouble) |
| 337 | DO_ARG("Ljava/lang/Float;", GetFloat, AppendDouble) |
| 338 | DO_ARG("Ljava/lang/Long;", GetLong, AppendDouble) |
| 339 | DO_ARG("Ljava/lang/Integer;", GetInt, AppendDouble) |
| 340 | DO_ARG("Ljava/lang/Character;", GetChar, AppendDouble) |
| 341 | DO_ARG("Ljava/lang/Short;", GetShort, AppendDouble) |
| 342 | DO_ARG("Ljava/lang/Byte;", GetByte, AppendDouble) |
| 343 | DO_FAIL("double") |
| 344 | break; |
| 345 | #ifndef NDEBUG |
| 346 | default: |
| 347 | LOG(FATAL) << "Unexpected shorty character: " << shorty_[i]; |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 348 | UNREACHABLE(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 349 | #endif |
| 350 | } |
| 351 | #undef DO_FIRST_ARG |
| 352 | #undef DO_ARG |
| 353 | #undef DO_FAIL |
| 354 | } |
| 355 | return true; |
| 356 | } |
| 357 | |
| 358 | private: |
| 359 | enum { kSmallArgArraySize = 16 }; |
| 360 | const char* const shorty_; |
| 361 | const uint32_t shorty_len_; |
| 362 | uint32_t num_bytes_; |
| 363 | uint32_t* arg_array_; |
| 364 | uint32_t small_arg_array_[kSmallArgArraySize]; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 365 | std::unique_ptr<uint32_t[]> large_arg_array_; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 366 | }; |
| 367 | |
Ian Rogers | 9e937be | 2018-02-15 17:06:58 -0800 | [diff] [blame] | 368 | void CheckMethodArguments(JavaVMExt* vm, ArtMethod* m, uint32_t* args) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 369 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 370 | const DexFile::TypeList* params = m->GetParameterTypeList(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 371 | if (params == nullptr) { |
| 372 | return; // No arguments so nothing to check. |
| 373 | } |
| 374 | uint32_t offset = 0; |
| 375 | uint32_t num_params = params->Size(); |
| 376 | size_t error_count = 0; |
| 377 | if (!m->IsStatic()) { |
| 378 | offset = 1; |
| 379 | } |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 380 | // TODO: If args contain object references, it may cause problems. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 381 | Thread* const self = Thread::Current(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 382 | for (uint32_t i = 0; i < num_params; i++) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 383 | dex::TypeIndex type_idx = params->GetTypeItem(i).type_idx_; |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 384 | ObjPtr<mirror::Class> param_type(m->ResolveClassFromTypeIndex(type_idx)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 385 | if (param_type == nullptr) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 386 | CHECK(self->IsExceptionPending()); |
| 387 | LOG(ERROR) << "Internal error: unresolvable type for argument type in JNI invoke: " |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 388 | << m->GetTypeDescriptorFromTypeIdx(type_idx) << "\n" |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 389 | << self->GetException()->Dump(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 390 | self->ClearException(); |
| 391 | ++error_count; |
| 392 | } else if (!param_type->IsPrimitive()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 393 | // TODO: There is a compaction bug here since GetClassFromTypeIdx can cause thread suspension, |
| 394 | // this is a hard to fix problem since the args can contain Object*, we need to save and |
| 395 | // restore them by using a visitor similar to the ones used in the trampoline entrypoints. |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 396 | ObjPtr<mirror::Object> argument = |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 397 | (reinterpret_cast<StackReference<mirror::Object>*>(&args[i + offset]))->AsMirrorPtr(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 398 | if (argument != nullptr && !argument->InstanceOf(param_type)) { |
| 399 | LOG(ERROR) << "JNI ERROR (app bug): attempt to pass an instance of " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 400 | << argument->PrettyTypeOf() << " as argument " << (i + 1) |
| 401 | << " to " << m->PrettyMethod(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 402 | ++error_count; |
| 403 | } |
| 404 | } else if (param_type->IsPrimitiveLong() || param_type->IsPrimitiveDouble()) { |
| 405 | offset++; |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 406 | } else { |
| 407 | int32_t arg = static_cast<int32_t>(args[i + offset]); |
| 408 | if (param_type->IsPrimitiveBoolean()) { |
| 409 | if (arg != JNI_TRUE && arg != JNI_FALSE) { |
| 410 | LOG(ERROR) << "JNI ERROR (app bug): expected jboolean (0/1) but got value of " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 411 | << arg << " as argument " << (i + 1) << " to " << m->PrettyMethod(); |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 412 | ++error_count; |
| 413 | } |
| 414 | } else if (param_type->IsPrimitiveByte()) { |
| 415 | if (arg < -128 || arg > 127) { |
| 416 | LOG(ERROR) << "JNI ERROR (app bug): expected jbyte but got value of " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 417 | << arg << " as argument " << (i + 1) << " to " << m->PrettyMethod(); |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 418 | ++error_count; |
| 419 | } |
| 420 | } else if (param_type->IsPrimitiveChar()) { |
| 421 | if (args[i + offset] > 0xFFFF) { |
| 422 | LOG(ERROR) << "JNI ERROR (app bug): expected jchar but got value of " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 423 | << arg << " as argument " << (i + 1) << " to " << m->PrettyMethod(); |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 424 | ++error_count; |
| 425 | } |
| 426 | } else if (param_type->IsPrimitiveShort()) { |
| 427 | if (arg < -32768 || arg > 0x7FFF) { |
| 428 | LOG(ERROR) << "JNI ERROR (app bug): expected jshort but got value of " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 429 | << arg << " as argument " << (i + 1) << " to " << m->PrettyMethod(); |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 430 | ++error_count; |
| 431 | } |
| 432 | } |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 435 | if (UNLIKELY(error_count > 0)) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 436 | // TODO: pass the JNI function name (such as "CallVoidMethodV") through so we can call JniAbort |
| 437 | // with an argument. |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 438 | vm->JniAbortF(nullptr, "bad arguments passed to %s (see above for details)", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 439 | m->PrettyMethod().c_str()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
Ian Rogers | 9e937be | 2018-02-15 17:06:58 -0800 | [diff] [blame] | 443 | ArtMethod* FindVirtualMethod(ObjPtr<mirror::Object> receiver, ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 444 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 445 | return receiver->GetClass()->FindVirtualMethodForVirtualOrInterface(method, kRuntimePointerSize); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
Ian Rogers | 9e937be | 2018-02-15 17:06:58 -0800 | [diff] [blame] | 449 | void InvokeWithArgArray(const ScopedObjectAccessAlreadyRunnable& soa, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 450 | ArtMethod* method, ArgArray* arg_array, JValue* result, |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 451 | const char* shorty) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 452 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 453 | uint32_t* args = arg_array->GetArray(); |
Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 454 | if (UNLIKELY(soa.Env()->IsCheckJniEnabled())) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 455 | CheckMethodArguments(soa.Vm(), method->GetInterfaceMethodIfProxy(kRuntimePointerSize), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 456 | } |
| 457 | method->Invoke(soa.Self(), args, arg_array->GetNumBytes(), result, shorty); |
| 458 | } |
| 459 | |
Ian Rogers | 9e937be | 2018-02-15 17:06:58 -0800 | [diff] [blame] | 460 | } // anonymous namespace |
| 461 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 462 | JValue InvokeWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, jobject obj, jmethodID mid, |
| 463 | va_list args) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 464 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 465 | // We want to make sure that the stack is not within a small distance from the |
| 466 | // protected region in case we are calling into a leaf function whose stack |
| 467 | // check has been elided. |
| 468 | if (UNLIKELY(__builtin_frame_address(0) < soa.Self()->GetStackEnd())) { |
| 469 | ThrowStackOverflowError(soa.Self()); |
| 470 | return JValue(); |
| 471 | } |
| 472 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 473 | ArtMethod* method = jni::DecodeArtMethod(mid); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 474 | bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); |
| 475 | if (is_string_init) { |
| 476 | // Replace calls to String.<init> with equivalent StringFactory call. |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 477 | method = WellKnownClasses::StringInitToStringFactory(method); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 478 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 479 | ObjPtr<mirror::Object> receiver = method->IsStatic() ? nullptr : soa.Decode<mirror::Object>(obj); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 480 | uint32_t shorty_len = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 481 | const char* shorty = |
| 482 | method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(&shorty_len); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 483 | JValue result; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 484 | ArgArray arg_array(shorty, shorty_len); |
Ian Rogers | e18fdd2 | 2014-03-14 13:29:43 -0700 | [diff] [blame] | 485 | arg_array.BuildArgArrayFromVarArgs(soa, receiver, args); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 486 | InvokeWithArgArray(soa, method, &arg_array, &result, shorty); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 487 | if (is_string_init) { |
| 488 | // For string init, remap original receiver to StringFactory result. |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 489 | UpdateReference(soa.Self(), obj, result.GetL()); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 490 | } |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 491 | return result; |
| 492 | } |
| 493 | |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 494 | JValue InvokeWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, jobject obj, jmethodID mid, |
| 495 | jvalue* args) { |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 496 | // We want to make sure that the stack is not within a small distance from the |
| 497 | // protected region in case we are calling into a leaf function whose stack |
| 498 | // check has been elided. |
| 499 | if (UNLIKELY(__builtin_frame_address(0) < soa.Self()->GetStackEnd())) { |
| 500 | ThrowStackOverflowError(soa.Self()); |
| 501 | return JValue(); |
| 502 | } |
| 503 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 504 | ArtMethod* method = jni::DecodeArtMethod(mid); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 505 | bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); |
| 506 | if (is_string_init) { |
| 507 | // Replace calls to String.<init> with equivalent StringFactory call. |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 508 | method = WellKnownClasses::StringInitToStringFactory(method); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 509 | } |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 510 | ObjPtr<mirror::Object> receiver = method->IsStatic() ? nullptr : soa.Decode<mirror::Object>(obj); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 511 | uint32_t shorty_len = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 512 | const char* shorty = |
| 513 | method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(&shorty_len); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 514 | JValue result; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 515 | ArgArray arg_array(shorty, shorty_len); |
Ian Rogers | e18fdd2 | 2014-03-14 13:29:43 -0700 | [diff] [blame] | 516 | arg_array.BuildArgArrayFromJValues(soa, receiver, args); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 517 | InvokeWithArgArray(soa, method, &arg_array, &result, shorty); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 518 | if (is_string_init) { |
| 519 | // For string init, remap original receiver to StringFactory result. |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 520 | UpdateReference(soa.Self(), obj, result.GetL()); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 521 | } |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 522 | return result; |
| 523 | } |
| 524 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 525 | JValue InvokeVirtualOrInterfaceWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 526 | jobject obj, jmethodID mid, jvalue* args) { |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 527 | // We want to make sure that the stack is not within a small distance from the |
| 528 | // protected region in case we are calling into a leaf function whose stack |
| 529 | // check has been elided. |
| 530 | if (UNLIKELY(__builtin_frame_address(0) < soa.Self()->GetStackEnd())) { |
| 531 | ThrowStackOverflowError(soa.Self()); |
| 532 | return JValue(); |
| 533 | } |
| 534 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 535 | ObjPtr<mirror::Object> receiver = soa.Decode<mirror::Object>(obj); |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 536 | ArtMethod* method = FindVirtualMethod(receiver, jni::DecodeArtMethod(mid)); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 537 | bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); |
| 538 | if (is_string_init) { |
| 539 | // Replace calls to String.<init> with equivalent StringFactory call. |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 540 | method = WellKnownClasses::StringInitToStringFactory(method); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 541 | receiver = nullptr; |
| 542 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 543 | uint32_t shorty_len = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 544 | const char* shorty = |
| 545 | method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(&shorty_len); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 546 | JValue result; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 547 | ArgArray arg_array(shorty, shorty_len); |
Ian Rogers | e18fdd2 | 2014-03-14 13:29:43 -0700 | [diff] [blame] | 548 | arg_array.BuildArgArrayFromJValues(soa, receiver, args); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 549 | InvokeWithArgArray(soa, method, &arg_array, &result, shorty); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 550 | if (is_string_init) { |
| 551 | // For string init, remap original receiver to StringFactory result. |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 552 | UpdateReference(soa.Self(), obj, result.GetL()); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 553 | } |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 554 | return result; |
| 555 | } |
| 556 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 557 | JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 558 | jobject obj, jmethodID mid, va_list args) { |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 559 | // We want to make sure that the stack is not within a small distance from the |
| 560 | // protected region in case we are calling into a leaf function whose stack |
| 561 | // check has been elided. |
| 562 | if (UNLIKELY(__builtin_frame_address(0) < soa.Self()->GetStackEnd())) { |
| 563 | ThrowStackOverflowError(soa.Self()); |
| 564 | return JValue(); |
| 565 | } |
| 566 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 567 | ObjPtr<mirror::Object> receiver = soa.Decode<mirror::Object>(obj); |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 568 | ArtMethod* method = FindVirtualMethod(receiver, jni::DecodeArtMethod(mid)); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 569 | bool is_string_init = method->GetDeclaringClass()->IsStringClass() && method->IsConstructor(); |
| 570 | if (is_string_init) { |
| 571 | // Replace calls to String.<init> with equivalent StringFactory call. |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 572 | method = WellKnownClasses::StringInitToStringFactory(method); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 573 | receiver = nullptr; |
| 574 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 575 | uint32_t shorty_len = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 576 | const char* shorty = |
| 577 | method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(&shorty_len); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 578 | JValue result; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 579 | ArgArray arg_array(shorty, shorty_len); |
Ian Rogers | e18fdd2 | 2014-03-14 13:29:43 -0700 | [diff] [blame] | 580 | arg_array.BuildArgArrayFromVarArgs(soa, receiver, args); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 581 | InvokeWithArgArray(soa, method, &arg_array, &result, shorty); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 582 | if (is_string_init) { |
| 583 | // For string init, remap original receiver to StringFactory result. |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 584 | UpdateReference(soa.Self(), obj, result.GetL()); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 585 | } |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 586 | return result; |
| 587 | } |
| 588 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 589 | jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaMethod, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 590 | jobject javaReceiver, jobject javaArgs, size_t num_frames) { |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 591 | // We want to make sure that the stack is not within a small distance from the |
| 592 | // protected region in case we are calling into a leaf function whose stack |
| 593 | // check has been elided. |
| 594 | if (UNLIKELY(__builtin_frame_address(0) < |
| 595 | soa.Self()->GetStackEndForInterpreter(true))) { |
| 596 | ThrowStackOverflowError(soa.Self()); |
| 597 | return nullptr; |
| 598 | } |
| 599 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 600 | ObjPtr<mirror::Executable> executable = soa.Decode<mirror::Executable>(javaMethod); |
Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 601 | const bool accessible = executable->IsAccessible(); |
| 602 | ArtMethod* m = executable->GetArtMethod(); |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 603 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 604 | ObjPtr<mirror::Class> declaring_class = m->GetDeclaringClass(); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 605 | if (UNLIKELY(!declaring_class->IsInitialized())) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 606 | StackHandleScope<1> hs(soa.Self()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 607 | HandleWrapperObjPtr<mirror::Class> h_class(hs.NewHandleWrapper(&declaring_class)); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 608 | if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(soa.Self(), h_class, true, true)) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 609 | return nullptr; |
| 610 | } |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 613 | ObjPtr<mirror::Object> receiver; |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 614 | if (!m->IsStatic()) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 615 | // Replace calls to String.<init> with equivalent StringFactory call. |
| 616 | if (declaring_class->IsStringClass() && m->IsConstructor()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 617 | m = WellKnownClasses::StringInitToStringFactory(m); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 618 | CHECK(javaReceiver == nullptr); |
| 619 | } else { |
| 620 | // Check that the receiver is non-null and an instance of the field's declaring class. |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 621 | receiver = soa.Decode<mirror::Object>(javaReceiver); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 622 | if (!VerifyObjectIsClass(receiver, declaring_class)) { |
| 623 | return nullptr; |
| 624 | } |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 625 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 626 | // Find the actual implementation of the virtual method. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 627 | m = receiver->GetClass()->FindVirtualMethodForVirtualOrInterface(m, kRuntimePointerSize); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 628 | } |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | // Get our arrays of arguments and their types, and check they're the same size. |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 632 | ObjPtr<mirror::ObjectArray<mirror::Object>> objects = |
| 633 | soa.Decode<mirror::ObjectArray<mirror::Object>>(javaArgs); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 634 | auto* np_method = m->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 635 | const DexFile::TypeList* classes = np_method->GetParameterTypeList(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 636 | uint32_t classes_size = (classes == nullptr) ? 0 : classes->Size(); |
| 637 | uint32_t arg_count = (objects != nullptr) ? objects->GetLength() : 0; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 638 | if (arg_count != classes_size) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 639 | ThrowIllegalArgumentException(StringPrintf("Wrong number of arguments; expected %d, got %d", |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 640 | classes_size, arg_count).c_str()); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 641 | return nullptr; |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Jeff Hao | cb4581a | 2014-03-28 15:43:37 -0700 | [diff] [blame] | 644 | // If method is not set to be accessible, verify it can be accessed by the caller. |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 645 | ObjPtr<mirror::Class> calling_class; |
Mathieu Chartier | 268764d | 2016-09-13 12:09:38 -0700 | [diff] [blame] | 646 | if (!accessible && !VerifyAccess(soa.Self(), |
| 647 | receiver, |
| 648 | declaring_class, |
| 649 | m->GetAccessFlags(), |
| 650 | &calling_class, |
| 651 | num_frames)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 652 | ThrowIllegalAccessException( |
Andreas Gampe | c0d8229 | 2014-09-23 10:38:30 -0700 | [diff] [blame] | 653 | StringPrintf("Class %s cannot access %s method %s of class %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 654 | calling_class == nullptr ? "null" : calling_class->PrettyClass().c_str(), |
Andreas Gampe | c0d8229 | 2014-09-23 10:38:30 -0700 | [diff] [blame] | 655 | PrettyJavaAccessFlags(m->GetAccessFlags()).c_str(), |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 656 | m->PrettyMethod().c_str(), |
Andreas Gampe | c0d8229 | 2014-09-23 10:38:30 -0700 | [diff] [blame] | 657 | m->GetDeclaringClass() == nullptr ? "null" : |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 658 | m->GetDeclaringClass()->PrettyClass().c_str()).c_str()); |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 659 | return nullptr; |
| 660 | } |
| 661 | |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 662 | // Invoke the method. |
| 663 | JValue result; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 664 | uint32_t shorty_len = 0; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 665 | const char* shorty = np_method->GetShorty(&shorty_len); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 666 | ArgArray arg_array(shorty, shorty_len); |
Nicolas Geoffray | 4c04117 | 2017-01-19 16:25:06 +0000 | [diff] [blame] | 667 | if (!arg_array.BuildArgArrayFromObjectArray(receiver, objects, np_method, soa.Self())) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 668 | CHECK(soa.Self()->IsExceptionPending()); |
| 669 | return nullptr; |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 672 | InvokeWithArgArray(soa, m, &arg_array, &result, shorty); |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 673 | |
| 674 | // Wrap any exception with "Ljava/lang/reflect/InvocationTargetException;" and return early. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 675 | if (soa.Self()->IsExceptionPending()) { |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 676 | // If we get another exception when we are trying to wrap, then just use that instead. |
Chang Xing | 443f862 | 2017-06-08 11:31:48 -0700 | [diff] [blame] | 677 | ScopedLocalRef<jthrowable> th(soa.Env(), soa.Env()->ExceptionOccurred()); |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 678 | soa.Self()->ClearException(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 679 | jclass exception_class = soa.Env()->FindClass("java/lang/reflect/InvocationTargetException"); |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 680 | if (exception_class == nullptr) { |
Mathieu Chartier | cc9d1cb | 2017-03-16 15:50:57 -0700 | [diff] [blame] | 681 | soa.Self()->AssertPendingException(); |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 682 | return nullptr; |
| 683 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 684 | jmethodID mid = soa.Env()->GetMethodID(exception_class, "<init>", "(Ljava/lang/Throwable;)V"); |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 685 | CHECK(mid != nullptr); |
Chang Xing | 443f862 | 2017-06-08 11:31:48 -0700 | [diff] [blame] | 686 | jobject exception_instance = soa.Env()->NewObject(exception_class, mid, th.get()); |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 687 | if (exception_instance == nullptr) { |
Mathieu Chartier | cc9d1cb | 2017-03-16 15:50:57 -0700 | [diff] [blame] | 688 | soa.Self()->AssertPendingException(); |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 689 | return nullptr; |
| 690 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 691 | soa.Env()->Throw(reinterpret_cast<jthrowable>(exception_instance)); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 692 | return nullptr; |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | // Box if necessary and return. |
Mathieu Chartier | f8ac97f | 2016-10-05 15:56:52 -0700 | [diff] [blame] | 696 | return soa.AddLocalReference<jobject>(BoxPrimitive(Primitive::GetType(shorty[0]), result)); |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 699 | ObjPtr<mirror::Object> BoxPrimitive(Primitive::Type src_class, const JValue& value) { |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 700 | if (src_class == Primitive::kPrimNot) { |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 701 | return MakeObjPtr(value.GetL()); |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 702 | } |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 703 | if (src_class == Primitive::kPrimVoid) { |
| 704 | // There's no such thing as a void field, and void methods invoked via reflection return null. |
| 705 | return nullptr; |
| 706 | } |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 707 | |
Ian Rogers | 84956ff | 2014-03-26 23:52:41 -0700 | [diff] [blame] | 708 | jmethodID m = nullptr; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 709 | const char* shorty; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 710 | switch (src_class) { |
| 711 | case Primitive::kPrimBoolean: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 712 | m = WellKnownClasses::java_lang_Boolean_valueOf; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 713 | shorty = "LZ"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 714 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 715 | case Primitive::kPrimByte: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 716 | m = WellKnownClasses::java_lang_Byte_valueOf; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 717 | shorty = "LB"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 718 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 719 | case Primitive::kPrimChar: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 720 | m = WellKnownClasses::java_lang_Character_valueOf; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 721 | shorty = "LC"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 722 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 723 | case Primitive::kPrimDouble: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 724 | m = WellKnownClasses::java_lang_Double_valueOf; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 725 | shorty = "LD"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 726 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 727 | case Primitive::kPrimFloat: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 728 | m = WellKnownClasses::java_lang_Float_valueOf; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 729 | shorty = "LF"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 730 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 731 | case Primitive::kPrimInt: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 732 | m = WellKnownClasses::java_lang_Integer_valueOf; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 733 | shorty = "LI"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 734 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 735 | case Primitive::kPrimLong: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 736 | m = WellKnownClasses::java_lang_Long_valueOf; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 737 | shorty = "LJ"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 738 | break; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 739 | case Primitive::kPrimShort: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 740 | m = WellKnownClasses::java_lang_Short_valueOf; |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 741 | shorty = "LS"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 742 | break; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 743 | default: |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 744 | LOG(FATAL) << static_cast<int>(src_class); |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 745 | shorty = nullptr; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 748 | ScopedObjectAccessUnchecked soa(Thread::Current()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 749 | DCHECK_EQ(soa.Self()->GetState(), kRunnable); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 750 | |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 751 | ArgArray arg_array(shorty, 2); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 752 | JValue result; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 753 | if (src_class == Primitive::kPrimDouble || src_class == Primitive::kPrimLong) { |
| 754 | arg_array.AppendWide(value.GetJ()); |
| 755 | } else { |
| 756 | arg_array.Append(value.GetI()); |
| 757 | } |
| 758 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 759 | jni::DecodeArtMethod(m)->Invoke(soa.Self(), |
| 760 | arg_array.GetArray(), |
| 761 | arg_array.GetNumBytes(), |
| 762 | &result, |
| 763 | shorty); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 764 | return result.GetL(); |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 767 | static std::string UnboxingFailureKind(ArtField* f) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 768 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 84956ff | 2014-03-26 23:52:41 -0700 | [diff] [blame] | 769 | if (f != nullptr) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 770 | return "field " + f->PrettyField(false); |
Elliott Hughes | aaa5edc | 2012-05-16 15:54:30 -0700 | [diff] [blame] | 771 | } |
| 772 | return "result"; |
| 773 | } |
| 774 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 775 | static bool UnboxPrimitive(ObjPtr<mirror::Object> o, |
| 776 | ObjPtr<mirror::Class> dst_class, |
| 777 | ArtField* f, |
Ian Rogers | 84956ff | 2014-03-26 23:52:41 -0700 | [diff] [blame] | 778 | JValue* unboxed_value) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 779 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 84956ff | 2014-03-26 23:52:41 -0700 | [diff] [blame] | 780 | bool unbox_for_result = (f == nullptr); |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 781 | if (!dst_class->IsPrimitive()) { |
Ian Rogers | 84956ff | 2014-03-26 23:52:41 -0700 | [diff] [blame] | 782 | if (UNLIKELY(o != nullptr && !o->InstanceOf(dst_class))) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 783 | if (!unbox_for_result) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 784 | ThrowIllegalArgumentException( |
| 785 | StringPrintf("%s has type %s, got %s", |
| 786 | UnboxingFailureKind(f).c_str(), |
| 787 | dst_class->PrettyDescriptor().c_str(), |
| 788 | o->PrettyTypeOf().c_str()).c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 789 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 790 | ThrowClassCastException( |
| 791 | StringPrintf("Couldn't convert result of type %s to %s", |
| 792 | o->PrettyTypeOf().c_str(), |
| 793 | dst_class->PrettyDescriptor().c_str()).c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 794 | } |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 795 | return false; |
| 796 | } |
Mathieu Chartier | 1a5337f | 2016-10-13 13:48:23 -0700 | [diff] [blame] | 797 | unboxed_value->SetL(o); |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 798 | return true; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 799 | } |
| 800 | if (UNLIKELY(dst_class->GetPrimitiveType() == Primitive::kPrimVoid)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 801 | ThrowIllegalArgumentException(StringPrintf("Can't unbox %s to void", |
Ian Rogers | 84956ff | 2014-03-26 23:52:41 -0700 | [diff] [blame] | 802 | UnboxingFailureKind(f).c_str()).c_str()); |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 803 | return false; |
| 804 | } |
Ian Rogers | 84956ff | 2014-03-26 23:52:41 -0700 | [diff] [blame] | 805 | if (UNLIKELY(o == nullptr)) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 806 | if (!unbox_for_result) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 807 | ThrowIllegalArgumentException( |
| 808 | StringPrintf("%s has type %s, got null", |
| 809 | UnboxingFailureKind(f).c_str(), |
| 810 | dst_class->PrettyDescriptor().c_str()).c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 811 | } else { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 812 | ThrowNullPointerException( |
| 813 | StringPrintf("Expected to unbox a '%s' primitive type but was returned null", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 814 | dst_class->PrettyDescriptor().c_str()).c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 815 | } |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 816 | return false; |
| 817 | } |
| 818 | |
Elliott Hughes | 1d878f3 | 2012-04-11 15:17:54 -0700 | [diff] [blame] | 819 | JValue boxed_value; |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 820 | ObjPtr<mirror::Class> klass = o->GetClass(); |
| 821 | ObjPtr<mirror::Class> src_class = nullptr; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 822 | ClassLinker* const class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 823 | ArtField* primitive_field = &klass->GetIFieldsPtr()->At(0); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 824 | if (klass->DescriptorEquals("Ljava/lang/Boolean;")) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 825 | src_class = class_linker->FindPrimitiveClass('Z'); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 826 | boxed_value.SetZ(primitive_field->GetBoolean(o)); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 827 | } else if (klass->DescriptorEquals("Ljava/lang/Byte;")) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 828 | src_class = class_linker->FindPrimitiveClass('B'); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 829 | boxed_value.SetB(primitive_field->GetByte(o)); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 830 | } else if (klass->DescriptorEquals("Ljava/lang/Character;")) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 831 | src_class = class_linker->FindPrimitiveClass('C'); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 832 | boxed_value.SetC(primitive_field->GetChar(o)); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 833 | } else if (klass->DescriptorEquals("Ljava/lang/Float;")) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 834 | src_class = class_linker->FindPrimitiveClass('F'); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 835 | boxed_value.SetF(primitive_field->GetFloat(o)); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 836 | } else if (klass->DescriptorEquals("Ljava/lang/Double;")) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 837 | src_class = class_linker->FindPrimitiveClass('D'); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 838 | boxed_value.SetD(primitive_field->GetDouble(o)); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 839 | } else if (klass->DescriptorEquals("Ljava/lang/Integer;")) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 840 | src_class = class_linker->FindPrimitiveClass('I'); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 841 | boxed_value.SetI(primitive_field->GetInt(o)); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 842 | } else if (klass->DescriptorEquals("Ljava/lang/Long;")) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 843 | src_class = class_linker->FindPrimitiveClass('J'); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 844 | boxed_value.SetJ(primitive_field->GetLong(o)); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 845 | } else if (klass->DescriptorEquals("Ljava/lang/Short;")) { |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 846 | src_class = class_linker->FindPrimitiveClass('S'); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 847 | boxed_value.SetS(primitive_field->GetShort(o)); |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 848 | } else { |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 849 | std::string temp; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 850 | ThrowIllegalArgumentException( |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 851 | StringPrintf("%s has type %s, got %s", UnboxingFailureKind(f).c_str(), |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 852 | dst_class->PrettyDescriptor().c_str(), |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 853 | PrettyDescriptor(o->GetClass()->GetDescriptor(&temp)).c_str()).c_str()); |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 854 | return false; |
| 855 | } |
| 856 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 857 | return ConvertPrimitiveValue(unbox_for_result, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 858 | src_class->GetPrimitiveType(), dst_class->GetPrimitiveType(), |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 859 | boxed_value, unboxed_value); |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 862 | bool UnboxPrimitiveForField(ObjPtr<mirror::Object> o, |
| 863 | ObjPtr<mirror::Class> dst_class, |
| 864 | ArtField* f, |
Ian Rogers | 84956ff | 2014-03-26 23:52:41 -0700 | [diff] [blame] | 865 | JValue* unboxed_value) { |
| 866 | DCHECK(f != nullptr); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 867 | return UnboxPrimitive(o, dst_class, f, unboxed_value); |
Elliott Hughes | aaa5edc | 2012-05-16 15:54:30 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 870 | bool UnboxPrimitiveForResult(ObjPtr<mirror::Object> o, |
| 871 | ObjPtr<mirror::Class> dst_class, |
| 872 | JValue* unboxed_value) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 873 | return UnboxPrimitive(o, dst_class, nullptr, unboxed_value); |
Elliott Hughes | aaa5edc | 2012-05-16 15:54:30 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 876 | ObjPtr<mirror::Class> GetCallingClass(Thread* self, size_t num_frames) { |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 877 | NthCallerVisitor visitor(self, num_frames); |
| 878 | visitor.WalkStack(); |
| 879 | return visitor.caller != nullptr ? visitor.caller->GetDeclaringClass() : nullptr; |
| 880 | } |
| 881 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 882 | bool VerifyAccess(Thread* self, |
| 883 | ObjPtr<mirror::Object> obj, |
| 884 | ObjPtr<mirror::Class> declaring_class, |
| 885 | uint32_t access_flags, |
| 886 | ObjPtr<mirror::Class>* calling_class, |
| 887 | size_t num_frames) { |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 888 | if ((access_flags & kAccPublic) != 0) { |
| 889 | return true; |
| 890 | } |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 891 | ObjPtr<mirror::Class> klass = GetCallingClass(self, num_frames); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 892 | if (UNLIKELY(klass == nullptr)) { |
Vladimir Marko | 3bd7a6c | 2014-06-12 15:22:31 +0100 | [diff] [blame] | 893 | // The caller is an attached native thread. |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 894 | return false; |
Vladimir Marko | 3bd7a6c | 2014-06-12 15:22:31 +0100 | [diff] [blame] | 895 | } |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 896 | *calling_class = klass; |
Mathieu Chartier | 268764d | 2016-09-13 12:09:38 -0700 | [diff] [blame] | 897 | return VerifyAccess(obj, declaring_class, access_flags, klass); |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 900 | bool VerifyAccess(ObjPtr<mirror::Object> obj, |
| 901 | ObjPtr<mirror::Class> declaring_class, |
Mathieu Chartier | 268764d | 2016-09-13 12:09:38 -0700 | [diff] [blame] | 902 | uint32_t access_flags, |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 903 | ObjPtr<mirror::Class> calling_class) { |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 904 | if (calling_class == declaring_class) { |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 905 | return true; |
| 906 | } |
Mathieu Chartier | 268764d | 2016-09-13 12:09:38 -0700 | [diff] [blame] | 907 | ScopedAssertNoThreadSuspension sants("verify-access"); |
Jeff Hao | cb4581a | 2014-03-28 15:43:37 -0700 | [diff] [blame] | 908 | if ((access_flags & kAccPrivate) != 0) { |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 909 | return false; |
| 910 | } |
Jeff Hao | cb4581a | 2014-03-28 15:43:37 -0700 | [diff] [blame] | 911 | if ((access_flags & kAccProtected) != 0) { |
Mathieu Chartier | f36cb5f | 2015-04-24 16:55:16 -0700 | [diff] [blame] | 912 | if (obj != nullptr && !obj->InstanceOf(calling_class) && |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 913 | !declaring_class->IsInSamePackage(calling_class)) { |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 914 | return false; |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 915 | } else if (declaring_class->IsAssignableFrom(calling_class)) { |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 916 | return true; |
| 917 | } |
| 918 | } |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 919 | return declaring_class->IsInSamePackage(calling_class); |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 922 | void InvalidReceiverError(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 923 | std::string expected_class_name(mirror::Class::PrettyDescriptor(c)); |
| 924 | std::string actual_class_name(mirror::Object::PrettyTypeOf(o)); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 925 | ThrowIllegalArgumentException(StringPrintf("Expected receiver of type %s, but got %s", |
| 926 | expected_class_name.c_str(), |
| 927 | actual_class_name.c_str()).c_str()); |
| 928 | } |
| 929 | |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 930 | // This only works if there's one reference which points to the object in obj. |
| 931 | // Will need to be fixed if there's cases where it's not. |
Mathieu Chartier | a59d9b2 | 2016-09-26 18:13:17 -0700 | [diff] [blame] | 932 | void UpdateReference(Thread* self, jobject obj, ObjPtr<mirror::Object> result) { |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 933 | IndirectRef ref = reinterpret_cast<IndirectRef>(obj); |
Andreas Gampe | dc061d0 | 2016-10-24 13:19:37 -0700 | [diff] [blame] | 934 | IndirectRefKind kind = IndirectReferenceTable::GetIndirectRefKind(ref); |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 935 | if (kind == kLocal) { |
Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 936 | self->GetJniEnv()->UpdateLocal(obj, result); |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 937 | } else if (kind == kHandleScopeOrInvalid) { |
| 938 | LOG(FATAL) << "Unsupported UpdateReference for kind kHandleScopeOrInvalid"; |
| 939 | } else if (kind == kGlobal) { |
Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 940 | self->GetJniEnv()->GetVm()->UpdateGlobal(self, ref, result); |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 941 | } else { |
| 942 | DCHECK_EQ(kind, kWeakGlobal); |
Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 943 | self->GetJniEnv()->GetVm()->UpdateWeakGlobal(self, ref, result); |
Jeff Hao | 83c8195 | 2015-05-27 19:29:29 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 947 | } // namespace art |