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 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 22 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 23 | #include "art_method-inl.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 24 | #include "base/enums.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 25 | #include "class_linker-inl.h" |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 26 | #include "dex_compilation_unit.h" |
Andreas Gampe | d482e73 | 2017-04-24 17:59:09 -0700 | [diff] [blame] | 27 | #include "handle_scope-inl.h" |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 28 | #include "mirror/class_loader.h" |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 29 | #include "mirror/dex_cache-inl.h" |
Andreas Gampe | d482e73 | 2017-04-24 17:59:09 -0700 | [diff] [blame] | 30 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 31 | #include "scoped_thread_state_change-inl.h" |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 35 | inline ObjPtr<mirror::Class> CompilerDriver::ResolveClass( |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 36 | const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 37 | Handle<mirror::ClassLoader> class_loader, dex::TypeIndex cls_index, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 38 | const DexCompilationUnit* mUnit) { |
| 39 | DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile()); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 40 | DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 41 | ObjPtr<mirror::Class> cls = mUnit->GetClassLinker()->ResolveType( |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 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 Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 51 | inline ObjPtr<mirror::Class> CompilerDriver::ResolveCompilingMethodsClass( |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 53 | Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 54 | DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile()); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 55 | DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 56 | const DexFile::MethodId& referrer_method_id = |
| 57 | mUnit->GetDexFile()->GetMethodId(mUnit->GetDexMethodIndex()); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 58 | 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] | 59 | } |
| 60 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 61 | inline ArtField* CompilerDriver::ResolveFieldWithDexFile( |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 63 | Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file, |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 64 | uint32_t field_idx, bool is_static) { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 65 | DCHECK_EQ(dex_cache->GetDexFile(), dex_file); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 66 | ArtField* resolved_field = Runtime::Current()->GetClassLinker()->ResolveField( |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 67 | *dex_file, field_idx, dex_cache, class_loader, is_static); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 68 | 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 Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 76 | // Silently return null on such incompatible class change. |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 77 | return nullptr; |
| 78 | } |
| 79 | return resolved_field; |
| 80 | } |
| 81 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 82 | inline ArtField* CompilerDriver::ResolveField( |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 83 | 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 Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 86 | DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 87 | return ResolveFieldWithDexFile(soa, dex_cache, class_loader, mUnit->GetDexFile(), field_idx, |
| 88 | is_static); |
| 89 | } |
| 90 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 91 | inline std::pair<bool, bool> CompilerDriver::IsFastInstanceField( |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 92 | ObjPtr<mirror::DexCache> dex_cache, |
| 93 | ObjPtr<mirror::Class> referrer_class, |
| 94 | ArtField* resolved_field, |
| 95 | uint16_t field_idx) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 96 | DCHECK(!resolved_field->IsStatic()); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 97 | ObjPtr<mirror::Class> fields_class = resolved_field->GetDeclaringClass(); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 98 | bool fast_get = referrer_class != nullptr && |
Mathieu Chartier | 1a5337f | 2016-10-13 13:48:23 -0700 | [diff] [blame] | 99 | referrer_class->CanAccessResolvedField(fields_class, |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 100 | resolved_field, |
| 101 | dex_cache, |
| 102 | field_idx); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 103 | bool fast_put = fast_get && (!resolved_field->IsFinal() || fields_class == referrer_class); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 104 | return std::make_pair(fast_get, fast_put); |
| 105 | } |
| 106 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 107 | inline ArtMethod* CompilerDriver::ResolveMethod( |
Vladimir Marko | f79aa7f | 2017-07-04 16:58:55 +0100 | [diff] [blame] | 108 | ScopedObjectAccess& soa, |
| 109 | Handle<mirror::DexCache> dex_cache, |
| 110 | Handle<mirror::ClassLoader> class_loader, |
| 111 | const DexCompilationUnit* mUnit, |
| 112 | uint32_t method_idx, |
| 113 | InvokeType invoke_type) { |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 114 | DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); |
Andreas Gampe | 42ef8ab | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 115 | ArtMethod* resolved_method = |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 116 | mUnit->GetClassLinker()->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( |
Vladimir Marko | f79aa7f | 2017-07-04 16:58:55 +0100 | [diff] [blame] | 117 | *dex_cache->GetDexFile(), method_idx, dex_cache, class_loader, nullptr, invoke_type); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 118 | if (UNLIKELY(resolved_method == nullptr)) { |
Andreas Gampe | 42ef8ab | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 119 | DCHECK(soa.Self()->IsExceptionPending()); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 120 | // Clean up any exception left by type resolution. |
| 121 | soa.Self()->ClearException(); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 122 | } |
| 123 | return resolved_method; |
| 124 | } |
| 125 | |
Andreas Gampe | d482e73 | 2017-04-24 17:59:09 -0700 | [diff] [blame] | 126 | inline VerificationResults* CompilerDriver::GetVerificationResults() const { |
| 127 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 128 | return verification_results_; |
| 129 | } |
| 130 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 131 | } // namespace art |
| 132 | |
| 133 | #endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_INL_H_ |