Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [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 | #ifndef ART_COMPILER_COMMON_COMPILER_TEST_H_ |
| 18 | #define ART_COMPILER_COMMON_COMPILER_TEST_H_ |
| 19 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 20 | #include <list> |
| 21 | #include <vector> |
| 22 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame^] | 23 | #include "arch/instruction_set.h" |
| 24 | #include "arch/instruction_set_features.h" |
Vladimir Marko | 54159c6 | 2018-06-20 14:30:08 +0100 | [diff] [blame] | 25 | #include "base/hash_set.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 26 | #include "common_runtime_test.h" |
Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 27 | #include "compiler.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 28 | #include "oat_file.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 29 | |
| 30 | namespace art { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 31 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 32 | class ClassLoader; |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 33 | } // namespace mirror |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 34 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 35 | class CompilerDriver; |
| 36 | class CompilerOptions; |
| 37 | class CumulativeLogger; |
Vladimir Marko | 213ee2d | 2018-06-22 11:56:34 +0100 | [diff] [blame] | 38 | class DexFile; |
Andreas Gampe | 3913e48 | 2018-01-22 18:58:01 -0800 | [diff] [blame] | 39 | class ProfileCompilationInfo; |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 40 | class VerificationResults; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 41 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 42 | template<class T> class Handle; |
Dmitry Petrochenko | f0972a4 | 2014-05-16 17:43:39 +0700 | [diff] [blame] | 43 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 44 | class CommonCompilerTest : public CommonRuntimeTest { |
| 45 | public: |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 46 | CommonCompilerTest(); |
| 47 | ~CommonCompilerTest(); |
| 48 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 49 | // Create an OatMethod based on pointers (for unit tests). |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 50 | OatFile::OatMethod CreateOatMethod(const void* code); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 51 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 52 | void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 53 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 54 | static void MakeExecutable(const void* code_start, size_t code_length); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 55 | |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 56 | void MakeExecutable(ObjPtr<mirror::ClassLoader> class_loader, const char* class_name) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 57 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 58 | |
| 59 | protected: |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame^] | 60 | void SetUp() OVERRIDE; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 61 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame^] | 62 | void SetUpRuntimeOptions(RuntimeOptions* options) OVERRIDE; |
Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 63 | |
| 64 | Compiler::Kind GetCompilerKind() const; |
| 65 | void SetCompilerKind(Compiler::Kind compiler_kind); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 66 | |
Vladimir Marko | 54159c6 | 2018-06-20 14:30:08 +0100 | [diff] [blame] | 67 | // Get the set of image classes given to the compiler-driver in SetUp. |
| 68 | virtual std::unique_ptr<HashSet<std::string>> GetImageClasses(); |
Andreas Gampe | 70bef0d | 2015-04-15 02:37:28 -0700 | [diff] [blame] | 69 | |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 70 | virtual ProfileCompilationInfo* GetProfileCompilationInfo(); |
| 71 | |
Mathieu Chartier | d0af56c | 2017-02-17 12:56:25 -0800 | [diff] [blame] | 72 | virtual CompilerFilter::Filter GetCompilerFilter() const { |
| 73 | return CompilerFilter::kDefaultCompilerFilter; |
| 74 | } |
| 75 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame^] | 76 | void TearDown() OVERRIDE; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 77 | |
| 78 | void CompileClass(mirror::ClassLoader* class_loader, const char* class_name) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 79 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 80 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 81 | void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 82 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 83 | void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 84 | const char* method_name, const char* signature) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 85 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 86 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 87 | void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 88 | const char* method_name, const char* signature) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 89 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 90 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame^] | 91 | void ApplyInstructionSet(); |
| 92 | void OverrideInstructionSetFeatures(InstructionSet instruction_set, const std::string& variant); |
| 93 | |
| 94 | void CreateCompilerDriver(); |
Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 95 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 96 | void ReserveImageSpace(); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 97 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 98 | void UnreserveImageSpace(); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 99 | |
Vladimir Marko | 213ee2d | 2018-06-22 11:56:34 +0100 | [diff] [blame] | 100 | void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files); |
| 101 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame^] | 102 | void ClearBootImageOption(); |
| 103 | |
Nicolas Geoffray | 409e809 | 2015-10-01 10:32:19 +0100 | [diff] [blame] | 104 | Compiler::Kind compiler_kind_ = Compiler::kOptimizing; |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame^] | 105 | size_t number_of_threads_ = 2u; |
| 106 | |
| 107 | InstructionSet instruction_set_ = |
| 108 | (kRuntimeISA == InstructionSet::kArm) ? InstructionSet::kThumb2 : kRuntimeISA; |
| 109 | // Take the default set of instruction features from the build. |
| 110 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features_ |
| 111 | = InstructionSetFeatures::FromCppDefines(); |
| 112 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 113 | std::unique_ptr<CompilerOptions> compiler_options_; |
| 114 | std::unique_ptr<VerificationResults> verification_results_; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 115 | std::unique_ptr<CompilerDriver> compiler_driver_; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 116 | |
| 117 | private: |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 118 | std::unique_ptr<MemMap> image_reservation_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 119 | |
| 120 | // Chunks must not move their storage after being created - use the node-based std::list. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 121 | std::list<std::vector<uint8_t>> header_code_and_maps_chunks_; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 124 | } // namespace art |
| 125 | |
| 126 | #endif // ART_COMPILER_COMMON_COMPILER_TEST_H_ |