blob: 6ec39f960523a9e85ff43c39ad259ab3657dca56 [file] [log] [blame]
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +00001/*
2 * Copyright (C) 2014 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
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000017#ifndef ART_COMPILER_COMPILER_H_
18#define ART_COMPILER_COMPILER_H_
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000019
20#include "dex_file.h"
21#include "os.h"
22
23namespace art {
24
25class Backend;
Ian Rogersb48b9eb2014-02-28 16:20:21 -080026struct CompilationUnit;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000027class CompilerDriver;
28class CompiledMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000029class OatWriter;
30
31namespace mirror {
32 class ArtMethod;
33}
34
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000035class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000036 public:
37 enum Kind {
38 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080039 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000040 };
41
Ian Rogers72d32622014-05-06 16:20:11 -070042 static Compiler* Create(CompilerDriver* driver, Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000043
David Brazdilee690a32014-12-01 17:04:16 +000044 virtual void Init() = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000045
Ian Rogers72d32622014-05-06 16:20:11 -070046 virtual void UnInit() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000047
Andreas Gampe53c913b2014-08-12 23:19:23 -070048 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, CompilationUnit* cu)
49 const = 0;
50
Ian Rogers72d32622014-05-06 16:20:11 -070051 virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000052 uint32_t access_flags,
53 InvokeType invoke_type,
54 uint16_t class_def_idx,
55 uint32_t method_idx,
56 jobject class_loader,
57 const DexFile& dex_file) const = 0;
58
Ian Rogers72d32622014-05-06 16:20:11 -070059 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000060 uint32_t method_idx,
61 const DexFile& dex_file) const = 0;
62
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070063 virtual uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const
64 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000065
66 virtual bool WriteElf(art::File* file,
Ian Rogers3d504072014-03-01 09:16:49 -080067 OatWriter* oat_writer,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000068 const std::vector<const art::DexFile*>& dex_files,
69 const std::string& android_root,
Ian Rogers72d32622014-05-06 16:20:11 -070070 bool is_host) const
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000071 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
72
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000073 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
74 return maximum_compilation_time_before_warning_;
75 }
76
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000077 virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
78
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000079 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000080
Mark Mendellae9fd932014-02-10 16:14:35 -080081 /*
82 * @brief Generate and return Dwarf CFI initialization, if supported by the
83 * backend.
84 * @param driver CompilerDriver for this compile.
85 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
86 * information.
87 * @note This is used for backtrace information in generated code.
88 */
89 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver)
90 const {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070091 UNUSED(driver);
Mark Mendellae9fd932014-02-10 16:14:35 -080092 return nullptr;
93 }
94
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000095 // Returns whether the method to compile is such a pathological case that
96 // it's not worth compiling.
97 static bool IsPathologicalCase(const DexFile::CodeItem& code_item,
98 uint32_t method_idx,
99 const DexFile& dex_file);
100
Ian Rogers72d32622014-05-06 16:20:11 -0700101 protected:
102 explicit Compiler(CompilerDriver* driver, uint64_t warning) :
103 driver_(driver), maximum_compilation_time_before_warning_(warning) {
104 }
105
106 CompilerDriver* GetCompilerDriver() const {
107 return driver_;
108 }
109
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000110 private:
Ian Rogers72d32622014-05-06 16:20:11 -0700111 CompilerDriver* const driver_;
Ian Rogers3d504072014-03-01 09:16:49 -0800112 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000113
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000114 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000115};
116
117} // namespace art
118
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000119#endif // ART_COMPILER_COMPILER_H_