Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [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 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_DRIVER_COMPILER_DRIVER_INL_H_ |
| 18 | #define ART_COMPILER_DRIVER_COMPILER_DRIVER_INL_H_ |
| 19 | |
| 20 | #include "compiler_driver.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 21 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 22 | #include "dex_compilation_unit.h" |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 23 | #include "mirror/art_field-inl.h" |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 24 | #include "mirror/art_method-inl.h" |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 25 | #include "mirror/class_loader.h" |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 26 | #include "mirror/dex_cache-inl.h" |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 27 | #include "mirror/art_field-inl.h" |
| 28 | #include "scoped_thread_state_change.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 29 | #include "handle_scope-inl.h" |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
| 33 | inline mirror::DexCache* CompilerDriver::GetDexCache(const DexCompilationUnit* mUnit) { |
| 34 | return mUnit->GetClassLinker()->FindDexCache(*mUnit->GetDexFile()); |
| 35 | } |
| 36 | |
| 37 | inline mirror::ClassLoader* CompilerDriver::GetClassLoader(ScopedObjectAccess& soa, |
| 38 | const DexCompilationUnit* mUnit) { |
| 39 | return soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader()); |
| 40 | } |
| 41 | |
| 42 | inline mirror::Class* CompilerDriver::ResolveCompilingMethodsClass( |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 43 | const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 44 | Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 45 | DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile()); |
| 46 | DCHECK_EQ(class_loader.Get(), soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader())); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 47 | const DexFile::MethodId& referrer_method_id = |
| 48 | mUnit->GetDexFile()->GetMethodId(mUnit->GetDexMethodIndex()); |
| 49 | mirror::Class* referrer_class = mUnit->GetClassLinker()->ResolveType( |
| 50 | *mUnit->GetDexFile(), referrer_method_id.class_idx_, dex_cache, class_loader); |
| 51 | DCHECK_EQ(referrer_class == nullptr, soa.Self()->IsExceptionPending()); |
| 52 | if (UNLIKELY(referrer_class == nullptr)) { |
| 53 | // Clean up any exception left by type resolution. |
| 54 | soa.Self()->ClearException(); |
| 55 | } |
| 56 | return referrer_class; |
| 57 | } |
| 58 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 59 | inline mirror::ArtField* CompilerDriver::ResolveFieldWithDexFile( |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 61 | Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file, |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 62 | uint32_t field_idx, bool is_static) { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 63 | DCHECK_EQ(dex_cache->GetDexFile(), dex_file); |
| 64 | mirror::ArtField* resolved_field = Runtime::Current()->GetClassLinker()->ResolveField( |
| 65 | *dex_file, field_idx, dex_cache, class_loader, is_static); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 66 | DCHECK_EQ(resolved_field == nullptr, soa.Self()->IsExceptionPending()); |
| 67 | if (UNLIKELY(resolved_field == nullptr)) { |
| 68 | // Clean up any exception left by type resolution. |
| 69 | soa.Self()->ClearException(); |
| 70 | return nullptr; |
| 71 | } |
| 72 | if (UNLIKELY(resolved_field->IsStatic() != is_static)) { |
| 73 | // ClassLinker can return a field of the wrong kind directly from the DexCache. |
| 74 | // Silently return nullptr on such incompatible class change. |
| 75 | return nullptr; |
| 76 | } |
| 77 | return resolved_field; |
| 78 | } |
| 79 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 80 | inline mirror::DexCache* CompilerDriver::FindDexCache(const DexFile* dex_file) { |
| 81 | return Runtime::Current()->GetClassLinker()->FindDexCache(*dex_file); |
| 82 | } |
| 83 | |
| 84 | inline mirror::ArtField* CompilerDriver::ResolveField( |
| 85 | const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, |
| 86 | Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit, |
| 87 | uint32_t field_idx, bool is_static) { |
| 88 | DCHECK_EQ(class_loader.Get(), soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader())); |
| 89 | return ResolveFieldWithDexFile(soa, dex_cache, class_loader, mUnit->GetDexFile(), field_idx, |
| 90 | is_static); |
| 91 | } |
| 92 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 93 | inline void CompilerDriver::GetResolvedFieldDexFileLocation( |
| 94 | mirror::ArtField* resolved_field, const DexFile** declaring_dex_file, |
| 95 | uint16_t* declaring_class_idx, uint16_t* declaring_field_idx) { |
| 96 | mirror::Class* declaring_class = resolved_field->GetDeclaringClass(); |
| 97 | *declaring_dex_file = declaring_class->GetDexCache()->GetDexFile(); |
| 98 | *declaring_class_idx = declaring_class->GetDexTypeIndex(); |
| 99 | *declaring_field_idx = resolved_field->GetDexFieldIndex(); |
| 100 | } |
| 101 | |
| 102 | inline bool CompilerDriver::IsFieldVolatile(mirror::ArtField* field) { |
| 103 | return field->IsVolatile(); |
| 104 | } |
| 105 | |
Vladimir Marko | 66c6d7b | 2014-10-16 15:41:48 +0100 | [diff] [blame] | 106 | inline MemberOffset CompilerDriver::GetFieldOffset(mirror::ArtField* field) { |
| 107 | return field->GetOffset(); |
| 108 | } |
| 109 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 110 | inline std::pair<bool, bool> CompilerDriver::IsFastInstanceField( |
| 111 | mirror::DexCache* dex_cache, mirror::Class* referrer_class, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 112 | mirror::ArtField* resolved_field, uint16_t field_idx) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 113 | DCHECK(!resolved_field->IsStatic()); |
| 114 | mirror::Class* fields_class = resolved_field->GetDeclaringClass(); |
| 115 | bool fast_get = referrer_class != nullptr && |
| 116 | referrer_class->CanAccessResolvedField(fields_class, resolved_field, |
| 117 | dex_cache, field_idx); |
| 118 | bool fast_put = fast_get && (!resolved_field->IsFinal() || fields_class == referrer_class); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 119 | return std::make_pair(fast_get, fast_put); |
| 120 | } |
| 121 | |
| 122 | inline std::pair<bool, bool> CompilerDriver::IsFastStaticField( |
| 123 | mirror::DexCache* dex_cache, mirror::Class* referrer_class, |
Vladimir Marko | 66c6d7b | 2014-10-16 15:41:48 +0100 | [diff] [blame] | 124 | mirror::ArtField* resolved_field, uint16_t field_idx, uint32_t* storage_index) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 125 | DCHECK(resolved_field->IsStatic()); |
| 126 | if (LIKELY(referrer_class != nullptr)) { |
| 127 | mirror::Class* fields_class = resolved_field->GetDeclaringClass(); |
| 128 | if (fields_class == referrer_class) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 129 | *storage_index = fields_class->GetDexTypeIndex(); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 130 | return std::make_pair(true, true); |
| 131 | } |
| 132 | if (referrer_class->CanAccessResolvedField(fields_class, resolved_field, |
| 133 | dex_cache, field_idx)) { |
| 134 | // We have the resolved field, we must make it into a index for the referrer |
| 135 | // in its static storage (which may fail if it doesn't have a slot for it) |
| 136 | // TODO: for images we can elide the static storage base null check |
| 137 | // if we know there's a non-null entry in the image |
| 138 | const DexFile* dex_file = dex_cache->GetDexFile(); |
| 139 | uint32_t storage_idx = DexFile::kDexNoIndex; |
| 140 | if (LIKELY(fields_class->GetDexCache() == dex_cache)) { |
| 141 | // common case where the dex cache of both the referrer and the field are the same, |
| 142 | // no need to search the dex file |
| 143 | storage_idx = fields_class->GetDexTypeIndex(); |
| 144 | } else { |
| 145 | // Search dex file for localized ssb index, may fail if field's class is a parent |
| 146 | // of the class mentioned in the dex file and there is no dex cache entry. |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 147 | std::string temp; |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 148 | const DexFile::StringId* string_id = |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 149 | dex_file->FindStringId(resolved_field->GetDeclaringClass()->GetDescriptor(&temp)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 150 | if (string_id != nullptr) { |
| 151 | const DexFile::TypeId* type_id = |
| 152 | dex_file->FindTypeId(dex_file->GetIndexForStringId(*string_id)); |
| 153 | if (type_id != nullptr) { |
| 154 | // medium path, needs check of static storage base being initialized |
| 155 | storage_idx = dex_file->GetIndexForTypeId(*type_id); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | if (storage_idx != DexFile::kDexNoIndex) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 160 | *storage_index = storage_idx; |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 161 | return std::make_pair(true, !resolved_field->IsFinal()); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | // Conservative defaults. |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 166 | *storage_index = DexFile::kDexNoIndex; |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 167 | return std::make_pair(false, false); |
| 168 | } |
| 169 | |
Vladimir Marko | 66c6d7b | 2014-10-16 15:41:48 +0100 | [diff] [blame] | 170 | inline bool CompilerDriver::IsStaticFieldInReferrerClass(mirror::Class* referrer_class, |
| 171 | mirror::ArtField* resolved_field) { |
| 172 | DCHECK(resolved_field->IsStatic()); |
| 173 | mirror::Class* fields_class = resolved_field->GetDeclaringClass(); |
| 174 | return referrer_class == fields_class; |
| 175 | } |
| 176 | |
| 177 | inline bool CompilerDriver::IsStaticFieldsClassInitialized(mirror::Class* referrer_class, |
| 178 | mirror::ArtField* resolved_field) { |
| 179 | DCHECK(resolved_field->IsStatic()); |
| 180 | mirror::Class* fields_class = resolved_field->GetDeclaringClass(); |
| 181 | return fields_class == referrer_class || fields_class->IsInitialized(); |
| 182 | } |
| 183 | |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 184 | inline mirror::ArtMethod* CompilerDriver::ResolveMethod( |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 185 | ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, |
| 186 | Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit, |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 187 | uint32_t method_idx, InvokeType invoke_type, bool check_incompatible_class_change) { |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 188 | DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile()); |
| 189 | DCHECK_EQ(class_loader.Get(), soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader())); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 190 | mirror::ArtMethod* resolved_method = mUnit->GetClassLinker()->ResolveMethod( |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 191 | *mUnit->GetDexFile(), method_idx, dex_cache, class_loader, NullHandle<mirror::ArtMethod>(), |
| 192 | invoke_type); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 193 | DCHECK_EQ(resolved_method == nullptr, soa.Self()->IsExceptionPending()); |
| 194 | if (UNLIKELY(resolved_method == nullptr)) { |
| 195 | // Clean up any exception left by type resolution. |
| 196 | soa.Self()->ClearException(); |
| 197 | return nullptr; |
| 198 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 199 | if (check_incompatible_class_change && |
| 200 | UNLIKELY(resolved_method->CheckIncompatibleClassChange(invoke_type))) { |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 201 | // Silently return nullptr on incompatible class change. |
| 202 | return nullptr; |
| 203 | } |
| 204 | return resolved_method; |
| 205 | } |
| 206 | |
| 207 | inline void CompilerDriver::GetResolvedMethodDexFileLocation( |
| 208 | mirror::ArtMethod* resolved_method, const DexFile** declaring_dex_file, |
| 209 | uint16_t* declaring_class_idx, uint16_t* declaring_method_idx) { |
| 210 | mirror::Class* declaring_class = resolved_method->GetDeclaringClass(); |
| 211 | *declaring_dex_file = declaring_class->GetDexCache()->GetDexFile(); |
| 212 | *declaring_class_idx = declaring_class->GetDexTypeIndex(); |
| 213 | *declaring_method_idx = resolved_method->GetDexMethodIndex(); |
| 214 | } |
| 215 | |
| 216 | inline uint16_t CompilerDriver::GetResolvedMethodVTableIndex( |
| 217 | mirror::ArtMethod* resolved_method, InvokeType type) { |
| 218 | if (type == kVirtual || type == kSuper) { |
| 219 | return resolved_method->GetMethodIndex(); |
| 220 | } else if (type == kInterface) { |
| 221 | return resolved_method->GetDexMethodIndex(); |
| 222 | } else { |
| 223 | return DexFile::kDexNoIndex16; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | inline int CompilerDriver::IsFastInvoke( |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 228 | ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, |
| 229 | Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 230 | mirror::Class* referrer_class, mirror::ArtMethod* resolved_method, InvokeType* invoke_type, |
| 231 | MethodReference* target_method, const MethodReference* devirt_target, |
| 232 | uintptr_t* direct_code, uintptr_t* direct_method) { |
| 233 | // Don't try to fast-path if we don't understand the caller's class. |
| 234 | if (UNLIKELY(referrer_class == nullptr)) { |
| 235 | return 0; |
| 236 | } |
| 237 | mirror::Class* methods_class = resolved_method->GetDeclaringClass(); |
| 238 | if (UNLIKELY(!referrer_class->CanAccessResolvedMethod(methods_class, resolved_method, |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 239 | dex_cache.Get(), |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 240 | target_method->dex_method_index))) { |
| 241 | return 0; |
| 242 | } |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 243 | // Sharpen a virtual call into a direct call when the target is known not to have been |
| 244 | // overridden (ie is final). |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 245 | const bool same_dex_file = target_method->dex_file == mUnit->GetDexFile(); |
| 246 | bool can_sharpen_virtual_based_on_type = same_dex_file && |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 247 | (*invoke_type == kVirtual) && (resolved_method->IsFinal() || methods_class->IsFinal()); |
| 248 | // For invoke-super, ensure the vtable index will be correct to dispatch in the vtable of |
| 249 | // the super class. |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 250 | bool can_sharpen_super_based_on_type = same_dex_file && (*invoke_type == kSuper) && |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 251 | (referrer_class != methods_class) && referrer_class->IsSubClass(methods_class) && |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 252 | resolved_method->GetMethodIndex() < methods_class->GetVTableLength() && |
Vladimir Marko | 920506d | 2014-11-18 14:47:31 +0000 | [diff] [blame] | 253 | (methods_class->GetVTableEntry(resolved_method->GetMethodIndex()) == resolved_method) && |
| 254 | !resolved_method->IsAbstract(); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 255 | |
| 256 | if (can_sharpen_virtual_based_on_type || can_sharpen_super_based_on_type) { |
| 257 | // Sharpen a virtual call into a direct call. The method_idx is into referrer's |
| 258 | // dex cache, check that this resolved method is where we expect it. |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame^] | 259 | CHECK_EQ(target_method->dex_file, mUnit->GetDexFile()); |
| 260 | DCHECK_EQ(dex_cache.Get(), mUnit->GetClassLinker()->FindDexCache(*mUnit->GetDexFile())); |
| 261 | CHECK_EQ(referrer_class->GetDexCache()->GetResolvedMethod(target_method->dex_method_index), |
| 262 | resolved_method) << PrettyMethod(resolved_method); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 263 | int stats_flags = kFlagMethodResolved; |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 264 | GetCodeAndMethodForDirectCall(/*out*/invoke_type, |
| 265 | kDirect, // Sharp type |
| 266 | false, // The dex cache is guaranteed to be available |
| 267 | referrer_class, resolved_method, |
| 268 | /*out*/&stats_flags, |
| 269 | target_method, |
| 270 | /*out*/direct_code, |
| 271 | /*out*/direct_method); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 272 | DCHECK_NE(*invoke_type, kSuper) << PrettyMethod(resolved_method); |
| 273 | if (*invoke_type == kDirect) { |
| 274 | stats_flags |= kFlagsMethodResolvedVirtualMadeDirect; |
| 275 | } |
| 276 | return stats_flags; |
| 277 | } |
| 278 | |
| 279 | if ((*invoke_type == kVirtual || *invoke_type == kInterface) && devirt_target != nullptr) { |
| 280 | // Post-verification callback recorded a more precise invoke target based on its type info. |
| 281 | mirror::ArtMethod* called_method; |
| 282 | ClassLinker* class_linker = mUnit->GetClassLinker(); |
| 283 | if (LIKELY(devirt_target->dex_file == mUnit->GetDexFile())) { |
| 284 | called_method = class_linker->ResolveMethod(*devirt_target->dex_file, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 285 | devirt_target->dex_method_index, dex_cache, |
| 286 | class_loader, NullHandle<mirror::ArtMethod>(), |
| 287 | kVirtual); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 288 | } else { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 289 | StackHandleScope<1> hs(soa.Self()); |
| 290 | Handle<mirror::DexCache> target_dex_cache( |
| 291 | hs.NewHandle(class_linker->FindDexCache(*devirt_target->dex_file))); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 292 | called_method = class_linker->ResolveMethod(*devirt_target->dex_file, |
| 293 | devirt_target->dex_method_index, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 294 | target_dex_cache, class_loader, |
| 295 | NullHandle<mirror::ArtMethod>(), kVirtual); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 296 | } |
| 297 | CHECK(called_method != NULL); |
| 298 | CHECK(!called_method->IsAbstract()); |
| 299 | int stats_flags = kFlagMethodResolved; |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 300 | GetCodeAndMethodForDirectCall(/*out*/invoke_type, |
| 301 | kDirect, // Sharp type |
| 302 | true, // The dex cache may not be available |
| 303 | referrer_class, called_method, |
| 304 | /*out*/&stats_flags, |
| 305 | target_method, |
| 306 | /*out*/direct_code, |
| 307 | /*out*/direct_method); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 308 | DCHECK_NE(*invoke_type, kSuper); |
| 309 | if (*invoke_type == kDirect) { |
| 310 | stats_flags |= kFlagsMethodResolvedPreciseTypeDevirtualization; |
| 311 | } |
| 312 | return stats_flags; |
| 313 | } |
| 314 | |
| 315 | if (UNLIKELY(*invoke_type == kSuper)) { |
| 316 | // Unsharpened super calls are suspicious so go slow-path. |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | // Sharpening failed so generate a regular resolved method dispatch. |
| 321 | int stats_flags = kFlagMethodResolved; |
Igor Murashkin | d6dee67 | 2014-10-16 18:36:16 -0700 | [diff] [blame] | 322 | GetCodeAndMethodForDirectCall(/*out*/invoke_type, |
| 323 | *invoke_type, // Sharp type |
| 324 | false, // The dex cache is guaranteed to be available |
| 325 | referrer_class, resolved_method, |
| 326 | /*out*/&stats_flags, |
| 327 | target_method, |
| 328 | /*out*/direct_code, |
| 329 | /*out*/direct_method); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 330 | return stats_flags; |
| 331 | } |
| 332 | |
Vladimir Marko | 66c6d7b | 2014-10-16 15:41:48 +0100 | [diff] [blame] | 333 | inline bool CompilerDriver::IsMethodsClassInitialized(mirror::Class* referrer_class, |
| 334 | mirror::ArtMethod* resolved_method) { |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 335 | if (!resolved_method->IsStatic()) { |
Vladimir Marko | 66c6d7b | 2014-10-16 15:41:48 +0100 | [diff] [blame] | 336 | return true; |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 337 | } |
| 338 | mirror::Class* methods_class = resolved_method->GetDeclaringClass(); |
Vladimir Marko | 66c6d7b | 2014-10-16 15:41:48 +0100 | [diff] [blame] | 339 | return methods_class == referrer_class || methods_class->IsInitialized(); |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 342 | } // namespace art |
| 343 | |
| 344 | #endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_INL_H_ |