blob: f070bbbeb8e97f78abb59aabf04e3783f446dfc3 [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 Marko54159c62018-06-20 14:30:08 +010023#include "base/hash_set.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080024#include "common_runtime_test.h"
Roland Levillainbbcc01a2015-06-30 14:16:48 +010025#include "compiler.h"
Ian Rogerse63db272014-07-15 15:36:11 -070026#include "oat_file.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080027
28namespace art {
Ian Rogerse63db272014-07-15 15:36:11 -070029namespace mirror {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080030class ClassLoader;
Ian Rogerse63db272014-07-15 15:36:11 -070031} // namespace mirror
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080032
Ian Rogerse63db272014-07-15 15:36:11 -070033class CompilerDriver;
34class CompilerOptions;
35class CumulativeLogger;
Vladimir Marko213ee2d2018-06-22 11:56:34 +010036class DexFile;
Andreas Gampe3913e482018-01-22 18:58:01 -080037class ProfileCompilationInfo;
Ian Rogerse63db272014-07-15 15:36:11 -070038class VerificationResults;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080039
Ian Rogerse63db272014-07-15 15:36:11 -070040template<class T> class Handle;
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +070041
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080042class CommonCompilerTest : public CommonRuntimeTest {
43 public:
Ian Rogerse63db272014-07-15 15:36:11 -070044 CommonCompilerTest();
45 ~CommonCompilerTest();
46
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080047 // Create an OatMethod based on pointers (for unit tests).
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080048 OatFile::OatMethod CreateOatMethod(const void* code);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080049
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070050 void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080051
Ian Rogerse63db272014-07-15 15:36:11 -070052 static void MakeExecutable(const void* code_start, size_t code_length);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080053
Mathieu Chartier0795f232016-09-27 18:43:30 -070054 void MakeExecutable(ObjPtr<mirror::ClassLoader> class_loader, const char* class_name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070055 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080056
57 protected:
Ian Rogerse63db272014-07-15 15:36:11 -070058 virtual void SetUp();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080059
Roland Levillainbbcc01a2015-06-30 14:16:48 +010060 virtual void SetUpRuntimeOptions(RuntimeOptions* options);
61
62 Compiler::Kind GetCompilerKind() const;
63 void SetCompilerKind(Compiler::Kind compiler_kind);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080064
Roland Levillain0d5a2812015-11-13 10:07:31 +000065 InstructionSet GetInstructionSet() const;
66
Vladimir Marko54159c62018-06-20 14:30:08 +010067 // Get the set of image classes given to the compiler-driver in SetUp.
68 virtual std::unique_ptr<HashSet<std::string>> GetImageClasses();
Andreas Gampe70bef0d2015-04-15 02:37:28 -070069
Calin Juravle877fd962016-01-05 14:29:29 +000070 virtual ProfileCompilationInfo* GetProfileCompilationInfo();
71
Mathieu Chartierd0af56c2017-02-17 12:56:25 -080072 virtual CompilerFilter::Filter GetCompilerFilter() const {
73 return CompilerFilter::kDefaultCompilerFilter;
74 }
75
Ian Rogerse63db272014-07-15 15:36:11 -070076 virtual void TearDown();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080077
78 void CompileClass(mirror::ClassLoader* class_loader, const char* class_name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070079 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080080
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070081 void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080082
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070083 void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080084 const char* method_name, const char* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070085 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080086
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070087 void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080088 const char* method_name, const char* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070089 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080090
Andreas Gampe3f41a012016-02-18 16:53:41 -080091 void CreateCompilerDriver(Compiler::Kind kind, InstructionSet isa, size_t number_of_threads = 2U);
Mathieu Chartierceb07b32015-12-10 09:33:21 -080092
Ian Rogerse63db272014-07-15 15:36:11 -070093 void ReserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080094
Ian Rogerse63db272014-07-15 15:36:11 -070095 void UnreserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080096
Vladimir Marko213ee2d2018-06-22 11:56:34 +010097 void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files);
98
Nicolas Geoffray409e8092015-10-01 10:32:19 +010099 Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
Ian Rogers700a4022014-05-19 16:49:03 -0700100 std::unique_ptr<CompilerOptions> compiler_options_;
101 std::unique_ptr<VerificationResults> verification_results_;
Ian Rogers700a4022014-05-19 16:49:03 -0700102 std::unique_ptr<CompilerDriver> compiler_driver_;
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700103 std::unique_ptr<const InstructionSetFeatures> instruction_set_features_;
104
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800105
106 private:
Ian Rogers700a4022014-05-19 16:49:03 -0700107 std::unique_ptr<MemMap> image_reservation_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100108
109 // Chunks must not move their storage after being created - use the node-based std::list.
Ian Rogers700a4022014-05-19 16:49:03 -0700110 std::list<std::vector<uint8_t>> header_code_and_maps_chunks_;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800111};
112
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800113} // namespace art
114
115#endif // ART_COMPILER_COMMON_COMPILER_TEST_H_