blob: f3cd13296c136ed1a5a38a77559e32a628dbb655 [file] [log] [blame]
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -08001/*
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 Rogerse63db272014-07-15 15:36:11 -070020#include <list>
21#include <vector>
22
Vladimir Marko2afaff72018-11-30 17:01:50 +000023#include <jni.h>
24
Vladimir Markoa0431112018-06-25 09:32:54 +010025#include "arch/instruction_set.h"
26#include "arch/instruction_set_features.h"
Vladimir Markobdbee062022-11-16 12:44:15 +000027#include "base/macros.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080028#include "common_runtime_test.h"
Roland Levillainbbcc01a2015-06-30 14:16:48 +010029#include "compiler.h"
Ian Rogerse63db272014-07-15 15:36:11 -070030#include "oat_file.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080031
Vladimir Markobdbee062022-11-16 12:44:15 +000032namespace art HIDDEN {
Ian Rogerse63db272014-07-15 15:36:11 -070033namespace mirror {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080034class ClassLoader;
Ian Rogerse63db272014-07-15 15:36:11 -070035} // namespace mirror
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080036
Ian Rogerse63db272014-07-15 15:36:11 -070037class CompilerOptions;
38class CumulativeLogger;
Vladimir Marko213ee2d2018-06-22 11:56:34 +010039class DexFile;
Vladimir Marko2afaff72018-11-30 17:01:50 +000040class TimingLogger;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080041
Ian Rogerse63db272014-07-15 15:36:11 -070042template<class T> class Handle;
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +070043
Vladimir Markobdbee062022-11-16 12:44:15 +000044// Export all symbols in `CommonCompilerTestImpl` for dex2oat tests.
45class EXPORT CommonCompilerTestImpl {
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080046 public:
Vladimir Markof91fc122020-05-13 09:21:00 +010047 static std::unique_ptr<CompilerOptions> CreateCompilerOptions(InstructionSet instruction_set,
48 const std::string& variant);
49
Alex Light3ac2f5a2020-11-18 12:23:48 -080050 CommonCompilerTestImpl();
51 virtual ~CommonCompilerTestImpl();
Ian Rogerse63db272014-07-15 15:36:11 -070052
Vladimir Marko37fd8002021-02-02 14:29:04 +000053 // 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 Carlstroma1ce1fe2014-02-24 23:23:58 -080058 protected:
Alex Light3ac2f5a2020-11-18 12:23:48 -080059 void SetUp();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080060
Alex Light3ac2f5a2020-11-18 12:23:48 -080061 void SetUpRuntimeOptionsImpl();
Roland Levillainbbcc01a2015-06-30 14:16:48 +010062
63 Compiler::Kind GetCompilerKind() const;
64 void SetCompilerKind(Compiler::Kind compiler_kind);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080065
Mathieu Chartierd0af56c2017-02-17 12:56:25 -080066 virtual CompilerFilter::Filter GetCompilerFilter() const {
67 return CompilerFilter::kDefaultCompilerFilter;
68 }
69
Alex Light3ac2f5a2020-11-18 12:23:48 -080070 void TearDown();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080071
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070072 void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080073
Vladimir Markoa0431112018-06-25 09:32:54 +010074 void ApplyInstructionSet();
75 void OverrideInstructionSetFeatures(InstructionSet instruction_set, const std::string& variant);
76
Vladimir Markoa0431112018-06-25 09:32:54 +010077 void ClearBootImageOption();
78
Nicolas Geoffray409e8092015-10-01 10:32:19 +010079 Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
Vladimir Markoa0431112018-06-25 09:32:54 +010080
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 Rogers700a4022014-05-19 16:49:03 -070087 std::unique_ptr<CompilerOptions> compiler_options_;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080088
Alex Light3ac2f5a2020-11-18 12:23:48 -080089 protected:
90 virtual ClassLinker* GetClassLinker() = 0;
91 virtual Runtime* GetRuntime() = 0;
92
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080093 private:
Vladimir Marko37fd8002021-02-02 14:29:04 +000094 class CodeAndMetadata;
Vladimir Markod5a43192022-09-30 16:18:02 +020095 class OneCompiledMethodStorage;
96
Vladimir Marko37fd8002021-02-02 14:29:04 +000097 std::vector<CodeAndMetadata> code_and_metadata_;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080098};
99
Alex Light3ac2f5a2020-11-18 12:23:48 -0800100template <typename RuntimeBase>
101class 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
125class CommonCompilerTest : public CommonCompilerTestBase<CommonRuntimeTest> {};
126
127template <typename Param>
128class CommonCompilerTestWithParam
129 : public CommonCompilerTestBase<CommonRuntimeTestWithParam<Param>> {};
130
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800131} // namespace art
132
133#endif // ART_COMPILER_COMMON_COMPILER_TEST_H_