blob: 2ca0b77a7380b43b5a1d3d3a6b2cc480cbad172a [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"
David Sehr7f019712016-10-26 16:09:13 -070021#include "base/mutex.h"
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000022#include "os.h"
23
24namespace art {
25
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000026namespace jit {
27 class JitCodeCache;
28}
David Sehr9323e6e2016-09-13 08:58:35 -070029namespace mirror {
30 class DexCache;
31}
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000032
Mathieu Chartiere401d142015-04-22 13:56:20 -070033class ArtMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000034class CompilerDriver;
35class CompiledMethod;
David Sehr9323e6e2016-09-13 08:58:35 -070036template<class T> class Handle;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000037class OatWriter;
David Sehr7f019712016-10-26 16:09:13 -070038class Thread;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000039
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000040class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000041 public:
42 enum Kind {
43 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080044 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000045 };
46
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070047 enum JniOptimizationFlags {
Igor Murashkin367f3dd2016-09-01 17:00:24 -070048 kNone = 0x0,
49 kFastNative = 0x1,
50 kCriticalNative = 0x2,
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070051 };
52
Ian Rogers72d32622014-05-06 16:20:11 -070053 static Compiler* Create(CompilerDriver* driver, Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000054
David Brazdilee690a32014-12-01 17:04:16 +000055 virtual void Init() = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000056
Ian Rogers72d32622014-05-06 16:20:11 -070057 virtual void UnInit() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000058
Vladimir Markodf739842016-03-23 16:59:07 +000059 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
Andreas Gampe53c913b2014-08-12 23:19:23 -070060
Ian Rogers72d32622014-05-06 16:20:11 -070061 virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000062 uint32_t access_flags,
63 InvokeType invoke_type,
64 uint16_t class_def_idx,
65 uint32_t method_idx,
66 jobject class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070067 const DexFile& dex_file,
68 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000069
Ian Rogers72d32622014-05-06 16:20:11 -070070 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000071 uint32_t method_idx,
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070072 const DexFile& dex_file,
73 JniOptimizationFlags optimization_flags) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000074
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000075 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED,
76 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +000077 ArtMethod* method ATTRIBUTE_UNUSED,
78 bool osr ATTRIBUTE_UNUSED)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070079 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000080 return false;
81 }
82
Mathieu Chartiere401d142015-04-22 13:56:20 -070083 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070084 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000085
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000086 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
87 return maximum_compilation_time_before_warning_;
88 }
89
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000090 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000091
Mark Mendellae9fd932014-02-10 16:14:35 -080092 /*
93 * @brief Generate and return Dwarf CFI initialization, if supported by the
94 * backend.
95 * @param driver CompilerDriver for this compile.
96 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
97 * information.
98 * @note This is used for backtrace information in generated code.
99 */
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100100 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(
101 const CompilerDriver& driver ATTRIBUTE_UNUSED) const {
Mark Mendellae9fd932014-02-10 16:14:35 -0800102 return nullptr;
103 }
104
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000105 // Returns whether the method to compile is such a pathological case that
106 // it's not worth compiling.
107 static bool IsPathologicalCase(const DexFile::CodeItem& code_item,
108 uint32_t method_idx,
109 const DexFile& dex_file);
110
Ian Rogers72d32622014-05-06 16:20:11 -0700111 protected:
Roland Levillain3887c462015-08-12 18:15:42 +0100112 Compiler(CompilerDriver* driver, uint64_t warning) :
Ian Rogers72d32622014-05-06 16:20:11 -0700113 driver_(driver), maximum_compilation_time_before_warning_(warning) {
114 }
115
116 CompilerDriver* GetCompilerDriver() const {
117 return driver_;
118 }
119
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000120 private:
Ian Rogers72d32622014-05-06 16:20:11 -0700121 CompilerDriver* const driver_;
Ian Rogers3d504072014-03-01 09:16:49 -0800122 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000123
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000124 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000125};
126
127} // namespace art
128
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000129#endif // ART_COMPILER_COMPILER_H_