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 <vector>
22 
23 #include <jni.h>
24 
25 #include "arch/instruction_set.h"
26 #include "arch/instruction_set_features.h"
27 #include "common_runtime_test.h"
28 #include "compiler.h"
29 #include "oat_file.h"
30 
31 namespace art {
32 namespace mirror {
33 class ClassLoader;
34 }  // namespace mirror
35 
36 class CompiledMethod;
37 class CompilerOptions;
38 class CumulativeLogger;
39 class DexFile;
40 class TimingLogger;
41 class VerificationResults;
42 
43 template<class T> class Handle;
44 
45 class CommonCompilerTest : public CommonRuntimeTest {
46  public:
47   static std::unique_ptr<CompilerOptions> CreateCompilerOptions(InstructionSet instruction_set,
48                                                                 const std::string& variant);
49 
50   CommonCompilerTest();
51   ~CommonCompilerTest();
52 
53   void MakeExecutable(ArtMethod* method, const CompiledMethod* compiled_method)
54       REQUIRES_SHARED(Locks::mutator_lock_);
55 
56   static void MakeExecutable(const void* code_start, size_t code_length);
57 
58  protected:
59   void SetUp() override;
60 
61   void SetUpRuntimeOptions(RuntimeOptions* options) override;
62 
63   Compiler::Kind GetCompilerKind() const;
64   void SetCompilerKind(Compiler::Kind compiler_kind);
65 
GetCompilerFilter()66   virtual CompilerFilter::Filter GetCompilerFilter() const {
67     return CompilerFilter::kDefaultCompilerFilter;
68   }
69 
70   void TearDown() override;
71 
72   void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
73 
74   void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
75                            const char* method_name, const char* signature)
76       REQUIRES_SHARED(Locks::mutator_lock_);
77 
78   void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
79                             const char* method_name, const char* signature)
80       REQUIRES_SHARED(Locks::mutator_lock_);
81 
82   void ApplyInstructionSet();
83   void OverrideInstructionSetFeatures(InstructionSet instruction_set, const std::string& variant);
84 
85   void ClearBootImageOption();
86 
87   Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
88 
89   InstructionSet instruction_set_ =
90       (kRuntimeISA == InstructionSet::kArm) ? InstructionSet::kThumb2 : kRuntimeISA;
91   // Take the default set of instruction features from the build.
92   std::unique_ptr<const InstructionSetFeatures> instruction_set_features_
93       = InstructionSetFeatures::FromCppDefines();
94 
95   std::unique_ptr<CompilerOptions> compiler_options_;
96   std::unique_ptr<VerificationResults> verification_results_;
97 
98  private:
99   // Chunks must not move their storage after being created - use the node-based std::list.
100   std::list<std::vector<uint8_t>> header_code_and_maps_chunks_;
101 };
102 
103 }  // namespace art
104 
105 #endif  // ART_COMPILER_COMMON_COMPILER_TEST_H_
106