blob: 6541043046458bdd524e9bd40175887bb73c0728 [file] [log] [blame]
Vladimir Markodc151b22015-10-15 18:02:30 +01001/*
2 * Copyright (C) 2015 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#include "sharpening.h"
18
Vladimir Marko65979462017-05-19 17:25:12 +010019#include "art_method-inl.h"
Vladimir Markodb8e62d2016-03-30 16:30:21 +010020#include "base/casts.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Vladimir Markocac5a7e2016-02-22 10:39:50 +000022#include "class_linker.h"
Vladimir Markodc151b22015-10-15 18:02:30 +010023#include "code_generator.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070024#include "driver/compiler_driver.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010025#include "driver/compiler_options.h"
Vladimir Markocac5a7e2016-02-22 10:39:50 +000026#include "driver/dex_compilation_unit.h"
Vladimir Markocac5a7e2016-02-22 10:39:50 +000027#include "gc/heap.h"
28#include "gc/space/image_space.h"
29#include "handle_scope-inl.h"
30#include "mirror/dex_cache.h"
31#include "mirror/string.h"
Vladimir Markodc151b22015-10-15 18:02:30 +010032#include "nodes.h"
Vladimir Markod1eaf0d2015-10-29 12:18:29 +000033#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070034#include "scoped_thread_state_change-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070035#include "utils/dex_cache_arrays_layout-inl.h"
Vladimir Markodc151b22015-10-15 18:02:30 +010036
37namespace art {
38
Aart Bik24773202018-04-26 10:28:51 -070039bool HSharpening::Run() {
Vladimir Markodc151b22015-10-15 18:02:30 +010040 // We don't care about the order of the blocks here.
41 for (HBasicBlock* block : graph_->GetReversePostOrder()) {
42 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
43 HInstruction* instruction = it.Current();
44 if (instruction->IsInvokeStaticOrDirect()) {
Vladimir Marko65979462017-05-19 17:25:12 +010045 SharpenInvokeStaticOrDirect(instruction->AsInvokeStaticOrDirect(),
46 codegen_,
47 compiler_driver_);
Vladimir Markodc151b22015-10-15 18:02:30 +010048 }
49 // TODO: Move the sharpening of invoke-virtual/-interface/-super from HGraphBuilder
50 // here. Rewrite it to avoid the CompilerDriver's reliance on verifier data
51 // because we know the type better when inlining.
Vladimir Markodc151b22015-10-15 18:02:30 +010052 }
53 }
Aart Bik24773202018-04-26 10:28:51 -070054 return true;
Vladimir Markodc151b22015-10-15 18:02:30 +010055}
56
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +000057static bool IsInBootImage(ArtMethod* method) {
58 const std::vector<gc::space::ImageSpace*>& image_spaces =
59 Runtime::Current()->GetHeap()->GetBootImageSpaces();
60 for (gc::space::ImageSpace* image_space : image_spaces) {
Vladimir Marko7d157fc2017-05-10 16:29:23 +010061 const ImageSection& method_section = image_space->GetImageHeader().GetMethodsSection();
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +000062 if (method_section.Contains(reinterpret_cast<uint8_t*>(method) - image_space->Begin())) {
63 return true;
64 }
65 }
66 return false;
67}
68
69static bool AOTCanEmbedMethod(ArtMethod* method, const CompilerOptions& options) {
Richard Uhlerc52f3032017-03-02 13:45:45 +000070 return IsInBootImage(method) && !options.GetCompilePic();
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +000071}
72
Vladimir Marko65979462017-05-19 17:25:12 +010073static bool BootImageAOTCanEmbedMethod(ArtMethod* method, CompilerDriver* compiler_driver) {
74 DCHECK(compiler_driver->GetCompilerOptions().IsBootImage());
75 if (!compiler_driver->GetSupportBootImageFixup()) {
76 return false;
77 }
78 ScopedObjectAccess soa(Thread::Current());
79 ObjPtr<mirror::Class> klass = method->GetDeclaringClass();
80 DCHECK(klass != nullptr);
81 const DexFile& dex_file = klass->GetDexFile();
82 return compiler_driver->IsImageClass(dex_file.StringByTypeIdx(klass->GetDexTypeIndex()));
83}
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000084
85void HSharpening::SharpenInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke,
Vladimir Marko65979462017-05-19 17:25:12 +010086 CodeGenerator* codegen,
87 CompilerDriver* compiler_driver) {
Vladimir Markodc151b22015-10-15 18:02:30 +010088 if (invoke->IsStringInit()) {
89 // Not using the dex cache arrays. But we could still try to use a better dispatch...
90 // TODO: Use direct_method and direct_code for the appropriate StringFactory method.
91 return;
92 }
93
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +000094 ArtMethod* callee = invoke->GetResolvedMethod();
95 DCHECK(callee != nullptr);
Vladimir Markodc151b22015-10-15 18:02:30 +010096
97 HInvokeStaticOrDirect::MethodLoadKind method_load_kind;
98 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location;
99 uint64_t method_load_data = 0u;
Vladimir Markodc151b22015-10-15 18:02:30 +0100100
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +0000101 // Note: we never call an ArtMethod through a known code pointer, as
102 // we do not want to keep on invoking it if it gets deoptimized. This
103 // applies to both AOT and JIT.
104 // This also avoids having to find out if the code pointer of an ArtMethod
105 // is the resolution trampoline (for ensuring the class is initialized), or
106 // the interpreter entrypoint. Such code pointers we do not want to call
107 // directly.
108 // Only in the case of a recursive call can we call directly, as we know the
109 // class is initialized already or being initialized, and the call will not
110 // be invoked once the method is deoptimized.
111
Alex Light1ebe4fe2017-01-30 14:57:11 -0800112 // We don't optimize for debuggable as it would prevent us from obsoleting the method in some
113 // situations.
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +0000114 if (callee == codegen->GetGraph()->GetArtMethod() && !codegen->GetGraph()->IsDebuggable()) {
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +0000115 // Recursive call.
Vladimir Markodc151b22015-10-15 18:02:30 +0100116 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kRecursive;
117 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallSelf;
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +0000118 } else if (Runtime::Current()->UseJitCompilation() ||
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +0000119 AOTCanEmbedMethod(callee, codegen->GetCompilerOptions())) {
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +0000120 // JIT or on-device AOT compilation referencing a boot image method.
121 // Use the method address directly.
122 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress;
123 method_load_data = reinterpret_cast<uintptr_t>(callee);
124 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
Vladimir Marko65979462017-05-19 17:25:12 +0100125 } else if (codegen->GetCompilerOptions().IsBootImage() &&
126 BootImageAOTCanEmbedMethod(callee, compiler_driver)) {
127 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative;
128 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
Vladimir Markob066d432018-01-03 13:14:37 +0000129 } else if (IsInBootImage(callee)) {
130 // Use PC-relative access to the .data.bimg.rel.ro methods array.
131 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo;
Vladimir Markob066d432018-01-03 13:14:37 +0000132 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
Vladimir Markodc151b22015-10-15 18:02:30 +0100133 } else {
Vladimir Markob066d432018-01-03 13:14:37 +0000134 // Use PC-relative access to the .bss methods array.
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100135 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kBssEntry;
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +0000136 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
Vladimir Markodc151b22015-10-15 18:02:30 +0100137 }
138
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +0000139 if (codegen->GetGraph()->IsDebuggable()) {
Vladimir Markodc151b22015-10-15 18:02:30 +0100140 // For debuggable apps always use the code pointer from ArtMethod
141 // so that we don't circumvent instrumentation stubs if installed.
142 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
143 }
144
145 HInvokeStaticOrDirect::DispatchInfo desired_dispatch_info = {
Nicolas Geoffrayc1a42cf2016-12-18 15:52:36 +0000146 method_load_kind, code_ptr_location, method_load_data
Vladimir Markodc151b22015-10-15 18:02:30 +0100147 };
148 HInvokeStaticOrDirect::DispatchInfo dispatch_info =
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +0000149 codegen->GetSupportedInvokeStaticOrDirectDispatch(desired_dispatch_info, invoke);
Vladimir Markodc151b22015-10-15 18:02:30 +0100150 invoke->SetDispatchInfo(dispatch_info);
151}
152
Vladimir Marko28e012a2017-12-07 11:22:59 +0000153HLoadClass::LoadKind HSharpening::ComputeLoadClassKind(
154 HLoadClass* load_class,
155 CodeGenerator* codegen,
156 CompilerDriver* compiler_driver,
157 const DexCompilationUnit& dex_compilation_unit) {
Nicolas Geoffray5247c082017-01-13 14:17:29 +0000158 Handle<mirror::Class> klass = load_class->GetClass();
Vladimir Marko847e6ce2017-06-02 13:55:07 +0100159 DCHECK(load_class->GetLoadKind() == HLoadClass::LoadKind::kRuntimeCall ||
Mathieu Chartier4a4a6012016-09-16 14:16:42 -0700160 load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass)
161 << load_class->GetLoadKind();
Mathieu Chartier4a4a6012016-09-16 14:16:42 -0700162 DCHECK(!load_class->IsInBootImage()) << "HLoadClass should not be optimized before sharpening.";
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100163
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000164 HLoadClass::LoadKind load_kind = load_class->GetLoadKind();
165
Vladimir Marko41559982017-01-06 14:04:23 +0000166 if (load_class->NeedsAccessCheck()) {
167 // We need to call the runtime anyway, so we simply get the class as that call's return value.
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000168 } else if (load_kind == HLoadClass::LoadKind::kReferrersClass) {
Vladimir Marko41559982017-01-06 14:04:23 +0000169 // Loading from the ArtMethod* is the most efficient retrieval in code size.
170 // TODO: This may not actually be true for all architectures and
171 // locations of target classes. The additional register pressure
172 // for using the ArtMethod* should be considered.
Nicolas Geoffray56876342016-12-16 16:09:08 +0000173 } else {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000174 const DexFile& dex_file = load_class->GetDexFile();
175 dex::TypeIndex type_index = load_class->GetTypeIndex();
176
177 bool is_in_boot_image = false;
178 HLoadClass::LoadKind desired_load_kind = HLoadClass::LoadKind::kInvalid;
179 Runtime* runtime = Runtime::Current();
180 if (codegen->GetCompilerOptions().IsBootImage()) {
181 // Compiling boot image. Check if the class is a boot image class.
182 DCHECK(!runtime->UseJitCompilation());
183 if (!compiler_driver->GetSupportBootImageFixup()) {
184 // compiler_driver_test. Do not sharpen.
Vladimir Marko847e6ce2017-06-02 13:55:07 +0100185 desired_load_kind = HLoadClass::LoadKind::kRuntimeCall;
Vladimir Marko65979462017-05-19 17:25:12 +0100186 } else if ((klass != nullptr) &&
187 compiler_driver->IsImageClass(dex_file.StringByTypeIdx(type_index))) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000188 is_in_boot_image = true;
Vladimir Marko764d4542017-05-16 10:31:41 +0100189 desired_load_kind = HLoadClass::LoadKind::kBootImageLinkTimePcRelative;
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000190 } else {
191 // Not a boot image class.
192 DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file));
193 desired_load_kind = HLoadClass::LoadKind::kBssEntry;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100194 }
Nicolas Geoffray56876342016-12-16 16:09:08 +0000195 } else {
Andreas Gampefa4333d2017-02-14 11:10:34 -0800196 is_in_boot_image = (klass != nullptr) &&
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000197 runtime->GetHeap()->ObjectIsInBootImageSpace(klass.Get());
198 if (runtime->UseJitCompilation()) {
Vladimir Marko764d4542017-05-16 10:31:41 +0100199 DCHECK(!codegen->GetCompilerOptions().GetCompilePic());
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000200 if (is_in_boot_image) {
201 // TODO: Use direct pointers for all non-moving spaces, not just boot image. Bug: 29530787
202 desired_load_kind = HLoadClass::LoadKind::kBootImageAddress;
Andreas Gampefa4333d2017-02-14 11:10:34 -0800203 } else if (klass != nullptr) {
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000204 desired_load_kind = HLoadClass::LoadKind::kJitTableAddress;
205 } else {
206 // Class not loaded yet. This happens when the dex code requesting
207 // this `HLoadClass` hasn't been executed in the interpreter.
208 // Fallback to the dex cache.
209 // TODO(ngeoffray): Generate HDeoptimize instead.
Vladimir Marko847e6ce2017-06-02 13:55:07 +0100210 desired_load_kind = HLoadClass::LoadKind::kRuntimeCall;
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000211 }
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100212 } else if (is_in_boot_image) {
213 // AOT app compilation, boot image class.
214 if (codegen->GetCompilerOptions().GetCompilePic()) {
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000215 desired_load_kind = HLoadClass::LoadKind::kBootImageRelRo;
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100216 } else {
217 desired_load_kind = HLoadClass::LoadKind::kBootImageAddress;
218 }
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000219 } else {
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100220 // Not JIT and the klass is not in boot image.
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000221 desired_load_kind = HLoadClass::LoadKind::kBssEntry;
222 }
223 }
224 DCHECK_NE(desired_load_kind, HLoadClass::LoadKind::kInvalid);
225
226 if (is_in_boot_image) {
227 load_class->MarkInBootImage();
228 }
229 load_kind = codegen->GetSupportedLoadClassKind(desired_load_kind);
230 }
231
232 if (!IsSameDexFile(load_class->GetDexFile(), *dex_compilation_unit.GetDexFile())) {
Vladimir Marko847e6ce2017-06-02 13:55:07 +0100233 if ((load_kind == HLoadClass::LoadKind::kRuntimeCall) ||
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000234 (load_kind == HLoadClass::LoadKind::kBssEntry)) {
235 // We actually cannot reference this class, we're forced to bail.
236 // We cannot reference this class with Bss, as the entrypoint will lookup the class
237 // in the caller's dex file, but that dex file does not reference the class.
238 return HLoadClass::LoadKind::kInvalid;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100239 }
240 }
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000241 return load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100242}
243
Vladimir Marko175e7862018-03-27 09:03:13 +0000244static inline bool CanUseTypeCheckBitstring(ObjPtr<mirror::Class> klass,
245 CodeGenerator* codegen,
246 CompilerDriver* compiler_driver)
247 REQUIRES_SHARED(Locks::mutator_lock_) {
248 DCHECK(!klass->IsProxyClass());
249 DCHECK(!klass->IsArrayClass());
250
251 if (Runtime::Current()->UseJitCompilation()) {
252 // If we're JITting, try to assign a type check bitstring (fall through).
253 } else if (codegen->GetCompilerOptions().IsBootImage()) {
254 const char* descriptor = klass->GetDexFile().StringByTypeIdx(klass->GetDexTypeIndex());
255 if (!compiler_driver->IsImageClass(descriptor)) {
256 return false;
257 }
258 // If the target is a boot image class, try to assign a type check bitstring (fall through).
259 // (If --force-determinism, this was already done; repeating is OK and yields the same result.)
260 } else {
261 // TODO: Use the bitstring also for AOT app compilation if the target class has a bitstring
262 // already assigned in the boot image.
263 return false;
264 }
265
266 // Try to assign a type check bitstring.
267 MutexLock subtype_check_lock(Thread::Current(), *Locks::subtype_check_lock_);
268 if ((false) && // FIXME: Inliner does not respect compiler_driver->IsClassToCompile()
269 // and we're hitting an unassigned bitstring in dex2oat_image_test. b/26687569
270 kIsDebugBuild &&
271 codegen->GetCompilerOptions().IsBootImage() &&
272 codegen->GetCompilerOptions().IsForceDeterminism()) {
273 SubtypeCheckInfo::State old_state = SubtypeCheck<ObjPtr<mirror::Class>>::GetState(klass);
274 CHECK(old_state == SubtypeCheckInfo::kAssigned || old_state == SubtypeCheckInfo::kOverflowed)
275 << klass->PrettyDescriptor() << "/" << old_state
276 << " in " << codegen->GetGraph()->PrettyMethod();
277 }
278 SubtypeCheckInfo::State state = SubtypeCheck<ObjPtr<mirror::Class>>::EnsureAssigned(klass);
279 return state == SubtypeCheckInfo::kAssigned;
280}
281
282TypeCheckKind HSharpening::ComputeTypeCheckKind(ObjPtr<mirror::Class> klass,
283 CodeGenerator* codegen,
284 CompilerDriver* compiler_driver,
285 bool needs_access_check) {
286 if (klass == nullptr) {
287 return TypeCheckKind::kUnresolvedCheck;
288 } else if (klass->IsInterface()) {
289 return TypeCheckKind::kInterfaceCheck;
290 } else if (klass->IsArrayClass()) {
291 if (klass->GetComponentType()->IsObjectClass()) {
292 return TypeCheckKind::kArrayObjectCheck;
293 } else if (klass->CannotBeAssignedFromOtherTypes()) {
294 return TypeCheckKind::kExactCheck;
295 } else {
296 return TypeCheckKind::kArrayCheck;
297 }
298 } else if (klass->IsFinal()) { // TODO: Consider using bitstring for final classes.
299 return TypeCheckKind::kExactCheck;
300 } else if (kBitstringSubtypeCheckEnabled &&
301 !needs_access_check &&
302 CanUseTypeCheckBitstring(klass, codegen, compiler_driver)) {
303 // TODO: We should not need the `!needs_access_check` check but getting rid of that
304 // requires rewriting some optimizations in instruction simplifier.
305 return TypeCheckKind::kBitstringCheck;
306 } else if (klass->IsAbstract()) {
307 return TypeCheckKind::kAbstractClassCheck;
308 } else {
309 return TypeCheckKind::kClassHierarchyCheck;
310 }
311}
312
Vladimir Marko28e012a2017-12-07 11:22:59 +0000313void HSharpening::ProcessLoadString(
314 HLoadString* load_string,
315 CodeGenerator* codegen,
316 CompilerDriver* compiler_driver,
317 const DexCompilationUnit& dex_compilation_unit,
318 VariableSizedHandleScope* handles) {
Vladimir Marko847e6ce2017-06-02 13:55:07 +0100319 DCHECK_EQ(load_string->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000320
321 const DexFile& dex_file = load_string->GetDexFile();
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800322 dex::StringIndex string_index = load_string->GetStringIndex();
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000323
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000324 HLoadString::LoadKind desired_load_kind = static_cast<HLoadString::LoadKind>(-1);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000325 {
326 Runtime* runtime = Runtime::Current();
327 ClassLinker* class_linker = runtime->GetClassLinker();
328 ScopedObjectAccess soa(Thread::Current());
329 StackHandleScope<1> hs(soa.Self());
Vladimir Marko28e012a2017-12-07 11:22:59 +0000330 Handle<mirror::DexCache> dex_cache = IsSameDexFile(dex_file, *dex_compilation_unit.GetDexFile())
331 ? dex_compilation_unit.GetDexCache()
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000332 : hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file));
Vladimir Marko28e012a2017-12-07 11:22:59 +0000333 ObjPtr<mirror::String> string = nullptr;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000334
Vladimir Marko28e012a2017-12-07 11:22:59 +0000335 if (codegen->GetCompilerOptions().IsBootImage()) {
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000336 // Compiling boot image. Resolve the string and allocate it if needed, to ensure
337 // the string will be added to the boot image.
Calin Juravleffc87072016-04-20 14:22:09 +0100338 DCHECK(!runtime->UseJitCompilation());
Vladimir Markoa64b52d2017-12-08 16:27:49 +0000339 string = class_linker->ResolveString(string_index, dex_cache);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000340 CHECK(string != nullptr);
Vladimir Marko28e012a2017-12-07 11:22:59 +0000341 if (compiler_driver->GetSupportBootImageFixup()) {
342 DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file));
Vladimir Marko764d4542017-05-16 10:31:41 +0100343 desired_load_kind = HLoadString::LoadKind::kBootImageLinkTimePcRelative;
Vladimir Marko95026872016-09-09 09:16:31 +0000344 } else {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000345 // compiler_driver_test. Do not sharpen.
Vladimir Marko847e6ce2017-06-02 13:55:07 +0100346 desired_load_kind = HLoadString::LoadKind::kRuntimeCall;
Vladimir Marko95026872016-09-09 09:16:31 +0000347 }
Calin Juravleffc87072016-04-20 14:22:09 +0100348 } else if (runtime->UseJitCompilation()) {
Vladimir Marko28e012a2017-12-07 11:22:59 +0000349 DCHECK(!codegen->GetCompilerOptions().GetCompilePic());
Vladimir Markoa64b52d2017-12-08 16:27:49 +0000350 string = class_linker->LookupString(string_index, dex_cache.Get());
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000351 if (string != nullptr) {
352 if (runtime->GetHeap()->ObjectIsInBootImageSpace(string)) {
353 desired_load_kind = HLoadString::LoadKind::kBootImageAddress;
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000354 } else {
355 desired_load_kind = HLoadString::LoadKind::kJitTableAddress;
356 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000357 } else {
Vladimir Marko847e6ce2017-06-02 13:55:07 +0100358 desired_load_kind = HLoadString::LoadKind::kRuntimeCall;
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100359 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000360 } else {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100361 // AOT app compilation. Try to lookup the string without allocating if not found.
Vladimir Markoa64b52d2017-12-08 16:27:49 +0000362 string = class_linker->LookupString(string_index, dex_cache.Get());
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100363 if (string != nullptr && runtime->GetHeap()->ObjectIsInBootImageSpace(string)) {
Vladimir Marko28e012a2017-12-07 11:22:59 +0000364 if (codegen->GetCompilerOptions().GetCompilePic()) {
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000365 desired_load_kind = HLoadString::LoadKind::kBootImageRelRo;
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100366 } else {
367 desired_load_kind = HLoadString::LoadKind::kBootImageAddress;
368 }
Vladimir Markoaad75c62016-10-03 08:46:48 +0000369 } else {
Vladimir Marko1bc4b172016-10-24 16:53:39 +0000370 desired_load_kind = HLoadString::LoadKind::kBssEntry;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000371 }
372 }
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000373 if (string != nullptr) {
Vladimir Marko28e012a2017-12-07 11:22:59 +0000374 load_string->SetString(handles->NewHandle(string));
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000375 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000376 }
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000377 DCHECK_NE(desired_load_kind, static_cast<HLoadString::LoadKind>(-1));
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000378
Vladimir Marko28e012a2017-12-07 11:22:59 +0000379 HLoadString::LoadKind load_kind = codegen->GetSupportedLoadStringKind(desired_load_kind);
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000380 load_string->SetLoadKind(load_kind);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000381}
382
Vladimir Markodc151b22015-10-15 18:02:30 +0100383} // namespace art