blob: 0fc68df48bd1ad341f037bdc0905e5381a245ed3 [file] [log] [blame]
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_COMPILER_H_
4#define ART_SRC_COMPILER_H_
5
Brian Carlstrom3320cf42011-10-04 14:58:28 -07006#include "compiled_method.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -07007#include "constants.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07008#include "dex_file.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -07009#include "jni_compiler.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070010#include "oat_file.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070011#include "object.h"
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070012#include "runtime.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070013#include "unordered_map.h"
Ian Rogersd6b1f612011-09-27 13:38:14 -070014
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070015namespace art {
16
17class Compiler {
18 public:
Brian Carlstromaded5f72011-10-07 17:15:04 -070019 // Create a compiler targeting the requested "instruction_set".
20 // "image" should be true if image specific optimizations should be enabled.
21 explicit Compiler(InstructionSet instruction_set, bool image);
Brian Carlstrom3320cf42011-10-04 14:58:28 -070022
23 ~Compiler();
Ian Rogers2c8f6532011-09-02 17:16:34 -070024
Brian Carlstrom8a487412011-08-29 20:08:52 -070025 // Compile all Methods of all the Classes of all the DexFiles that are part of a ClassLoader.
26 void CompileAll(const ClassLoader* class_loader);
27
28 // Compile a single Method
Brian Carlstrom3320cf42011-10-04 14:58:28 -070029 void CompileOne(const Method* method);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070030
Brian Carlstrom3320cf42011-10-04 14:58:28 -070031 InstructionSet GetInstructionSet() const {
32 return instruction_set_;
33 }
34
Brian Carlstromaded5f72011-10-07 17:15:04 -070035 bool IsImage() const {
36 return image_;
37 }
38
39 void SetVerbose(bool verbose) {
40 verbose_ = verbose;
41 }
42
Brian Carlstrom16192862011-09-12 17:50:06 -070043 bool IsVerbose() const {
44 return verbose_;
45 }
46
Brian Carlstrome24fa612011-09-29 00:53:55 -070047 // Stub to throw AbstractMethodError
Brian Carlstrome24fa612011-09-29 00:53:55 -070048 static ByteArray* CreateAbstractMethodErrorStub(InstructionSet instruction_set);
49
Brian Carlstrom3320cf42011-10-04 14:58:28 -070050
Ian Rogersad25ac52011-10-04 19:13:33 -070051 // Generate the trampoline that's invoked by unresolved direct methods
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070052 static ByteArray* CreateResolutionStub(InstructionSet instruction_set,
53 Runtime::TrampolineType type);
Ian Rogersad25ac52011-10-04 19:13:33 -070054
Brian Carlstrom3320cf42011-10-04 14:58:28 -070055 const CompiledMethod* GetCompiledMethod(const Method* method) const;
56 const CompiledInvokeStub* GetCompiledInvokeStub(const Method* method) const;
57
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070058 private:
59 // Attempt to resolve all type, methods, fields, and strings
60 // referenced from code in the dex file following PathClassLoader
61 // ordering semantics.
62 void Resolve(const ClassLoader* class_loader);
63 void ResolveDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
64
jeffhao98eacac2011-09-14 16:11:53 -070065 void Verify(const ClassLoader* class_loader);
66 void VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
67
Brian Carlstroma5a97a22011-09-15 14:08:49 -070068 void InitializeClassesWithoutClinit(const ClassLoader* class_loader);
69 void InitializeClassesWithoutClinit(const ClassLoader* class_loader, const DexFile& dex_file);
70
Brian Carlstrom83db7722011-08-26 17:32:56 -070071 void Compile(const ClassLoader* class_loader);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070072 void CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
Brian Carlstrom3320cf42011-10-04 14:58:28 -070073 void CompileClass(const Class* klass);
74 void CompileMethod(const Method* method);
Brian Carlstrom83db7722011-08-26 17:32:56 -070075
76 // After compiling, walk all the DexCaches and set the code and
Brian Carlstrom9cc262e2011-08-28 12:45:30 -070077 // method pointers of CodeAndDirectMethods entries in the DexCaches.
78 void SetCodeAndDirectMethods(const ClassLoader* class_loader);
Brian Carlstrom8a487412011-08-29 20:08:52 -070079 void SetCodeAndDirectMethodsDexFile(const DexFile& dex_file);
Ian Rogers2c8f6532011-09-02 17:16:34 -070080
81 InstructionSet instruction_set_;
82 JniCompiler jni_compiler_;
83
Brian Carlstrom3320cf42011-10-04 14:58:28 -070084 typedef std::tr1::unordered_map<const Method*, CompiledMethod*, ObjectIdentityHash> MethodTable;
85 MethodTable compiled_methods_;
86
87 typedef std::tr1::unordered_map<const Method*, CompiledInvokeStub*, ObjectIdentityHash> InvokeStubTable;
88 InvokeStubTable compiled_invoke_stubs_;
89
Brian Carlstromaded5f72011-10-07 17:15:04 -070090 bool image_;
91
Brian Carlstrom16192862011-09-12 17:50:06 -070092 bool verbose_;
93
Ian Rogers2c8f6532011-09-02 17:16:34 -070094 DISALLOW_COPY_AND_ASSIGN(Compiler);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070095};
96
97} // namespace art
98
99#endif // ART_SRC_COMPILER_H_