Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_CLASS_LINKER_H_ |
| 18 | #define ART_SRC_CLASS_LINKER_H_ |
| 19 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 20 | #include <string> |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 21 | #include <utility> |
| 22 | #include <vector> |
| 23 | |
Ian Rogers | caab8c4 | 2011-10-12 12:11:18 -0700 | [diff] [blame] | 24 | #include "dex_cache.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 25 | #include "dex_file.h" |
Elliott Hughes | e5448b5 | 2012-01-18 16:44:06 -0800 | [diff] [blame] | 26 | #include "gtest/gtest.h" |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 27 | #include "heap.h" |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 28 | #include "macros.h" |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 29 | #include "mutex.h" |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 30 | #include "oat_file.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 31 | #include "object.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 32 | #include "safe_map.h" |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 33 | #include "stack_indirect_reference_table.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 34 | |
| 35 | namespace art { |
| 36 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 37 | class ClassLoader; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 38 | class ImageSpace; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 39 | class InternTable; |
Brian Carlstrom | d1422f8 | 2011-09-28 11:37:09 -0700 | [diff] [blame] | 40 | class ObjectLock; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 41 | |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 42 | typedef bool (ClassVisitor)(Class* c, void* arg); |
| 43 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 44 | class ClassLinker { |
| 45 | public: |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 46 | // Creates the class linker by boot strapping from dex files. |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 47 | static ClassLinker* CreateFromCompiler(const std::vector<const DexFile*>& boot_class_path, |
| 48 | InternTable* intern_table); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 49 | |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 50 | // Creates the class linker from an image. |
| 51 | static ClassLinker* CreateFromImage(InternTable* intern_table); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 52 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 53 | ~ClassLinker(); |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 54 | |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 55 | // Finds a class by its descriptor, loading it if necessary. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 56 | // If class_loader is null, searches boot_class_path_. |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 57 | Class* FindClass(const char* descriptor, const ClassLoader* class_loader); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 58 | |
Elliott Hughes | db7d5e9 | 2011-12-16 18:47:37 -0800 | [diff] [blame] | 59 | Class* FindSystemClass(const char* descriptor); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 60 | |
| 61 | // Define a new a class based on a ClassDef from a DexFile |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 62 | Class* DefineClass(const StringPiece& descriptor, const ClassLoader* class_loader, |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 63 | const DexFile& dex_file, const DexFile::ClassDef& dex_class_def); |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 64 | |
| 65 | // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded |
| 66 | // by the given 'class_loader'. |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 67 | Class* LookupClass(const char* descriptor, const ClassLoader* class_loader); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 68 | |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 69 | // Finds all the classes with the given descriptor, regardless of ClassLoader. |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 70 | void LookupClasses(const char* descriptor, std::vector<Class*>& classes); |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 71 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 72 | Class* FindPrimitiveClass(char type); |
| 73 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 74 | // General class unloading is not supported, this is used to prune |
| 75 | // unwanted classes during image writing. |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 76 | bool RemoveClass(const char* descriptor, const ClassLoader* class_loader); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 77 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 78 | void DumpAllClasses(int flags) const; |
| 79 | |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 80 | void DumpForSigQuit(std::ostream& os) const; |
| 81 | |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 82 | size_t NumLoadedClasses() const; |
| 83 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 84 | // Resolve a String with the given index from the DexFile, storing the |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 85 | // result in the DexCache. The referrer is used to identify the |
| 86 | // target DexCache and ClassLoader to use for resolution. |
| 87 | String* ResolveString(uint32_t string_idx, const Method* referrer) { |
Ian Rogers | caab8c4 | 2011-10-12 12:11:18 -0700 | [diff] [blame] | 88 | String* resolved_string = referrer->GetDexCacheStrings()->Get(string_idx); |
| 89 | if (UNLIKELY(resolved_string == NULL)) { |
| 90 | Class* declaring_class = referrer->GetDeclaringClass(); |
| 91 | DexCache* dex_cache = declaring_class->GetDexCache(); |
| 92 | const DexFile& dex_file = FindDexFile(dex_cache); |
| 93 | resolved_string = ResolveString(dex_file, string_idx, dex_cache); |
| 94 | } |
| 95 | return resolved_string; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | // Resolve a String with the given index from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 99 | // result in the DexCache. |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 100 | String* ResolveString(const DexFile& dex_file, uint32_t string_idx, DexCache* dex_cache); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 101 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 102 | // Resolve a Type with the given index from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 103 | // result in the DexCache. The referrer is used to identity the |
| 104 | // target DexCache and ClassLoader to use for resolution. |
| 105 | Class* ResolveType(const DexFile& dex_file, |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 106 | uint16_t type_idx, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 107 | const Class* referrer) { |
| 108 | return ResolveType(dex_file, |
| 109 | type_idx, |
| 110 | referrer->GetDexCache(), |
| 111 | referrer->GetClassLoader()); |
| 112 | } |
| 113 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 114 | // Resolve a Type with the given index from the DexFile, storing the |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 115 | // result in the DexCache. The referrer is used to identify the |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 116 | // target DexCache and ClassLoader to use for resolution. |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 117 | Class* ResolveType(uint16_t type_idx, const Method* referrer) { |
Ian Rogers | caab8c4 | 2011-10-12 12:11:18 -0700 | [diff] [blame] | 118 | Class* resolved_type = referrer->GetDexCacheResolvedTypes()->Get(type_idx); |
| 119 | if (UNLIKELY(resolved_type == NULL)) { |
| 120 | Class* declaring_class = referrer->GetDeclaringClass(); |
| 121 | DexCache* dex_cache = declaring_class->GetDexCache(); |
| 122 | const ClassLoader* class_loader = declaring_class->GetClassLoader(); |
| 123 | const DexFile& dex_file = FindDexFile(dex_cache); |
| 124 | resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader); |
| 125 | } |
| 126 | return resolved_type; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 129 | Class* ResolveType(uint16_t type_idx, const Field* referrer) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 130 | Class* declaring_class = referrer->GetDeclaringClass(); |
| 131 | DexCache* dex_cache = declaring_class->GetDexCache(); |
Ian Rogers | caab8c4 | 2011-10-12 12:11:18 -0700 | [diff] [blame] | 132 | Class* resolved_type = dex_cache->GetResolvedType(type_idx); |
| 133 | if (UNLIKELY(resolved_type == NULL)) { |
| 134 | const ClassLoader* class_loader = declaring_class->GetClassLoader(); |
| 135 | const DexFile& dex_file = FindDexFile(dex_cache); |
| 136 | resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader); |
| 137 | } |
| 138 | return resolved_type; |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 141 | // Resolve a type with the given ID from the DexFile, storing the |
| 142 | // result in DexCache. The ClassLoader is used to search for the |
| 143 | // type, since it may be referenced from but not contained within |
| 144 | // the given DexFile. |
| 145 | Class* ResolveType(const DexFile& dex_file, |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 146 | uint16_t type_idx, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 147 | DexCache* dex_cache, |
| 148 | const ClassLoader* class_loader); |
| 149 | |
| 150 | // Resolve a method with a given ID from the DexFile, storing the |
| 151 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 152 | // in ResolveType. What is unique is the method type argument which |
| 153 | // is used to determine if this method is a direct, static, or |
| 154 | // virtual method. |
| 155 | Method* ResolveMethod(const DexFile& dex_file, |
| 156 | uint32_t method_idx, |
| 157 | DexCache* dex_cache, |
| 158 | const ClassLoader* class_loader, |
Brian Carlstrom | 20cfffa | 2011-08-26 02:31:27 -0700 | [diff] [blame] | 159 | bool is_direct); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 160 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 161 | Method* ResolveMethod(uint32_t method_idx, const Method* referrer, bool is_direct) { |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 162 | Method* resolved_method = referrer->GetDexCacheResolvedMethods()->Get(method_idx); |
| 163 | if (UNLIKELY(resolved_method == NULL || resolved_method->IsRuntimeMethod())) { |
| 164 | Class* declaring_class = referrer->GetDeclaringClass(); |
| 165 | DexCache* dex_cache = declaring_class->GetDexCache(); |
Ian Rogers | caab8c4 | 2011-10-12 12:11:18 -0700 | [diff] [blame] | 166 | const ClassLoader* class_loader = declaring_class->GetClassLoader(); |
| 167 | const DexFile& dex_file = FindDexFile(dex_cache); |
| 168 | resolved_method = ResolveMethod(dex_file, method_idx, dex_cache, class_loader, is_direct); |
| 169 | } |
| 170 | return resolved_method; |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Brian Carlstrom | 845490b | 2011-09-19 15:56:53 -0700 | [diff] [blame] | 173 | Field* ResolveField(uint32_t field_idx, const Method* referrer, bool is_static) { |
Ian Rogers | b5d6a49 | 2012-02-14 04:00:51 -0800 | [diff] [blame] | 174 | Field* resolved_field = |
| 175 | referrer->GetDeclaringClass()->GetDexCache()->GetResolvedField(field_idx); |
Ian Rogers | caab8c4 | 2011-10-12 12:11:18 -0700 | [diff] [blame] | 176 | if (UNLIKELY(resolved_field == NULL)) { |
Ian Rogers | b5d6a49 | 2012-02-14 04:00:51 -0800 | [diff] [blame] | 177 | Class* declaring_class = referrer->GetDeclaringClass(); |
| 178 | DexCache* dex_cache = declaring_class->GetDexCache(); |
Ian Rogers | caab8c4 | 2011-10-12 12:11:18 -0700 | [diff] [blame] | 179 | const ClassLoader* class_loader = declaring_class->GetClassLoader(); |
| 180 | const DexFile& dex_file = FindDexFile(dex_cache); |
| 181 | resolved_field = ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static); |
| 182 | } |
| 183 | return resolved_field; |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 186 | // Resolve a field with a given ID from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 187 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 188 | // in ResolveType. What is unique is the is_static argument which is |
| 189 | // used to determine if we are resolving a static or non-static |
| 190 | // field. |
| 191 | Field* ResolveField(const DexFile& dex_file, |
| 192 | uint32_t field_idx, |
| 193 | DexCache* dex_cache, |
| 194 | const ClassLoader* class_loader, |
| 195 | bool is_static); |
| 196 | |
Ian Rogers | b067ac2 | 2011-12-13 18:05:09 -0800 | [diff] [blame] | 197 | // Resolve a field with a given ID from the DexFile, storing the |
| 198 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 199 | // in ResolveType. No is_static argument is provided so that Java |
| 200 | // field resolution semantics are followed. |
| 201 | Field* ResolveFieldJLS(const DexFile& dex_file, |
| 202 | uint32_t field_idx, |
| 203 | DexCache* dex_cache, |
| 204 | const ClassLoader* class_loader); |
| 205 | |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 206 | // Get shorty from method index without resolution. Used to do handlerization. |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 207 | const char* MethodShorty(uint32_t method_idx, Method* referrer, uint32_t* length); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 208 | |
Elliott Hughes | f4c21c9 | 2011-08-19 17:31:31 -0700 | [diff] [blame] | 209 | // Returns true on success, false if there's an exception pending. |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 210 | // can_run_clinit=false allows the compiler to attempt to init a class, |
| 211 | // given the restriction that no <clinit> execution is possible. |
Ian Rogers | 0045a29 | 2012-03-31 21:08:41 -0700 | [diff] [blame] | 212 | bool EnsureInitialized(Class* c, bool can_run_clinit, bool can_init_fields); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 213 | |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 214 | // Initializes classes that have instances in the image but that have |
| 215 | // <clinit> methods so they could not be initialized by the compiler. |
| 216 | void RunRootClinits(); |
| 217 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 218 | void RegisterDexFile(const DexFile& dex_file); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 219 | void RegisterDexFile(const DexFile& dex_file, SirtRef<DexCache>& dex_cache); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 220 | |
Brian Carlstrom | 866c862 | 2012-01-06 16:35:13 -0800 | [diff] [blame] | 221 | void RegisterOatFile(const OatFile& oat_file); |
| 222 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 223 | const std::vector<const DexFile*>& GetBootClassPath() { |
| 224 | return boot_class_path_; |
| 225 | } |
| 226 | |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 227 | void VisitClasses(ClassVisitor* visitor, void* arg) const; |
| 228 | |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 229 | void VisitRoots(Heap::RootVisitor* visitor, void* arg) const; |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 230 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 231 | const DexFile& FindDexFile(const DexCache* dex_cache) const; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 232 | DexCache* FindDexCache(const DexFile& dex_file) const; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 233 | bool IsDexFileRegistered(const DexFile& dex_file) const; |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 234 | void FixupDexCaches(Method* resolution_method) const; |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 235 | |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 236 | // Generate an oat file from a dex file |
Brian Carlstrom | d601af8 | 2012-01-06 10:15:19 -0800 | [diff] [blame] | 237 | bool GenerateOatFile(const std::string& dex_filename, |
| 238 | int oat_fd, |
| 239 | const std::string& oat_cache_filename); |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 240 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 241 | const OatFile* FindOatFileFromOatLocation(const std::string& location); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 242 | |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 243 | // Finds the oat file for a dex location, generating the oat file if |
| 244 | // it is missing or out of date. Returns the DexFile from within the |
| 245 | // created oat file. |
| 246 | const DexFile* FindOrCreateOatFileForDexLocation(const std::string& dex_location, |
| 247 | const std::string& oat_location); |
| 248 | // Find a DexFile within an OatFile given a DexFile location. Note |
| 249 | // that this returns null if the location checksum of the DexFile |
| 250 | // does not match the OatFile. |
| 251 | const DexFile* FindDexFileInOatFileFromDexLocation(const std::string& location); |
| 252 | |
jeffhao | f6174e8 | 2012-01-31 16:14:17 -0800 | [diff] [blame] | 253 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 254 | // TODO: replace this with multiple methods that allocate the correct managed type. |
Shih-wei Liao | 4417536 | 2011-08-28 16:59:17 -0700 | [diff] [blame] | 255 | template <class T> |
| 256 | ObjectArray<T>* AllocObjectArray(size_t length) { |
| 257 | return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length); |
| 258 | } |
| 259 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 260 | ObjectArray<Class>* AllocClassArray(size_t length) { |
| 261 | return ObjectArray<Class>::Alloc(GetClassRoot(kClassArrayClass), length); |
| 262 | } |
| 263 | |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 264 | ObjectArray<StackTraceElement>* AllocStackTraceElementArray(size_t length); |
| 265 | |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 266 | void VerifyClass(Class* klass); |
Elliott Hughes | 634eb2e | 2012-03-22 16:06:28 -0700 | [diff] [blame] | 267 | bool VerifyClassUsingOatFile(const DexFile& dex_file, Class* klass, |
| 268 | Class::Status& oat_file_class_status); |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 269 | void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, Class* klass); |
| 270 | void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, Method* klass); |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 271 | |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 272 | Class* CreateProxyClass(String* name, ObjectArray<Class>* interfaces, ClassLoader* loader, |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 273 | ObjectArray<Method>* methods, ObjectArray<ObjectArray<Class> >* throws); |
| 274 | std::string GetDescriptorForProxy(const Class* proxy_class); |
Ian Rogers | 16f9367 | 2012-02-14 12:29:06 -0800 | [diff] [blame] | 275 | Method* FindMethodForProxy(const Class* proxy_class, const Method* proxy_method); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 276 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 277 | // Get the oat code for a method when its class isn't yet initialized |
| 278 | const void* GetOatCodeFor(const Method* method); |
| 279 | |
TDYa127 | 8532191 | 2012-04-01 15:24:56 -0700 | [diff] [blame] | 280 | void LinkOatCodeFor(Method* method); |
| 281 | |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 282 | // Relocate the OatFiles (ELF images) |
| 283 | void RelocateExecutable(); |
| 284 | |
Brian Carlstrom | 47d237a | 2011-10-18 15:08:33 -0700 | [diff] [blame] | 285 | pid_t GetClassesLockOwner(); // For SignalCatcher. |
| 286 | pid_t GetDexLockOwner(); // For SignalCatcher. |
Brian Carlstrom | 24a3c2e | 2011-10-17 18:07:52 -0700 | [diff] [blame] | 287 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 288 | private: |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 289 | explicit ClassLinker(InternTable*); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 290 | |
TDYa127 | 8532191 | 2012-04-01 15:24:56 -0700 | [diff] [blame] | 291 | const OatFile::OatMethod GetOatMethodFor(const Method* method); |
| 292 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 293 | // Initialize class linker by bootstraping from dex files |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 294 | void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 295 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 296 | // Initialize class linker from one or more images. |
| 297 | void InitFromImage(); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 298 | OatFile* OpenOat(const ImageSpace* space); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 299 | static void InitFromImageCallback(Object* obj, void* arg); |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 300 | struct InitFromImageCallbackState; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 301 | |
| 302 | void FinishInit(); |
| 303 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 304 | // For early bootstrapping by Init |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 305 | Class* AllocClass(Class* java_lang_Class, size_t class_size); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 306 | |
| 307 | // Alloc* convenience functions to avoid needing to pass in Class* |
| 308 | // values that are known to the ClassLinker such as |
| 309 | // kObjectArrayClass and kJavaLangString etc. |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 310 | Class* AllocClass(size_t class_size); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 311 | DexCache* AllocDexCache(const DexFile& dex_file); |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 312 | Field* AllocField(); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 313 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 314 | Method* AllocMethod(); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 315 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 316 | InterfaceEntry* AllocInterfaceEntry(Class* interface); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 317 | |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 318 | Class* CreatePrimitiveClass(const char* descriptor, Primitive::Type type) { |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 319 | return InitializePrimitiveClass(AllocClass(sizeof(Class)), descriptor, type); |
| 320 | } |
| 321 | Class* InitializePrimitiveClass(Class* primitive_class, |
| 322 | const char* descriptor, |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 323 | Primitive::Type type); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 324 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 325 | |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 326 | Class* CreateArrayClass(const std::string& descriptor, const ClassLoader* class_loader); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 327 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 328 | void AppendToBootClassPath(const DexFile& dex_file); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 329 | void AppendToBootClassPath(const DexFile& dex_file, SirtRef<DexCache>& dex_cache); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 330 | |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 331 | void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def, |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 332 | Class* c, SafeMap<uint32_t, Field*>& field_map); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 333 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 334 | size_t SizeOfClass(const DexFile& dex_file, |
| 335 | const DexFile::ClassDef& dex_class_def); |
| 336 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 337 | void LoadClass(const DexFile& dex_file, |
| 338 | const DexFile::ClassDef& dex_class_def, |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 339 | SirtRef<Class>& klass, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 340 | const ClassLoader* class_loader); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 341 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 342 | void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it, SirtRef<Class>& klass, |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 343 | SirtRef<Field>& dst); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 344 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 345 | void LoadMethod(const DexFile& dex_file, const ClassDataItemIterator& dex_method, |
| 346 | SirtRef<Class>& klass, SirtRef<Method>& dst); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 347 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 348 | void FixupStaticTrampolines(Class* klass); |
| 349 | |
| 350 | // Finds the associated oat class for a dex_file and descriptor |
| 351 | const OatFile::OatClass* GetOatClass(const DexFile& dex_file, const char* descriptor); |
| 352 | |
Brian Carlstrom | 07bb855 | 2012-01-18 22:10:50 -0800 | [diff] [blame] | 353 | // Attempts to insert a class into a class table. Returns NULL if |
| 354 | // the class was inserted, otherwise returns an existing class with |
| 355 | // the same descriptor and ClassLoader. |
| 356 | Class* InsertClass(const StringPiece& descriptor, Class* klass, bool image_class); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 357 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 358 | void RegisterDexFileLocked(const DexFile& dex_file, SirtRef<DexCache>& dex_cache) EXCLUSIVE_LOCKS_REQUIRED(dex_lock_); |
| 359 | bool IsDexFileRegisteredLocked(const DexFile& dex_file) const EXCLUSIVE_LOCKS_REQUIRED(dex_lock_); |
| 360 | void RegisterOatFileLocked(const OatFile& oat_file) EXCLUSIVE_LOCKS_REQUIRED(dex_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 361 | |
Ian Rogers | 0045a29 | 2012-03-31 21:08:41 -0700 | [diff] [blame] | 362 | bool InitializeClass(Class* klass, bool can_run_clinit, bool can_init_statics); |
Brian Carlstrom | d1422f8 | 2011-09-28 11:37:09 -0700 | [diff] [blame] | 363 | bool WaitForInitializeClass(Class* klass, Thread* self, ObjectLock& lock); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 364 | bool ValidateSuperClassDescriptors(const Class* klass); |
Ian Rogers | 0045a29 | 2012-03-31 21:08:41 -0700 | [diff] [blame] | 365 | bool InitializeSuperClass(Class* klass, bool can_run_clinit, bool can_init_fields); |
| 366 | // Initialize static fields, returns true if fields were initialized. |
| 367 | bool InitializeStaticFields(Class* klass); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 368 | |
Ian Rogers | 595799e | 2012-01-11 17:32:51 -0800 | [diff] [blame] | 369 | bool IsSameDescriptorInDifferentClassContexts(const char* descriptor, |
| 370 | const Class* klass1, |
| 371 | const Class* klass2); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 372 | |
Ian Rogers | 595799e | 2012-01-11 17:32:51 -0800 | [diff] [blame] | 373 | bool IsSameMethodSignatureInDifferentClassContexts(const Method* descriptor, |
| 374 | const Class* klass1, |
| 375 | const Class* klass2); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 376 | |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 377 | bool LinkClass(SirtRef<Class>& klass, ObjectArray<Class>* interfaces); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 378 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 379 | bool LinkSuperClass(SirtRef<Class>& klass); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 380 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 381 | bool LoadSuperAndInterfaces(SirtRef<Class>& klass, const DexFile& dex_file); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 382 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 383 | bool LinkMethods(SirtRef<Class>& klass, ObjectArray<Class>* interfaces); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 384 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 385 | bool LinkVirtualMethods(SirtRef<Class>& klass); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 386 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 387 | bool LinkInterfaceMethods(SirtRef<Class>& klass, ObjectArray<Class>* interfaces); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 388 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 389 | bool LinkStaticFields(SirtRef<Class>& klass); |
| 390 | bool LinkInstanceFields(SirtRef<Class>& klass); |
| 391 | bool LinkFields(SirtRef<Class>& klass, bool is_static); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 392 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 393 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 394 | void CreateReferenceInstanceOffsets(SirtRef<Class>& klass); |
| 395 | void CreateReferenceStaticOffsets(SirtRef<Class>& klass); |
| 396 | void CreateReferenceOffsets(SirtRef<Class>& klass, bool is_static, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 397 | uint32_t reference_offsets); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 398 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 399 | // For use by ImageWriter to find DexCaches for its roots |
| 400 | const std::vector<DexCache*>& GetDexCaches() { |
| 401 | return dex_caches_; |
| 402 | } |
| 403 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 404 | const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file); |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 405 | const OatFile* FindOpenedOatFileFromDexLocation(const std::string& dex_location); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 406 | const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location); |
Brian Carlstrom | 46b8a62 | 2012-06-19 23:13:22 -0700 | [diff] [blame] | 407 | const DexFile* VerifyOatFileChecksums(const OatFile* oat_file, |
| 408 | const std::string& dex_location, |
| 409 | uint32_t dex_location_checksum) |
| 410 | EXCLUSIVE_LOCKS_REQUIRED(dex_lock_); |
Brian Carlstrom | fad7143 | 2011-10-16 20:25:10 -0700 | [diff] [blame] | 411 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 412 | Method* CreateProxyConstructor(SirtRef<Class>& klass, Class* proxy_class); |
| 413 | Method* CreateProxyMethod(SirtRef<Class>& klass, SirtRef<Method>& prototype); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 414 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 415 | std::vector<const DexFile*> boot_class_path_; |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 416 | |
Brian Carlstrom | 47d237a | 2011-10-18 15:08:33 -0700 | [diff] [blame] | 417 | mutable Mutex dex_lock_; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 418 | std::vector<const DexFile*> dex_files_ GUARDED_BY(dex_lock_); |
| 419 | std::vector<DexCache*> dex_caches_ GUARDED_BY(dex_lock_); |
| 420 | std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_); |
Brian Carlstrom | 47d237a | 2011-10-18 15:08:33 -0700 | [diff] [blame] | 421 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 422 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 423 | // multimap from a string hash code of a class descriptor to |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 424 | // Class* instances. Results should be compared for a matching |
| 425 | // Class::descriptor_ and Class::class_loader_. |
Brian Carlstrom | 47d237a | 2011-10-18 15:08:33 -0700 | [diff] [blame] | 426 | mutable Mutex classes_lock_; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 427 | typedef std::multimap<size_t, Class*> Table; |
| 428 | Table image_classes_ GUARDED_BY(classes_lock_); |
| 429 | Table classes_ GUARDED_BY(classes_lock_); |
| 430 | |
| 431 | Class* LookupClassLocked(const char* descriptor, const ClassLoader* class_loader, |
| 432 | size_t hash, const Table& classes) EXCLUSIVE_LOCKS_REQUIRED(classes_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 433 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 434 | // indexes into class_roots_. |
| 435 | // needs to be kept in sync with class_roots_descriptors_. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 436 | enum ClassRoot { |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 437 | kJavaLangClass, |
| 438 | kJavaLangObject, |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 439 | kClassArrayClass, |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 440 | kObjectArrayClass, |
| 441 | kJavaLangString, |
Elliott Hughes | bf61ba3 | 2011-10-11 10:53:09 -0700 | [diff] [blame] | 442 | kJavaLangRefReference, |
Elliott Hughes | 8060925 | 2011-09-23 17:24:51 -0700 | [diff] [blame] | 443 | kJavaLangReflectConstructor, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 444 | kJavaLangReflectField, |
| 445 | kJavaLangReflectMethod, |
Ian Rogers | 466bb25 | 2011-10-14 03:29:56 -0700 | [diff] [blame] | 446 | kJavaLangReflectProxy, |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 447 | kJavaLangClassLoader, |
| 448 | kDalvikSystemBaseDexClassLoader, |
| 449 | kDalvikSystemPathClassLoader, |
Ian Rogers | 5167c97 | 2012-02-03 10:41:20 -0800 | [diff] [blame] | 450 | kJavaLangThrowable, |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 451 | kJavaLangClassNotFoundException, |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 452 | kJavaLangStackTraceElement, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 453 | kPrimitiveBoolean, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 454 | kPrimitiveByte, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 455 | kPrimitiveChar, |
| 456 | kPrimitiveDouble, |
| 457 | kPrimitiveFloat, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 458 | kPrimitiveInt, |
| 459 | kPrimitiveLong, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 460 | kPrimitiveShort, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 461 | kPrimitiveVoid, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 462 | kBooleanArrayClass, |
| 463 | kByteArrayClass, |
| 464 | kCharArrayClass, |
| 465 | kDoubleArrayClass, |
| 466 | kFloatArrayClass, |
| 467 | kIntArrayClass, |
| 468 | kLongArrayClass, |
| 469 | kShortArrayClass, |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 470 | kJavaLangStackTraceElementArrayClass, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 471 | kClassRootsMax, |
| 472 | }; |
| 473 | ObjectArray<Class>* class_roots_; |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 474 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 475 | Class* GetClassRoot(ClassRoot class_root) { |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 476 | DCHECK(class_roots_ != NULL); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 477 | Class* klass = class_roots_->Get(class_root); |
| 478 | DCHECK(klass != NULL); |
| 479 | return klass; |
| 480 | } |
| 481 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 482 | void SetClassRoot(ClassRoot class_root, Class* klass); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 483 | |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 484 | ObjectArray<Class>* GetClassRoots() { |
| 485 | DCHECK(class_roots_ != NULL); |
| 486 | return class_roots_; |
| 487 | } |
| 488 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 489 | static const char* class_roots_descriptors_[]; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 490 | |
| 491 | const char* GetClassRootDescriptor(ClassRoot class_root) { |
| 492 | const char* descriptor = class_roots_descriptors_[class_root]; |
| 493 | CHECK(descriptor != NULL); |
| 494 | return descriptor; |
| 495 | } |
| 496 | |
Brian Carlstrom | 4b620ff | 2011-09-11 01:11:01 -0700 | [diff] [blame] | 497 | ObjectArray<InterfaceEntry>* array_iftable_; |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 498 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 499 | bool init_done_; |
| 500 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 501 | InternTable* intern_table_; |
| 502 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 503 | friend class CommonTest; |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 504 | friend class ImageWriter; // for GetClassRoots |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 505 | friend class ObjectTest; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 506 | FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 507 | FRIEND_TEST(DexCacheTest, Open); |
| 508 | FRIEND_TEST(ExceptionTest, FindExceptionHandler); |
| 509 | FRIEND_TEST(ObjectTest, AllocObjectArray); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 510 | DISALLOW_COPY_AND_ASSIGN(ClassLinker); |
| 511 | }; |
| 512 | |
| 513 | } // namespace art |
| 514 | |
| 515 | #endif // ART_SRC_CLASS_LINKER_H_ |