blob: cd4c59101e7720d43dce79e40236a9c2efdd1a0d [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;
Andreas Gampedeae7db2017-05-30 09:56:41 -070028} // namespace jit
David Sehr9323e6e2016-09-13 08:58:35 -070029namespace mirror {
Vladimir Marko8d6768d2017-03-14 10:13:21 +000030 class ClassLoader;
David Sehr9323e6e2016-09-13 08:58:35 -070031 class DexCache;
Andreas Gampedeae7db2017-05-30 09:56:41 -070032} // namespace mirror
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000033
Mathieu Chartiere401d142015-04-22 13:56:20 -070034class ArtMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000035class CompilerDriver;
36class CompiledMethod;
David Sehr9323e6e2016-09-13 08:58:35 -070037template<class T> class Handle;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000038class OatWriter;
David Sehr7f019712016-10-26 16:09:13 -070039class Thread;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000040
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000041class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000042 public:
43 enum Kind {
44 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080045 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000046 };
47
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070048 enum JniOptimizationFlags {
Igor Murashkin367f3dd2016-09-01 17:00:24 -070049 kNone = 0x0,
50 kFastNative = 0x1,
51 kCriticalNative = 0x2,
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070052 };
53
Ian Rogers72d32622014-05-06 16:20:11 -070054 static Compiler* Create(CompilerDriver* driver, Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000055
David Brazdilee690a32014-12-01 17:04:16 +000056 virtual void Init() = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000057
Ian Rogers72d32622014-05-06 16:20:11 -070058 virtual void UnInit() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000059
Vladimir Markodf739842016-03-23 16:59:07 +000060 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
Andreas Gampe53c913b2014-08-12 23:19:23 -070061
Ian Rogers72d32622014-05-06 16:20:11 -070062 virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000063 uint32_t access_flags,
64 InvokeType invoke_type,
65 uint16_t class_def_idx,
66 uint32_t method_idx,
Vladimir Marko8d6768d2017-03-14 10:13:21 +000067 Handle<mirror::ClassLoader> class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070068 const DexFile& dex_file,
69 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000070
Ian Rogers72d32622014-05-06 16:20:11 -070071 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000072 uint32_t method_idx,
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070073 const DexFile& dex_file,
74 JniOptimizationFlags optimization_flags) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000075
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000076 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED,
77 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +000078 ArtMethod* method ATTRIBUTE_UNUSED,
79 bool osr ATTRIBUTE_UNUSED)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070080 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000081 return false;
82 }
83
Mathieu Chartiere401d142015-04-22 13:56:20 -070084 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070085 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000086
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000087 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
88 return maximum_compilation_time_before_warning_;
89 }
90
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000091 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000092
Mark Mendellae9fd932014-02-10 16:14:35 -080093 /*
94 * @brief Generate and return Dwarf CFI initialization, if supported by the
95 * backend.
96 * @param driver CompilerDriver for this compile.
97 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
98 * information.
99 * @note This is used for backtrace information in generated code.
100 */
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100101 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(
102 const CompilerDriver& driver ATTRIBUTE_UNUSED) const {
Mark Mendellae9fd932014-02-10 16:14:35 -0800103 return nullptr;
104 }
105
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000106 // Returns whether the method to compile is such a pathological case that
107 // it's not worth compiling.
108 static bool IsPathologicalCase(const DexFile::CodeItem& code_item,
109 uint32_t method_idx,
110 const DexFile& dex_file);
111
Ian Rogers72d32622014-05-06 16:20:11 -0700112 protected:
Roland Levillain3887c462015-08-12 18:15:42 +0100113 Compiler(CompilerDriver* driver, uint64_t warning) :
Ian Rogers72d32622014-05-06 16:20:11 -0700114 driver_(driver), maximum_compilation_time_before_warning_(warning) {
115 }
116
117 CompilerDriver* GetCompilerDriver() const {
118 return driver_;
119 }
120
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000121 private:
Ian Rogers72d32622014-05-06 16:20:11 -0700122 CompilerDriver* const driver_;
Ian Rogers3d504072014-03-01 09:16:49 -0800123 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000124
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000125 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000126};
127
128} // namespace art
129
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000130#endif // ART_COMPILER_COMPILER_H_