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 20#include <list> 21#include <unordered_set> 22#include <vector> 23 24#include "common_runtime_test.h" 25#include "compiler.h" 26#include "jit/offline_profiling_info.h" 27#include "oat_file.h" 28 29namespace art { 30namespace mirror { 31 class ClassLoader; 32} // namespace mirror 33 34class CompilerDriver; 35class CompilerOptions; 36class CumulativeLogger; 37class DexFileToMethodInlinerMap; 38class VerificationResults; 39 40template<class T> class Handle; 41 42class CommonCompilerTest : public CommonRuntimeTest { 43 public: 44 CommonCompilerTest(); 45 ~CommonCompilerTest(); 46 47 // Create an OatMethod based on pointers (for unit tests). 48 OatFile::OatMethod CreateOatMethod(const void* code); 49 50 void MakeExecutable(ArtMethod* method) SHARED_REQUIRES(Locks::mutator_lock_); 51 52 static void MakeExecutable(const void* code_start, size_t code_length); 53 54 void MakeExecutable(mirror::ClassLoader* class_loader, const char* class_name) 55 SHARED_REQUIRES(Locks::mutator_lock_); 56 57 protected: 58 virtual void SetUp(); 59 60 virtual void SetUpRuntimeOptions(RuntimeOptions* options); 61 62 Compiler::Kind GetCompilerKind() const; 63 void SetCompilerKind(Compiler::Kind compiler_kind); 64 65 InstructionSet GetInstructionSet() const; 66 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 79 virtual ProfileCompilationInfo* GetProfileCompilationInfo(); 80 81 virtual void TearDown(); 82 83 void CompileClass(mirror::ClassLoader* class_loader, const char* class_name) 84 SHARED_REQUIRES(Locks::mutator_lock_); 85 86 void CompileMethod(ArtMethod* method) SHARED_REQUIRES(Locks::mutator_lock_); 87 88 void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, 89 const char* method_name, const char* signature) 90 SHARED_REQUIRES(Locks::mutator_lock_); 91 92 void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, 93 const char* method_name, const char* signature) 94 SHARED_REQUIRES(Locks::mutator_lock_); 95 96 void CreateCompilerDriver(Compiler::Kind kind, InstructionSet isa, size_t number_of_threads = 2U); 97 98 void ReserveImageSpace(); 99 100 void UnreserveImageSpace(); 101 102 Compiler::Kind compiler_kind_ = Compiler::kOptimizing; 103 std::unique_ptr<CompilerOptions> compiler_options_; 104 std::unique_ptr<VerificationResults> verification_results_; 105 std::unique_ptr<DexFileToMethodInlinerMap> method_inliner_map_; 106 std::unique_ptr<CompilerDriver> compiler_driver_; 107 std::unique_ptr<CumulativeLogger> timer_; 108 std::unique_ptr<const InstructionSetFeatures> instruction_set_features_; 109 110 111 private: 112 std::unique_ptr<MemMap> image_reservation_; 113 114 // Chunks must not move their storage after being created - use the node-based std::list. 115 std::list<std::vector<uint8_t>> header_code_and_maps_chunks_; 116}; 117 118// TODO: When read barrier works with all tests, get rid of this. 119#define TEST_DISABLED_FOR_READ_BARRIER() \ 120 if (kUseReadBarrier) { \ 121 printf("WARNING: TEST DISABLED FOR READ BARRIER\n"); \ 122 return; \ 123 } 124 125// TODO: When read barrier works with all Optimizing back ends, get rid of this. 126#define TEST_DISABLED_FOR_READ_BARRIER_WITH_OPTIMIZING_FOR_UNSUPPORTED_INSTRUCTION_SETS() \ 127 if (kUseReadBarrier && GetCompilerKind() == Compiler::kOptimizing) { \ 128 switch (GetInstructionSet()) { \ 129 case kArm64: \ 130 case kThumb2: \ 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 144} // namespace art 145 146#endif // ART_COMPILER_COMMON_COMPILER_TEST_H_ 147