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 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 6 | #include "constants.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 7 | #include "dex_file.h" |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 8 | #include "jni_compiler.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 9 | #include "object.h" |
| 10 | |
Ian Rogers | d6b1f61 | 2011-09-27 13:38:14 -0700 | [diff] [blame] | 11 | int oatVRegOffsetFromMethod(art::Method* method, int reg); |
| 12 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 13 | namespace art { |
| 14 | |
| 15 | class Compiler { |
| 16 | public: |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 17 | explicit Compiler(InstructionSet insns); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 18 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 19 | // Compile all Methods of all the Classes of all the DexFiles that are part of a ClassLoader. |
| 20 | void CompileAll(const ClassLoader* class_loader); |
| 21 | |
| 22 | // Compile a single Method |
| 23 | void CompileOne(Method* method); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 24 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 25 | void SetVerbose(bool verbose) { |
| 26 | verbose_ = verbose; |
| 27 | } |
| 28 | |
| 29 | bool IsVerbose() const { |
| 30 | return verbose_; |
| 31 | } |
| 32 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 33 | // Stub to throw AbstractMethodError |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 34 | static ByteArray* CreateAbstractMethodErrorStub(InstructionSet instruction_set); |
| 35 | |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame^] | 36 | // Generate the trampoline that's invoked by unresolved direct methods |
| 37 | static ByteArray* CreateResolutionStub(InstructionSet instruction_set, bool is_static); |
| 38 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 39 | private: |
| 40 | // Attempt to resolve all type, methods, fields, and strings |
| 41 | // referenced from code in the dex file following PathClassLoader |
| 42 | // ordering semantics. |
| 43 | void Resolve(const ClassLoader* class_loader); |
| 44 | void ResolveDexFile(const ClassLoader* class_loader, const DexFile& dex_file); |
| 45 | |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 46 | void Verify(const ClassLoader* class_loader); |
| 47 | void VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file); |
| 48 | |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 49 | void InitializeClassesWithoutClinit(const ClassLoader* class_loader); |
| 50 | void InitializeClassesWithoutClinit(const ClassLoader* class_loader, const DexFile& dex_file); |
| 51 | |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 52 | void Compile(const ClassLoader* class_loader); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 53 | void CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file); |
| 54 | void CompileClass(Class* klass); |
| 55 | void CompileMethod(Method* klass); |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 56 | |
| 57 | // After compiling, walk all the DexCaches and set the code and |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 58 | // method pointers of CodeAndDirectMethods entries in the DexCaches. |
| 59 | void SetCodeAndDirectMethods(const ClassLoader* class_loader); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 60 | void SetCodeAndDirectMethodsDexFile(const DexFile& dex_file); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 61 | |
| 62 | InstructionSet instruction_set_; |
| 63 | JniCompiler jni_compiler_; |
| 64 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 65 | bool verbose_; |
| 66 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 67 | DISALLOW_COPY_AND_ASSIGN(Compiler); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // namespace art |
| 71 | |
| 72 | #endif // ART_SRC_COMPILER_H_ |