blob: a71908e6c81fcdfc2c036a3828b7b8c74a3b7b45 [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 Marko54159c62018-06-20 14:30:08 +010027#include "base/hash_set.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
32namespace art {
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 CompilerDriver;
38class CompilerOptions;
39class CumulativeLogger;
Vladimir Marko213ee2d2018-06-22 11:56:34 +010040class DexFile;
Andreas Gampe3913e482018-01-22 18:58:01 -080041class ProfileCompilationInfo;
Vladimir Marko2afaff72018-11-30 17:01:50 +000042class TimingLogger;
Ian Rogerse63db272014-07-15 15:36:11 -070043class VerificationResults;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080044
Ian Rogerse63db272014-07-15 15:36:11 -070045template<class T> class Handle;
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +070046
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080047class CommonCompilerTest : public CommonRuntimeTest {
48 public:
Ian Rogerse63db272014-07-15 15:36:11 -070049 CommonCompilerTest();
50 ~CommonCompilerTest();
51
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080052 // Create an OatMethod based on pointers (for unit tests).
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080053 OatFile::OatMethod CreateOatMethod(const void* code);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080054
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070055 void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080056
Ian Rogerse63db272014-07-15 15:36:11 -070057 static void MakeExecutable(const void* code_start, size_t code_length);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080058
Mathieu Chartier0795f232016-09-27 18:43:30 -070059 void MakeExecutable(ObjPtr<mirror::ClassLoader> class_loader, const char* class_name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070060 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080061
62 protected:
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010063 void SetUp() override;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080064
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010065 void SetUpRuntimeOptions(RuntimeOptions* options) override;
Roland Levillainbbcc01a2015-06-30 14:16:48 +010066
67 Compiler::Kind GetCompilerKind() const;
68 void SetCompilerKind(Compiler::Kind compiler_kind);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080069
Vladimir Marko54159c62018-06-20 14:30:08 +010070 // Get the set of image classes given to the compiler-driver in SetUp.
71 virtual std::unique_ptr<HashSet<std::string>> GetImageClasses();
Andreas Gampe70bef0d2015-04-15 02:37:28 -070072
Calin Juravle877fd962016-01-05 14:29:29 +000073 virtual ProfileCompilationInfo* GetProfileCompilationInfo();
74
Mathieu Chartierd0af56c2017-02-17 12:56:25 -080075 virtual CompilerFilter::Filter GetCompilerFilter() const {
76 return CompilerFilter::kDefaultCompilerFilter;
77 }
78
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010079 void TearDown() override;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080080
81 void CompileClass(mirror::ClassLoader* class_loader, const char* class_name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070082 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080083
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070084 void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080085
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070086 void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080087 const char* method_name, const char* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070088 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080089
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070090 void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080091 const char* method_name, const char* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070092 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080093
Vladimir Marko2afaff72018-11-30 17:01:50 +000094 void CompileAll(jobject class_loader,
95 const std::vector<const DexFile*>& dex_files,
96 TimingLogger* timings) REQUIRES(!Locks::mutator_lock_);
97
Vladimir Markoa0431112018-06-25 09:32:54 +010098 void ApplyInstructionSet();
99 void OverrideInstructionSetFeatures(InstructionSet instruction_set, const std::string& variant);
100
101 void CreateCompilerDriver();
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800102
Ian Rogerse63db272014-07-15 15:36:11 -0700103 void ReserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800104
Ian Rogerse63db272014-07-15 15:36:11 -0700105 void UnreserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800106
Vladimir Marko213ee2d2018-06-22 11:56:34 +0100107 void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files);
108
Vladimir Markoa0431112018-06-25 09:32:54 +0100109 void ClearBootImageOption();
110
Nicolas Geoffray409e8092015-10-01 10:32:19 +0100111 Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
Vladimir Markoa0431112018-06-25 09:32:54 +0100112 size_t number_of_threads_ = 2u;
113
114 InstructionSet instruction_set_ =
115 (kRuntimeISA == InstructionSet::kArm) ? InstructionSet::kThumb2 : kRuntimeISA;
116 // Take the default set of instruction features from the build.
117 std::unique_ptr<const InstructionSetFeatures> instruction_set_features_
118 = InstructionSetFeatures::FromCppDefines();
119
Ian Rogers700a4022014-05-19 16:49:03 -0700120 std::unique_ptr<CompilerOptions> compiler_options_;
121 std::unique_ptr<VerificationResults> verification_results_;
Ian Rogers700a4022014-05-19 16:49:03 -0700122 std::unique_ptr<CompilerDriver> compiler_driver_;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800123
124 private:
Vladimir Markoc34bebf2018-08-16 16:12:49 +0100125 MemMap image_reservation_;
Vladimir Marko2afaff72018-11-30 17:01:50 +0000126 void* inaccessible_page_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100127
128 // Chunks must not move their storage after being created - use the node-based std::list.
Ian Rogers700a4022014-05-19 16:49:03 -0700129 std::list<std::vector<uint8_t>> header_code_and_maps_chunks_;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800130};
131
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800132} // namespace art
133
134#endif // ART_COMPILER_COMMON_COMPILER_TEST_H_