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 | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 23 | #include <jni.h> |
| 24 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 25 | #include "arch/instruction_set.h" |
| 26 | #include "arch/instruction_set_features.h" |
Vladimir Marko | bdbee06 | 2022-11-16 12:44:15 +0000 | [diff] [blame] | 27 | #include "base/macros.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 28 | #include "common_runtime_test.h" |
Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 29 | #include "compiler.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 30 | #include "oat_file.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 31 | |
Vladimir Marko | bdbee06 | 2022-11-16 12:44:15 +0000 | [diff] [blame] | 32 | namespace art HIDDEN { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 33 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 34 | class ClassLoader; |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 35 | } // namespace mirror |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 36 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 37 | class CompilerOptions; |
| 38 | class CumulativeLogger; |
Vladimir Marko | 213ee2d | 2018-06-22 11:56:34 +0100 | [diff] [blame] | 39 | class DexFile; |
Vladimir Marko | 2afaff7 | 2018-11-30 17:01:50 +0000 | [diff] [blame] | 40 | class TimingLogger; |
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 | |
Vladimir Marko | bdbee06 | 2022-11-16 12:44:15 +0000 | [diff] [blame] | 44 | // Export all symbols in `CommonCompilerTestImpl` for dex2oat tests. |
| 45 | class EXPORT CommonCompilerTestImpl { |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 46 | public: |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 47 | static std::unique_ptr<CompilerOptions> CreateCompilerOptions(InstructionSet instruction_set, |
| 48 | const std::string& variant); |
| 49 | |
Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 50 | CommonCompilerTestImpl(); |
| 51 | virtual ~CommonCompilerTestImpl(); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 52 | |
Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 53 | // Create an executable copy of the code with given metadata. |
| 54 | const void* MakeExecutable(ArrayRef<const uint8_t> code, |
| 55 | ArrayRef<const uint8_t> vmap_table, |
| 56 | InstructionSet instruction_set); |
| 57 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 58 | protected: |
Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 59 | void SetUp(); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 60 | |
Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 61 | void SetUpRuntimeOptionsImpl(); |
Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 62 | |
| 63 | Compiler::Kind GetCompilerKind() const; |
| 64 | void SetCompilerKind(Compiler::Kind compiler_kind); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 65 | |
Mathieu Chartier | d0af56c | 2017-02-17 12:56:25 -0800 | [diff] [blame] | 66 | virtual CompilerFilter::Filter GetCompilerFilter() const { |
| 67 | return CompilerFilter::kDefaultCompilerFilter; |
| 68 | } |
| 69 | |
Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 70 | void TearDown(); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 71 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 72 | void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 73 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 74 | void ApplyInstructionSet(); |
| 75 | void OverrideInstructionSetFeatures(InstructionSet instruction_set, const std::string& variant); |
| 76 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 77 | void ClearBootImageOption(); |
| 78 | |
Nicolas Geoffray | 409e809 | 2015-10-01 10:32:19 +0100 | [diff] [blame] | 79 | Compiler::Kind compiler_kind_ = Compiler::kOptimizing; |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 80 | |
| 81 | InstructionSet instruction_set_ = |
| 82 | (kRuntimeISA == InstructionSet::kArm) ? InstructionSet::kThumb2 : kRuntimeISA; |
| 83 | // Take the default set of instruction features from the build. |
| 84 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features_ |
| 85 | = InstructionSetFeatures::FromCppDefines(); |
| 86 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 87 | std::unique_ptr<CompilerOptions> compiler_options_; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 88 | |
Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 89 | protected: |
| 90 | virtual ClassLinker* GetClassLinker() = 0; |
| 91 | virtual Runtime* GetRuntime() = 0; |
| 92 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 93 | private: |
Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 94 | class CodeAndMetadata; |
Vladimir Marko | d5a4319 | 2022-09-30 16:18:02 +0200 | [diff] [blame] | 95 | class OneCompiledMethodStorage; |
| 96 | |
Vladimir Marko | 37fd800 | 2021-02-02 14:29:04 +0000 | [diff] [blame] | 97 | std::vector<CodeAndMetadata> code_and_metadata_; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
Alex Light | 3ac2f5a | 2020-11-18 12:23:48 -0800 | [diff] [blame] | 100 | template <typename RuntimeBase> |
| 101 | class CommonCompilerTestBase : public CommonCompilerTestImpl, public RuntimeBase { |
| 102 | public: |
| 103 | void SetUp() override { |
| 104 | RuntimeBase::SetUp(); |
| 105 | CommonCompilerTestImpl::SetUp(); |
| 106 | } |
| 107 | void SetUpRuntimeOptions(RuntimeOptions* options) override { |
| 108 | RuntimeBase::SetUpRuntimeOptions(options); |
| 109 | CommonCompilerTestImpl::SetUpRuntimeOptionsImpl(); |
| 110 | } |
| 111 | void TearDown() override { |
| 112 | CommonCompilerTestImpl::TearDown(); |
| 113 | RuntimeBase::TearDown(); |
| 114 | } |
| 115 | |
| 116 | protected: |
| 117 | ClassLinker* GetClassLinker() override { |
| 118 | return RuntimeBase::class_linker_; |
| 119 | } |
| 120 | Runtime* GetRuntime() override { |
| 121 | return RuntimeBase::runtime_.get(); |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | class CommonCompilerTest : public CommonCompilerTestBase<CommonRuntimeTest> {}; |
| 126 | |
| 127 | template <typename Param> |
| 128 | class CommonCompilerTestWithParam |
| 129 | : public CommonCompilerTestBase<CommonRuntimeTestWithParam<Param>> {}; |
| 130 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 131 | } // namespace art |
| 132 | |
| 133 | #endif // ART_COMPILER_COMMON_COMPILER_TEST_H_ |