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 17 #ifndef ART_COMPILER_COMPILER_H_ 18 #define ART_COMPILER_COMPILER_H_ 19 20 #include "base/mutex.h" 21 #include "base/os.h" 22 #include "dex/invoke_type.h" 23 24 namespace art { 25 26 namespace dex { 27 struct CodeItem; 28 } // namespace dex 29 namespace jit { 30 class JitCodeCache; 31 class JitLogger; 32 class JitMemoryRegion; 33 } // namespace jit 34 namespace mirror { 35 class ClassLoader; 36 class DexCache; 37 } // namespace mirror 38 39 class ArtMethod; 40 class CompiledMethod; 41 class CompiledMethodStorage; 42 class CompilerOptions; 43 class DexFile; 44 template<class T> class Handle; 45 class Thread; 46 47 class Compiler { 48 public: 49 enum Kind { 50 kQuick, 51 kOptimizing 52 }; 53 54 static Compiler* Create(const CompilerOptions& compiler_options, 55 CompiledMethodStorage* storage, 56 Kind kind); 57 58 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0; 59 60 virtual CompiledMethod* Compile(const dex::CodeItem* code_item, 61 uint32_t access_flags, 62 InvokeType invoke_type, 63 uint16_t class_def_idx, 64 uint32_t method_idx, 65 Handle<mirror::ClassLoader> class_loader, 66 const DexFile& dex_file, 67 Handle<mirror::DexCache> dex_cache) const = 0; 68 69 virtual CompiledMethod* JniCompile(uint32_t access_flags, 70 uint32_t method_idx, 71 const DexFile& dex_file, 72 Handle<mirror::DexCache> dex_cache) const = 0; 73 JitCompile(Thread * self ATTRIBUTE_UNUSED,jit::JitCodeCache * code_cache ATTRIBUTE_UNUSED,jit::JitMemoryRegion * region ATTRIBUTE_UNUSED,ArtMethod * method ATTRIBUTE_UNUSED,bool baseline ATTRIBUTE_UNUSED,bool osr ATTRIBUTE_UNUSED,jit::JitLogger * jit_logger ATTRIBUTE_UNUSED)74 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED, 75 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED, 76 jit::JitMemoryRegion* region ATTRIBUTE_UNUSED, 77 ArtMethod* method ATTRIBUTE_UNUSED, 78 bool baseline ATTRIBUTE_UNUSED, 79 bool osr ATTRIBUTE_UNUSED, 80 jit::JitLogger* jit_logger ATTRIBUTE_UNUSED) 81 REQUIRES_SHARED(Locks::mutator_lock_) { 82 return false; 83 } 84 85 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const 86 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 87 GetMaximumCompilationTimeBeforeWarning()88 uint64_t GetMaximumCompilationTimeBeforeWarning() const { 89 return maximum_compilation_time_before_warning_; 90 } 91 ~Compiler()92 virtual ~Compiler() {} 93 94 // Returns whether the method to compile is such a pathological case that 95 // it's not worth compiling. 96 static bool IsPathologicalCase(const dex::CodeItem& code_item, 97 uint32_t method_idx, 98 const DexFile& dex_file); 99 100 protected: Compiler(const CompilerOptions & compiler_options,CompiledMethodStorage * storage,uint64_t warning)101 Compiler(const CompilerOptions& compiler_options, 102 CompiledMethodStorage* storage, 103 uint64_t warning) : 104 compiler_options_(compiler_options), 105 storage_(storage), 106 maximum_compilation_time_before_warning_(warning) { 107 } 108 GetCompilerOptions()109 const CompilerOptions& GetCompilerOptions() const { 110 return compiler_options_; 111 } 112 GetCompiledMethodStorage()113 CompiledMethodStorage* GetCompiledMethodStorage() const { 114 return storage_; 115 } 116 117 private: 118 const CompilerOptions& compiler_options_; 119 CompiledMethodStorage* const storage_; 120 const uint64_t maximum_compilation_time_before_warning_; 121 122 DISALLOW_COPY_AND_ASSIGN(Compiler); 123 }; 124 125 } // namespace art 126 127 #endif // ART_COMPILER_COMPILER_H_ 128