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" 21 22 #include "art_field-inl.h" 23 #include "art_method-inl.h" 24 #include "base/enums.h" 25 #include "class_linker-inl.h" 26 #include "dex_compilation_unit.h" 27 #include "handle_scope-inl.h" 28 #include "mirror/class_loader.h" 29 #include "mirror/dex_cache-inl.h" 30 #include "runtime.h" 31 #include "scoped_thread_state_change-inl.h" 32 33 namespace art { 34 35 inline mirror::Class* CompilerDriver::ResolveClass( 36 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 37 Handle<mirror::ClassLoader> class_loader, dex::TypeIndex cls_index, 38 const DexCompilationUnit* mUnit) { 39 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile()); 40 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); 41 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 51 inline mirror::Class* CompilerDriver::ResolveCompilingMethodsClass( 52 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 53 Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit) { 54 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile()); 55 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); 56 const DexFile::MethodId& referrer_method_id = 57 mUnit->GetDexFile()->GetMethodId(mUnit->GetDexMethodIndex()); 58 return ResolveClass(soa, dex_cache, class_loader, referrer_method_id.class_idx_, mUnit); 59 } 60 61 inline ArtField* CompilerDriver::ResolveFieldWithDexFile( 62 const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, 63 Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file, 64 uint32_t field_idx, bool is_static) { 65 DCHECK_EQ(dex_cache->GetDexFile(), dex_file); 66 ArtField* resolved_field = Runtime::Current()->GetClassLinker()->ResolveField( 67 *dex_file, field_idx, dex_cache, class_loader, is_static); 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. 76 // Silently return null on such incompatible class change. 77 return nullptr; 78 } 79 return resolved_field; 80 } 81 82 inline ArtField* CompilerDriver::ResolveField( 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) { 86 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); 87 return ResolveFieldWithDexFile(soa, dex_cache, class_loader, mUnit->GetDexFile(), field_idx, 88 is_static); 89 } 90 91 inline std::pair<bool, bool> CompilerDriver::IsFastInstanceField( 92 mirror::DexCache* dex_cache, mirror::Class* referrer_class, 93 ArtField* resolved_field, uint16_t field_idx) { 94 DCHECK(!resolved_field->IsStatic()); 95 ObjPtr<mirror::Class> fields_class = resolved_field->GetDeclaringClass(); 96 bool fast_get = referrer_class != nullptr && 97 referrer_class->CanAccessResolvedField(fields_class, 98 resolved_field, 99 dex_cache, 100 field_idx); 101 bool fast_put = fast_get && (!resolved_field->IsFinal() || fields_class == referrer_class); 102 return std::make_pair(fast_get, fast_put); 103 } 104 105 inline ArtMethod* CompilerDriver::ResolveMethod( 106 ScopedObjectAccess& soa, 107 Handle<mirror::DexCache> dex_cache, 108 Handle<mirror::ClassLoader> class_loader, 109 const DexCompilationUnit* mUnit, 110 uint32_t method_idx, 111 InvokeType invoke_type) { 112 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); 113 ArtMethod* resolved_method = 114 mUnit->GetClassLinker()->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( 115 *dex_cache->GetDexFile(), method_idx, dex_cache, class_loader, nullptr, invoke_type); 116 if (UNLIKELY(resolved_method == nullptr)) { 117 DCHECK(soa.Self()->IsExceptionPending()); 118 // Clean up any exception left by type resolution. 119 soa.Self()->ClearException(); 120 } 121 return resolved_method; 122 } 123 124 inline VerificationResults* CompilerDriver::GetVerificationResults() const { 125 DCHECK(Runtime::Current()->IsAotCompiler()); 126 return verification_results_; 127 } 128 129 } // namespace art 130 131 #endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_INL_H_ 132