blob: 8cc1cc38e2abf882a513678f286ebba34e23d75e [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"
Mathieu Chartiere401d142015-04-22 13:56:20 -070023#include "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070024#include "base/enums.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070025#include "class_linker-inl.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070026#include "dex_compilation_unit.h"
Andreas Gamped482e732017-04-24 17:59:09 -070027#include "handle_scope-inl.h"
Vladimir Markobe0e5462014-02-26 11:24:15 +000028#include "mirror/class_loader.h"
Vladimir Markof096aad2014-01-23 15:51:58 +000029#include "mirror/dex_cache-inl.h"
Andreas Gamped482e732017-04-24 17:59:09 -070030#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070031#include "scoped_thread_state_change-inl.h"
Vladimir Markobe0e5462014-02-26 11:24:15 +000032
33namespace art {
34
Nicolas Geoffray9437b782015-03-25 10:08:51 +000035inline mirror::Class* CompilerDriver::ResolveClass(
36 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
Andreas Gampea5b09a62016-11-17 15:21:22 -080037 Handle<mirror::ClassLoader> class_loader, dex::TypeIndex cls_index,
Nicolas Geoffray9437b782015-03-25 10:08:51 +000038 const DexCompilationUnit* mUnit) {
39 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile());
Vladimir Marko8d6768d2017-03-14 10:13:21 +000040 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get());
Nicolas Geoffray9437b782015-03-25 10:08:51 +000041 mirror::Class* cls = mUnit->GetClassLinker()->ResolveType(
42 *mUnit->GetDexFile(), cls_index, dex_cache, class_loader);
43 DCHECK_EQ(cls == nullptr, soa.Self()->IsExceptionPending());
44 if (UNLIKELY(cls == nullptr)) {
45 // Clean up any exception left by type resolution.
46 soa.Self()->ClearException();
47 }
48 return cls;
49}
50
Vladimir Markobe0e5462014-02-26 11:24:15 +000051inline mirror::Class* CompilerDriver::ResolveCompilingMethodsClass(
Nicolas Geoffraye5038322014-07-04 09:41:32 +010052 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
Mathieu Chartier0cd81352014-05-22 16:48:55 -070053 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit) {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070054 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile());
Vladimir Marko8d6768d2017-03-14 10:13:21 +000055 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get());
Vladimir Markobe0e5462014-02-26 11:24:15 +000056 const DexFile::MethodId& referrer_method_id =
57 mUnit->GetDexFile()->GetMethodId(mUnit->GetDexMethodIndex());
Nicolas Geoffray9437b782015-03-25 10:08:51 +000058 return ResolveClass(soa, dex_cache, class_loader, referrer_method_id.class_idx_, mUnit);
Vladimir Markobe0e5462014-02-26 11:24:15 +000059}
60
Mathieu Chartierc7853442015-03-27 14:35:38 -070061inline ArtField* CompilerDriver::ResolveFieldWithDexFile(
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080063 Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file,
Vladimir Markobe0e5462014-02-26 11:24:15 +000064 uint32_t field_idx, bool is_static) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080065 DCHECK_EQ(dex_cache->GetDexFile(), dex_file);
Mathieu Chartierc7853442015-03-27 14:35:38 -070066 ArtField* resolved_field = Runtime::Current()->GetClassLinker()->ResolveField(
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080067 *dex_file, field_idx, dex_cache, class_loader, is_static);
Vladimir Markobe0e5462014-02-26 11:24:15 +000068 DCHECK_EQ(resolved_field == nullptr, soa.Self()->IsExceptionPending());
69 if (UNLIKELY(resolved_field == nullptr)) {
70 // Clean up any exception left by type resolution.
71 soa.Self()->ClearException();
72 return nullptr;
73 }
74 if (UNLIKELY(resolved_field->IsStatic() != is_static)) {
75 // ClassLinker can return a field of the wrong kind directly from the DexCache.
Mathieu Chartier2cebb242015-04-21 16:50:40 -070076 // Silently return null on such incompatible class change.
Vladimir Markobe0e5462014-02-26 11:24:15 +000077 return nullptr;
78 }
79 return resolved_field;
80}
81
Mathieu Chartierc7853442015-03-27 14:35:38 -070082inline ArtField* CompilerDriver::ResolveField(
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080083 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
84 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit,
85 uint32_t field_idx, bool is_static) {
Vladimir Marko8d6768d2017-03-14 10:13:21 +000086 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get());
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080087 return ResolveFieldWithDexFile(soa, dex_cache, class_loader, mUnit->GetDexFile(), field_idx,
88 is_static);
89}
90
Vladimir Markobe0e5462014-02-26 11:24:15 +000091inline std::pair<bool, bool> CompilerDriver::IsFastInstanceField(
92 mirror::DexCache* dex_cache, mirror::Class* referrer_class,
Mathieu Chartierc7853442015-03-27 14:35:38 -070093 ArtField* resolved_field, uint16_t field_idx) {
Vladimir Markobe0e5462014-02-26 11:24:15 +000094 DCHECK(!resolved_field->IsStatic());
Mathieu Chartier3398c782016-09-30 10:27:43 -070095 ObjPtr<mirror::Class> fields_class = resolved_field->GetDeclaringClass();
Vladimir Markobe0e5462014-02-26 11:24:15 +000096 bool fast_get = referrer_class != nullptr &&
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070097 referrer_class->CanAccessResolvedField(fields_class,
Mathieu Chartier3398c782016-09-30 10:27:43 -070098 resolved_field,
99 dex_cache,
100 field_idx);
Vladimir Markobe0e5462014-02-26 11:24:15 +0000101 bool fast_put = fast_get && (!resolved_field->IsFinal() || fields_class == referrer_class);
Vladimir Markobe0e5462014-02-26 11:24:15 +0000102 return std::make_pair(fast_get, fast_put);
103}
104
Roland Levillain4c0eb422015-04-24 16:43:49 +0100105template <typename ArtMember>
106inline bool CompilerDriver::CanAccessResolvedMember(mirror::Class* referrer_class ATTRIBUTE_UNUSED,
107 mirror::Class* access_to ATTRIBUTE_UNUSED,
108 ArtMember* member ATTRIBUTE_UNUSED,
109 mirror::DexCache* dex_cache ATTRIBUTE_UNUSED,
110 uint32_t field_idx ATTRIBUTE_UNUSED) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700111 // Not defined for ArtMember values other than ArtField or ArtMethod.
Roland Levillain4c0eb422015-04-24 16:43:49 +0100112 UNREACHABLE();
113}
114
115template <>
116inline bool CompilerDriver::CanAccessResolvedMember<ArtField>(mirror::Class* referrer_class,
117 mirror::Class* access_to,
118 ArtField* field,
119 mirror::DexCache* dex_cache,
120 uint32_t field_idx) {
121 return referrer_class->CanAccessResolvedField(access_to, field, dex_cache, field_idx);
122}
123
124template <>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700125inline bool CompilerDriver::CanAccessResolvedMember<ArtMethod>(
Roland Levillain4c0eb422015-04-24 16:43:49 +0100126 mirror::Class* referrer_class,
127 mirror::Class* access_to,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700128 ArtMethod* method,
Roland Levillain4c0eb422015-04-24 16:43:49 +0100129 mirror::DexCache* dex_cache,
130 uint32_t field_idx) {
131 return referrer_class->CanAccessResolvedMethod(access_to, method, dex_cache, field_idx);
132}
133
Mathieu Chartiere401d142015-04-22 13:56:20 -0700134inline ArtMethod* CompilerDriver::ResolveMethod(
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700135 ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache,
136 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit,
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800137 uint32_t method_idx, InvokeType invoke_type, bool check_incompatible_class_change) {
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000138 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get());
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800139 ArtMethod* resolved_method =
140 check_incompatible_class_change
141 ? mUnit->GetClassLinker()->ResolveMethod<ClassLinker::kForceICCECheck>(
142 *dex_cache->GetDexFile(), method_idx, dex_cache, class_loader, nullptr, invoke_type)
143 : mUnit->GetClassLinker()->ResolveMethod<ClassLinker::kNoICCECheckForCache>(
144 *dex_cache->GetDexFile(), method_idx, dex_cache, class_loader, nullptr, invoke_type);
Vladimir Markof096aad2014-01-23 15:51:58 +0000145 if (UNLIKELY(resolved_method == nullptr)) {
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800146 DCHECK(soa.Self()->IsExceptionPending());
Vladimir Markof096aad2014-01-23 15:51:58 +0000147 // Clean up any exception left by type resolution.
148 soa.Self()->ClearException();
Vladimir Markof096aad2014-01-23 15:51:58 +0000149 }
150 return resolved_method;
151}
152
Andreas Gamped482e732017-04-24 17:59:09 -0700153inline VerificationResults* CompilerDriver::GetVerificationResults() const {
154 DCHECK(Runtime::Current()->IsAotCompiler());
155 return verification_results_;
156}
157
Vladimir Markobe0e5462014-02-26 11:24:15 +0000158} // namespace art
159
160#endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_INL_H_