compiler.h revision 956af0f0cb05422e38c1d22cbef309d16b8a1a12
1f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray/* 2f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 3f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * 4f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * you may not use this file except in compliance with the License. 6f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * You may obtain a copy of the License at 7f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * 8f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * 10f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * See the License for the specific language governing permissions and 14f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray * limitations under the License. 15f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray */ 16f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 17b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#ifndef ART_COMPILER_COMPILER_H_ 18b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#define ART_COMPILER_COMPILER_H_ 19f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 20f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray#include "dex_file.h" 21f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray#include "os.h" 22f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 23f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffraynamespace art { 24f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 25f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass Backend; 26b48b9eb6d181a1f52e2e605cf26a21505f1d46edIan Rogersstruct CompilationUnit; 27f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass CompilerDriver; 28f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass CompiledMethod; 29f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffrayclass OatWriter; 30f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 31f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffraynamespace mirror { 32f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray class ArtMethod; 33f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray} 34f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 35b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffrayclass Compiler { 36f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray public: 37f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray enum Kind { 38f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray kQuick, 39956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes kOptimizing 40f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray }; 41f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 4272d32629303f8f39362a4099481f48646aed042fIan Rogers static Compiler* Create(CompilerDriver* driver, Kind kind); 43f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 4472d32629303f8f39362a4099481f48646aed042fIan Rogers virtual void Init() const = 0; 45f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 4672d32629303f8f39362a4099481f48646aed042fIan Rogers virtual void UnInit() const = 0; 47f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 4853c913bb71b218714823c8c87a1f92830c336f61Andreas Gampe virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, CompilationUnit* cu) 4953c913bb71b218714823c8c87a1f92830c336f61Andreas Gampe const = 0; 5053c913bb71b218714823c8c87a1f92830c336f61Andreas Gampe 5172d32629303f8f39362a4099481f48646aed042fIan Rogers virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item, 52f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray uint32_t access_flags, 53f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray InvokeType invoke_type, 54f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray uint16_t class_def_idx, 55f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray uint32_t method_idx, 56f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray jobject class_loader, 57f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray const DexFile& dex_file) const = 0; 58f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 5972d32629303f8f39362a4099481f48646aed042fIan Rogers virtual CompiledMethod* JniCompile(uint32_t access_flags, 60f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray uint32_t method_idx, 61f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray const DexFile& dex_file) const = 0; 62f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 63b0fa5dc7769c1e054032f39de0a3f6d6dd06f8cfIan Rogers virtual uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const 64b0fa5dc7769c1e054032f39de0a3f6d6dd06f8cfIan Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; 65f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 66f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray virtual bool WriteElf(art::File* file, 673d504075f7c1204d581923460754bf6d3714b13fIan Rogers OatWriter* oat_writer, 68f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray const std::vector<const art::DexFile*>& dex_files, 69f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray const std::string& android_root, 7072d32629303f8f39362a4099481f48646aed042fIan Rogers bool is_host) const 71f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; 72f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 7372d32629303f8f39362a4099481f48646aed042fIan Rogers virtual Backend* GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const = 0; 74f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 75f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray uint64_t GetMaximumCompilationTimeBeforeWarning() const { 76f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray return maximum_compilation_time_before_warning_; 77f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray } 78f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 79f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray virtual void InitCompilationUnit(CompilationUnit& cu) const = 0; 80f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 81b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray virtual ~Compiler() {} 82f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 83ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell /* 84ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell * @brief Generate and return Dwarf CFI initialization, if supported by the 85ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell * backend. 86ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell * @param driver CompilerDriver for this compile. 87ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF 88ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell * information. 89ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell * @note This is used for backtrace information in generated code. 90ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell */ 91ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver) 92ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell const { 936a3c1fcb4ba42ad4d5d142c17a3712a6ddd3866fIan Rogers UNUSED(driver); 94ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell return nullptr; 95ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell } 96ae9fd93c39a341e2dffe15c61cc7d9e841fa92c4Mark Mendell 97b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray // Returns whether the method to compile is such a pathological case that 98b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray // it's not worth compiling. 99b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray static bool IsPathologicalCase(const DexFile::CodeItem& code_item, 100b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray uint32_t method_idx, 101b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray const DexFile& dex_file); 102b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray 10372d32629303f8f39362a4099481f48646aed042fIan Rogers protected: 10472d32629303f8f39362a4099481f48646aed042fIan Rogers explicit Compiler(CompilerDriver* driver, uint64_t warning) : 10572d32629303f8f39362a4099481f48646aed042fIan Rogers driver_(driver), maximum_compilation_time_before_warning_(warning) { 10672d32629303f8f39362a4099481f48646aed042fIan Rogers } 10772d32629303f8f39362a4099481f48646aed042fIan Rogers 10872d32629303f8f39362a4099481f48646aed042fIan Rogers CompilerDriver* GetCompilerDriver() const { 10972d32629303f8f39362a4099481f48646aed042fIan Rogers return driver_; 11072d32629303f8f39362a4099481f48646aed042fIan Rogers } 11172d32629303f8f39362a4099481f48646aed042fIan Rogers 112f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray private: 11372d32629303f8f39362a4099481f48646aed042fIan Rogers CompilerDriver* const driver_; 1143d504075f7c1204d581923460754bf6d3714b13fIan Rogers const uint64_t maximum_compilation_time_before_warning_; 115f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 116b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(Compiler); 117f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray}; 118f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 119f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray} // namespace art 120f5df8974173124faddb8e2b6a331959afdb94fdfNicolas Geoffray 121b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#endif // ART_COMPILER_COMPILER_H_ 122