blob: 9b4dbe02e2846451b7f620a71e9a03e68d6b72a1 [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
Mathieu Chartiere401d142015-04-22 13:56:20 -070025class ArtMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000026class Backend;
Ian Rogersb48b9eb2014-02-28 16:20:21 -080027struct CompilationUnit;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000028class CompilerDriver;
29class CompiledMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000030class OatWriter;
31
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000032class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000033 public:
34 enum Kind {
35 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080036 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000037 };
38
Ian Rogers72d32622014-05-06 16:20:11 -070039 static Compiler* Create(CompilerDriver* driver, Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000040
David Brazdilee690a32014-12-01 17:04:16 +000041 virtual void Init() = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000042
Ian Rogers72d32622014-05-06 16:20:11 -070043 virtual void UnInit() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000044
Andreas Gampe53c913b2014-08-12 23:19:23 -070045 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, CompilationUnit* cu)
46 const = 0;
47
Ian Rogers72d32622014-05-06 16:20:11 -070048 virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000049 uint32_t access_flags,
50 InvokeType invoke_type,
51 uint16_t class_def_idx,
52 uint32_t method_idx,
53 jobject class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070054 const DexFile& dex_file,
55 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000056
Ian Rogers72d32622014-05-06 16:20:11 -070057 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000058 uint32_t method_idx,
59 const DexFile& dex_file) const = 0;
60
Mathieu Chartiere401d142015-04-22 13:56:20 -070061 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
Mathieu Chartier90443472015-07-16 20:32:27 -070062 SHARED_REQUIRES(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000063
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000064 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
65 return maximum_compilation_time_before_warning_;
66 }
67
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000068 virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
69
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000070 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000071
Mark Mendellae9fd932014-02-10 16:14:35 -080072 /*
73 * @brief Generate and return Dwarf CFI initialization, if supported by the
74 * backend.
75 * @param driver CompilerDriver for this compile.
76 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
77 * information.
78 * @note This is used for backtrace information in generated code.
79 */
80 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver)
81 const {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070082 UNUSED(driver);
Mark Mendellae9fd932014-02-10 16:14:35 -080083 return nullptr;
84 }
85
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000086 // Returns whether the method to compile is such a pathological case that
87 // it's not worth compiling.
88 static bool IsPathologicalCase(const DexFile::CodeItem& code_item,
89 uint32_t method_idx,
90 const DexFile& dex_file);
91
Ian Rogers72d32622014-05-06 16:20:11 -070092 protected:
Roland Levillain3887c462015-08-12 18:15:42 +010093 Compiler(CompilerDriver* driver, uint64_t warning) :
Ian Rogers72d32622014-05-06 16:20:11 -070094 driver_(driver), maximum_compilation_time_before_warning_(warning) {
95 }
96
97 CompilerDriver* GetCompilerDriver() const {
98 return driver_;
99 }
100
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000101 private:
Ian Rogers72d32622014-05-06 16:20:11 -0700102 CompilerDriver* const driver_;
Ian Rogers3d504072014-03-01 09:16:49 -0800103 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000104
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000105 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000106};
107
108} // namespace art
109
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000110#endif // ART_COMPILER_COMPILER_H_