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