Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | */ |
buzbee | 5433072 | 2011-08-23 16:46:55 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_RUNTIME_SUPPORT_H_ |
| 18 | #define ART_SRC_RUNTIME_SUPPORT_H_ |
| 19 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 20 | #include "class_linker.h" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 21 | #include "common_throws.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 22 | #include "dex_file.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 23 | #include "indirect_reference_table.h" |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 24 | #include "invoke_type.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 25 | #include "jni_internal.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 26 | #include "mirror/abstract_method.h" |
| 27 | #include "mirror/array.h" |
Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame^] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "mirror/throwable.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 30 | #include "object_utils.h" |
| 31 | #include "thread.h" |
| 32 | |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 33 | extern "C" void art_interpreter_invoke_handler(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 34 | extern "C" void art_proxy_invoke_handler(); |
| 35 | extern "C" void art_work_around_app_jni_bugs(); |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 36 | |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 37 | extern "C" double art_l2d(int64_t l); |
| 38 | extern "C" float art_l2f(int64_t l); |
| 39 | extern "C" int64_t art_d2l(double d); |
| 40 | extern "C" int32_t art_d2i(double d); |
| 41 | extern "C" int64_t art_f2l(float f); |
| 42 | extern "C" int32_t art_f2i(float f); |
| 43 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 44 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 45 | namespace mirror { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 46 | class Class; |
| 47 | class Field; |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 48 | class Object; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 49 | } |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 50 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 51 | // Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it |
| 52 | // cannot be resolved, throw an error. If it can, use it to create an instance. |
| 53 | // When verification/compiler hasn't been able to verify access, optionally perform an access |
| 54 | // check. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 55 | static inline mirror::Object* AllocObjectFromCode(uint32_t type_idx, mirror::AbstractMethod* method, |
| 56 | Thread* self, |
| 57 | bool access_check) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 58 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 59 | mirror::Class* klass = method->GetDexCacheResolvedTypes()->Get(type_idx); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 60 | Runtime* runtime = Runtime::Current(); |
| 61 | if (UNLIKELY(klass == NULL)) { |
| 62 | klass = runtime->GetClassLinker()->ResolveType(type_idx, method); |
| 63 | if (klass == NULL) { |
| 64 | DCHECK(self->IsExceptionPending()); |
| 65 | return NULL; // Failure |
| 66 | } |
| 67 | } |
| 68 | if (access_check) { |
| 69 | if (UNLIKELY(!klass->IsInstantiable())) { |
| 70 | self->ThrowNewException("Ljava/lang/InstantiationError;", |
| 71 | PrettyDescriptor(klass).c_str()); |
| 72 | return NULL; // Failure |
| 73 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 74 | mirror::Class* referrer = method->GetDeclaringClass(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 75 | if (UNLIKELY(!referrer->CanAccess(klass))) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 76 | ThrowIllegalAccessErrorClass(referrer, klass); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 77 | return NULL; // Failure |
| 78 | } |
| 79 | } |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 80 | if (!klass->IsInitialized() && |
| 81 | !runtime->GetClassLinker()->EnsureInitialized(klass, true, true)) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 82 | DCHECK(self->IsExceptionPending()); |
| 83 | return NULL; // Failure |
| 84 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 85 | return klass->AllocObject(self); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | // Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If |
| 89 | // it cannot be resolved, throw an error. If it can, use it to create an array. |
| 90 | // When verification/compiler hasn't been able to verify access, optionally perform an access |
| 91 | // check. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 92 | static inline mirror::Array* AllocArrayFromCode(uint32_t type_idx, mirror::AbstractMethod* method, |
| 93 | int32_t component_count, |
| 94 | Thread* self, bool access_check) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 95 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 96 | if (UNLIKELY(component_count < 0)) { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 97 | self->ThrowNewExceptionF("Ljava/lang/NegativeArraySizeException;", "%d", component_count); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 98 | return NULL; // Failure |
| 99 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 100 | mirror::Class* klass = method->GetDexCacheResolvedTypes()->Get(type_idx); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 101 | if (UNLIKELY(klass == NULL)) { // Not in dex cache so try to resolve |
| 102 | klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method); |
| 103 | if (klass == NULL) { // Error |
| 104 | DCHECK(Thread::Current()->IsExceptionPending()); |
| 105 | return NULL; // Failure |
| 106 | } |
| 107 | CHECK(klass->IsArrayClass()) << PrettyClass(klass); |
| 108 | } |
| 109 | if (access_check) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 110 | mirror::Class* referrer = method->GetDeclaringClass(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 111 | if (UNLIKELY(!referrer->CanAccess(klass))) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 112 | ThrowIllegalAccessErrorClass(referrer, klass); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 113 | return NULL; // Failure |
| 114 | } |
| 115 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 116 | return mirror::Array::Alloc(self, klass, component_count); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 119 | extern mirror::Array* CheckAndAllocArrayFromCode(uint32_t type_idx, mirror::AbstractMethod* method, |
| 120 | int32_t component_count, |
| 121 | Thread* self, bool access_check) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 122 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 123 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 124 | // Type of find field operation for fast and slow case. |
| 125 | enum FindFieldType { |
| 126 | InstanceObjectRead, |
| 127 | InstanceObjectWrite, |
| 128 | InstancePrimitiveRead, |
| 129 | InstancePrimitiveWrite, |
| 130 | StaticObjectRead, |
| 131 | StaticObjectWrite, |
| 132 | StaticPrimitiveRead, |
| 133 | StaticPrimitiveWrite, |
| 134 | }; |
| 135 | |
| 136 | // Slow field find that can initialize classes and may throw exceptions. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 137 | extern mirror::Field* FindFieldFromCode(uint32_t field_idx, const mirror::AbstractMethod* referrer, |
| 138 | Thread* self, FindFieldType type, size_t expected_size) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 139 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 140 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 141 | // Fast path field resolution that can't initialize classes or throw exceptions. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 142 | static inline mirror::Field* FindFieldFast(uint32_t field_idx, |
| 143 | const mirror::AbstractMethod* referrer, |
| 144 | FindFieldType type, size_t expected_size) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 145 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 146 | mirror::Field* resolved_field = |
| 147 | referrer->GetDeclaringClass()->GetDexCache()->GetResolvedField(field_idx); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 148 | if (UNLIKELY(resolved_field == NULL)) { |
| 149 | return NULL; |
| 150 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 151 | mirror::Class* fields_class = resolved_field->GetDeclaringClass(); |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 152 | // Check class is initiliazed or initializing. |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 153 | if (UNLIKELY(!fields_class->IsInitializing())) { |
| 154 | return NULL; |
| 155 | } |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 156 | // Check for incompatible class change. |
| 157 | bool is_primitive; |
| 158 | bool is_set; |
| 159 | bool is_static; |
| 160 | switch (type) { |
| 161 | case InstanceObjectRead: is_primitive = false; is_set = false; is_static = false; break; |
| 162 | case InstanceObjectWrite: is_primitive = false; is_set = true; is_static = false; break; |
| 163 | case InstancePrimitiveRead: is_primitive = true; is_set = false; is_static = false; break; |
| 164 | case InstancePrimitiveWrite: is_primitive = true; is_set = true; is_static = false; break; |
| 165 | case StaticObjectRead: is_primitive = false; is_set = false; is_static = true; break; |
| 166 | case StaticObjectWrite: is_primitive = false; is_set = true; is_static = true; break; |
| 167 | case StaticPrimitiveRead: is_primitive = true; is_set = false; is_static = true; break; |
| 168 | case StaticPrimitiveWrite: is_primitive = true; is_set = true; is_static = true; break; |
| 169 | default: LOG(FATAL) << "UNREACHABLE"; // Assignment below to avoid GCC warnings. |
| 170 | is_primitive = true; is_set = true; is_static = true; break; |
| 171 | } |
| 172 | if (UNLIKELY(resolved_field->IsStatic() != is_static)) { |
| 173 | // Incompatible class change. |
| 174 | return NULL; |
| 175 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 176 | mirror::Class* referring_class = referrer->GetDeclaringClass(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 177 | if (UNLIKELY(!referring_class->CanAccess(fields_class) || |
| 178 | !referring_class->CanAccessMember(fields_class, |
| 179 | resolved_field->GetAccessFlags()) || |
| 180 | (is_set && resolved_field->IsFinal() && (fields_class != referring_class)))) { |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 181 | // Illegal access. |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 182 | return NULL; |
| 183 | } |
| 184 | FieldHelper fh(resolved_field); |
| 185 | if (UNLIKELY(fh.IsPrimitiveType() != is_primitive || |
| 186 | fh.FieldSize() != expected_size)) { |
| 187 | return NULL; |
| 188 | } |
| 189 | return resolved_field; |
| 190 | } |
| 191 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 192 | // Fast path method resolution that can't throw exceptions. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 193 | static inline mirror::AbstractMethod* FindMethodFast(uint32_t method_idx, |
| 194 | mirror::Object* this_object, |
| 195 | const mirror::AbstractMethod* referrer, |
| 196 | bool access_check, InvokeType type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 197 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 198 | bool is_direct = type == kStatic || type == kDirect; |
| 199 | if (UNLIKELY(this_object == NULL && !is_direct)) { |
| 200 | return NULL; |
| 201 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 202 | mirror::AbstractMethod* resolved_method = |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 203 | referrer->GetDeclaringClass()->GetDexCache()->GetResolvedMethod(method_idx); |
| 204 | if (UNLIKELY(resolved_method == NULL)) { |
| 205 | return NULL; |
| 206 | } |
| 207 | if (access_check) { |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 208 | // Check for incompatible class change errors and access. |
| 209 | bool icce = resolved_method->CheckIncompatibleClassChange(type); |
| 210 | if (UNLIKELY(icce)) { |
| 211 | return NULL; |
| 212 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 213 | mirror::Class* methods_class = resolved_method->GetDeclaringClass(); |
| 214 | mirror::Class* referring_class = referrer->GetDeclaringClass(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 215 | if (UNLIKELY(!referring_class->CanAccess(methods_class) || |
| 216 | !referring_class->CanAccessMember(methods_class, |
| 217 | resolved_method->GetAccessFlags()))) { |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 218 | // Potential illegal access, may need to refine the method's class. |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 219 | return NULL; |
| 220 | } |
| 221 | } |
| 222 | if (type == kInterface) { // Most common form of slow path dispatch. |
| 223 | return this_object->GetClass()->FindVirtualMethodForInterface(resolved_method); |
| 224 | } else if (is_direct) { |
| 225 | return resolved_method; |
| 226 | } else if (type == kSuper) { |
| 227 | return referrer->GetDeclaringClass()->GetSuperClass()->GetVTable()-> |
| 228 | Get(resolved_method->GetMethodIndex()); |
| 229 | } else { |
| 230 | DCHECK(type == kVirtual); |
| 231 | return this_object->GetClass()->GetVTable()->Get(resolved_method->GetMethodIndex()); |
| 232 | } |
| 233 | } |
| 234 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 235 | extern mirror::AbstractMethod* FindMethodFromCode(uint32_t method_idx, mirror::Object* this_object, |
| 236 | mirror::AbstractMethod* referrer, |
| 237 | Thread* self, bool access_check, InvokeType type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 238 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 239 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 240 | extern mirror::Class* ResolveVerifyAndClinit(uint32_t type_idx, |
| 241 | const mirror::AbstractMethod* referrer, Thread* self, |
| 242 | bool can_run_clinit, bool verify_access) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 243 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 244 | |
jeffhao | d752132 | 2012-11-21 15:38:24 -0800 | [diff] [blame] | 245 | extern void ThrowStackOverflowError(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 246 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 247 | static inline mirror::String* ResolveStringFromCode(const mirror::AbstractMethod* referrer, |
| 248 | uint32_t string_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 249 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 250 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 251 | return class_linker->ResolveString(string_idx, referrer); |
| 252 | } |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 253 | |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 254 | static inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 255 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 256 | UNLOCK_FUNCTION(monitor_lock_) { |
| 257 | // Save any pending exception over monitor exit call. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 258 | mirror::Throwable* saved_exception = NULL; |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 259 | if (UNLIKELY(self->IsExceptionPending())) { |
| 260 | saved_exception = self->GetException(); |
| 261 | self->ClearException(); |
| 262 | } |
| 263 | // Decode locked object and unlock, before popping local references. |
| 264 | self->DecodeJObject(locked)->MonitorExit(self); |
| 265 | if (UNLIKELY(self->IsExceptionPending())) { |
| 266 | LOG(FATAL) << "Synchronized JNI code returning with an exception:\n" |
| 267 | << saved_exception->Dump() |
| 268 | << "\nEncountered second exception during implicit MonitorExit:\n" |
| 269 | << self->GetException()->Dump(); |
| 270 | } |
| 271 | // Restore pending exception. |
| 272 | if (saved_exception != NULL) { |
| 273 | self->SetException(saved_exception); |
| 274 | } |
| 275 | } |
| 276 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 277 | static inline void CheckReferenceResult(mirror::Object* o, Thread* self) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 278 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 279 | if (o == NULL) { |
| 280 | return; |
| 281 | } |
| 282 | if (o == kInvalidIndirectRefObject) { |
| 283 | JniAbortF(NULL, "invalid reference returned from %s", |
| 284 | PrettyMethod(self->GetCurrentMethod()).c_str()); |
| 285 | } |
| 286 | // Make sure that the result is an instance of the type this method was expected to return. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 287 | mirror::AbstractMethod* m = self->GetCurrentMethod(); |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 288 | MethodHelper mh(m); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 289 | mirror::Class* return_type = mh.GetReturnType(); |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 290 | |
| 291 | if (!o->InstanceOf(return_type)) { |
| 292 | JniAbortF(NULL, "attempt to return an instance of %s from %s", |
| 293 | PrettyTypeOf(o).c_str(), PrettyMethod(m).c_str()); |
| 294 | } |
| 295 | } |
| 296 | |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 297 | static inline void CheckSuspend(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
jeffhao | 373c52f | 2012-11-20 16:11:52 -0800 | [diff] [blame] | 298 | for (;;) { |
| 299 | if (thread->ReadFlag(kCheckpointRequest)) { |
| 300 | thread->RunCheckpointFunction(); |
| 301 | thread->AtomicClearFlag(kCheckpointRequest); |
| 302 | } else if (thread->ReadFlag(kSuspendRequest)) { |
| 303 | thread->FullSuspendCheck(); |
| 304 | } else { |
| 305 | break; |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 310 | JValue InvokeProxyInvocationHandler(ScopedObjectAccessUnchecked& soa, const char* shorty, |
| 311 | jobject rcvr_jobj, jobject interface_method_jobj, |
| 312 | std::vector<jvalue>& args) |
| 313 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ; |
| 314 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 315 | } // namespace art |
Ian Rogers | ad42e13 | 2011-09-17 20:23:33 -0700 | [diff] [blame] | 316 | |
buzbee | 5433072 | 2011-08-23 16:46:55 -0700 | [diff] [blame] | 317 | #endif // ART_SRC_RUNTIME_SUPPORT_H_ |