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