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 "oat_file.h" 26 27 namespace art { 28 namespace mirror { 29 class ClassLoader; 30 } // namespace mirror 31 32 class CompilerDriver; 33 class CompilerOptions; 34 class CumulativeLogger; 35 class DexFileToMethodInlinerMap; 36 class VerificationResults; 37 38 template<class T> class Handle; 39 40 class CommonCompilerTest : public CommonRuntimeTest { 41 public: 42 CommonCompilerTest(); 43 ~CommonCompilerTest(); 44 45 // Create an OatMethod based on pointers (for unit tests). 46 OatFile::OatMethod CreateOatMethod(const void* code); 47 48 void MakeExecutable(ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 49 50 static void MakeExecutable(const void* code_start, size_t code_length); 51 52 void MakeExecutable(mirror::ClassLoader* class_loader, const char* class_name) 53 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 54 55 protected: 56 virtual void SetUp(); 57 58 virtual void SetUpRuntimeOptions(RuntimeOptions *options); 59 60 // Get the set of image classes given to the compiler-driver in SetUp. Note: the compiler 61 // driver assumes ownership of the set, so the test should properly release the set. 62 virtual std::unordered_set<std::string>* GetImageClasses(); 63 64 // Get the set of compiled classes given to the compiler-driver in SetUp. Note: the compiler 65 // driver assumes ownership of the set, so the test should properly release the set. 66 virtual std::unordered_set<std::string>* GetCompiledClasses(); 67 68 // Get the set of compiled methods given to the compiler-driver in SetUp. Note: the compiler 69 // driver assumes ownership of the set, so the test should properly release the set. 70 virtual std::unordered_set<std::string>* GetCompiledMethods(); 71 72 virtual void TearDown(); 73 74 void CompileClass(mirror::ClassLoader* class_loader, const char* class_name) 75 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 76 77 void CompileMethod(ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 78 79 void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, 80 const char* method_name, const char* signature) 81 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 82 83 void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name, 84 const char* method_name, const char* signature) 85 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 86 87 void ReserveImageSpace(); 88 89 void UnreserveImageSpace(); 90 91 std::unique_ptr<CompilerOptions> compiler_options_; 92 std::unique_ptr<VerificationResults> verification_results_; 93 std::unique_ptr<DexFileToMethodInlinerMap> method_inliner_map_; 94 std::unique_ptr<CompilerDriver> compiler_driver_; 95 std::unique_ptr<CumulativeLogger> timer_; 96 std::unique_ptr<const InstructionSetFeatures> instruction_set_features_; 97 98 99 private: 100 std::unique_ptr<MemMap> image_reservation_; 101 102 // Chunks must not move their storage after being created - use the node-based std::list. 103 std::list<std::vector<uint8_t>> header_code_and_maps_chunks_; 104 }; 105 106 } // namespace art 107 108 #endif // ART_COMPILER_COMMON_COMPILER_TEST_H_ 109