1 /*
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 
19 #include "art_method-inl.h"
20 #include "base/casts.h"
21 #include "base/logging.h"
22 #include "base/pointer_size.h"
23 #include "class_linker.h"
24 #include "code_generator.h"
25 #include "driver/compiler_options.h"
26 #include "driver/dex_compilation_unit.h"
27 #include "gc/heap.h"
28 #include "gc/space/image_space.h"
29 #include "handle_scope-inl.h"
30 #include "jit/jit.h"
31 #include "mirror/dex_cache.h"
32 #include "mirror/string.h"
33 #include "nodes.h"
34 #include "runtime.h"
35 #include "scoped_thread_state_change-inl.h"
36 
37 namespace art HIDDEN {
38 
IsInBootImage(ArtMethod * method)39 static bool IsInBootImage(ArtMethod* method) {
40   gc::Heap* heap = Runtime::Current()->GetHeap();
41   DCHECK_EQ(heap->IsBootImageAddress(method),
42             std::any_of(heap->GetBootImageSpaces().begin(),
43                         heap->GetBootImageSpaces().end(),
44                         [=](gc::space::ImageSpace* space) REQUIRES_SHARED(Locks::mutator_lock_) {
45                           return space->GetImageHeader().GetMethodsSection().Contains(
46                               reinterpret_cast<uint8_t*>(method) - space->Begin());
47                         }));
48   return heap->IsBootImageAddress(method);
49 }
50 
BootImageAOTCanEmbedMethod(ArtMethod * method,const CompilerOptions & compiler_options)51 static bool BootImageAOTCanEmbedMethod(ArtMethod* method, const CompilerOptions& compiler_options) {
52   DCHECK(compiler_options.IsBootImage() || compiler_options.IsBootImageExtension());
53   ScopedObjectAccess soa(Thread::Current());
54   ObjPtr<mirror::Class> klass = method->GetDeclaringClass();
55   DCHECK(klass != nullptr);
56   const DexFile& dex_file = klass->GetDexFile();
57   return compiler_options.IsImageClass(dex_file.GetTypeDescriptor(klass->GetDexTypeIndex()));
58 }
59 
SharpenLoadMethod(ArtMethod * callee,bool has_method_id,bool for_interface_call,CodeGenerator * codegen)60 HInvokeStaticOrDirect::DispatchInfo HSharpening::SharpenLoadMethod(
61     ArtMethod* callee,
62     bool has_method_id,
63     bool for_interface_call,
64     CodeGenerator* codegen) {
65   if (kIsDebugBuild) {
66     ScopedObjectAccess soa(Thread::Current());  // Required for `IsStringConstructor()` below.
67     DCHECK(callee != nullptr);
68     DCHECK(!callee->IsStringConstructor());
69   }
70 
71   MethodLoadKind method_load_kind;
72   CodePtrLocation code_ptr_location;
73   uint64_t method_load_data = 0u;
74 
75   // Note: we never call an ArtMethod through a known code pointer, as
76   // we do not want to keep on invoking it if it gets deoptimized. This
77   // applies to both AOT and JIT.
78   // This also avoids having to find out if the code pointer of an ArtMethod
79   // is the resolution trampoline (for ensuring the class is initialized), or
80   // the interpreter entrypoint. Such code pointers we do not want to call
81   // directly.
82   // Only in the case of a recursive call can we call directly, as we know the
83   // class is initialized already or being initialized, and the call will not
84   // be invoked once the method is deoptimized.
85 
86   // We don't optimize for debuggable as it would prevent us from obsoleting the method in some
87   // situations.
88   const CompilerOptions& compiler_options = codegen->GetCompilerOptions();
89   if (callee == codegen->GetGraph()->GetArtMethod() &&
90       !codegen->GetGraph()->IsDebuggable() &&
91       // The runtime expects the canonical interface method being passed as
92       // hidden argument when doing an invokeinterface. Because default methods
93       // can be called through invokevirtual, we may get a copied method if we
94       // load 'recursively'.
95       (!for_interface_call || !callee->IsDefault())) {
96     // Recursive load.
97     method_load_kind = MethodLoadKind::kRecursive;
98     code_ptr_location = CodePtrLocation::kCallSelf;
99   } else if (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) {
100     if (!compiler_options.GetCompilePic()) {
101       // Test configuration, do not sharpen.
102       method_load_kind = MethodLoadKind::kRuntimeCall;
103     } else if (IsInBootImage(callee)) {
104       DCHECK(compiler_options.IsBootImageExtension());
105       method_load_kind = MethodLoadKind::kBootImageRelRo;
106     } else if (BootImageAOTCanEmbedMethod(callee, compiler_options)) {
107       method_load_kind = MethodLoadKind::kBootImageLinkTimePcRelative;
108     } else if (!has_method_id) {
109       method_load_kind = MethodLoadKind::kRuntimeCall;
110     } else {
111       DCHECK(!callee->IsCopied());
112       // Use PC-relative access to the .bss methods array.
113       method_load_kind = MethodLoadKind::kBssEntry;
114     }
115     code_ptr_location = CodePtrLocation::kCallArtMethod;
116   } else if (compiler_options.IsJitCompiler()) {
117     ScopedObjectAccess soa(Thread::Current());
118     if (Runtime::Current()->GetJit()->CanEncodeMethod(
119             callee,
120             compiler_options.IsJitCompilerForSharedCode())) {
121       method_load_kind = MethodLoadKind::kJitDirectAddress;
122       method_load_data = reinterpret_cast<uintptr_t>(callee);
123       code_ptr_location = CodePtrLocation::kCallArtMethod;
124     } else {
125       // Do not sharpen.
126       method_load_kind = MethodLoadKind::kRuntimeCall;
127       code_ptr_location = CodePtrLocation::kCallArtMethod;
128     }
129   } else if (IsInBootImage(callee)) {
130     // Use PC-relative access to the .data.img.rel.ro boot image methods array.
131     method_load_kind = MethodLoadKind::kBootImageRelRo;
132     code_ptr_location = CodePtrLocation::kCallArtMethod;
133   } else if (!has_method_id) {
134     method_load_kind = MethodLoadKind::kRuntimeCall;
135     code_ptr_location = CodePtrLocation::kCallArtMethod;
136   } else {
137     DCHECK(!callee->IsCopied());
138     // Use PC-relative access to the .bss methods array.
139     method_load_kind = MethodLoadKind::kBssEntry;
140     code_ptr_location = CodePtrLocation::kCallArtMethod;
141   }
142 
143   if (method_load_kind != MethodLoadKind::kRuntimeCall && callee->IsCriticalNative()) {
144     DCHECK_NE(method_load_kind, MethodLoadKind::kRecursive);
145     DCHECK(callee->IsStatic());
146     code_ptr_location = CodePtrLocation::kCallCriticalNative;
147   }
148 
149   if (codegen->GetGraph()->IsDebuggable()) {
150     // For debuggable apps always use the code pointer from ArtMethod
151     // so that we don't circumvent instrumentation stubs if installed.
152     code_ptr_location = CodePtrLocation::kCallArtMethod;
153   }
154 
155   HInvokeStaticOrDirect::DispatchInfo desired_dispatch_info = {
156       method_load_kind, code_ptr_location, method_load_data
157   };
158   return codegen->GetSupportedInvokeStaticOrDirectDispatch(desired_dispatch_info, callee);
159 }
160 
ComputeLoadClassKind(HLoadClass * load_class,CodeGenerator * codegen,const DexCompilationUnit & dex_compilation_unit)161 HLoadClass::LoadKind HSharpening::ComputeLoadClassKind(
162     HLoadClass* load_class,
163     CodeGenerator* codegen,
164     const DexCompilationUnit& dex_compilation_unit) {
165   Handle<mirror::Class> klass = load_class->GetClass();
166   DCHECK(load_class->GetLoadKind() == HLoadClass::LoadKind::kRuntimeCall ||
167          load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass)
168       << load_class->GetLoadKind();
169   DCHECK(!load_class->IsInImage()) << "HLoadClass should not be optimized before sharpening.";
170   const DexFile& dex_file = load_class->GetDexFile();
171   dex::TypeIndex type_index = load_class->GetTypeIndex();
172   const CompilerOptions& compiler_options = codegen->GetCompilerOptions();
173 
174   auto is_class_in_current_image = [&]() {
175     return compiler_options.IsGeneratingImage() &&
176            compiler_options.IsImageClass(dex_file.GetTypeDescriptor(type_index));
177   };
178 
179   bool is_in_image = false;
180   HLoadClass::LoadKind desired_load_kind = HLoadClass::LoadKind::kInvalid;
181 
182   if (load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) {
183     DCHECK(!load_class->NeedsAccessCheck());
184     // Loading from the ArtMethod* is the most efficient retrieval in code size.
185     // TODO: This may not actually be true for all architectures and
186     // locations of target classes. The additional register pressure
187     // for using the ArtMethod* should be considered.
188     desired_load_kind = HLoadClass::LoadKind::kReferrersClass;
189     // Determine whether the referrer's class is in the boot image.
190     is_in_image = is_class_in_current_image();
191   } else if (load_class->NeedsAccessCheck()) {
192     DCHECK_EQ(load_class->GetLoadKind(), HLoadClass::LoadKind::kRuntimeCall);
193     if (klass != nullptr) {
194       // Resolved class that needs access check must be really inaccessible
195       // and the access check is bound to fail. Just emit the runtime call.
196       desired_load_kind = HLoadClass::LoadKind::kRuntimeCall;
197       // Determine whether the class is in the boot image.
198       is_in_image = Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(klass.Get()) ||
199                     is_class_in_current_image();
200     } else if (compiler_options.IsJitCompiler()) {
201       // Unresolved class while JITting means that either we never hit this
202       // instruction or it failed. Either way, just emit the runtime call.
203       // (Though we could consider emitting Deoptimize instead and
204       // recompile if the instruction succeeds in interpreter.)
205       desired_load_kind = HLoadClass::LoadKind::kRuntimeCall;
206     } else {
207       // For AOT, check if the class is in the same literal package as the
208       // compiling class and pick an appropriate .bss entry.
209       auto package_length = [](const char* descriptor) {
210         const char* slash_pos = strrchr(descriptor, '/');
211         return (slash_pos != nullptr) ? static_cast<size_t>(slash_pos - descriptor) : 0u;
212       };
213       const char* klass_descriptor = dex_file.GetTypeDescriptor(type_index);
214       const uint32_t klass_package_length = package_length(klass_descriptor);
215       const DexFile* referrer_dex_file = dex_compilation_unit.GetDexFile();
216       const dex::TypeIndex referrer_type_index =
217           referrer_dex_file->GetClassDef(dex_compilation_unit.GetClassDefIndex()).class_idx_;
218       const char* referrer_descriptor = referrer_dex_file->GetTypeDescriptor(referrer_type_index);
219       const uint32_t referrer_package_length = package_length(referrer_descriptor);
220       bool same_package =
221           (referrer_package_length == klass_package_length) &&
222           memcmp(referrer_descriptor, klass_descriptor, referrer_package_length) == 0;
223       desired_load_kind = same_package
224           ? HLoadClass::LoadKind::kBssEntryPackage
225           : HLoadClass::LoadKind::kBssEntryPublic;
226     }
227   } else {
228     Runtime* runtime = Runtime::Current();
229     if (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) {
230       // Compiling boot image or boot image extension. Check if the class is a boot image class.
231       DCHECK(!compiler_options.IsJitCompiler());
232       if (!compiler_options.GetCompilePic()) {
233         // Test configuration, do not sharpen.
234         desired_load_kind = HLoadClass::LoadKind::kRuntimeCall;
235         // Determine whether the class is in the boot image.
236         is_in_image = Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(klass.Get()) ||
237                       is_class_in_current_image();
238       } else if (klass != nullptr && runtime->GetHeap()->ObjectIsInBootImageSpace(klass.Get())) {
239         DCHECK(compiler_options.IsBootImageExtension());
240         is_in_image = true;
241         desired_load_kind = HLoadClass::LoadKind::kBootImageRelRo;
242       } else if ((klass != nullptr) &&
243                  compiler_options.IsImageClass(dex_file.GetTypeDescriptor(type_index))) {
244         is_in_image = true;
245         desired_load_kind = HLoadClass::LoadKind::kBootImageLinkTimePcRelative;
246       } else {
247         // Not a boot image class.
248         desired_load_kind = HLoadClass::LoadKind::kBssEntry;
249       }
250     } else {
251       is_in_image = (klass != nullptr) && runtime->GetHeap()->ObjectIsInBootImageSpace(klass.Get());
252       if (compiler_options.IsJitCompiler()) {
253         DCHECK(!compiler_options.GetCompilePic());
254         if (is_in_image) {
255           desired_load_kind = HLoadClass::LoadKind::kJitBootImageAddress;
256         } else if (klass != nullptr) {
257           if (runtime->GetJit()->CanEncodeClass(
258                   klass.Get(),
259                   compiler_options.IsJitCompilerForSharedCode())) {
260             desired_load_kind = HLoadClass::LoadKind::kJitTableAddress;
261           } else {
262             // Shared JIT code cannot encode a literal that the GC can move.
263             VLOG(jit) << "Unable to encode in shared region class literal: "
264                       << klass->PrettyClass();
265             desired_load_kind = HLoadClass::LoadKind::kRuntimeCall;
266           }
267         } else {
268           // Class not loaded yet. This happens when the dex code requesting
269           // this `HLoadClass` hasn't been executed in the interpreter.
270           // Fallback to the dex cache.
271           // TODO(ngeoffray): Generate HDeoptimize instead.
272           desired_load_kind = HLoadClass::LoadKind::kRuntimeCall;
273         }
274       } else if (is_in_image) {
275         // AOT app compilation, boot image class.
276         desired_load_kind = HLoadClass::LoadKind::kBootImageRelRo;
277       } else if (compiler_options.IsAppImage() && is_class_in_current_image()) {
278         // AOT app compilation, app image class.
279         is_in_image = true;
280         desired_load_kind = HLoadClass::LoadKind::kAppImageRelRo;
281       } else {
282         // Not JIT and the klass is not in boot image or app image.
283         desired_load_kind = HLoadClass::LoadKind::kBssEntry;
284       }
285     }
286   }
287   DCHECK_NE(desired_load_kind, HLoadClass::LoadKind::kInvalid);
288 
289   if (is_in_image) {
290     load_class->MarkInImage();
291   }
292   HLoadClass::LoadKind load_kind = codegen->GetSupportedLoadClassKind(desired_load_kind);
293 
294   if (!IsSameDexFile(load_class->GetDexFile(), *dex_compilation_unit.GetDexFile())) {
295     if (load_kind == HLoadClass::LoadKind::kRuntimeCall ||
296         load_kind == HLoadClass::LoadKind::kBssEntry ||
297         load_kind == HLoadClass::LoadKind::kBssEntryPublic ||
298         load_kind == HLoadClass::LoadKind::kBssEntryPackage) {
299       // We actually cannot reference this class, we're forced to bail.
300       // We cannot reference this class with Bss, as the entrypoint will lookup the class
301       // in the caller's dex file, but that dex file does not reference the class.
302       // TODO(solanes): We could theoretically enable this optimization for kBssEntry* but this
303       // requires some changes to the entrypoints, particularly artResolveTypeFromCode and
304       // artResolveTypeAndVerifyAccessFromCode. Currently, they assume that the `load_class`'s
305       // Dexfile and the `dex_compilation_unit` DexFile is the same and will try to use the type
306       // index in the incorrect DexFile by using the `caller`'s DexFile. A possibility is to add
307       // another parameter to it pointing to the correct DexFile to use.
308       return HLoadClass::LoadKind::kInvalid;
309     }
310   }
311   return load_kind;
312 }
313 
CanUseTypeCheckBitstring(ObjPtr<mirror::Class> klass,CodeGenerator * codegen)314 static inline bool CanUseTypeCheckBitstring(ObjPtr<mirror::Class> klass, CodeGenerator* codegen)
315     REQUIRES_SHARED(Locks::mutator_lock_) {
316   DCHECK(!klass->IsProxyClass());
317   DCHECK(!klass->IsArrayClass());
318 
319   const CompilerOptions& compiler_options = codegen->GetCompilerOptions();
320   if (compiler_options.IsJitCompiler()) {
321     // If we're JITting, try to assign a type check bitstring (fall through).
322   } else if (codegen->GetCompilerOptions().IsBootImage()) {
323     const char* descriptor = klass->GetDexFile().GetTypeDescriptor(klass->GetDexTypeIndex());
324     if (!codegen->GetCompilerOptions().IsImageClass(descriptor)) {
325       return false;
326     }
327     // If the target is a boot image class, try to assign a type check bitstring (fall through).
328     // (If --force-determinism, this was already done; repeating is OK and yields the same result.)
329   } else {
330     // TODO: Use the bitstring also for AOT app compilation if the target class has a bitstring
331     // already assigned in the boot image.
332     return false;
333   }
334 
335   // Try to assign a type check bitstring.
336   MutexLock subtype_check_lock(Thread::Current(), *Locks::subtype_check_lock_);
337   if ((false) &&  // FIXME: Inliner does not respect CompilerDriver::ShouldCompileMethod()
338                   // and we're hitting an unassigned bitstring in dex2oat_image_test. b/26687569
339       kIsDebugBuild &&
340       compiler_options.IsBootImage() &&
341       compiler_options.IsForceDeterminism()) {
342     SubtypeCheckInfo::State old_state = SubtypeCheck<ObjPtr<mirror::Class>>::GetState(klass);
343     CHECK(old_state == SubtypeCheckInfo::kAssigned || old_state == SubtypeCheckInfo::kOverflowed)
344         << klass->PrettyDescriptor() << "/" << old_state
345         << " in " << codegen->GetGraph()->PrettyMethod();
346   }
347   SubtypeCheckInfo::State state = SubtypeCheck<ObjPtr<mirror::Class>>::EnsureAssigned(klass);
348   return state == SubtypeCheckInfo::kAssigned;
349 }
350 
ComputeTypeCheckKind(ObjPtr<mirror::Class> klass,CodeGenerator * codegen,bool needs_access_check)351 TypeCheckKind HSharpening::ComputeTypeCheckKind(ObjPtr<mirror::Class> klass,
352                                                 CodeGenerator* codegen,
353                                                 bool needs_access_check) {
354   if (klass == nullptr) {
355     return TypeCheckKind::kUnresolvedCheck;
356   } else if (klass->IsInterface()) {
357     return TypeCheckKind::kInterfaceCheck;
358   } else if (klass->IsArrayClass()) {
359     if (klass->GetComponentType()->IsObjectClass()) {
360       return TypeCheckKind::kArrayObjectCheck;
361     } else if (klass->CannotBeAssignedFromOtherTypes()) {
362       return TypeCheckKind::kExactCheck;
363     } else {
364       return TypeCheckKind::kArrayCheck;
365     }
366   } else if (klass->IsFinal()) {  // TODO: Consider using bitstring for final classes.
367     return TypeCheckKind::kExactCheck;
368   } else if (kBitstringSubtypeCheckEnabled &&
369              !needs_access_check &&
370              CanUseTypeCheckBitstring(klass, codegen)) {
371     // TODO: We should not need the `!needs_access_check` check but getting rid of that
372     // requires rewriting some optimizations in instruction simplifier.
373     return TypeCheckKind::kBitstringCheck;
374   } else if (klass->IsAbstract()) {
375     return TypeCheckKind::kAbstractClassCheck;
376   } else {
377     return TypeCheckKind::kClassHierarchyCheck;
378   }
379 }
380 
ProcessLoadString(HLoadString * load_string,CodeGenerator * codegen,const DexCompilationUnit & dex_compilation_unit,VariableSizedHandleScope * handles)381 void HSharpening::ProcessLoadString(
382     HLoadString* load_string,
383     CodeGenerator* codegen,
384     const DexCompilationUnit& dex_compilation_unit,
385     VariableSizedHandleScope* handles) {
386   DCHECK_EQ(load_string->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall);
387 
388   const DexFile& dex_file = load_string->GetDexFile();
389   dex::StringIndex string_index = load_string->GetStringIndex();
390 
391   HLoadString::LoadKind desired_load_kind = static_cast<HLoadString::LoadKind>(-1);
392   {
393     Runtime* runtime = Runtime::Current();
394     ClassLinker* class_linker = runtime->GetClassLinker();
395     ScopedObjectAccess soa(Thread::Current());
396     StackHandleScope<1> hs(soa.Self());
397     Handle<mirror::DexCache> dex_cache = IsSameDexFile(dex_file, *dex_compilation_unit.GetDexFile())
398         ? dex_compilation_unit.GetDexCache()
399         : hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file));
400     ObjPtr<mirror::String> string = nullptr;
401 
402     const CompilerOptions& compiler_options = codegen->GetCompilerOptions();
403     if (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) {
404       // Compiling boot image or boot image extension. Resolve the string and allocate it
405       // if needed, to ensure the string will be added to the boot image.
406       DCHECK(!compiler_options.IsJitCompiler());
407       if (compiler_options.GetCompilePic()) {
408         if (compiler_options.IsForceDeterminism()) {
409           // Strings for methods we're compiling should be pre-resolved but Strings in inlined
410           // methods may not be if these inlined methods are not in the boot image profile.
411           // Multiple threads allocating new Strings can cause non-deterministic boot image
412           // because of the image relying on the order of GC roots we walk. (We could fix that
413           // by ordering the roots we walk in ImageWriter.) Therefore we avoid allocating these
414           // strings even if that results in omitting them from the boot image and using the
415           // sub-optimal load kind kBssEntry.
416           string = class_linker->LookupString(string_index, dex_cache.Get());
417         } else {
418           string = class_linker->ResolveString(string_index, dex_cache);
419           CHECK(string != nullptr);
420         }
421         if (string != nullptr) {
422           if (runtime->GetHeap()->ObjectIsInBootImageSpace(string)) {
423             DCHECK(compiler_options.IsBootImageExtension());
424             desired_load_kind = HLoadString::LoadKind::kBootImageRelRo;
425           } else {
426             desired_load_kind = HLoadString::LoadKind::kBootImageLinkTimePcRelative;
427           }
428         } else {
429           desired_load_kind = HLoadString::LoadKind::kBssEntry;
430         }
431       } else {
432         // Test configuration, do not sharpen.
433         desired_load_kind = HLoadString::LoadKind::kRuntimeCall;
434       }
435     } else if (compiler_options.IsJitCompiler()) {
436       DCHECK(!codegen->GetCompilerOptions().GetCompilePic());
437       string = class_linker->LookupString(string_index, dex_cache.Get());
438       if (string != nullptr) {
439         gc::Heap* heap = runtime->GetHeap();
440         if (heap->ObjectIsInBootImageSpace(string)) {
441           desired_load_kind = HLoadString::LoadKind::kJitBootImageAddress;
442         } else if (runtime->GetJit()->CanEncodeString(
443                   string,
444                   compiler_options.IsJitCompilerForSharedCode())) {
445           desired_load_kind = HLoadString::LoadKind::kJitTableAddress;
446         } else {
447           // Shared JIT code cannot encode a literal that the GC can move.
448           VLOG(jit) << "Unable to encode in shared region string literal: "
449                     << string->ToModifiedUtf8();
450           desired_load_kind = HLoadString::LoadKind::kRuntimeCall;
451         }
452       } else {
453         desired_load_kind = HLoadString::LoadKind::kRuntimeCall;
454       }
455     } else {
456       // AOT app compilation. Try to lookup the string without allocating if not found.
457       string = class_linker->LookupString(string_index, dex_cache.Get());
458       if (string != nullptr && runtime->GetHeap()->ObjectIsInBootImageSpace(string)) {
459         desired_load_kind = HLoadString::LoadKind::kBootImageRelRo;
460       } else {
461         desired_load_kind = HLoadString::LoadKind::kBssEntry;
462       }
463     }
464     if (string != nullptr) {
465       load_string->SetString(handles->NewHandle(string));
466     }
467   }
468   DCHECK_NE(desired_load_kind, static_cast<HLoadString::LoadKind>(-1));
469 
470   HLoadString::LoadKind load_kind = codegen->GetSupportedLoadStringKind(desired_load_kind);
471   load_string->SetLoadKind(load_kind);
472 }
473 
474 }  // namespace art
475