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