Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 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 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 19 | #include "art_method-inl.h" |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 20 | #include "base/casts.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 21 | #include "base/enums.h" |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 22 | #include "base/logging.h" |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 23 | #include "class_linker.h" |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 24 | #include "code_generator.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 25 | #include "driver/compiler_options.h" |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 26 | #include "driver/dex_compilation_unit.h" |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 27 | #include "gc/heap.h" |
| 28 | #include "gc/space/image_space.h" |
| 29 | #include "handle_scope-inl.h" |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 30 | #include "jit/jit.h" |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 31 | #include "mirror/dex_cache.h" |
| 32 | #include "mirror/string.h" |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 33 | #include "nodes.h" |
Vladimir Marko | d1eaf0d | 2015-10-29 12:18:29 +0000 | [diff] [blame] | 34 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 35 | #include "scoped_thread_state_change-inl.h" |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 36 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 37 | namespace art { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 38 | |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 39 | static bool IsInBootImage(ArtMethod* method) { |
Vladimir Marko | 7cde458 | 2019-07-05 13:26:11 +0100 | [diff] [blame] | 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); |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 51 | static bool BootImageAOTCanEmbedMethod(ArtMethod* method, const CompilerOptions& compiler_options) { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 52 | DCHECK(compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 53 | ScopedObjectAccess soa(Thread::Current()); |
| 54 | ObjPtr<mirror::Class> klass = method->GetDeclaringClass(); |
| 55 | DCHECK(klass != nullptr); |
| 56 | const DexFile& dex_file = klass->GetDexFile(); |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 57 | return compiler_options.IsImageClass(dex_file.StringByTypeIdx(klass->GetDexTypeIndex())); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 58 | } |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 59 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 60 | HInvokeStaticOrDirect::DispatchInfo HSharpening::SharpenLoadMethod( |
Nicolas Geoffray | d5a8695 | 2021-01-19 10:35:54 +0000 | [diff] [blame] | 61 | ArtMethod* callee, |
| 62 | bool has_method_id, |
| 63 | bool for_interface_call, |
| 64 | CodeGenerator* codegen) { |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 65 | if (kIsDebugBuild) { |
| 66 | ScopedObjectAccess soa(Thread::Current()); // Required for GetDeclaringClass below. |
| 67 | DCHECK(callee != nullptr); |
| 68 | DCHECK(!(callee->IsConstructor() && callee->GetDeclaringClass()->IsStringClass())); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 71 | MethodLoadKind method_load_kind; |
| 72 | CodePtrLocation code_ptr_location; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 73 | uint64_t method_load_data = 0u; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 74 | |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 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 | |
Alex Light | 1ebe4fe | 2017-01-30 14:57:11 -0800 | [diff] [blame] | 86 | // We don't optimize for debuggable as it would prevent us from obsoleting the method in some |
| 87 | // situations. |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 88 | const CompilerOptions& compiler_options = codegen->GetCompilerOptions(); |
Nicolas Geoffray | d5a8695 | 2021-01-19 10:35:54 +0000 | [diff] [blame] | 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. |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 97 | method_load_kind = MethodLoadKind::kRecursive; |
| 98 | code_ptr_location = CodePtrLocation::kCallSelf; |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 99 | } else if (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) { |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 100 | if (!compiler_options.GetCompilePic()) { |
| 101 | // Test configuration, do not sharpen. |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 102 | method_load_kind = MethodLoadKind::kRuntimeCall; |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 103 | } else if (IsInBootImage(callee)) { |
| 104 | DCHECK(compiler_options.IsBootImageExtension()); |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 105 | method_load_kind = MethodLoadKind::kBootImageRelRo; |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 106 | } else if (BootImageAOTCanEmbedMethod(callee, compiler_options)) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 107 | method_load_kind = MethodLoadKind::kBootImageLinkTimePcRelative; |
Nicolas Geoffray | 1fef877 | 2020-09-09 13:57:17 +0100 | [diff] [blame] | 108 | } else if (!has_method_id) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 109 | method_load_kind = MethodLoadKind::kRuntimeCall; |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 110 | } else { |
Nicolas Geoffray | 25b9c7d | 2020-09-17 17:34:34 +0100 | [diff] [blame] | 111 | DCHECK(!callee->IsCopied()); |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 112 | // Use PC-relative access to the .bss methods array. |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 113 | method_load_kind = MethodLoadKind::kBssEntry; |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 114 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 115 | code_ptr_location = CodePtrLocation::kCallArtMethod; |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 116 | } else if (compiler_options.IsJitCompiler()) { |
Nicolas Geoffray | 05b41c4 | 2019-06-28 12:46:33 +0100 | [diff] [blame] | 117 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 118 | if (Runtime::Current()->GetJit()->CanEncodeMethod( |
| 119 | callee, |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 120 | compiler_options.IsJitCompilerForSharedCode())) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 121 | method_load_kind = MethodLoadKind::kJitDirectAddress; |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 122 | method_load_data = reinterpret_cast<uintptr_t>(callee); |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 123 | code_ptr_location = CodePtrLocation::kCallArtMethod; |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 124 | } else { |
| 125 | // Do not sharpen. |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 126 | method_load_kind = MethodLoadKind::kRuntimeCall; |
| 127 | code_ptr_location = CodePtrLocation::kCallArtMethod; |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 128 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 129 | } else if (IsInBootImage(callee)) { |
| 130 | // Use PC-relative access to the .data.bimg.rel.ro methods array. |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 131 | method_load_kind = MethodLoadKind::kBootImageRelRo; |
| 132 | code_ptr_location = CodePtrLocation::kCallArtMethod; |
Nicolas Geoffray | 1fef877 | 2020-09-09 13:57:17 +0100 | [diff] [blame] | 133 | } else if (!has_method_id) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 134 | method_load_kind = MethodLoadKind::kRuntimeCall; |
| 135 | code_ptr_location = CodePtrLocation::kCallArtMethod; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 136 | } else { |
Nicolas Geoffray | 25b9c7d | 2020-09-17 17:34:34 +0100 | [diff] [blame] | 137 | DCHECK(!callee->IsCopied()); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 138 | // Use PC-relative access to the .bss methods array. |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 139 | method_load_kind = MethodLoadKind::kBssEntry; |
| 140 | code_ptr_location = CodePtrLocation::kCallArtMethod; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 143 | if (method_load_kind != MethodLoadKind::kRuntimeCall && callee->IsCriticalNative()) { |
| 144 | DCHECK_NE(method_load_kind, MethodLoadKind::kRecursive); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 145 | DCHECK(callee->IsStatic()); |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 146 | code_ptr_location = CodePtrLocation::kCallCriticalNative; |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 149 | if (codegen->GetGraph()->IsDebuggable()) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 150 | // For debuggable apps always use the code pointer from ArtMethod |
| 151 | // so that we don't circumvent instrumentation stubs if installed. |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 152 | code_ptr_location = CodePtrLocation::kCallArtMethod; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | HInvokeStaticOrDirect::DispatchInfo desired_dispatch_info = { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 156 | method_load_kind, code_ptr_location, method_load_data |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 157 | }; |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 158 | return codegen->GetSupportedInvokeStaticOrDirectDispatch(desired_dispatch_info, callee); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 161 | HLoadClass::LoadKind HSharpening::ComputeLoadClassKind( |
| 162 | HLoadClass* load_class, |
| 163 | CodeGenerator* codegen, |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 164 | const DexCompilationUnit& dex_compilation_unit) { |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 165 | Handle<mirror::Class> klass = load_class->GetClass(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 166 | DCHECK(load_class->GetLoadKind() == HLoadClass::LoadKind::kRuntimeCall || |
Mathieu Chartier | 4a4a601 | 2016-09-16 14:16:42 -0700 | [diff] [blame] | 167 | load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) |
| 168 | << load_class->GetLoadKind(); |
Mathieu Chartier | 4a4a601 | 2016-09-16 14:16:42 -0700 | [diff] [blame] | 169 | DCHECK(!load_class->IsInBootImage()) << "HLoadClass should not be optimized before sharpening."; |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 170 | const DexFile& dex_file = load_class->GetDexFile(); |
| 171 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 172 | const CompilerOptions& compiler_options = codegen->GetCompilerOptions(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 173 | |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 174 | auto is_class_in_current_boot_image = [&]() { |
| 175 | return (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) && |
| 176 | compiler_options.IsImageClass(dex_file.StringByTypeIdx(type_index)); |
| 177 | }; |
| 178 | |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 179 | bool is_in_boot_image = false; |
| 180 | HLoadClass::LoadKind desired_load_kind = HLoadClass::LoadKind::kInvalid; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 181 | |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 182 | if (load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) { |
| 183 | DCHECK(!load_class->NeedsAccessCheck()); |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 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. |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 188 | desired_load_kind = HLoadClass::LoadKind::kReferrersClass; |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 189 | // Determine whether the referrer's class is in the boot image. |
| 190 | is_in_boot_image = is_class_in_current_boot_image(); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 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; |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 197 | // Determine whether the class is in the boot image. |
| 198 | is_in_boot_image = Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(klass.Get()) || |
| 199 | is_class_in_current_boot_image(); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 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.StringByTypeIdx(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->StringByTypeIdx(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 | } |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 227 | } else { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 228 | Runtime* runtime = Runtime::Current(); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 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. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 231 | DCHECK(!compiler_options.IsJitCompiler()); |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 232 | if (!compiler_options.GetCompilePic()) { |
| 233 | // Test configuration, do not sharpen. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 234 | desired_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 235 | // Determine whether the class is in the boot image. |
| 236 | is_in_boot_image = Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(klass.Get()) || |
| 237 | is_class_in_current_boot_image(); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 238 | } else if (klass != nullptr && runtime->GetHeap()->ObjectIsInBootImageSpace(klass.Get())) { |
| 239 | DCHECK(compiler_options.IsBootImageExtension()); |
| 240 | is_in_boot_image = true; |
| 241 | desired_load_kind = HLoadClass::LoadKind::kBootImageRelRo; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 242 | } else if ((klass != nullptr) && |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 243 | compiler_options.IsImageClass(dex_file.StringByTypeIdx(type_index))) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 244 | is_in_boot_image = true; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 245 | desired_load_kind = HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 246 | } else { |
| 247 | // Not a boot image class. |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 248 | desired_load_kind = HLoadClass::LoadKind::kBssEntry; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 249 | } |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 250 | } else { |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 251 | is_in_boot_image = (klass != nullptr) && |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 252 | runtime->GetHeap()->ObjectIsInBootImageSpace(klass.Get()); |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 253 | if (compiler_options.IsJitCompiler()) { |
Vladimir Marko | 213ee2d | 2018-06-22 11:56:34 +0100 | [diff] [blame] | 254 | DCHECK(!compiler_options.GetCompilePic()); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 255 | if (is_in_boot_image) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 256 | desired_load_kind = HLoadClass::LoadKind::kJitBootImageAddress; |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 257 | } else if (klass != nullptr) { |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 258 | if (runtime->GetJit()->CanEncodeClass( |
| 259 | klass.Get(), |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 260 | compiler_options.IsJitCompilerForSharedCode())) { |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 261 | desired_load_kind = HLoadClass::LoadKind::kJitTableAddress; |
| 262 | } else { |
| 263 | // Shared JIT code cannot encode a literal that the GC can move. |
| 264 | VLOG(jit) << "Unable to encode in shared region class literal: " |
| 265 | << klass->PrettyClass(); |
| 266 | desired_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
| 267 | } |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 268 | } else { |
| 269 | // Class not loaded yet. This happens when the dex code requesting |
| 270 | // this `HLoadClass` hasn't been executed in the interpreter. |
| 271 | // Fallback to the dex cache. |
| 272 | // TODO(ngeoffray): Generate HDeoptimize instead. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 273 | desired_load_kind = HLoadClass::LoadKind::kRuntimeCall; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 274 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 275 | } else if (is_in_boot_image) { |
| 276 | // AOT app compilation, boot image class. |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 277 | desired_load_kind = HLoadClass::LoadKind::kBootImageRelRo; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 278 | } else { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 279 | // Not JIT and the klass is not in boot image. |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 280 | desired_load_kind = HLoadClass::LoadKind::kBssEntry; |
| 281 | } |
| 282 | } |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 283 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 284 | DCHECK_NE(desired_load_kind, HLoadClass::LoadKind::kInvalid); |
| 285 | |
| 286 | if (is_in_boot_image) { |
| 287 | load_class->MarkInBootImage(); |
| 288 | } |
| 289 | HLoadClass::LoadKind load_kind = codegen->GetSupportedLoadClassKind(desired_load_kind); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 290 | |
| 291 | if (!IsSameDexFile(load_class->GetDexFile(), *dex_compilation_unit.GetDexFile())) { |
Nicolas Geoffray | ee7bd32 | 2022-01-17 09:17:23 +0000 | [diff] [blame] | 292 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall || |
| 293 | load_kind == HLoadClass::LoadKind::kBssEntry || |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 294 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 295 | load_kind == HLoadClass::LoadKind::kBssEntryPackage) { |
Nicolas Geoffray | ee7bd32 | 2022-01-17 09:17:23 +0000 | [diff] [blame] | 296 | // We actually cannot reference this class, we're forced to bail. |
| 297 | // We cannot reference this class with Bss, as the entrypoint will lookup the class |
| 298 | // in the caller's dex file, but that dex file does not reference the class. |
Santiago Aboy Solanes | 69559a5 | 2022-02-09 11:37:33 +0000 | [diff] [blame] | 299 | // TODO(solanes): We could theoretically enable this optimization for kBssEntry* but this |
| 300 | // requires some changes to the entrypoints, particularly artResolveTypeFromCode and |
| 301 | // artResolveTypeAndVerifyAccessFromCode. Currently, they assume that the `load_class`'s |
| 302 | // Dexfile and the `dex_compilation_unit` DexFile is the same and will try to use the type |
| 303 | // index in the incorrect DexFile by using the `caller`'s DexFile. A possibility is to add |
| 304 | // another parameter to it pointing to the correct DexFile to use. |
Nicolas Geoffray | ee7bd32 | 2022-01-17 09:17:23 +0000 | [diff] [blame] | 305 | return HLoadClass::LoadKind::kInvalid; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 306 | } |
| 307 | } |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 308 | return load_kind; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 309 | } |
| 310 | |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 311 | static inline bool CanUseTypeCheckBitstring(ObjPtr<mirror::Class> klass, CodeGenerator* codegen) |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 312 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 313 | DCHECK(!klass->IsProxyClass()); |
| 314 | DCHECK(!klass->IsArrayClass()); |
| 315 | |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 316 | const CompilerOptions& compiler_options = codegen->GetCompilerOptions(); |
| 317 | if (compiler_options.IsJitCompiler()) { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 318 | // If we're JITting, try to assign a type check bitstring (fall through). |
| 319 | } else if (codegen->GetCompilerOptions().IsBootImage()) { |
| 320 | const char* descriptor = klass->GetDexFile().StringByTypeIdx(klass->GetDexTypeIndex()); |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 321 | if (!codegen->GetCompilerOptions().IsImageClass(descriptor)) { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | // If the target is a boot image class, try to assign a type check bitstring (fall through). |
| 325 | // (If --force-determinism, this was already done; repeating is OK and yields the same result.) |
| 326 | } else { |
| 327 | // TODO: Use the bitstring also for AOT app compilation if the target class has a bitstring |
| 328 | // already assigned in the boot image. |
| 329 | return false; |
| 330 | } |
| 331 | |
| 332 | // Try to assign a type check bitstring. |
| 333 | MutexLock subtype_check_lock(Thread::Current(), *Locks::subtype_check_lock_); |
Mathieu Chartier | a297b55 | 2018-11-07 11:41:01 -0800 | [diff] [blame] | 334 | if ((false) && // FIXME: Inliner does not respect CompilerDriver::ShouldCompileMethod() |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 335 | // and we're hitting an unassigned bitstring in dex2oat_image_test. b/26687569 |
| 336 | kIsDebugBuild && |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 337 | compiler_options.IsBootImage() && |
| 338 | compiler_options.IsForceDeterminism()) { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 339 | SubtypeCheckInfo::State old_state = SubtypeCheck<ObjPtr<mirror::Class>>::GetState(klass); |
| 340 | CHECK(old_state == SubtypeCheckInfo::kAssigned || old_state == SubtypeCheckInfo::kOverflowed) |
| 341 | << klass->PrettyDescriptor() << "/" << old_state |
| 342 | << " in " << codegen->GetGraph()->PrettyMethod(); |
| 343 | } |
| 344 | SubtypeCheckInfo::State state = SubtypeCheck<ObjPtr<mirror::Class>>::EnsureAssigned(klass); |
| 345 | return state == SubtypeCheckInfo::kAssigned; |
| 346 | } |
| 347 | |
| 348 | TypeCheckKind HSharpening::ComputeTypeCheckKind(ObjPtr<mirror::Class> klass, |
| 349 | CodeGenerator* codegen, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 350 | bool needs_access_check) { |
| 351 | if (klass == nullptr) { |
| 352 | return TypeCheckKind::kUnresolvedCheck; |
| 353 | } else if (klass->IsInterface()) { |
| 354 | return TypeCheckKind::kInterfaceCheck; |
| 355 | } else if (klass->IsArrayClass()) { |
| 356 | if (klass->GetComponentType()->IsObjectClass()) { |
| 357 | return TypeCheckKind::kArrayObjectCheck; |
| 358 | } else if (klass->CannotBeAssignedFromOtherTypes()) { |
| 359 | return TypeCheckKind::kExactCheck; |
| 360 | } else { |
| 361 | return TypeCheckKind::kArrayCheck; |
| 362 | } |
| 363 | } else if (klass->IsFinal()) { // TODO: Consider using bitstring for final classes. |
| 364 | return TypeCheckKind::kExactCheck; |
| 365 | } else if (kBitstringSubtypeCheckEnabled && |
| 366 | !needs_access_check && |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 367 | CanUseTypeCheckBitstring(klass, codegen)) { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 368 | // TODO: We should not need the `!needs_access_check` check but getting rid of that |
| 369 | // requires rewriting some optimizations in instruction simplifier. |
| 370 | return TypeCheckKind::kBitstringCheck; |
| 371 | } else if (klass->IsAbstract()) { |
| 372 | return TypeCheckKind::kAbstractClassCheck; |
| 373 | } else { |
| 374 | return TypeCheckKind::kClassHierarchyCheck; |
| 375 | } |
| 376 | } |
| 377 | |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 378 | void HSharpening::ProcessLoadString( |
| 379 | HLoadString* load_string, |
| 380 | CodeGenerator* codegen, |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 381 | const DexCompilationUnit& dex_compilation_unit, |
| 382 | VariableSizedHandleScope* handles) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 383 | DCHECK_EQ(load_string->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 384 | |
| 385 | const DexFile& dex_file = load_string->GetDexFile(); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 386 | dex::StringIndex string_index = load_string->GetStringIndex(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 387 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 388 | HLoadString::LoadKind desired_load_kind = static_cast<HLoadString::LoadKind>(-1); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 389 | { |
| 390 | Runtime* runtime = Runtime::Current(); |
| 391 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 392 | ScopedObjectAccess soa(Thread::Current()); |
| 393 | StackHandleScope<1> hs(soa.Self()); |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 394 | Handle<mirror::DexCache> dex_cache = IsSameDexFile(dex_file, *dex_compilation_unit.GetDexFile()) |
| 395 | ? dex_compilation_unit.GetDexCache() |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 396 | : hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file)); |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 397 | ObjPtr<mirror::String> string = nullptr; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 398 | |
Vladimir Marko | 213ee2d | 2018-06-22 11:56:34 +0100 | [diff] [blame] | 399 | const CompilerOptions& compiler_options = codegen->GetCompilerOptions(); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 400 | if (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) { |
| 401 | // Compiling boot image or boot image extension. Resolve the string and allocate it |
| 402 | // if needed, to ensure the string will be added to the boot image. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 403 | DCHECK(!compiler_options.IsJitCompiler()); |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 404 | if (compiler_options.GetCompilePic()) { |
Vladimir Marko | 403aafa | 2019-03-06 18:04:14 +0000 | [diff] [blame] | 405 | if (compiler_options.IsForceDeterminism()) { |
| 406 | // Strings for methods we're compiling should be pre-resolved but Strings in inlined |
| 407 | // methods may not be if these inlined methods are not in the boot image profile. |
| 408 | // Multiple threads allocating new Strings can cause non-deterministic boot image |
| 409 | // because of the image relying on the order of GC roots we walk. (We could fix that |
| 410 | // by ordering the roots we walk in ImageWriter.) Therefore we avoid allocating these |
| 411 | // strings even if that results in omitting them from the boot image and using the |
| 412 | // sub-optimal load kind kBssEntry. |
| 413 | string = class_linker->LookupString(string_index, dex_cache.Get()); |
| 414 | } else { |
| 415 | string = class_linker->ResolveString(string_index, dex_cache); |
| 416 | CHECK(string != nullptr); |
| 417 | } |
| 418 | if (string != nullptr) { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 419 | if (runtime->GetHeap()->ObjectIsInBootImageSpace(string)) { |
| 420 | DCHECK(compiler_options.IsBootImageExtension()); |
| 421 | desired_load_kind = HLoadString::LoadKind::kBootImageRelRo; |
| 422 | } else { |
| 423 | desired_load_kind = HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 424 | } |
Vladimir Marko | 403aafa | 2019-03-06 18:04:14 +0000 | [diff] [blame] | 425 | } else { |
| 426 | desired_load_kind = HLoadString::LoadKind::kBssEntry; |
| 427 | } |
Vladimir Marko | 9502687 | 2016-09-09 09:16:31 +0000 | [diff] [blame] | 428 | } else { |
Vladimir Marko | bb089b6 | 2018-06-28 17:30:16 +0100 | [diff] [blame] | 429 | // Test configuration, do not sharpen. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 430 | desired_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Vladimir Marko | 9502687 | 2016-09-09 09:16:31 +0000 | [diff] [blame] | 431 | } |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 432 | } else if (compiler_options.IsJitCompiler()) { |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 433 | DCHECK(!codegen->GetCompilerOptions().GetCompilePic()); |
Vladimir Marko | a64b52d | 2017-12-08 16:27:49 +0000 | [diff] [blame] | 434 | string = class_linker->LookupString(string_index, dex_cache.Get()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 435 | if (string != nullptr) { |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 436 | gc::Heap* heap = runtime->GetHeap(); |
| 437 | if (heap->ObjectIsInBootImageSpace(string)) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 438 | desired_load_kind = HLoadString::LoadKind::kJitBootImageAddress; |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 439 | } else if (runtime->GetJit()->CanEncodeString( |
| 440 | string, |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 441 | compiler_options.IsJitCompilerForSharedCode())) { |
Nicolas Geoffray | 2fef66b | 2019-06-26 22:00:02 +0000 | [diff] [blame] | 442 | desired_load_kind = HLoadString::LoadKind::kJitTableAddress; |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 443 | } else { |
| 444 | // Shared JIT code cannot encode a literal that the GC can move. |
| 445 | VLOG(jit) << "Unable to encode in shared region string literal: " |
| 446 | << string->ToModifiedUtf8(); |
| 447 | desired_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 448 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 449 | } else { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 450 | desired_load_kind = HLoadString::LoadKind::kRuntimeCall; |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 451 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 452 | } else { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 453 | // AOT app compilation. Try to lookup the string without allocating if not found. |
Vladimir Marko | a64b52d | 2017-12-08 16:27:49 +0000 | [diff] [blame] | 454 | string = class_linker->LookupString(string_index, dex_cache.Get()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 455 | if (string != nullptr && runtime->GetHeap()->ObjectIsInBootImageSpace(string)) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 456 | desired_load_kind = HLoadString::LoadKind::kBootImageRelRo; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 457 | } else { |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 458 | desired_load_kind = HLoadString::LoadKind::kBssEntry; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 459 | } |
| 460 | } |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 461 | if (string != nullptr) { |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 462 | load_string->SetString(handles->NewHandle(string)); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 463 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 464 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 465 | DCHECK_NE(desired_load_kind, static_cast<HLoadString::LoadKind>(-1)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 466 | |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 467 | HLoadString::LoadKind load_kind = codegen->GetSupportedLoadStringKind(desired_load_kind); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 468 | load_string->SetLoadKind(load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 471 | } // namespace art |