blob: 00271a5f3bbe748794b401d8771fc17f8e7e8706 [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
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070023 // Finds a class by its descriptor name.
24 Class* FindClass(const char* descriptor,
25 Object* class_loader,
26 DexFile* dex_file);
27
Carl Shapiro565f5072011-07-10 13:39:43 -070028 Class* FindSystemClass(const char* descriptor) {
29 return FindClass(descriptor, NULL, NULL);
30 }
31
Brian Carlstrom934486c2011-07-12 23:42:50 -070032 bool LoadClass(const char* descriptor, Class* klass);
33
34 bool LoadClass(const RawDexFile::ClassDef& class_def, Class* klass);
35
Carl Shapiro565f5072011-07-10 13:39:43 -070036 Class* FindPrimitiveClass(JType type);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070037
38 bool InitializeClass(Class* klass);
39
40 Class* LookupClass(const char* descriptor, Object* class_loader);
41
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070042 Class* ResolveClass(const Class* referring, uint32_t class_idx);
43
44 String* ResolveString(const Class* referring, uint32_t string_idx);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070045
46 DexFile* FindInClassPath(const char* descriptor);
47
48 void AppendToClassPath(DexFile* dex_file);
49
50 private:
Carl Shapiro61e019d2011-07-14 16:53:09 -070051 ClassLinker() {}
52
53 void Init();
54
Carl Shapiro565f5072011-07-10 13:39:43 -070055 Class* CreatePrimitiveClass(JType type, const char* descriptor);
56
Brian Carlstrom934486c2011-07-12 23:42:50 -070057 void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass);
58
59 void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst);
60
61 void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst);
62
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070063 // Inserts a class into the class table. Returns true if the class
64 // was inserted.
65 bool InsertClass(Class* klass);
66
67 bool InitializeSuperClass(Class* klass);
68
69 void InitializeStaticFields(Class* klass);
70
71 bool ValidateSuperClassDescriptors(const Class* klass);
72
73 bool HasSameDescriptorClasses(const char* descriptor,
74 const Class* klass1,
75 const Class* klass2);
76
77 bool HasSameMethodDescriptorClasses(const Method* descriptor,
78 const Class* klass1,
79 const Class* klass2);
80
81 bool LinkClass(Class* klass);
82
83 bool LinkSuperClass(Class* klass);
84
85 bool LinkInterfaces(Class* klass);
86
87 bool LinkMethods(Class* klass);
88
89 bool LinkVirtualMethods(Class* klass);
90
91 bool LinkInterfaceMethods(Class* klass);
92
93 void LinkAbstractMethods(Class* klass);
94
95 bool LinkInstanceFields(Class* klass);
96
97 void CreateReferenceOffsets(Class* klass);
98
99 std::vector<DexFile*> class_path_;
100
101 // TODO: multimap
102 typedef std::map<const char*, Class*, CStringLt> Table;
103
104 Table classes_;
105
106 Mutex* classes_lock_;
107
108 // TODO: classpath
109
Carl Shapiro565f5072011-07-10 13:39:43 -0700110 Class* primitive_boolean_;
111 Class* primitive_char_;
112 Class* primitive_float_;
113 Class* primitive_double_;
114 Class* primitive_byte_;
115 Class* primitive_short_;
116 Class* primitive_int_;
117 Class* primitive_long_;
118 Class* primitive_void_;
119
Brian Carlstrom934486c2011-07-12 23:42:50 -0700120 Class* java_lang_Object_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700121 Class* java_lang_Class_;
122
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700123 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
124};
125
126} // namespace art
127
128#endif // ART_SRC_CLASS_LINKER_H_