blob: a121f8b7a052326bf46e05b8ed825ed160a6be0d [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"
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 {
30 class ClassLoader;
31} // namespace mirror
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080032
Ian Rogerse63db272014-07-15 15:36:11 -070033class CompilerDriver;
34class CompilerOptions;
35class CumulativeLogger;
36class DexFileToMethodInlinerMap;
37class VerificationResults;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080038
Ian Rogerse63db272014-07-15 15:36:11 -070039template<class T> class Handle;
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +070040
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080041class CommonCompilerTest : public CommonRuntimeTest {
42 public:
Ian Rogerse63db272014-07-15 15:36:11 -070043 CommonCompilerTest();
44 ~CommonCompilerTest();
45
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080046 // Create an OatMethod based on pointers (for unit tests).
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080047 OatFile::OatMethod CreateOatMethod(const void* code);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080048
Mathieu Chartier90443472015-07-16 20:32:27 -070049 void MakeExecutable(ArtMethod* method) SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080050
Ian Rogerse63db272014-07-15 15:36:11 -070051 static void MakeExecutable(const void* code_start, size_t code_length);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080052
53 void MakeExecutable(mirror::ClassLoader* class_loader, const char* class_name)
Mathieu Chartier90443472015-07-16 20:32:27 -070054 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080055
56 protected:
Ian Rogerse63db272014-07-15 15:36:11 -070057 virtual void SetUp();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080058
Roland Levillainbbcc01a2015-06-30 14:16:48 +010059 virtual void SetUpRuntimeOptions(RuntimeOptions* options);
60
61 Compiler::Kind GetCompilerKind() const;
62 void SetCompilerKind(Compiler::Kind compiler_kind);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080063
Roland Levillain0d5a2812015-11-13 10:07:31 +000064 InstructionSet GetInstructionSet() const;
65
Andreas Gampe70bef0d2015-04-15 02:37:28 -070066 // Get the set of image classes given to the compiler-driver in SetUp. Note: the compiler
67 // driver assumes ownership of the set, so the test should properly release the set.
68 virtual std::unordered_set<std::string>* GetImageClasses();
69
70 // Get the set of compiled classes given to the compiler-driver in SetUp. Note: the compiler
71 // driver assumes ownership of the set, so the test should properly release the set.
72 virtual std::unordered_set<std::string>* GetCompiledClasses();
73
74 // Get the set of compiled methods given to the compiler-driver in SetUp. Note: the compiler
75 // driver assumes ownership of the set, so the test should properly release the set.
76 virtual std::unordered_set<std::string>* GetCompiledMethods();
77
Ian Rogerse63db272014-07-15 15:36:11 -070078 virtual void TearDown();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080079
80 void CompileClass(mirror::ClassLoader* class_loader, const char* class_name)
Mathieu Chartier90443472015-07-16 20:32:27 -070081 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080082
Mathieu Chartier90443472015-07-16 20:32:27 -070083 void CompileMethod(ArtMethod* method) SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080084
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070085 void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080086 const char* method_name, const char* signature)
Mathieu Chartier90443472015-07-16 20:32:27 -070087 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080088
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070089 void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080090 const char* method_name, const char* signature)
Mathieu Chartier90443472015-07-16 20:32:27 -070091 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -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
Nicolas Geoffray409e8092015-10-01 10:32:19 +010097 Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
Ian Rogers700a4022014-05-19 16:49:03 -070098 std::unique_ptr<CompilerOptions> compiler_options_;
99 std::unique_ptr<VerificationResults> verification_results_;
100 std::unique_ptr<DexFileToMethodInlinerMap> method_inliner_map_;
Ian Rogers700a4022014-05-19 16:49:03 -0700101 std::unique_ptr<CompilerDriver> compiler_driver_;
102 std::unique_ptr<CumulativeLogger> timer_;
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
Roland Levillain4d027112015-07-01 15:41:14 +0100113// TODO: When heap reference poisoning works with all compilers in use, get rid of this.
114#define TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING_WITH_QUICK() \
115 if (kPoisonHeapReferences && GetCompilerKind() == Compiler::kQuick) { \
116 printf("WARNING: TEST DISABLED FOR HEAP REFERENCE POISONING WITH QUICK\n"); \
117 return; \
118 }
119
Roland Levillain0d5a2812015-11-13 10:07:31 +0000120// TODO: When read barrier works with all compilers in use, get rid of this.
121#define TEST_DISABLED_FOR_READ_BARRIER_WITH_QUICK() \
122 if (kUseReadBarrier && GetCompilerKind() == Compiler::kQuick) { \
123 printf("WARNING: TEST DISABLED FOR READ BARRIER WITH QUICK\n"); \
124 return; \
125 }
126
127// TODO: When read barrier works with all Optimizing back ends, get rid of this.
128#define TEST_DISABLED_FOR_READ_BARRIER_WITH_OPTIMIZING_FOR_UNSUPPORTED_INSTRUCTION_SETS() \
129 if (kUseReadBarrier && GetCompilerKind() == Compiler::kOptimizing) { \
130 switch (GetInstructionSet()) { \
131 case kX86: \
132 case kX86_64: \
133 /* Instruction set has read barrier support. */ \
134 break; \
135 \
136 default: \
137 /* Instruction set does not have barrier support. */ \
138 printf("WARNING: TEST DISABLED FOR READ BARRIER WITH OPTIMIZING " \
139 "FOR THIS INSTRUCTION SET\n"); \
140 return; \
141 } \
142 }
143
Roland Levillainbbcc01a2015-06-30 14:16:48 +0100144// TODO: When non-PIC works with all compilers in use, get rid of this.
145#define TEST_DISABLED_FOR_NON_PIC_COMPILING_WITH_OPTIMIZING() \
146 if (GetCompilerKind() == Compiler::kOptimizing) { \
147 printf("WARNING: TEST DISABLED FOR NON-PIC COMPILING WITH OPTIMIZING\n"); \
148 return; \
149 }
150
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800151} // namespace art
152
153#endif // ART_COMPILER_COMMON_COMPILER_TEST_H_