blob: 3a9ce1bc0ed99b1081faf1785816f7cf35fd6a23 [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
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000025namespace jit {
26 class JitCodeCache;
27}
28
Mathieu Chartiere401d142015-04-22 13:56:20 -070029class ArtMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000030class Backend;
Ian Rogersb48b9eb2014-02-28 16:20:21 -080031struct CompilationUnit;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000032class CompilerDriver;
33class CompiledMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000034class OatWriter;
35
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000036class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000037 public:
38 enum Kind {
39 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080040 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000041 };
42
Ian Rogers72d32622014-05-06 16:20:11 -070043 static Compiler* Create(CompilerDriver* driver, Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000044
David Brazdilee690a32014-12-01 17:04:16 +000045 virtual void Init() = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000046
Ian Rogers72d32622014-05-06 16:20:11 -070047 virtual void UnInit() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000048
Andreas Gampe53c913b2014-08-12 23:19:23 -070049 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, CompilationUnit* cu)
50 const = 0;
51
Ian Rogers72d32622014-05-06 16:20:11 -070052 virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000053 uint32_t access_flags,
54 InvokeType invoke_type,
55 uint16_t class_def_idx,
56 uint32_t method_idx,
57 jobject class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070058 const DexFile& dex_file,
59 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000060
Ian Rogers72d32622014-05-06 16:20:11 -070061 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000062 uint32_t method_idx,
63 const DexFile& dex_file) const = 0;
64
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000065 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED,
66 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED,
67 ArtMethod* method ATTRIBUTE_UNUSED)
68 SHARED_REQUIRES(Locks::mutator_lock_) {
69 return false;
70 }
71
Mathieu Chartiere401d142015-04-22 13:56:20 -070072 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
Mathieu Chartier90443472015-07-16 20:32:27 -070073 SHARED_REQUIRES(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000074
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000075 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
76 return maximum_compilation_time_before_warning_;
77 }
78
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000079 virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
80
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000081 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000082
Mark Mendellae9fd932014-02-10 16:14:35 -080083 /*
84 * @brief Generate and return Dwarf CFI initialization, if supported by the
85 * backend.
86 * @param driver CompilerDriver for this compile.
87 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
88 * information.
89 * @note This is used for backtrace information in generated code.
90 */
Roland Levillain4b8f1ec2015-08-26 18:34:03 +010091 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(
92 const CompilerDriver& driver ATTRIBUTE_UNUSED) const {
Mark Mendellae9fd932014-02-10 16:14:35 -080093 return nullptr;
94 }
95
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000096 // Returns whether the method to compile is such a pathological case that
97 // it's not worth compiling.
98 static bool IsPathologicalCase(const DexFile::CodeItem& code_item,
99 uint32_t method_idx,
100 const DexFile& dex_file);
101
Ian Rogers72d32622014-05-06 16:20:11 -0700102 protected:
Roland Levillain3887c462015-08-12 18:15:42 +0100103 Compiler(CompilerDriver* driver, uint64_t warning) :
Ian Rogers72d32622014-05-06 16:20:11 -0700104 driver_(driver), maximum_compilation_time_before_warning_(warning) {
105 }
106
107 CompilerDriver* GetCompilerDriver() const {
108 return driver_;
109 }
110
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000111 private:
Ian Rogers72d32622014-05-06 16:20:11 -0700112 CompilerDriver* const driver_;
Ian Rogers3d504072014-03-01 09:16:49 -0800113 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000114
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000115 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000116};
117
118} // namespace art
119
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000120#endif // ART_COMPILER_COMPILER_H_