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" |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 26 | #include "jit/offline_profiling_info.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 27 | #include "oat_file.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 28 | |
| 29 | namespace art { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 30 | namespace mirror { |
| 31 | class ClassLoader; |
| 32 | } // namespace mirror |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 33 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 34 | class CompilerDriver; |
| 35 | class CompilerOptions; |
| 36 | class CumulativeLogger; |
| 37 | class DexFileToMethodInlinerMap; |
| 38 | class VerificationResults; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 39 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 40 | template<class T> class Handle; |
Dmitry Petrochenko | f0972a4 | 2014-05-16 17:43:39 +0700 | [diff] [blame] | 41 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 42 | class CommonCompilerTest : public CommonRuntimeTest { |
| 43 | public: |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 44 | CommonCompilerTest(); |
| 45 | ~CommonCompilerTest(); |
| 46 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 47 | // Create an OatMethod based on pointers (for unit tests). |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 48 | OatFile::OatMethod CreateOatMethod(const void* code); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 49 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 50 | void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 51 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 52 | static void MakeExecutable(const void* code_start, size_t code_length); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 53 | |
| 54 | void MakeExecutable(mirror::ClassLoader* class_loader, const char* class_name) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 55 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 56 | |
| 57 | protected: |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 58 | virtual void SetUp(); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 59 | |
Roland Levillain | bbcc01a | 2015-06-30 14:16:48 +0100 | [diff] [blame] | 60 | virtual void SetUpRuntimeOptions(RuntimeOptions* options); |
| 61 | |
| 62 | Compiler::Kind GetCompilerKind() const; |
| 63 | void SetCompilerKind(Compiler::Kind compiler_kind); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 64 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 65 | InstructionSet GetInstructionSet() const; |
| 66 | |
Andreas Gampe | 70bef0d | 2015-04-15 02:37:28 -0700 | [diff] [blame] | 67 | // 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 Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 79 | virtual ProfileCompilationInfo* GetProfileCompilationInfo(); |
| 80 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 81 | virtual void TearDown(); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 82 | |
| 83 | void CompileClass(mirror::ClassLoader* class_loader, const char* class_name) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 84 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 85 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 86 | void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 87 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 88 | void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 89 | const char* method_name, const char* signature) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 90 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 91 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 92 | void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 93 | const char* method_name, const char* signature) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 94 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 95 | |
Andreas Gampe | 3f41a01 | 2016-02-18 16:53:41 -0800 | [diff] [blame] | 96 | void CreateCompilerDriver(Compiler::Kind kind, InstructionSet isa, size_t number_of_threads = 2U); |
Mathieu Chartier | ceb07b3 | 2015-12-10 09:33:21 -0800 | [diff] [blame] | 97 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 98 | void ReserveImageSpace(); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 99 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 100 | void UnreserveImageSpace(); |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 101 | |
Nicolas Geoffray | 409e809 | 2015-10-01 10:32:19 +0100 | [diff] [blame] | 102 | Compiler::Kind compiler_kind_ = Compiler::kOptimizing; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 103 | std::unique_ptr<CompilerOptions> compiler_options_; |
| 104 | std::unique_ptr<VerificationResults> verification_results_; |
| 105 | std::unique_ptr<DexFileToMethodInlinerMap> method_inliner_map_; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 106 | std::unique_ptr<CompilerDriver> compiler_driver_; |
| 107 | std::unique_ptr<CumulativeLogger> timer_; |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 108 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features_; |
| 109 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 110 | |
| 111 | private: |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 112 | std::unique_ptr<MemMap> image_reservation_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 113 | |
| 114 | // 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] | 115 | std::list<std::vector<uint8_t>> header_code_and_maps_chunks_; |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 116 | }; |
| 117 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 118 | // 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 Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 122 | case kArm64: \ |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 123 | case kThumb2: \ |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 124 | 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 Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 137 | } // namespace art |
| 138 | |
| 139 | #endif // ART_COMPILER_COMMON_COMPILER_TEST_H_ |