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 "common_runtime_test.h"
24#include "oat_file.h"
25
26namespace art {
27namespace mirror {
28  class ClassLoader;
29}  // namespace mirror
30
31class CompilerDriver;
32class CompilerOptions;
33class CumulativeLogger;
34class DexFileToMethodInlinerMap;
35class VerificationResults;
36
37template<class T> class Handle;
38
39class CommonCompilerTest : public CommonRuntimeTest {
40 public:
41  CommonCompilerTest();
42  ~CommonCompilerTest();
43
44  // Create an OatMethod based on pointers (for unit tests).
45  OatFile::OatMethod CreateOatMethod(const void* code, const uint8_t* gc_map);
46
47  void MakeExecutable(mirror::ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
48
49  static void MakeExecutable(const void* code_start, size_t code_length);
50
51  void MakeExecutable(mirror::ClassLoader* class_loader, const char* class_name)
52      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
53
54 protected:
55  virtual void SetUp();
56
57  virtual void SetUpRuntimeOptions(RuntimeOptions *options);
58
59  virtual void TearDown();
60
61  void CompileClass(mirror::ClassLoader* class_loader, const char* class_name)
62      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
63
64  void CompileMethod(mirror::ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
65
66  void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
67                           const char* method_name, const char* signature)
68      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
69
70  void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
71                            const char* method_name, const char* signature)
72      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
73
74  void ReserveImageSpace();
75
76  void UnreserveImageSpace();
77
78  std::unique_ptr<CompilerOptions> compiler_options_;
79  std::unique_ptr<VerificationResults> verification_results_;
80  std::unique_ptr<DexFileToMethodInlinerMap> method_inliner_map_;
81  std::unique_ptr<CompilerCallbacks> callbacks_;
82  std::unique_ptr<CompilerDriver> compiler_driver_;
83  std::unique_ptr<CumulativeLogger> timer_;
84
85 private:
86  std::unique_ptr<MemMap> image_reservation_;
87
88  // Chunks must not move their storage after being created - use the node-based std::list.
89  std::list<std::vector<uint8_t>> header_code_and_maps_chunks_;
90};
91
92}  // namespace art
93
94#endif  // ART_COMPILER_COMMON_COMPILER_TEST_H_
95