blob: e54cbf6fb6d71d8a013ba1a1987dcf3791d84cf6 [file] [log] [blame]
Vladimir Markobe0e5462014-02-26 11:24:15 +00001/*
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 Yang98d1cc82014-05-15 17:02:16 -070021
Mathieu Chartierc7853442015-03-27 14:35:38 -070022#include "art_field-inl.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070023#include "dex_compilation_unit.h"
Vladimir Markof096aad2014-01-23 15:51:58 +000024#include "mirror/art_method-inl.h"
Vladimir Markobe0e5462014-02-26 11:24:15 +000025#include "mirror/class_loader.h"
Vladimir Markof096aad2014-01-23 15:51:58 +000026#include "mirror/dex_cache-inl.h"
Vladimir Markobe0e5462014-02-26 11:24:15 +000027#include "scoped_thread_state_change.h"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070028#include "handle_scope-inl.h"
Vladimir Markobe0e5462014-02-26 11:24:15 +000029
30namespace art {
31
32inline mirror::DexCache* CompilerDriver::GetDexCache(const DexCompilationUnit* mUnit) {
33 return mUnit->GetClassLinker()->FindDexCache(*mUnit->GetDexFile());
34}
35
36inline mirror::ClassLoader* CompilerDriver::GetClassLoader(ScopedObjectAccess& soa,
37 const DexCompilationUnit* mUnit) {
38 return soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader());
39}
40
Nicolas Geoffray9437b782015-03-25 10:08:51 +000041inline mirror::Class* CompilerDriver::ResolveClass(
42 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
43 Handle<mirror::ClassLoader> class_loader, uint16_t cls_index,
44 const DexCompilationUnit* mUnit) {
45 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile());
46 DCHECK_EQ(class_loader.Get(), soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader()));
47 mirror::Class* cls = mUnit->GetClassLinker()->ResolveType(
48 *mUnit->GetDexFile(), cls_index, dex_cache, class_loader);
49 DCHECK_EQ(cls == nullptr, soa.Self()->IsExceptionPending());
50 if (UNLIKELY(cls == nullptr)) {
51 // Clean up any exception left by type resolution.
52 soa.Self()->ClearException();
53 }
54 return cls;
55}
56
Vladimir Markobe0e5462014-02-26 11:24:15 +000057inline mirror::Class* CompilerDriver::ResolveCompilingMethodsClass(
Nicolas Geoffraye5038322014-07-04 09:41:32 +010058 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
Mathieu Chartier0cd81352014-05-22 16:48:55 -070059 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit) {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070060 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile());
61 DCHECK_EQ(class_loader.Get(), soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader()));
Vladimir Markobe0e5462014-02-26 11:24:15 +000062 const DexFile::MethodId& referrer_method_id =
63 mUnit->GetDexFile()->GetMethodId(mUnit->GetDexMethodIndex());
Nicolas Geoffray9437b782015-03-25 10:08:51 +000064 return ResolveClass(soa, dex_cache, class_loader, referrer_method_id.class_idx_, mUnit);
Vladimir Markobe0e5462014-02-26 11:24:15 +000065}
66
Mathieu Chartierc7853442015-03-27 14:35:38 -070067inline ArtField* CompilerDriver::ResolveFieldWithDexFile(
Nicolas Geoffraye5038322014-07-04 09:41:32 +010068 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080069 Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file,
Vladimir Markobe0e5462014-02-26 11:24:15 +000070 uint32_t field_idx, bool is_static) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080071 DCHECK_EQ(dex_cache->GetDexFile(), dex_file);
Mathieu Chartierc7853442015-03-27 14:35:38 -070072 ArtField* resolved_field = Runtime::Current()->GetClassLinker()->ResolveField(
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080073 *dex_file, field_idx, dex_cache, class_loader, is_static);
Vladimir Markobe0e5462014-02-26 11:24:15 +000074 DCHECK_EQ(resolved_field == nullptr, soa.Self()->IsExceptionPending());
75 if (UNLIKELY(resolved_field == nullptr)) {
76 // Clean up any exception left by type resolution.
77 soa.Self()->ClearException();
78 return nullptr;
79 }
80 if (UNLIKELY(resolved_field->IsStatic() != is_static)) {
81 // ClassLinker can return a field of the wrong kind directly from the DexCache.
Mathieu Chartier2cebb242015-04-21 16:50:40 -070082 // Silently return null on such incompatible class change.
Vladimir Markobe0e5462014-02-26 11:24:15 +000083 return nullptr;
84 }
85 return resolved_field;
86}
87
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080088inline mirror::DexCache* CompilerDriver::FindDexCache(const DexFile* dex_file) {
89 return Runtime::Current()->GetClassLinker()->FindDexCache(*dex_file);
90}
91
Mathieu Chartierc7853442015-03-27 14:35:38 -070092inline ArtField* CompilerDriver::ResolveField(
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080093 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
94 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit,
95 uint32_t field_idx, bool is_static) {
96 DCHECK_EQ(class_loader.Get(), soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader()));
97 return ResolveFieldWithDexFile(soa, dex_cache, class_loader, mUnit->GetDexFile(), field_idx,
98 is_static);
99}
100
Vladimir Markobe0e5462014-02-26 11:24:15 +0000101inline void CompilerDriver::GetResolvedFieldDexFileLocation(
Mathieu Chartierc7853442015-03-27 14:35:38 -0700102 ArtField* resolved_field, const DexFile** declaring_dex_file,
Vladimir Markobe0e5462014-02-26 11:24:15 +0000103 uint16_t* declaring_class_idx, uint16_t* declaring_field_idx) {
104 mirror::Class* declaring_class = resolved_field->GetDeclaringClass();
105 *declaring_dex_file = declaring_class->GetDexCache()->GetDexFile();
106 *declaring_class_idx = declaring_class->GetDexTypeIndex();
107 *declaring_field_idx = resolved_field->GetDexFieldIndex();
108}
109
Mathieu Chartierc7853442015-03-27 14:35:38 -0700110inline bool CompilerDriver::IsFieldVolatile(ArtField* field) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000111 return field->IsVolatile();
112}
113
Mathieu Chartierc7853442015-03-27 14:35:38 -0700114inline MemberOffset CompilerDriver::GetFieldOffset(ArtField* field) {
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100115 return field->GetOffset();
116}
117
Vladimir Markobe0e5462014-02-26 11:24:15 +0000118inline std::pair<bool, bool> CompilerDriver::IsFastInstanceField(
119 mirror::DexCache* dex_cache, mirror::Class* referrer_class,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700120 ArtField* resolved_field, uint16_t field_idx) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000121 DCHECK(!resolved_field->IsStatic());
122 mirror::Class* fields_class = resolved_field->GetDeclaringClass();
123 bool fast_get = referrer_class != nullptr &&
124 referrer_class->CanAccessResolvedField(fields_class, resolved_field,
125 dex_cache, field_idx);
126 bool fast_put = fast_get && (!resolved_field->IsFinal() || fields_class == referrer_class);
Vladimir Markobe0e5462014-02-26 11:24:15 +0000127 return std::make_pair(fast_get, fast_put);
128}
129
Roland Levillain4c0eb422015-04-24 16:43:49 +0100130template <typename ArtMember>
131inline bool CompilerDriver::CanAccessResolvedMember(mirror::Class* referrer_class ATTRIBUTE_UNUSED,
132 mirror::Class* access_to ATTRIBUTE_UNUSED,
133 ArtMember* member ATTRIBUTE_UNUSED,
134 mirror::DexCache* dex_cache ATTRIBUTE_UNUSED,
135 uint32_t field_idx ATTRIBUTE_UNUSED) {
136 // Not defined for ArtMember values other than ArtField or mirror::ArtMethod.
137 UNREACHABLE();
138}
139
140template <>
141inline bool CompilerDriver::CanAccessResolvedMember<ArtField>(mirror::Class* referrer_class,
142 mirror::Class* access_to,
143 ArtField* field,
144 mirror::DexCache* dex_cache,
145 uint32_t field_idx) {
146 return referrer_class->CanAccessResolvedField(access_to, field, dex_cache, field_idx);
147}
148
149template <>
150inline bool CompilerDriver::CanAccessResolvedMember<mirror::ArtMethod>(
151 mirror::Class* referrer_class,
152 mirror::Class* access_to,
153 mirror::ArtMethod* method,
154 mirror::DexCache* dex_cache,
155 uint32_t field_idx) {
156 return referrer_class->CanAccessResolvedMethod(access_to, method, dex_cache, field_idx);
157}
158
159template <typename ArtMember>
160inline std::pair<bool, bool> CompilerDriver::IsClassOfStaticMemberAvailableToReferrer(
161 mirror::DexCache* dex_cache,
162 mirror::Class* referrer_class,
163 ArtMember* resolved_member,
164 uint16_t member_idx,
165 uint32_t* storage_index) {
166 DCHECK(resolved_member->IsStatic());
Vladimir Markobe0e5462014-02-26 11:24:15 +0000167 if (LIKELY(referrer_class != nullptr)) {
Roland Levillain4c0eb422015-04-24 16:43:49 +0100168 mirror::Class* members_class = resolved_member->GetDeclaringClass();
169 if (members_class == referrer_class) {
170 *storage_index = members_class->GetDexTypeIndex();
Vladimir Markobe0e5462014-02-26 11:24:15 +0000171 return std::make_pair(true, true);
172 }
Roland Levillain4c0eb422015-04-24 16:43:49 +0100173 if (CanAccessResolvedMember<ArtMember>(
174 referrer_class, members_class, resolved_member, dex_cache, member_idx)) {
175 // We have the resolved member, we must make it into a index for the referrer
Vladimir Markobe0e5462014-02-26 11:24:15 +0000176 // in its static storage (which may fail if it doesn't have a slot for it)
177 // TODO: for images we can elide the static storage base null check
178 // if we know there's a non-null entry in the image
179 const DexFile* dex_file = dex_cache->GetDexFile();
180 uint32_t storage_idx = DexFile::kDexNoIndex;
Roland Levillain4c0eb422015-04-24 16:43:49 +0100181 if (LIKELY(members_class->GetDexCache() == dex_cache)) {
182 // common case where the dex cache of both the referrer and the member are the same,
Vladimir Markobe0e5462014-02-26 11:24:15 +0000183 // no need to search the dex file
Roland Levillain4c0eb422015-04-24 16:43:49 +0100184 storage_idx = members_class->GetDexTypeIndex();
Vladimir Markobe0e5462014-02-26 11:24:15 +0000185 } else {
Roland Levillain4c0eb422015-04-24 16:43:49 +0100186 // Search dex file for localized ssb index, may fail if member's class is a parent
Vladimir Markobe0e5462014-02-26 11:24:15 +0000187 // of the class mentioned in the dex file and there is no dex cache entry.
Ian Rogers08f1f502014-12-02 15:04:37 -0800188 std::string temp;
Vladimir Markobe0e5462014-02-26 11:24:15 +0000189 const DexFile::StringId* string_id =
Roland Levillain4c0eb422015-04-24 16:43:49 +0100190 dex_file->FindStringId(resolved_member->GetDeclaringClass()->GetDescriptor(&temp));
Vladimir Markobe0e5462014-02-26 11:24:15 +0000191 if (string_id != nullptr) {
192 const DexFile::TypeId* type_id =
193 dex_file->FindTypeId(dex_file->GetIndexForStringId(*string_id));
194 if (type_id != nullptr) {
195 // medium path, needs check of static storage base being initialized
196 storage_idx = dex_file->GetIndexForTypeId(*type_id);
197 }
198 }
199 }
200 if (storage_idx != DexFile::kDexNoIndex) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000201 *storage_index = storage_idx;
Roland Levillain4c0eb422015-04-24 16:43:49 +0100202 return std::make_pair(true, !resolved_member->IsFinal());
Vladimir Markobe0e5462014-02-26 11:24:15 +0000203 }
204 }
205 }
206 // Conservative defaults.
Vladimir Markobe0e5462014-02-26 11:24:15 +0000207 *storage_index = DexFile::kDexNoIndex;
Vladimir Markobe0e5462014-02-26 11:24:15 +0000208 return std::make_pair(false, false);
209}
210
Roland Levillain4c0eb422015-04-24 16:43:49 +0100211inline std::pair<bool, bool> CompilerDriver::IsFastStaticField(
212 mirror::DexCache* dex_cache, mirror::Class* referrer_class,
213 ArtField* resolved_field, uint16_t field_idx, uint32_t* storage_index) {
214 return IsClassOfStaticMemberAvailableToReferrer(
215 dex_cache, referrer_class, resolved_field, field_idx, storage_index);
216}
217
218inline bool CompilerDriver::IsClassOfStaticMethodAvailableToReferrer(
219 mirror::DexCache* dex_cache, mirror::Class* referrer_class,
220 mirror::ArtMethod* resolved_method, uint16_t method_idx, uint32_t* storage_index) {
221 std::pair<bool, bool> result = IsClassOfStaticMemberAvailableToReferrer(
222 dex_cache, referrer_class, resolved_method, method_idx, storage_index);
223 // Only the first member of `result` is meaningful, as there is no
224 // "write access" to a method.
225 return result.first;
226}
227
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100228inline bool CompilerDriver::IsStaticFieldInReferrerClass(mirror::Class* referrer_class,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700229 ArtField* resolved_field) {
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100230 DCHECK(resolved_field->IsStatic());
231 mirror::Class* fields_class = resolved_field->GetDeclaringClass();
232 return referrer_class == fields_class;
233}
234
235inline bool CompilerDriver::IsStaticFieldsClassInitialized(mirror::Class* referrer_class,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700236 ArtField* resolved_field) {
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100237 DCHECK(resolved_field->IsStatic());
238 mirror::Class* fields_class = resolved_field->GetDeclaringClass();
239 return fields_class == referrer_class || fields_class->IsInitialized();
240}
241
Vladimir Markof096aad2014-01-23 15:51:58 +0000242inline mirror::ArtMethod* CompilerDriver::ResolveMethod(
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700243 ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
244 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit,
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800245 uint32_t method_idx, InvokeType invoke_type, bool check_incompatible_class_change) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700246 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile());
247 DCHECK_EQ(class_loader.Get(), soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader()));
Vladimir Markof096aad2014-01-23 15:51:58 +0000248 mirror::ArtMethod* resolved_method = mUnit->GetClassLinker()->ResolveMethod(
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700249 *mUnit->GetDexFile(), method_idx, dex_cache, class_loader, NullHandle<mirror::ArtMethod>(),
250 invoke_type);
Vladimir Markof096aad2014-01-23 15:51:58 +0000251 DCHECK_EQ(resolved_method == nullptr, soa.Self()->IsExceptionPending());
252 if (UNLIKELY(resolved_method == nullptr)) {
253 // Clean up any exception left by type resolution.
254 soa.Self()->ClearException();
255 return nullptr;
256 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800257 if (check_incompatible_class_change &&
258 UNLIKELY(resolved_method->CheckIncompatibleClassChange(invoke_type))) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700259 // Silently return null on incompatible class change.
Vladimir Markof096aad2014-01-23 15:51:58 +0000260 return nullptr;
261 }
262 return resolved_method;
263}
264
265inline void CompilerDriver::GetResolvedMethodDexFileLocation(
266 mirror::ArtMethod* resolved_method, const DexFile** declaring_dex_file,
267 uint16_t* declaring_class_idx, uint16_t* declaring_method_idx) {
268 mirror::Class* declaring_class = resolved_method->GetDeclaringClass();
269 *declaring_dex_file = declaring_class->GetDexCache()->GetDexFile();
270 *declaring_class_idx = declaring_class->GetDexTypeIndex();
271 *declaring_method_idx = resolved_method->GetDexMethodIndex();
272}
273
274inline uint16_t CompilerDriver::GetResolvedMethodVTableIndex(
275 mirror::ArtMethod* resolved_method, InvokeType type) {
276 if (type == kVirtual || type == kSuper) {
277 return resolved_method->GetMethodIndex();
278 } else if (type == kInterface) {
279 return resolved_method->GetDexMethodIndex();
280 } else {
281 return DexFile::kDexNoIndex16;
282 }
283}
284
285inline int CompilerDriver::IsFastInvoke(
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700286 ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
287 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit,
Vladimir Markof096aad2014-01-23 15:51:58 +0000288 mirror::Class* referrer_class, mirror::ArtMethod* resolved_method, InvokeType* invoke_type,
289 MethodReference* target_method, const MethodReference* devirt_target,
290 uintptr_t* direct_code, uintptr_t* direct_method) {
291 // Don't try to fast-path if we don't understand the caller's class.
292 if (UNLIKELY(referrer_class == nullptr)) {
293 return 0;
294 }
295 mirror::Class* methods_class = resolved_method->GetDeclaringClass();
296 if (UNLIKELY(!referrer_class->CanAccessResolvedMethod(methods_class, resolved_method,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700297 dex_cache.Get(),
Vladimir Markof096aad2014-01-23 15:51:58 +0000298 target_method->dex_method_index))) {
299 return 0;
300 }
Vladimir Markof096aad2014-01-23 15:51:58 +0000301 // Sharpen a virtual call into a direct call when the target is known not to have been
302 // overridden (ie is final).
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800303 const bool same_dex_file = target_method->dex_file == mUnit->GetDexFile();
304 bool can_sharpen_virtual_based_on_type = same_dex_file &&
Vladimir Markof096aad2014-01-23 15:51:58 +0000305 (*invoke_type == kVirtual) && (resolved_method->IsFinal() || methods_class->IsFinal());
306 // For invoke-super, ensure the vtable index will be correct to dispatch in the vtable of
307 // the super class.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800308 bool can_sharpen_super_based_on_type = same_dex_file && (*invoke_type == kSuper) &&
Vladimir Markof096aad2014-01-23 15:51:58 +0000309 (referrer_class != methods_class) && referrer_class->IsSubClass(methods_class) &&
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700310 resolved_method->GetMethodIndex() < methods_class->GetVTableLength() &&
Vladimir Marko920506d2014-11-18 14:47:31 +0000311 (methods_class->GetVTableEntry(resolved_method->GetMethodIndex()) == resolved_method) &&
312 !resolved_method->IsAbstract();
Vladimir Markof096aad2014-01-23 15:51:58 +0000313
314 if (can_sharpen_virtual_based_on_type || can_sharpen_super_based_on_type) {
315 // Sharpen a virtual call into a direct call. The method_idx is into referrer's
316 // dex cache, check that this resolved method is where we expect it.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800317 CHECK_EQ(target_method->dex_file, mUnit->GetDexFile());
318 DCHECK_EQ(dex_cache.Get(), mUnit->GetClassLinker()->FindDexCache(*mUnit->GetDexFile()));
319 CHECK_EQ(referrer_class->GetDexCache()->GetResolvedMethod(target_method->dex_method_index),
320 resolved_method) << PrettyMethod(resolved_method);
Vladimir Markof096aad2014-01-23 15:51:58 +0000321 int stats_flags = kFlagMethodResolved;
Igor Murashkind6dee672014-10-16 18:36:16 -0700322 GetCodeAndMethodForDirectCall(/*out*/invoke_type,
323 kDirect, // 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 Markof096aad2014-01-23 15:51:58 +0000330 DCHECK_NE(*invoke_type, kSuper) << PrettyMethod(resolved_method);
331 if (*invoke_type == kDirect) {
332 stats_flags |= kFlagsMethodResolvedVirtualMadeDirect;
333 }
334 return stats_flags;
335 }
336
337 if ((*invoke_type == kVirtual || *invoke_type == kInterface) && devirt_target != nullptr) {
338 // Post-verification callback recorded a more precise invoke target based on its type info.
339 mirror::ArtMethod* called_method;
340 ClassLinker* class_linker = mUnit->GetClassLinker();
341 if (LIKELY(devirt_target->dex_file == mUnit->GetDexFile())) {
342 called_method = class_linker->ResolveMethod(*devirt_target->dex_file,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700343 devirt_target->dex_method_index, dex_cache,
344 class_loader, NullHandle<mirror::ArtMethod>(),
345 kVirtual);
Vladimir Markof096aad2014-01-23 15:51:58 +0000346 } else {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700347 StackHandleScope<1> hs(soa.Self());
348 Handle<mirror::DexCache> target_dex_cache(
349 hs.NewHandle(class_linker->FindDexCache(*devirt_target->dex_file)));
Vladimir Markof096aad2014-01-23 15:51:58 +0000350 called_method = class_linker->ResolveMethod(*devirt_target->dex_file,
351 devirt_target->dex_method_index,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700352 target_dex_cache, class_loader,
353 NullHandle<mirror::ArtMethod>(), kVirtual);
Vladimir Markof096aad2014-01-23 15:51:58 +0000354 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700355 CHECK(called_method != nullptr);
Vladimir Markof096aad2014-01-23 15:51:58 +0000356 CHECK(!called_method->IsAbstract());
357 int stats_flags = kFlagMethodResolved;
Igor Murashkind6dee672014-10-16 18:36:16 -0700358 GetCodeAndMethodForDirectCall(/*out*/invoke_type,
359 kDirect, // Sharp type
360 true, // The dex cache may not be available
361 referrer_class, called_method,
362 /*out*/&stats_flags,
363 target_method,
364 /*out*/direct_code,
365 /*out*/direct_method);
Vladimir Markof096aad2014-01-23 15:51:58 +0000366 DCHECK_NE(*invoke_type, kSuper);
367 if (*invoke_type == kDirect) {
368 stats_flags |= kFlagsMethodResolvedPreciseTypeDevirtualization;
369 }
370 return stats_flags;
371 }
372
373 if (UNLIKELY(*invoke_type == kSuper)) {
374 // Unsharpened super calls are suspicious so go slow-path.
375 return 0;
376 }
377
378 // Sharpening failed so generate a regular resolved method dispatch.
379 int stats_flags = kFlagMethodResolved;
Igor Murashkind6dee672014-10-16 18:36:16 -0700380 GetCodeAndMethodForDirectCall(/*out*/invoke_type,
381 *invoke_type, // Sharp type
382 false, // The dex cache is guaranteed to be available
383 referrer_class, resolved_method,
384 /*out*/&stats_flags,
385 target_method,
386 /*out*/direct_code,
387 /*out*/direct_method);
Vladimir Markof096aad2014-01-23 15:51:58 +0000388 return stats_flags;
389}
390
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100391inline bool CompilerDriver::IsMethodsClassInitialized(mirror::Class* referrer_class,
392 mirror::ArtMethod* resolved_method) {
Vladimir Marko9820b7c2014-01-02 16:40:37 +0000393 if (!resolved_method->IsStatic()) {
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100394 return true;
Vladimir Marko9820b7c2014-01-02 16:40:37 +0000395 }
396 mirror::Class* methods_class = resolved_method->GetDeclaringClass();
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100397 return methods_class == referrer_class || methods_class->IsInitialized();
Vladimir Marko9820b7c2014-01-02 16:40:37 +0000398}
399
Vladimir Markobe0e5462014-02-26 11:24:15 +0000400} // namespace art
401
402#endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_INL_H_