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