blob: 487a27fec0ccdcad16631e8b34ea084858c95288 [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 CompilerDriver;
31class CompiledMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000032class OatWriter;
33
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000034class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000035 public:
36 enum Kind {
37 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080038 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000039 };
40
Ian Rogers72d32622014-05-06 16:20:11 -070041 static Compiler* Create(CompilerDriver* driver, Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000042
David Brazdilee690a32014-12-01 17:04:16 +000043 virtual void Init() = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000044
Ian Rogers72d32622014-05-06 16:20:11 -070045 virtual void UnInit() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000046
Vladimir Markodf739842016-03-23 16:59:07 +000047 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
Andreas Gampe53c913b2014-08-12 23:19:23 -070048
Ian Rogers72d32622014-05-06 16:20:11 -070049 virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000050 uint32_t access_flags,
51 InvokeType invoke_type,
52 uint16_t class_def_idx,
53 uint32_t method_idx,
54 jobject class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070055 const DexFile& dex_file,
56 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000057
Ian Rogers72d32622014-05-06 16:20:11 -070058 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000059 uint32_t method_idx,
60 const DexFile& dex_file) const = 0;
61
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000062 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED,
63 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +000064 ArtMethod* method ATTRIBUTE_UNUSED,
65 bool osr ATTRIBUTE_UNUSED)
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000066 SHARED_REQUIRES(Locks::mutator_lock_) {
67 return false;
68 }
69
Mathieu Chartiere401d142015-04-22 13:56:20 -070070 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
Mathieu Chartier90443472015-07-16 20:32:27 -070071 SHARED_REQUIRES(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000072
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000073 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
74 return maximum_compilation_time_before_warning_;
75 }
76
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000077 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000078
Mark Mendellae9fd932014-02-10 16:14:35 -080079 /*
80 * @brief Generate and return Dwarf CFI initialization, if supported by the
81 * backend.
82 * @param driver CompilerDriver for this compile.
83 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
84 * information.
85 * @note This is used for backtrace information in generated code.
86 */
Roland Levillain4b8f1ec2015-08-26 18:34:03 +010087 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(
88 const CompilerDriver& driver ATTRIBUTE_UNUSED) const {
Mark Mendellae9fd932014-02-10 16:14:35 -080089 return nullptr;
90 }
91
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000092 // Returns whether the method to compile is such a pathological case that
93 // it's not worth compiling.
94 static bool IsPathologicalCase(const DexFile::CodeItem& code_item,
95 uint32_t method_idx,
96 const DexFile& dex_file);
97
Ian Rogers72d32622014-05-06 16:20:11 -070098 protected:
Roland Levillain3887c462015-08-12 18:15:42 +010099 Compiler(CompilerDriver* driver, uint64_t warning) :
Ian Rogers72d32622014-05-06 16:20:11 -0700100 driver_(driver), maximum_compilation_time_before_warning_(warning) {
101 }
102
103 CompilerDriver* GetCompilerDriver() const {
104 return driver_;
105 }
106
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000107 private:
Ian Rogers72d32622014-05-06 16:20:11 -0700108 CompilerDriver* const driver_;
Ian Rogers3d504072014-03-01 09:16:49 -0800109 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000110
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000111 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000112};
113
114} // namespace art
115
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000116#endif // ART_COMPILER_COMPILER_H_