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 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 19 | #include "arch/instruction_set_features.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_field-inl.h" |
| 21 | #include "art_method.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 22 | #include "base/enums.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 23 | #include "class_linker.h" |
| 24 | #include "compiled_method.h" |
| 25 | #include "dex/quick_compiler_callbacks.h" |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 26 | #include "dex/verification_results.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 27 | #include "driver/compiler_driver.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 28 | #include "driver/compiler_options.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 29 | #include "interpreter/interpreter.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 30 | #include "mirror/class_loader.h" |
| 31 | #include "mirror/class-inl.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 32 | #include "mirror/dex_cache.h" |
| 33 | #include "mirror/object-inl.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 34 | #include "oat_quick_method_header.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 35 | #include "scoped_thread_state_change-inl.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 36 | #include "thread-inl.h" |
| 37 | #include "utils.h" |
| 38 | |
| 39 | namespace art { |
| 40 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 41 | CommonCompilerTest::CommonCompilerTest() {} |
| 42 | CommonCompilerTest::~CommonCompilerTest() {} |
| 43 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 44 | void CommonCompilerTest::MakeExecutable(ArtMethod* method) { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 45 | CHECK(method != nullptr); |
| 46 | |
| 47 | const CompiledMethod* compiled_method = nullptr; |
| 48 | if (!method->IsAbstract()) { |
| 49 | mirror::DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache(); |
| 50 | const DexFile& dex_file = *dex_cache->GetDexFile(); |
| 51 | compiled_method = |
| 52 | compiler_driver_->GetCompiledMethod(MethodReference(&dex_file, |
| 53 | method->GetDexMethodIndex())); |
| 54 | } |
| 55 | if (compiled_method != nullptr) { |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 56 | ArrayRef<const uint8_t> code = compiled_method->GetQuickCode(); |
| 57 | uint32_t code_size = code.size(); |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 58 | CHECK_NE(0u, code_size); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 59 | ArrayRef<const uint8_t> vmap_table = compiled_method->GetVmapTable(); |
| 60 | uint32_t vmap_table_offset = vmap_table.empty() ? 0u |
| 61 | : sizeof(OatQuickMethodHeader) + vmap_table.size(); |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 62 | OatQuickMethodHeader method_header(vmap_table_offset, |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 63 | compiled_method->GetFrameSizeInBytes(), |
| 64 | compiled_method->GetCoreSpillMask(), |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 65 | compiled_method->GetFpSpillMask(), |
| 66 | code_size); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 67 | |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 68 | header_code_and_maps_chunks_.push_back(std::vector<uint8_t>()); |
| 69 | std::vector<uint8_t>* chunk = &header_code_and_maps_chunks_.back(); |
Vladimir Marko | 562ff44 | 2015-10-27 18:51:20 +0000 | [diff] [blame] | 70 | const size_t max_padding = GetInstructionSetAlignment(compiled_method->GetInstructionSet()); |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 71 | const size_t size = vmap_table.size() + sizeof(method_header) + code_size; |
Vladimir Marko | 562ff44 | 2015-10-27 18:51:20 +0000 | [diff] [blame] | 72 | chunk->reserve(size + max_padding); |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 73 | chunk->resize(sizeof(method_header)); |
| 74 | memcpy(&(*chunk)[0], &method_header, sizeof(method_header)); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 75 | chunk->insert(chunk->begin(), vmap_table.begin(), vmap_table.end()); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 76 | chunk->insert(chunk->end(), code.begin(), code.end()); |
Vladimir Marko | 562ff44 | 2015-10-27 18:51:20 +0000 | [diff] [blame] | 77 | CHECK_EQ(chunk->size(), size); |
| 78 | const void* unaligned_code_ptr = chunk->data() + (size - code_size); |
| 79 | size_t offset = dchecked_integral_cast<size_t>(reinterpret_cast<uintptr_t>(unaligned_code_ptr)); |
| 80 | size_t padding = compiled_method->AlignCode(offset) - offset; |
| 81 | // Make sure no resizing takes place. |
| 82 | CHECK_GE(chunk->capacity(), chunk->size() + padding); |
| 83 | chunk->insert(chunk->begin(), padding, 0); |
| 84 | const void* code_ptr = reinterpret_cast<const uint8_t*>(unaligned_code_ptr) + padding; |
| 85 | CHECK_EQ(code_ptr, static_cast<const void*>(chunk->data() + (chunk->size() - code_size))); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 86 | MakeExecutable(code_ptr, code.size()); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 87 | const void* method_code = CompiledMethod::CodePointer(code_ptr, |
| 88 | compiled_method->GetInstructionSet()); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 89 | LOG(INFO) << "MakeExecutable " << method->PrettyMethod() << " code=" << method_code; |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 90 | class_linker_->SetEntryPointsToCompiledCode(method, method_code); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 91 | } else { |
| 92 | // No code? You must mean to go into the interpreter. |
| 93 | // Or the generic JNI... |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 94 | class_linker_->SetEntryPointsToInterpreter(method); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | void CommonCompilerTest::MakeExecutable(const void* code_start, size_t code_length) { |
| 99 | CHECK(code_start != nullptr); |
| 100 | CHECK_NE(code_length, 0U); |
| 101 | uintptr_t data = reinterpret_cast<uintptr_t>(code_start); |
| 102 | uintptr_t base = RoundDown(data, kPageSize); |
| 103 | uintptr_t limit = RoundUp(data + code_length, kPageSize); |
| 104 | uintptr_t len = limit - base; |
| 105 | int result = mprotect(reinterpret_cast<void*>(base), len, PROT_READ | PROT_WRITE | PROT_EXEC); |
| 106 | CHECK_EQ(result, 0); |
| 107 | |
Roland Levillain | 3243026 | 2016-02-01 15:23:20 +0000 | [diff] [blame] | 108 | FlushInstructionCache(reinterpret_cast<char*>(base), reinterpret_cast<char*>(base + len)); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 111 | void CommonCompilerTest::MakeExecutable(ObjPtr<mirror::ClassLoader> class_loader, |
| 112 | const char* class_name) { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 113 | std::string class_descriptor(DotToDescriptor(class_name)); |
| 114 | Thread* self = Thread::Current(); |
| 115 | StackHandleScope<1> hs(self); |
| 116 | Handle<mirror::ClassLoader> loader(hs.NewHandle(class_loader)); |
| 117 | mirror::Class* klass = class_linker_->FindClass(self, class_descriptor.c_str(), loader); |
| 118 | CHECK(klass != nullptr) << "Class not found " << class_name; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 119 | PointerSize pointer_size = class_linker_->GetImagePointerSize(); |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 120 | for (auto& m : klass->GetMethods(pointer_size)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 121 | MakeExecutable(&m); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Andreas Gampe | 70bef0d | 2015-04-15 02:37:28 -0700 | [diff] [blame] | 125 | // Get the set of image classes given to the compiler-driver in SetUp. Note: the compiler |
| 126 | // driver assumes ownership of the set, so the test should properly release the set. |
| 127 | std::unordered_set<std::string>* CommonCompilerTest::GetImageClasses() { |
| 128 | // Empty set: by default no classes are retained in the image. |
| 129 | return new std::unordered_set<std::string>(); |
| 130 | } |
| 131 | |
| 132 | // Get the set of compiled classes given to the compiler-driver in SetUp. Note: the compiler |
| 133 | // driver assumes ownership of the set, so the test should properly release the set. |
| 134 | std::unordered_set<std::string>* CommonCompilerTest::GetCompiledClasses() { |
| 135 | // Null, no selection of compiled-classes. |
| 136 | return nullptr; |
| 137 | } |
| 138 | |
| 139 | // Get the set of compiled methods given to the compiler-driver in SetUp. Note: the compiler |
| 140 | // driver assumes ownership of the set, so the test should properly release the set. |
| 141 | std::unordered_set<std::string>* CommonCompilerTest::GetCompiledMethods() { |
| 142 | // Null, no selection of compiled-methods. |
| 143 | return nullptr; |
| 144 | } |
| 145 | |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 146 | // Get ProfileCompilationInfo that should be passed to the driver. |
| 147 | ProfileCompilationInfo* CommonCompilerTest::GetProfileCompilationInfo() { |
| 148 | // Null, profile information will not be taken into account. |
| 149 | return nullptr; |
| 150 | } |
| 151 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 152 | void CommonCompilerTest::SetUp() { |
| 153 | CommonRuntimeTest::SetUp(); |
| 154 | { |
| 155 | ScopedObjectAccess soa(Thread::Current()); |
| 156 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 157 | const InstructionSet instruction_set = kRuntimeISA; |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 158 | // Take the default set of instruction features from the build. |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 159 | instruction_set_features_ = InstructionSetFeatures::FromCppDefines(); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 160 | |
| 161 | runtime_->SetInstructionSet(instruction_set); |
| 162 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 163 | Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i); |
| 164 | if (!runtime_->HasCalleeSaveMethod(type)) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 165 | runtime_->SetCalleeSaveMethod(runtime_->CreateCalleeSaveMethod(), type); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 169 | timer_.reset(new CumulativeLogger("Compilation times")); |
Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 170 | CreateCompilerDriver(compiler_kind_, instruction_set); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 171 | } |
Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Andreas Gampe | 3f41a01 | 2016-02-18 16:53:41 -0800 | [diff] [blame] | 174 | void CommonCompilerTest::CreateCompilerDriver(Compiler::Kind kind, |
| 175 | InstructionSet isa, |
| 176 | size_t number_of_threads) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 177 | compiler_options_->boot_image_ = true; |
Mathieu Chartier | d0af56c | 2017-02-17 12:56:25 -0800 | [diff] [blame^] | 178 | compiler_options_->SetCompilerFilter(GetCompilerFilter()); |
Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 179 | compiler_driver_.reset(new CompilerDriver(compiler_options_.get(), |
| 180 | verification_results_.get(), |
Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 181 | kind, |
| 182 | isa, |
| 183 | instruction_set_features_.get(), |
Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 184 | GetImageClasses(), |
| 185 | GetCompiledClasses(), |
| 186 | GetCompiledMethods(), |
Andreas Gampe | 3f41a01 | 2016-02-18 16:53:41 -0800 | [diff] [blame] | 187 | number_of_threads, |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 188 | /* dump_stats */ true, |
| 189 | /* dump_passes */ true, |
Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 190 | timer_.get(), |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 191 | /* swap_fd */ -1, |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 192 | GetProfileCompilationInfo())); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 193 | // We typically don't generate an image in unit tests, disable this optimization by default. |
| 194 | compiler_driver_->SetSupportBootImageFixup(false); |
| 195 | } |
| 196 | |
| 197 | void CommonCompilerTest::SetUpRuntimeOptions(RuntimeOptions* options) { |
| 198 | CommonRuntimeTest::SetUpRuntimeOptions(options); |
| 199 | |
| 200 | compiler_options_.reset(new CompilerOptions); |
| 201 | verification_results_.reset(new VerificationResults(compiler_options_.get())); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 202 | callbacks_.reset(new QuickCompilerCallbacks(verification_results_.get(), |
Andreas Gampe | 4585f87 | 2015-03-27 23:45:15 -0700 | [diff] [blame] | 203 | CompilerCallbacks::CallbackMode::kCompileApp)); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 206 | Compiler::Kind CommonCompilerTest::GetCompilerKind() const { |
| 207 | return compiler_kind_; |
| 208 | } |
| 209 | |
| 210 | void CommonCompilerTest::SetCompilerKind(Compiler::Kind compiler_kind) { |
| 211 | compiler_kind_ = compiler_kind; |
| 212 | } |
| 213 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 214 | InstructionSet CommonCompilerTest::GetInstructionSet() const { |
| 215 | DCHECK(compiler_driver_.get() != nullptr); |
| 216 | return compiler_driver_->GetInstructionSet(); |
| 217 | } |
| 218 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 219 | void CommonCompilerTest::TearDown() { |
| 220 | timer_.reset(); |
| 221 | compiler_driver_.reset(); |
| 222 | callbacks_.reset(); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 223 | verification_results_.reset(); |
| 224 | compiler_options_.reset(); |
Mathieu Chartier | 496577f | 2016-09-20 15:33:31 -0700 | [diff] [blame] | 225 | image_reservation_.reset(); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 226 | |
| 227 | CommonRuntimeTest::TearDown(); |
| 228 | } |
| 229 | |
| 230 | void CommonCompilerTest::CompileClass(mirror::ClassLoader* class_loader, const char* class_name) { |
| 231 | std::string class_descriptor(DotToDescriptor(class_name)); |
| 232 | Thread* self = Thread::Current(); |
| 233 | StackHandleScope<1> hs(self); |
| 234 | Handle<mirror::ClassLoader> loader(hs.NewHandle(class_loader)); |
| 235 | mirror::Class* klass = class_linker_->FindClass(self, class_descriptor.c_str(), loader); |
| 236 | CHECK(klass != nullptr) << "Class not found " << class_name; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 237 | auto pointer_size = class_linker_->GetImagePointerSize(); |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 238 | for (auto& m : klass->GetMethods(pointer_size)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 239 | CompileMethod(&m); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 243 | void CommonCompilerTest::CompileMethod(ArtMethod* method) { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 244 | CHECK(method != nullptr); |
| 245 | TimingLogger timings("CommonTest::CompileMethod", false, false); |
| 246 | TimingLogger::ScopedTiming t(__FUNCTION__, &timings); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 247 | compiler_driver_->CompileOne(Thread::Current(), method, &timings); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 248 | TimingLogger::ScopedTiming t2("MakeExecutable", &timings); |
| 249 | MakeExecutable(method); |
| 250 | } |
| 251 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 252 | void CommonCompilerTest::CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 253 | const char* class_name, const char* method_name, |
| 254 | const char* signature) { |
| 255 | std::string class_descriptor(DotToDescriptor(class_name)); |
| 256 | Thread* self = Thread::Current(); |
| 257 | mirror::Class* klass = class_linker_->FindClass(self, class_descriptor.c_str(), class_loader); |
| 258 | CHECK(klass != nullptr) << "Class not found " << class_name; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 259 | auto pointer_size = class_linker_->GetImagePointerSize(); |
| 260 | ArtMethod* method = klass->FindDirectMethod(method_name, signature, pointer_size); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 261 | CHECK(method != nullptr) << "Direct method not found: " |
| 262 | << class_name << "." << method_name << signature; |
| 263 | CompileMethod(method); |
| 264 | } |
| 265 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 266 | void CommonCompilerTest::CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 267 | const char* class_name, const char* method_name, |
| 268 | const char* signature) { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 269 | std::string class_descriptor(DotToDescriptor(class_name)); |
| 270 | Thread* self = Thread::Current(); |
| 271 | mirror::Class* klass = class_linker_->FindClass(self, class_descriptor.c_str(), class_loader); |
| 272 | CHECK(klass != nullptr) << "Class not found " << class_name; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 273 | auto pointer_size = class_linker_->GetImagePointerSize(); |
| 274 | ArtMethod* method = klass->FindVirtualMethod(method_name, signature, pointer_size); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 275 | CHECK(method != nullptr) << "Virtual method not found: " |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 276 | << class_name << "." << method_name << signature; |
| 277 | CompileMethod(method); |
| 278 | } |
| 279 | |
| 280 | void CommonCompilerTest::ReserveImageSpace() { |
| 281 | // Reserve where the image will be loaded up front so that other parts of test set up don't |
| 282 | // accidentally end up colliding with the fixed memory address when we need to load the image. |
| 283 | std::string error_msg; |
Mathieu Chartier | 6e88ef6 | 2014-10-14 15:01:24 -0700 | [diff] [blame] | 284 | MemMap::Init(); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 285 | image_reservation_.reset(MemMap::MapAnonymous("image reservation", |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 286 | reinterpret_cast<uint8_t*>(ART_BASE_ADDRESS), |
Hiroshi Yamauchi | 1d6fdaf | 2016-04-07 11:31:26 -0700 | [diff] [blame] | 287 | (size_t)120 * 1024 * 1024, // 120MB |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 288 | PROT_NONE, |
| 289 | false /* no need for 4gb flag with fixed mmap*/, |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 290 | false /* not reusing existing reservation */, |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 291 | &error_msg)); |
| 292 | CHECK(image_reservation_.get() != nullptr) << error_msg; |
| 293 | } |
| 294 | |
| 295 | void CommonCompilerTest::UnreserveImageSpace() { |
| 296 | image_reservation_.reset(); |
| 297 | } |
| 298 | |
| 299 | } // namespace art |