Home | History | Annotate | Download | only in compiler
      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/profile_compilation_info.h"
     27 #include "oat_file.h"
     28 
     29 namespace art {
     30 namespace mirror {
     31   class ClassLoader;
     32 }  // namespace mirror
     33 
     34 class CompilerDriver;
     35 class CompilerOptions;
     36 class CumulativeLogger;
     37 class VerificationResults;
     38 
     39 template<class T> class Handle;
     40 
     41 class CommonCompilerTest : public CommonRuntimeTest {
     42  public:
     43   CommonCompilerTest();
     44   ~CommonCompilerTest();
     45 
     46   // Create an OatMethod based on pointers (for unit tests).
     47   OatFile::OatMethod CreateOatMethod(const void* code);
     48 
     49   void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
     50 
     51   static void MakeExecutable(const void* code_start, size_t code_length);
     52 
     53   void MakeExecutable(ObjPtr<mirror::ClassLoader> class_loader, const char* class_name)
     54       REQUIRES_SHARED(Locks::mutator_lock_);
     55 
     56  protected:
     57   virtual void SetUp();
     58 
     59   virtual void SetUpRuntimeOptions(RuntimeOptions* options);
     60 
     61   Compiler::Kind GetCompilerKind() const;
     62   void SetCompilerKind(Compiler::Kind compiler_kind);
     63 
     64   InstructionSet GetInstructionSet() const;
     65 
     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 
     78   virtual ProfileCompilationInfo* GetProfileCompilationInfo();
     79 
     80   virtual CompilerFilter::Filter GetCompilerFilter() const {
     81     return CompilerFilter::kDefaultCompilerFilter;
     82   }
     83 
     84   virtual void TearDown();
     85 
     86   void CompileClass(mirror::ClassLoader* class_loader, const char* class_name)
     87       REQUIRES_SHARED(Locks::mutator_lock_);
     88 
     89   void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
     90 
     91   void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
     92                            const char* method_name, const char* signature)
     93       REQUIRES_SHARED(Locks::mutator_lock_);
     94 
     95   void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
     96                             const char* method_name, const char* signature)
     97       REQUIRES_SHARED(Locks::mutator_lock_);
     98 
     99   void CreateCompilerDriver(Compiler::Kind kind, InstructionSet isa, size_t number_of_threads = 2U);
    100 
    101   void ReserveImageSpace();
    102 
    103   void UnreserveImageSpace();
    104 
    105   Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
    106   std::unique_ptr<CompilerOptions> compiler_options_;
    107   std::unique_ptr<VerificationResults> verification_results_;
    108   std::unique_ptr<CompilerDriver> compiler_driver_;
    109   std::unique_ptr<CumulativeLogger> timer_;
    110   std::unique_ptr<const InstructionSetFeatures> instruction_set_features_;
    111 
    112 
    113  private:
    114   std::unique_ptr<MemMap> image_reservation_;
    115 
    116   // Chunks must not move their storage after being created - use the node-based std::list.
    117   std::list<std::vector<uint8_t>> header_code_and_maps_chunks_;
    118 };
    119 
    120 }  // namespace art
    121 
    122 #endif  // ART_COMPILER_COMMON_COMPILER_TEST_H_
    123