Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_COMPILER_H_ |
| 4 | #define ART_SRC_COMPILER_H_ |
| 5 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 6 | #include "compiled_method.h" |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 7 | #include "constants.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 8 | #include "dex_file.h" |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 9 | #include "jni_compiler.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 10 | #include "oat_file.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 11 | #include "object.h" |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 12 | #include "runtime.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 13 | #include "unordered_map.h" |
Ian Rogers | d6b1f61 | 2011-09-27 13:38:14 -0700 | [diff] [blame] | 14 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 15 | namespace art { |
| 16 | |
| 17 | class Compiler { |
| 18 | public: |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 19 | explicit Compiler(InstructionSet instruction_set); |
| 20 | |
| 21 | ~Compiler(); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 22 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 23 | // Compile all Methods of all the Classes of all the DexFiles that are part of a ClassLoader. |
| 24 | void CompileAll(const ClassLoader* class_loader); |
| 25 | |
| 26 | // Compile a single Method |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 27 | void CompileOne(const Method* method); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 28 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 29 | void SetVerbose(bool verbose) { |
| 30 | verbose_ = verbose; |
| 31 | } |
| 32 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 33 | InstructionSet GetInstructionSet() const { |
| 34 | return instruction_set_; |
| 35 | } |
| 36 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 37 | bool IsVerbose() const { |
| 38 | return verbose_; |
| 39 | } |
| 40 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 41 | // Stub to throw AbstractMethodError |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 42 | static ByteArray* CreateAbstractMethodErrorStub(InstructionSet instruction_set); |
| 43 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 44 | |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 45 | // Generate the trampoline that's invoked by unresolved direct methods |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 46 | static ByteArray* CreateResolutionStub(InstructionSet instruction_set, |
| 47 | Runtime::TrampolineType type); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 48 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 49 | const CompiledMethod* GetCompiledMethod(const Method* method) const; |
| 50 | const CompiledInvokeStub* GetCompiledInvokeStub(const Method* method) const; |
| 51 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 52 | private: |
| 53 | // Attempt to resolve all type, methods, fields, and strings |
| 54 | // referenced from code in the dex file following PathClassLoader |
| 55 | // ordering semantics. |
| 56 | void Resolve(const ClassLoader* class_loader); |
| 57 | void ResolveDexFile(const ClassLoader* class_loader, const DexFile& dex_file); |
| 58 | |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 59 | void Verify(const ClassLoader* class_loader); |
| 60 | void VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file); |
| 61 | |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 62 | void InitializeClassesWithoutClinit(const ClassLoader* class_loader); |
| 63 | void InitializeClassesWithoutClinit(const ClassLoader* class_loader, const DexFile& dex_file); |
| 64 | |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 65 | void Compile(const ClassLoader* class_loader); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 66 | void CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 67 | void CompileClass(const Class* klass); |
| 68 | void CompileMethod(const Method* method); |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 69 | |
| 70 | // After compiling, walk all the DexCaches and set the code and |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 71 | // method pointers of CodeAndDirectMethods entries in the DexCaches. |
| 72 | void SetCodeAndDirectMethods(const ClassLoader* class_loader); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 73 | void SetCodeAndDirectMethodsDexFile(const DexFile& dex_file); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 74 | |
| 75 | InstructionSet instruction_set_; |
| 76 | JniCompiler jni_compiler_; |
| 77 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 78 | typedef std::tr1::unordered_map<const Method*, CompiledMethod*, ObjectIdentityHash> MethodTable; |
| 79 | MethodTable compiled_methods_; |
| 80 | |
| 81 | typedef std::tr1::unordered_map<const Method*, CompiledInvokeStub*, ObjectIdentityHash> InvokeStubTable; |
| 82 | InvokeStubTable compiled_invoke_stubs_; |
| 83 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 84 | bool verbose_; |
| 85 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 86 | DISALLOW_COPY_AND_ASSIGN(Compiler); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // namespace art |
| 90 | |
| 91 | #endif // ART_SRC_COMPILER_H_ |