| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 20 | #include <list> | 
| Andreas Gampe | 70bef0d | 2015-04-15 02:37:28 -0700 | [diff] [blame] | 21 | #include <unordered_set> | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 22 | #include <vector> | 
|  | 23 |  | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 24 | #include "common_runtime_test.h" | 
| Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 25 | #include "compiler.h" | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 26 | #include "oat_file.h" | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 27 |  | 
|  | 28 | namespace art { | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 29 | namespace mirror { | 
|  | 30 | class ClassLoader; | 
|  | 31 | }  // namespace mirror | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 32 |  | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 33 | class CompilerDriver; | 
|  | 34 | class CompilerOptions; | 
|  | 35 | class CumulativeLogger; | 
|  | 36 | class DexFileToMethodInlinerMap; | 
|  | 37 | class VerificationResults; | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 38 |  | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 39 | template<class T> class Handle; | 
| Dmitry Petrochenko | f0972a4 | 2014-05-16 17:43:39 +0700 | [diff] [blame] | 40 |  | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 41 | class CommonCompilerTest : public CommonRuntimeTest { | 
|  | 42 | public: | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 43 | CommonCompilerTest(); | 
|  | 44 | ~CommonCompilerTest(); | 
|  | 45 |  | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 46 | // Create an OatMethod based on pointers (for unit tests). | 
| Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 47 | OatFile::OatMethod CreateOatMethod(const void* code); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 48 |  | 
| Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 49 | void MakeExecutable(ArtMethod* method) SHARED_REQUIRES(Locks::mutator_lock_); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 50 |  | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 51 | static void MakeExecutable(const void* code_start, size_t code_length); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 52 |  | 
|  | 53 | void MakeExecutable(mirror::ClassLoader* class_loader, const char* class_name) | 
| Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 54 | SHARED_REQUIRES(Locks::mutator_lock_); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 55 |  | 
|  | 56 | protected: | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 57 | virtual void SetUp(); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 58 |  | 
| Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 59 | virtual void SetUpRuntimeOptions(RuntimeOptions* options); | 
|  | 60 |  | 
|  | 61 | Compiler::Kind GetCompilerKind() const; | 
|  | 62 | void SetCompilerKind(Compiler::Kind compiler_kind); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 63 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 64 | InstructionSet GetInstructionSet() const; | 
|  | 65 |  | 
| Andreas Gampe | 70bef0d | 2015-04-15 02:37:28 -0700 | [diff] [blame] | 66 | // 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 Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 78 | virtual void TearDown(); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 79 |  | 
|  | 80 | void CompileClass(mirror::ClassLoader* class_loader, const char* class_name) | 
| Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 81 | SHARED_REQUIRES(Locks::mutator_lock_); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 82 |  | 
| Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 83 | void CompileMethod(ArtMethod* method) SHARED_REQUIRES(Locks::mutator_lock_); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 84 |  | 
| Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 85 | void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 86 | const char* method_name, const char* signature) | 
| Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 87 | SHARED_REQUIRES(Locks::mutator_lock_); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 88 |  | 
| Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 89 | void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 90 | const char* method_name, const char* signature) | 
| Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 91 | SHARED_REQUIRES(Locks::mutator_lock_); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 92 |  | 
| Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 93 | void CreateCompilerDriver(Compiler::Kind kind, InstructionSet isa); | 
|  | 94 |  | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 95 | void ReserveImageSpace(); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 96 |  | 
| Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 97 | void UnreserveImageSpace(); | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 98 |  | 
| Nicolas Geoffray | 409e809 | 2015-10-01 10:32:19 +0100 | [diff] [blame] | 99 | Compiler::Kind compiler_kind_ = Compiler::kOptimizing; | 
| Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 100 | std::unique_ptr<CompilerOptions> compiler_options_; | 
|  | 101 | std::unique_ptr<VerificationResults> verification_results_; | 
|  | 102 | std::unique_ptr<DexFileToMethodInlinerMap> method_inliner_map_; | 
| Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 103 | std::unique_ptr<CompilerDriver> compiler_driver_; | 
|  | 104 | std::unique_ptr<CumulativeLogger> timer_; | 
| Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 105 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features_; | 
|  | 106 |  | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 107 |  | 
|  | 108 | private: | 
| Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 109 | std::unique_ptr<MemMap> image_reservation_; | 
| Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 110 |  | 
|  | 111 | // Chunks must not move their storage after being created - use the node-based std::list. | 
| Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 112 | std::list<std::vector<uint8_t>> header_code_and_maps_chunks_; | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 113 | }; | 
|  | 114 |  | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 115 | // TODO: When heap reference poisoning works with all compilers in use, get rid of this. | 
|  | 116 | #define TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING_WITH_QUICK() \ | 
|  | 117 | if (kPoisonHeapReferences && GetCompilerKind() == Compiler::kQuick) { \ | 
|  | 118 | printf("WARNING: TEST DISABLED FOR HEAP REFERENCE POISONING WITH QUICK\n"); \ | 
|  | 119 | return; \ | 
|  | 120 | } | 
|  | 121 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 122 | // TODO: When read barrier works with all compilers in use, get rid of this. | 
|  | 123 | #define TEST_DISABLED_FOR_READ_BARRIER_WITH_QUICK() \ | 
|  | 124 | if (kUseReadBarrier && GetCompilerKind() == Compiler::kQuick) { \ | 
|  | 125 | printf("WARNING: TEST DISABLED FOR READ BARRIER WITH QUICK\n"); \ | 
|  | 126 | return; \ | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | // TODO: When read barrier works with all Optimizing back ends, get rid of this. | 
|  | 130 | #define TEST_DISABLED_FOR_READ_BARRIER_WITH_OPTIMIZING_FOR_UNSUPPORTED_INSTRUCTION_SETS() \ | 
|  | 131 | if (kUseReadBarrier && GetCompilerKind() == Compiler::kOptimizing) {                    \ | 
|  | 132 | switch (GetInstructionSet()) {                                                        \ | 
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 133 | case kArm64:                                                                        \ | 
| Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 134 | case kThumb2:                                                                       \ | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 135 | case kX86:                                                                          \ | 
|  | 136 | case kX86_64:                                                                       \ | 
|  | 137 | /* Instruction set has read barrier support. */                                   \ | 
|  | 138 | break;                                                                            \ | 
|  | 139 | \ | 
|  | 140 | default:                                                                            \ | 
|  | 141 | /* Instruction set does not have barrier support. */                              \ | 
|  | 142 | printf("WARNING: TEST DISABLED FOR READ BARRIER WITH OPTIMIZING "                 \ | 
|  | 143 | "FOR THIS INSTRUCTION SET\n");                                             \ | 
|  | 144 | return;                                                                           \ | 
|  | 145 | }                                                                                     \ | 
|  | 146 | } | 
|  | 147 |  | 
| Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 148 | // TODO: When non-PIC works with all compilers in use, get rid of this. | 
|  | 149 | #define TEST_DISABLED_FOR_NON_PIC_COMPILING_WITH_OPTIMIZING() \ | 
|  | 150 | if (GetCompilerKind() == Compiler::kOptimizing) { \ | 
|  | 151 | printf("WARNING: TEST DISABLED FOR NON-PIC COMPILING WITH OPTIMIZING\n"); \ | 
|  | 152 | return; \ | 
|  | 153 | } | 
|  | 154 |  | 
| Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 155 | }  // namespace art | 
|  | 156 |  | 
|  | 157 | #endif  // ART_COMPILER_COMMON_COMPILER_TEST_H_ |