Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 1 | /* |
| 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 Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 17 | #ifndef ART_COMPILER_COMPILER_H_ |
| 18 | #define ART_COMPILER_COMPILER_H_ |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 19 | |
| 20 | #include "dex_file.h" |
| 21 | #include "os.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 25 | class ArtMethod; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 26 | class Backend; |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 27 | struct CompilationUnit; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 28 | class CompilerDriver; |
| 29 | class CompiledMethod; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 30 | class OatWriter; |
| 31 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 32 | class Compiler { |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 33 | public: |
| 34 | enum Kind { |
| 35 | kQuick, |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 36 | kOptimizing |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 39 | static Compiler* Create(CompilerDriver* driver, Kind kind); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 40 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 41 | virtual void Init() = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 42 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 43 | virtual void UnInit() const = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 44 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 45 | virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, CompilationUnit* cu) |
| 46 | const = 0; |
| 47 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 48 | virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 49 | uint32_t access_flags, |
| 50 | InvokeType invoke_type, |
| 51 | uint16_t class_def_idx, |
| 52 | uint32_t method_idx, |
| 53 | jobject class_loader, |
| 54 | const DexFile& dex_file) const = 0; |
| 55 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 56 | virtual CompiledMethod* JniCompile(uint32_t access_flags, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 57 | uint32_t method_idx, |
| 58 | const DexFile& dex_file) const = 0; |
| 59 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 60 | virtual uintptr_t GetEntryPointOf(ArtMethod* method) const |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 61 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 62 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 63 | uint64_t GetMaximumCompilationTimeBeforeWarning() const { |
| 64 | return maximum_compilation_time_before_warning_; |
| 65 | } |
| 66 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 67 | virtual void InitCompilationUnit(CompilationUnit& cu) const = 0; |
| 68 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 69 | virtual ~Compiler() {} |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 70 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 71 | /* |
| 72 | * @brief Generate and return Dwarf CFI initialization, if supported by the |
| 73 | * backend. |
| 74 | * @param driver CompilerDriver for this compile. |
| 75 | * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF |
| 76 | * information. |
| 77 | * @note This is used for backtrace information in generated code. |
| 78 | */ |
| 79 | virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver) |
| 80 | const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 81 | UNUSED(driver); |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 82 | return nullptr; |
| 83 | } |
| 84 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 85 | // Returns whether the method to compile is such a pathological case that |
| 86 | // it's not worth compiling. |
| 87 | static bool IsPathologicalCase(const DexFile::CodeItem& code_item, |
| 88 | uint32_t method_idx, |
| 89 | const DexFile& dex_file); |
| 90 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 91 | protected: |
| 92 | explicit Compiler(CompilerDriver* driver, uint64_t warning) : |
| 93 | driver_(driver), maximum_compilation_time_before_warning_(warning) { |
| 94 | } |
| 95 | |
| 96 | CompilerDriver* GetCompilerDriver() const { |
| 97 | return driver_; |
| 98 | } |
| 99 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 100 | private: |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 101 | CompilerDriver* const driver_; |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 102 | const uint64_t maximum_compilation_time_before_warning_; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 103 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(Compiler); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | } // namespace art |
| 108 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 109 | #endif // ART_COMPILER_COMPILER_H_ |