| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 "common_compiler_test.h" |
| 18 | |
| Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 19 | #include <android-base/unique_fd.h> |
| Andreas Gampe | b68ed2c | 2018-06-20 10:39:31 -0700 | [diff] [blame] | 20 | #include <type_traits> |
| 21 | |
| Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 22 | #include "arch/instruction_set_features.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 23 | #include "art_field-inl.h" |
| Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 24 | #include "art_method-inl.h" |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 25 | #include "base/callee_save_type.h" |
| Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 26 | #include "base/casts.h" |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 27 | #include "base/enums.h" |
| Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 28 | #include "base/memfd.h" |
| David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 29 | #include "base/utils.h" |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 30 | #include "class_linker.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 31 | #include "compiled_method-inl.h" |
| David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 32 | #include "dex/descriptors_names.h" |
| Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 33 | #include "dex/verification_results.h" |
| Vladimir Marko | 815d5e5 | 2019-03-04 10:18:31 +0000 | [diff] [blame] | 34 | #include "driver/compiled_method_storage.h" |
| Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 35 | #include "driver/compiler_options.h" |
| Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 36 | #include "jni/java_vm_ext.h" |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 37 | #include "interpreter/interpreter.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 38 | #include "mirror/class-inl.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 39 | #include "mirror/class_loader.h" |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 40 | #include "mirror/dex_cache.h" |
| 41 | #include "mirror/object-inl.h" |
| Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 42 | #include "oat_quick_method_header.h" |
| Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 43 | #include "scoped_thread_state_change-inl.h" |
| Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 44 | #include "thread-current-inl.h" |
| Vladimir Marko | 213ee2d | 2018-06-22 11:56:34 +0100 | [diff] [blame] | 45 | #include "utils/atomic_dex_ref_map-inl.h" |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 46 | |
| 47 | namespace art { |
| 48 | |
| Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 49 | class CommonCompilerTestImpl::CodeAndMetadata { |
| 50 | public: |
| 51 | CodeAndMetadata(CodeAndMetadata&& other) = default; |
| 52 | |
| 53 | CodeAndMetadata(ArrayRef<const uint8_t> code, |
| 54 | ArrayRef<const uint8_t> vmap_table, |
| 55 | InstructionSet instruction_set) { |
| 56 | const uint32_t code_size = code.size(); |
| 57 | CHECK_NE(code_size, 0u); |
| 58 | const uint32_t vmap_table_offset = vmap_table.empty() ? 0u |
| 59 | : sizeof(OatQuickMethodHeader) + vmap_table.size(); |
| David Srbecky | 113d6ea | 2021-03-02 22:49:46 +0000 | [diff] [blame] | 60 | OatQuickMethodHeader method_header(vmap_table_offset); |
| Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 61 | const size_t code_alignment = GetInstructionSetAlignment(instruction_set); |
| 62 | DCHECK_ALIGNED_PARAM(kPageSize, code_alignment); |
| 63 | code_offset_ = RoundUp(vmap_table.size() + sizeof(method_header), code_alignment); |
| 64 | const uint32_t capacity = RoundUp(code_offset_ + code_size, kPageSize); |
| 65 | |
| 66 | // Create a memfd handle with sufficient capacity. |
| Vladimir Marko | 26bf47a | 2021-02-04 17:17:27 +0000 | [diff] [blame] | 67 | android::base::unique_fd mem_fd(art::memfd_create_compat("test code", /*flags=*/ 0)); |
| Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 68 | CHECK_GE(mem_fd.get(), 0); |
| 69 | int err = ftruncate(mem_fd, capacity); |
| 70 | CHECK_EQ(err, 0); |
| 71 | |
| 72 | // Map the memfd contents for read/write. |
| 73 | std::string error_msg; |
| 74 | rw_map_ = MemMap::MapFile(capacity, |
| 75 | PROT_READ | PROT_WRITE, |
| 76 | MAP_SHARED, |
| 77 | mem_fd, |
| 78 | /*start=*/ 0, |
| 79 | /*low_4gb=*/ false, |
| 80 | /*filename=*/ "test code", |
| 81 | &error_msg); |
| 82 | CHECK(rw_map_.IsValid()) << error_msg; |
| 83 | |
| 84 | // Store data. |
| 85 | uint8_t* code_addr = rw_map_.Begin() + code_offset_; |
| 86 | CHECK_ALIGNED_PARAM(code_addr, code_alignment); |
| 87 | CHECK_LE(vmap_table_offset, code_offset_); |
| 88 | memcpy(code_addr - vmap_table_offset, vmap_table.data(), vmap_table.size()); |
| 89 | static_assert(std::is_trivially_copyable<OatQuickMethodHeader>::value, "Cannot use memcpy"); |
| 90 | CHECK_LE(sizeof(method_header), code_offset_); |
| 91 | memcpy(code_addr - sizeof(method_header), &method_header, sizeof(method_header)); |
| 92 | CHECK_LE(code_size, static_cast<size_t>(rw_map_.End() - code_addr)); |
| 93 | memcpy(code_addr, code.data(), code_size); |
| 94 | |
| 95 | // Sync data. |
| 96 | bool success = rw_map_.Sync(); |
| 97 | CHECK(success); |
| 98 | success = FlushCpuCaches(rw_map_.Begin(), rw_map_.End()); |
| 99 | CHECK(success); |
| 100 | |
| 101 | // Map the data as read/executable. |
| 102 | rx_map_ = MemMap::MapFile(capacity, |
| 103 | PROT_READ | PROT_EXEC, |
| 104 | MAP_SHARED, |
| 105 | mem_fd, |
| 106 | /*start=*/ 0, |
| 107 | /*low_4gb=*/ false, |
| 108 | /*filename=*/ "test code", |
| 109 | &error_msg); |
| 110 | CHECK(rx_map_.IsValid()) << error_msg; |
| 111 | } |
| 112 | |
| 113 | const void* GetCodePointer() const { |
| 114 | DCHECK(rx_map_.IsValid()); |
| 115 | DCHECK_LE(code_offset_, rx_map_.Size()); |
| 116 | return rx_map_.Begin() + code_offset_; |
| 117 | } |
| 118 | |
| 119 | private: |
| 120 | MemMap rw_map_; |
| 121 | MemMap rx_map_; |
| 122 | uint32_t code_offset_; |
| 123 | |
| 124 | DISALLOW_COPY_AND_ASSIGN(CodeAndMetadata); |
| 125 | }; |
| 126 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 127 | std::unique_ptr<CompilerOptions> CommonCompilerTestImpl::CreateCompilerOptions( |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 128 | InstructionSet instruction_set, const std::string& variant) { |
| 129 | std::unique_ptr<CompilerOptions> compiler_options = std::make_unique<CompilerOptions>(); |
| 130 | compiler_options->instruction_set_ = instruction_set; |
| 131 | std::string error_msg; |
| 132 | compiler_options->instruction_set_features_ = |
| 133 | InstructionSetFeatures::FromVariant(instruction_set, variant, &error_msg); |
| 134 | CHECK(compiler_options->instruction_set_features_ != nullptr) << error_msg; |
| 135 | return compiler_options; |
| 136 | } |
| 137 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 138 | CommonCompilerTestImpl::CommonCompilerTestImpl() {} |
| 139 | CommonCompilerTestImpl::~CommonCompilerTestImpl() {} |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 140 | |
| Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 141 | const void* CommonCompilerTestImpl::MakeExecutable(ArrayRef<const uint8_t> code, |
| 142 | ArrayRef<const uint8_t> vmap_table, |
| 143 | InstructionSet instruction_set) { |
| 144 | CHECK_NE(code.size(), 0u); |
| 145 | code_and_metadata_.emplace_back(code, vmap_table, instruction_set); |
| 146 | return code_and_metadata_.back().GetCodePointer(); |
| 147 | } |
| 148 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 149 | void CommonCompilerTestImpl::MakeExecutable(ArtMethod* method, |
| 150 | const CompiledMethod* compiled_method) { |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 151 | CHECK(method != nullptr); |
| Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 152 | // If the code size is 0 it means the method was skipped due to profile guided compilation. |
| 153 | if (compiled_method != nullptr && compiled_method->GetQuickCode().size() != 0u) { |
| Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 154 | const void* code_ptr = MakeExecutable(compiled_method->GetQuickCode(), |
| 155 | compiled_method->GetVmapTable(), |
| 156 | compiled_method->GetInstructionSet()); |
| 157 | const void* method_code = |
| 158 | CompiledMethod::CodePointer(code_ptr, compiled_method->GetInstructionSet()); |
| David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 159 | LOG(INFO) << "MakeExecutable " << method->PrettyMethod() << " code=" << method_code; |
| Vladimir Marko | fbfc394 | 2017-07-27 16:51:35 +0100 | [diff] [blame] | 160 | method->SetEntryPointFromQuickCompiledCode(method_code); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 161 | } else { |
| 162 | // No code? You must mean to go into the interpreter. |
| 163 | // Or the generic JNI... |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 164 | GetClassLinker()->SetEntryPointsToInterpreter(method); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 168 | void CommonCompilerTestImpl::SetUp() { |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 169 | { |
| 170 | ScopedObjectAccess soa(Thread::Current()); |
| 171 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 172 | Runtime* runtime = GetRuntime(); |
| 173 | runtime->SetInstructionSet(instruction_set_); |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 174 | for (uint32_t i = 0; i < static_cast<uint32_t>(CalleeSaveType::kLastCalleeSaveType); ++i) { |
| 175 | CalleeSaveType type = CalleeSaveType(i); |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 176 | if (!runtime->HasCalleeSaveMethod(type)) { |
| 177 | runtime->SetCalleeSaveMethod(runtime->CreateCalleeSaveMethod(), type); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 178 | } |
| 179 | } |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 180 | } |
| Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 183 | void CommonCompilerTestImpl::ApplyInstructionSet() { |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 184 | // Copy local instruction_set_ and instruction_set_features_ to *compiler_options_; |
| 185 | CHECK(instruction_set_features_ != nullptr); |
| 186 | if (instruction_set_ == InstructionSet::kThumb2) { |
| 187 | CHECK_EQ(InstructionSet::kArm, instruction_set_features_->GetInstructionSet()); |
| 188 | } else { |
| 189 | CHECK_EQ(instruction_set_, instruction_set_features_->GetInstructionSet()); |
| 190 | } |
| 191 | compiler_options_->instruction_set_ = instruction_set_; |
| 192 | compiler_options_->instruction_set_features_ = |
| 193 | InstructionSetFeatures::FromBitmap(instruction_set_, instruction_set_features_->AsBitmap()); |
| 194 | CHECK(compiler_options_->instruction_set_features_->Equals(instruction_set_features_.get())); |
| 195 | } |
| 196 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 197 | void CommonCompilerTestImpl::OverrideInstructionSetFeatures(InstructionSet instruction_set, |
| 198 | const std::string& variant) { |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 199 | instruction_set_ = instruction_set; |
| 200 | std::string error_msg; |
| 201 | instruction_set_features_ = |
| 202 | InstructionSetFeatures::FromVariant(instruction_set, variant, &error_msg); |
| 203 | CHECK(instruction_set_features_ != nullptr) << error_msg; |
| 204 | |
| 205 | if (compiler_options_ != nullptr) { |
| 206 | ApplyInstructionSet(); |
| 207 | } |
| 208 | } |
| 209 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 210 | void CommonCompilerTestImpl::SetUpRuntimeOptionsImpl() { |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 211 | compiler_options_.reset(new CompilerOptions); |
| Nicolas Geoffray | 9e050ab | 2021-07-14 14:59:25 +0100 | [diff] [blame] | 212 | verification_results_.reset(new VerificationResults()); |
| Vladimir Marko | 815d5e5 | 2019-03-04 10:18:31 +0000 | [diff] [blame] | 213 | ApplyInstructionSet(); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 216 | Compiler::Kind CommonCompilerTestImpl::GetCompilerKind() const { |
| Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 217 | return compiler_kind_; |
| 218 | } |
| 219 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 220 | void CommonCompilerTestImpl::SetCompilerKind(Compiler::Kind compiler_kind) { |
| Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 221 | compiler_kind_ = compiler_kind; |
| 222 | } |
| 223 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 224 | void CommonCompilerTestImpl::TearDown() { |
| Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 225 | code_and_metadata_.clear(); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 226 | verification_results_.reset(); |
| 227 | compiler_options_.reset(); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 230 | void CommonCompilerTestImpl::CompileMethod(ArtMethod* method) { |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 231 | CHECK(method != nullptr); |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 232 | TimingLogger timings("CommonCompilerTestImpl::CompileMethod", false, false); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 233 | TimingLogger::ScopedTiming t(__FUNCTION__, &timings); |
| Vladimir Marko | 815d5e5 | 2019-03-04 10:18:31 +0000 | [diff] [blame] | 234 | CompiledMethodStorage storage(/*swap_fd=*/ -1); |
| Vladimir Marko | 4b2d1c5 | 2019-03-06 11:21:11 +0000 | [diff] [blame] | 235 | CompiledMethod* compiled_method = nullptr; |
| Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 236 | { |
| Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 237 | DCHECK(!Runtime::Current()->IsStarted()); |
| Vladimir Marko | 815d5e5 | 2019-03-04 10:18:31 +0000 | [diff] [blame] | 238 | Thread* self = Thread::Current(); |
| Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 239 | StackHandleScope<2> hs(self); |
| Vladimir Marko | 815d5e5 | 2019-03-04 10:18:31 +0000 | [diff] [blame] | 240 | std::unique_ptr<Compiler> compiler( |
| 241 | Compiler::Create(*compiler_options_, &storage, compiler_kind_)); |
| 242 | const DexFile& dex_file = *method->GetDexFile(); |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 243 | Handle<mirror::DexCache> dex_cache = |
| 244 | hs.NewHandle(GetClassLinker()->FindDexCache(self, dex_file)); |
| Vladimir Marko | 815d5e5 | 2019-03-04 10:18:31 +0000 | [diff] [blame] | 245 | Handle<mirror::ClassLoader> class_loader = hs.NewHandle(method->GetClassLoader()); |
| Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 246 | compiler_options_->verification_results_ = verification_results_.get(); |
| Vladimir Marko | 815d5e5 | 2019-03-04 10:18:31 +0000 | [diff] [blame] | 247 | if (method->IsNative()) { |
| 248 | compiled_method = compiler->JniCompile(method->GetAccessFlags(), |
| 249 | method->GetDexMethodIndex(), |
| 250 | dex_file, |
| 251 | dex_cache); |
| 252 | } else { |
| Vladimir Marko | 815d5e5 | 2019-03-04 10:18:31 +0000 | [diff] [blame] | 253 | compiled_method = compiler->Compile(method->GetCodeItem(), |
| 254 | method->GetAccessFlags(), |
| 255 | method->GetInvokeType(), |
| 256 | method->GetClassDefIndex(), |
| 257 | method->GetDexMethodIndex(), |
| 258 | class_loader, |
| 259 | dex_file, |
| 260 | dex_cache); |
| 261 | } |
| Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 262 | compiler_options_->verification_results_ = nullptr; |
| Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 263 | } |
| Vladimir Marko | 4b2d1c5 | 2019-03-06 11:21:11 +0000 | [diff] [blame] | 264 | CHECK(method != nullptr); |
| 265 | { |
| 266 | TimingLogger::ScopedTiming t2("MakeExecutable", &timings); |
| 267 | MakeExecutable(method, compiled_method); |
| 268 | } |
| 269 | CompiledMethod::ReleaseSwapAllocatedCompiledMethod(&storage, compiled_method); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 272 | void CommonCompilerTestImpl::CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, |
| 273 | const char* class_name, |
| 274 | const char* method_name, |
| 275 | const char* signature) { |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 276 | std::string class_descriptor(DotToDescriptor(class_name)); |
| 277 | Thread* self = Thread::Current(); |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 278 | ClassLinker* class_linker = GetClassLinker(); |
| Vladimir Marko | e9987b0 | 2018-05-22 16:26:43 +0100 | [diff] [blame] | 279 | ObjPtr<mirror::Class> klass = |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 280 | class_linker->FindClass(self, class_descriptor.c_str(), class_loader); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 281 | CHECK(klass != nullptr) << "Class not found " << class_name; |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 282 | auto pointer_size = class_linker->GetImagePointerSize(); |
| Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 283 | ArtMethod* method = klass->FindClassMethod(method_name, signature, pointer_size); |
| 284 | CHECK(method != nullptr && method->IsDirect()) << "Direct method not found: " |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 285 | << class_name << "." << method_name << signature; |
| 286 | CompileMethod(method); |
| 287 | } |
| 288 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 289 | void CommonCompilerTestImpl::CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, |
| 290 | const char* class_name, |
| 291 | const char* method_name, |
| 292 | const char* signature) { |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 293 | std::string class_descriptor(DotToDescriptor(class_name)); |
| 294 | Thread* self = Thread::Current(); |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 295 | ClassLinker* class_linker = GetClassLinker(); |
| Vladimir Marko | e9987b0 | 2018-05-22 16:26:43 +0100 | [diff] [blame] | 296 | ObjPtr<mirror::Class> klass = |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 297 | class_linker->FindClass(self, class_descriptor.c_str(), class_loader); |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 298 | CHECK(klass != nullptr) << "Class not found " << class_name; |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 299 | auto pointer_size = class_linker->GetImagePointerSize(); |
| Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 300 | ArtMethod* method = klass->FindClassMethod(method_name, signature, pointer_size); |
| 301 | CHECK(method != nullptr && !method->IsDirect()) << "Virtual method not found: " |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 302 | << class_name << "." << method_name << signature; |
| 303 | CompileMethod(method); |
| 304 | } |
| 305 | |
| Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 306 | void CommonCompilerTestImpl::ClearBootImageOption() { |
| Vladimir Marko | 9c4b970 | 2018-11-14 15:09:02 +0000 | [diff] [blame] | 307 | compiler_options_->image_type_ = CompilerOptions::ImageType::kNone; |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 310 | } // namespace art |