blob: e4c5ff96c43144ffc6fe7cba950b4037c1a6f196 [file] [log] [blame]
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_CLASS_LINKER_H_
4#define ART_SRC_CLASS_LINKER_H_
5
6#include <map>
7#include <utility>
8#include <vector>
9
10#include "src/macros.h"
11#include "src/thread.h"
12#include "src/object.h"
13
14namespace art {
15
16class ClassLinker {
17 public:
Carl Shapiro565f5072011-07-10 13:39:43 -070018 // Initializes the class linker.
Carl Shapiro61e019d2011-07-14 16:53:09 -070019 static ClassLinker* Create();
20
21 ~ClassLinker() {}
Carl Shapiro565f5072011-07-10 13:39:43 -070022
Brian Carlstroma0808032011-07-18 00:39:23 -070023 Class* AllocClass(DexFile* dex_file);
24 StaticField* AllocStaticField();
25 InstanceField* AllocInstanceField();
26 Method* AllocMethod();
27
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070028 // Finds a class by its descriptor name.
29 Class* FindClass(const char* descriptor,
30 Object* class_loader,
31 DexFile* dex_file);
32
Carl Shapiro565f5072011-07-10 13:39:43 -070033 Class* FindSystemClass(const char* descriptor) {
34 return FindClass(descriptor, NULL, NULL);
35 }
36
Brian Carlstrom934486c2011-07-12 23:42:50 -070037 bool LoadClass(const char* descriptor, Class* klass);
38
39 bool LoadClass(const RawDexFile::ClassDef& class_def, Class* klass);
40
Carl Shapiro565f5072011-07-10 13:39:43 -070041 Class* FindPrimitiveClass(JType type);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070042
43 bool InitializeClass(Class* klass);
44
45 Class* LookupClass(const char* descriptor, Object* class_loader);
46
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070047 Class* ResolveClass(const Class* referring, uint32_t class_idx);
48
49 String* ResolveString(const Class* referring, uint32_t string_idx);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070050
Brian Carlstroma0808032011-07-18 00:39:23 -070051 typedef std::pair<DexFile*, const RawDexFile::ClassDef*> ClassPathEntry;
52
53 ClassPathEntry FindInClassPath(const char* descriptor);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070054
55 void AppendToClassPath(DexFile* dex_file);
56
57 private:
Carl Shapiro61e019d2011-07-14 16:53:09 -070058 ClassLinker() {}
59
60 void Init();
61
Carl Shapiro565f5072011-07-10 13:39:43 -070062 Class* CreatePrimitiveClass(JType type, const char* descriptor);
63
Brian Carlstrom934486c2011-07-12 23:42:50 -070064 void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass);
65
66 void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst);
67
68 void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst);
69
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070070 // Inserts a class into the class table. Returns true if the class
71 // was inserted.
72 bool InsertClass(Class* klass);
73
74 bool InitializeSuperClass(Class* klass);
75
76 void InitializeStaticFields(Class* klass);
77
78 bool ValidateSuperClassDescriptors(const Class* klass);
79
80 bool HasSameDescriptorClasses(const char* descriptor,
81 const Class* klass1,
82 const Class* klass2);
83
84 bool HasSameMethodDescriptorClasses(const Method* descriptor,
85 const Class* klass1,
86 const Class* klass2);
87
88 bool LinkClass(Class* klass);
89
90 bool LinkSuperClass(Class* klass);
91
92 bool LinkInterfaces(Class* klass);
93
94 bool LinkMethods(Class* klass);
95
96 bool LinkVirtualMethods(Class* klass);
97
98 bool LinkInterfaceMethods(Class* klass);
99
100 void LinkAbstractMethods(Class* klass);
101
102 bool LinkInstanceFields(Class* klass);
103
104 void CreateReferenceOffsets(Class* klass);
105
106 std::vector<DexFile*> class_path_;
107
108 // TODO: multimap
109 typedef std::map<const char*, Class*, CStringLt> Table;
110
111 Table classes_;
112
113 Mutex* classes_lock_;
114
115 // TODO: classpath
116
Carl Shapiro565f5072011-07-10 13:39:43 -0700117 Class* primitive_boolean_;
118 Class* primitive_char_;
119 Class* primitive_float_;
120 Class* primitive_double_;
121 Class* primitive_byte_;
122 Class* primitive_short_;
123 Class* primitive_int_;
124 Class* primitive_long_;
125 Class* primitive_void_;
126
127 Class* java_lang_Class_;
Brian Carlstroma0808032011-07-18 00:39:23 -0700128 Class* java_lang_Object_;
129 Class* java_lang_ref_Field_;
130 Class* java_lang_ref_Method_;
131 Class* java_lang_String_;
132 Class* char_array_class_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700133
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700134 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
135};
136
137} // namespace art
138
139#endif // ART_SRC_CLASS_LINKER_H_