blob: 523912119e872ab20d6880d68f50244c9b225430 [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>
Andreas Gampe70bef0d2015-04-15 02:37:28 -070021#include <unordered_set>
Ian Rogerse63db272014-07-15 15:36:11 -070022#include <vector>
23
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080024#include "common_runtime_test.h"
Roland Levillainbbcc01a2015-06-30 14:16:48 +010025#include "compiler.h"
Calin Juravle877fd962016-01-05 14:29:29 +000026#include "jit/offline_profiling_info.h"
Ian Rogerse63db272014-07-15 15:36:11 -070027#include "oat_file.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080028
29namespace art {
Ian Rogerse63db272014-07-15 15:36:11 -070030namespace mirror {
31 class ClassLoader;
32} // namespace mirror
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080033
Ian Rogerse63db272014-07-15 15:36:11 -070034class CompilerDriver;
35class CompilerOptions;
36class CumulativeLogger;
37class DexFileToMethodInlinerMap;
38class 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
54 void MakeExecutable(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
Andreas Gampe70bef0d2015-04-15 02:37:28 -070067 // Get the set of image classes given to the compiler-driver in SetUp. Note: the compiler
68 // driver assumes ownership of the set, so the test should properly release the set.
69 virtual std::unordered_set<std::string>* GetImageClasses();
70
71 // Get the set of compiled classes given to the compiler-driver in SetUp. Note: the compiler
72 // driver assumes ownership of the set, so the test should properly release the set.
73 virtual std::unordered_set<std::string>* GetCompiledClasses();
74
75 // Get the set of compiled methods given to the compiler-driver in SetUp. Note: the compiler
76 // driver assumes ownership of the set, so the test should properly release the set.
77 virtual std::unordered_set<std::string>* GetCompiledMethods();
78
Calin Juravle877fd962016-01-05 14:29:29 +000079 virtual ProfileCompilationInfo* GetProfileCompilationInfo();
80
Ian Rogerse63db272014-07-15 15:36:11 -070081 virtual void TearDown();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080082
83 void CompileClass(mirror::ClassLoader* class_loader, const char* class_name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070084 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080085
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070086 void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080087
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070088 void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080089 const char* method_name, const char* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070090 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080091
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070092 void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080093 const char* method_name, const char* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070094 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080095
Andreas Gampe3f41a012016-02-18 16:53:41 -080096 void CreateCompilerDriver(Compiler::Kind kind, InstructionSet isa, size_t number_of_threads = 2U);
Mathieu Chartierceb07b32015-12-10 09:33:21 -080097
Ian Rogerse63db272014-07-15 15:36:11 -070098 void ReserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080099
Ian Rogerse63db272014-07-15 15:36:11 -0700100 void UnreserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800101
Nicolas Geoffray409e8092015-10-01 10:32:19 +0100102 Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
Ian Rogers700a4022014-05-19 16:49:03 -0700103 std::unique_ptr<CompilerOptions> compiler_options_;
104 std::unique_ptr<VerificationResults> verification_results_;
105 std::unique_ptr<DexFileToMethodInlinerMap> method_inliner_map_;
Ian Rogers700a4022014-05-19 16:49:03 -0700106 std::unique_ptr<CompilerDriver> compiler_driver_;
107 std::unique_ptr<CumulativeLogger> timer_;
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700108 std::unique_ptr<const InstructionSetFeatures> instruction_set_features_;
109
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800110
111 private:
Ian Rogers700a4022014-05-19 16:49:03 -0700112 std::unique_ptr<MemMap> image_reservation_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100113
114 // Chunks must not move their storage after being created - use the node-based std::list.
Ian Rogers700a4022014-05-19 16:49:03 -0700115 std::list<std::vector<uint8_t>> header_code_and_maps_chunks_;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800116};
117
Roland Levillain0d5a2812015-11-13 10:07:31 +0000118// TODO: When read barrier works with all Optimizing back ends, get rid of this.
119#define TEST_DISABLED_FOR_READ_BARRIER_WITH_OPTIMIZING_FOR_UNSUPPORTED_INSTRUCTION_SETS() \
120 if (kUseReadBarrier && GetCompilerKind() == Compiler::kOptimizing) { \
121 switch (GetInstructionSet()) { \
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000122 case kArm64: \
Roland Levillain3b359c72015-11-17 19:35:12 +0000123 case kThumb2: \
Roland Levillain0d5a2812015-11-13 10:07:31 +0000124 case kX86: \
125 case kX86_64: \
126 /* Instruction set has read barrier support. */ \
127 break; \
128 \
129 default: \
130 /* Instruction set does not have barrier support. */ \
131 printf("WARNING: TEST DISABLED FOR READ BARRIER WITH OPTIMIZING " \
132 "FOR THIS INSTRUCTION SET\n"); \
133 return; \
134 } \
135 }
136
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800137} // namespace art
138
139#endif // ART_COMPILER_COMMON_COMPILER_TEST_H_