blob: 294072d7e724f38f1c64affff50998647f097b80 [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
Vladimir Marko28e012a2017-12-07 11:22:59 +000035inline ObjPtr<mirror::Class> CompilerDriver::ResolveClass(
Vladimir Marko666ee3d2017-12-11 18:37:36 +000036 const ScopedObjectAccess& soa,
37 Handle<mirror::DexCache> dex_cache,
38 Handle<mirror::ClassLoader> class_loader,
39 dex::TypeIndex cls_index,
Nicolas Geoffray9437b782015-03-25 10:08:51 +000040 const DexCompilationUnit* mUnit) {
41 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile());
Vladimir Marko8d6768d2017-03-14 10:13:21 +000042 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get());
Vladimir Marko666ee3d2017-12-11 18:37:36 +000043 ObjPtr<mirror::Class> cls =
44 mUnit->GetClassLinker()->ResolveType(cls_index, dex_cache, class_loader);
Nicolas Geoffray9437b782015-03-25 10:08:51 +000045 DCHECK_EQ(cls == nullptr, soa.Self()->IsExceptionPending());
46 if (UNLIKELY(cls == nullptr)) {
47 // Clean up any exception left by type resolution.
48 soa.Self()->ClearException();
49 }
50 return cls;
51}
52
Vladimir Marko28e012a2017-12-07 11:22:59 +000053inline ObjPtr<mirror::Class> CompilerDriver::ResolveCompilingMethodsClass(
Vladimir Marko666ee3d2017-12-11 18:37:36 +000054 const ScopedObjectAccess& soa,
55 Handle<mirror::DexCache> dex_cache,
56 Handle<mirror::ClassLoader> class_loader,
57 const DexCompilationUnit* mUnit) {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070058 DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile());
Vladimir Marko8d6768d2017-03-14 10:13:21 +000059 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get());
Vladimir Markobe0e5462014-02-26 11:24:15 +000060 const DexFile::MethodId& referrer_method_id =
61 mUnit->GetDexFile()->GetMethodId(mUnit->GetDexMethodIndex());
Nicolas Geoffray9437b782015-03-25 10:08:51 +000062 return ResolveClass(soa, dex_cache, class_loader, referrer_method_id.class_idx_, mUnit);
Vladimir Markobe0e5462014-02-26 11:24:15 +000063}
64
Vladimir Markoe11dd502017-12-08 14:09:45 +000065inline ArtField* CompilerDriver::ResolveField(const ScopedObjectAccess& soa,
66 Handle<mirror::DexCache> dex_cache,
67 Handle<mirror::ClassLoader> class_loader,
68 uint32_t field_idx,
69 bool is_static) {
Mathieu Chartierc7853442015-03-27 14:35:38 -070070 ArtField* resolved_field = Runtime::Current()->GetClassLinker()->ResolveField(
Vladimir Markoe11dd502017-12-08 14:09:45 +000071 field_idx, dex_cache, class_loader, is_static);
Vladimir Markobe0e5462014-02-26 11:24:15 +000072 DCHECK_EQ(resolved_field == nullptr, soa.Self()->IsExceptionPending());
73 if (UNLIKELY(resolved_field == nullptr)) {
74 // Clean up any exception left by type resolution.
75 soa.Self()->ClearException();
76 return nullptr;
77 }
78 if (UNLIKELY(resolved_field->IsStatic() != is_static)) {
79 // ClassLinker can return a field of the wrong kind directly from the DexCache.
Mathieu Chartier2cebb242015-04-21 16:50:40 -070080 // Silently return null on such incompatible class change.
Vladimir Markobe0e5462014-02-26 11:24:15 +000081 return nullptr;
82 }
83 return resolved_field;
84}
85
Vladimir Markobe0e5462014-02-26 11:24:15 +000086inline std::pair<bool, bool> CompilerDriver::IsFastInstanceField(
Vladimir Marko28e012a2017-12-07 11:22:59 +000087 ObjPtr<mirror::DexCache> dex_cache,
88 ObjPtr<mirror::Class> referrer_class,
89 ArtField* resolved_field,
90 uint16_t field_idx) {
Vladimir Markobe0e5462014-02-26 11:24:15 +000091 DCHECK(!resolved_field->IsStatic());
Mathieu Chartier3398c782016-09-30 10:27:43 -070092 ObjPtr<mirror::Class> fields_class = resolved_field->GetDeclaringClass();
Vladimir Markobe0e5462014-02-26 11:24:15 +000093 bool fast_get = referrer_class != nullptr &&
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070094 referrer_class->CanAccessResolvedField(fields_class,
Mathieu Chartier3398c782016-09-30 10:27:43 -070095 resolved_field,
96 dex_cache,
97 field_idx);
Vladimir Markobe0e5462014-02-26 11:24:15 +000098 bool fast_put = fast_get && (!resolved_field->IsFinal() || fields_class == referrer_class);
Vladimir Markobe0e5462014-02-26 11:24:15 +000099 return std::make_pair(fast_get, fast_put);
100}
101
Mathieu Chartiere401d142015-04-22 13:56:20 -0700102inline ArtMethod* CompilerDriver::ResolveMethod(
Vladimir Markof79aa7f2017-07-04 16:58:55 +0100103 ScopedObjectAccess& soa,
104 Handle<mirror::DexCache> dex_cache,
105 Handle<mirror::ClassLoader> class_loader,
106 const DexCompilationUnit* mUnit,
107 uint32_t method_idx,
108 InvokeType invoke_type) {
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000109 DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get());
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800110 ArtMethod* resolved_method =
Vladimir Markoba118822017-06-12 15:41:56 +0100111 mUnit->GetClassLinker()->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
Vladimir Marko89011192017-12-11 13:45:05 +0000112 method_idx, dex_cache, class_loader, /* referrer */ nullptr, invoke_type);
Vladimir Markof096aad2014-01-23 15:51:58 +0000113 if (UNLIKELY(resolved_method == nullptr)) {
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800114 DCHECK(soa.Self()->IsExceptionPending());
Vladimir Markof096aad2014-01-23 15:51:58 +0000115 // Clean up any exception left by type resolution.
116 soa.Self()->ClearException();
Vladimir Markof096aad2014-01-23 15:51:58 +0000117 }
118 return resolved_method;
119}
120
Andreas Gamped482e732017-04-24 17:59:09 -0700121inline VerificationResults* CompilerDriver::GetVerificationResults() const {
122 DCHECK(Runtime::Current()->IsAotCompiler());
123 return verification_results_;
124}
125
Vladimir Markobe0e5462014-02-26 11:24:15 +0000126} // namespace art
127
128#endif // ART_COMPILER_DRIVER_COMPILER_DRIVER_INL_H_