blob: 8d80a2da5c27d70830026af2d696eff2bb858779 [file] [log] [blame]
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -08001/*
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
Ian Rogerse63db272014-07-15 15:36:11 -070020#include <list>
Andreas Gampe70bef0d2015-04-15 02:37:28 -070021#include <unordered_set>
Ian Rogerse63db272014-07-15 15:36:11 -070022#include <vector>
23
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080024#include "common_runtime_test.h"
Ian Rogerse63db272014-07-15 15:36:11 -070025#include "oat_file.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080026
27namespace art {
Ian Rogerse63db272014-07-15 15:36:11 -070028namespace mirror {
29 class ClassLoader;
30} // namespace mirror
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080031
Ian Rogerse63db272014-07-15 15:36:11 -070032class CompilerDriver;
33class CompilerOptions;
34class CumulativeLogger;
35class DexFileToMethodInlinerMap;
36class VerificationResults;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080037
Ian Rogerse63db272014-07-15 15:36:11 -070038template<class T> class Handle;
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +070039
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080040class CommonCompilerTest : public CommonRuntimeTest {
41 public:
Ian Rogerse63db272014-07-15 15:36:11 -070042 CommonCompilerTest();
43 ~CommonCompilerTest();
44
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080045 // Create an OatMethod based on pointers (for unit tests).
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080046 OatFile::OatMethod CreateOatMethod(const void* code);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080047
Ian Rogerse63db272014-07-15 15:36:11 -070048 void MakeExecutable(mirror::ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080049
Ian Rogerse63db272014-07-15 15:36:11 -070050 static void MakeExecutable(const void* code_start, size_t code_length);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080051
52 void MakeExecutable(mirror::ClassLoader* class_loader, const char* class_name)
Ian Rogerse63db272014-07-15 15:36:11 -070053 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080054
55 protected:
Ian Rogerse63db272014-07-15 15:36:11 -070056 virtual void SetUp();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080057
Ian Rogerse63db272014-07-15 15:36:11 -070058 virtual void SetUpRuntimeOptions(RuntimeOptions *options);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080059
Andreas Gampe70bef0d2015-04-15 02:37:28 -070060 // 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
Ian Rogerse63db272014-07-15 15:36:11 -070072 virtual void TearDown();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080073
74 void CompileClass(mirror::ClassLoader* class_loader, const char* class_name)
Ian Rogerse63db272014-07-15 15:36:11 -070075 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080076
Ian Rogerse63db272014-07-15 15:36:11 -070077 void CompileMethod(mirror::ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080078
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070079 void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080080 const char* method_name, const char* signature)
Ian Rogerse63db272014-07-15 15:36:11 -070081 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080082
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070083 void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080084 const char* method_name, const char* signature)
Ian Rogerse63db272014-07-15 15:36:11 -070085 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080086
Ian Rogerse63db272014-07-15 15:36:11 -070087 void ReserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080088
Ian Rogerse63db272014-07-15 15:36:11 -070089 void UnreserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080090
Ian Rogers700a4022014-05-19 16:49:03 -070091 std::unique_ptr<CompilerOptions> compiler_options_;
92 std::unique_ptr<VerificationResults> verification_results_;
93 std::unique_ptr<DexFileToMethodInlinerMap> method_inliner_map_;
Ian Rogers700a4022014-05-19 16:49:03 -070094 std::unique_ptr<CompilerDriver> compiler_driver_;
95 std::unique_ptr<CumulativeLogger> timer_;
Ian Rogers6f3dbba2014-10-14 17:41:57 -070096 std::unique_ptr<const InstructionSetFeatures> instruction_set_features_;
97
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080098
99 private:
Ian Rogers700a4022014-05-19 16:49:03 -0700100 std::unique_ptr<MemMap> image_reservation_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100101
102 // Chunks must not move their storage after being created - use the node-based std::list.
Ian Rogers700a4022014-05-19 16:49:03 -0700103 std::list<std::vector<uint8_t>> header_code_and_maps_chunks_;
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800104};
105
106} // namespace art
107
108#endif // ART_COMPILER_COMMON_COMPILER_TEST_H_