Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [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 | */ |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 16 | |
| 17 | #include "compiler.h" |
| 18 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 19 | #include <vector> |
| 20 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 21 | #include <dlfcn.h> |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 22 | #include <unistd.h> |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 23 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 24 | #include "class_linker.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 25 | #include "class_loader.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 26 | #include "dex_cache.h" |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 27 | #include "jni_internal.h" |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 28 | #include "oat_compilation_unit.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 29 | #include "oat_file.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 30 | #include "object_utils.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 31 | #include "runtime.h" |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 32 | #include "space.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 33 | #include "stl_util.h" |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 34 | #include "timing_logger.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 35 | #include "verifier/method_verifier.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 36 | |
Elliott Hughes | 059d5c1 | 2012-03-12 17:39:18 -0700 | [diff] [blame] | 37 | #if defined(__APPLE__) |
| 38 | #include <mach-o/dyld.h> |
| 39 | #endif |
| 40 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 41 | namespace art { |
| 42 | |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 43 | namespace arm { |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 44 | ByteArray* CreateAbstractMethodErrorStub(); |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 45 | ByteArray* ArmCreateResolutionTrampoline(Runtime::TrampolineType type); |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 46 | ByteArray* CreateJniDlsymLookupStub(); |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 47 | } |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 48 | namespace x86 { |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 49 | ByteArray* CreateAbstractMethodErrorStub(); |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 50 | ByteArray* X86CreateResolutionTrampoline(Runtime::TrampolineType type); |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 51 | ByteArray* CreateJniDlsymLookupStub(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 54 | static double Percentage(size_t x, size_t y) { |
Elliott Hughes | 398f64b | 2012-03-26 18:05:48 -0700 | [diff] [blame] | 55 | return 100.0 * (static_cast<double>(x)) / (static_cast<double>(x + y)); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void DumpStat(size_t x, size_t y, const char* str) { |
| 59 | if (x == 0 && y == 0) { |
| 60 | return; |
| 61 | } |
| 62 | LOG(INFO) << Percentage(x, y) << "% of " << str << " for " << (x + y) << " cases"; |
| 63 | } |
| 64 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 65 | class AOTCompilationStats { |
| 66 | public: |
| 67 | AOTCompilationStats() : stats_lock_("AOT compilation statistics lock"), |
| 68 | types_in_dex_cache_(0), types_not_in_dex_cache_(0), |
| 69 | strings_in_dex_cache_(0), strings_not_in_dex_cache_(0), |
| 70 | resolved_types_(0), unresolved_types_(0), |
| 71 | resolved_instance_fields_(0), unresolved_instance_fields_(0), |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 72 | resolved_local_static_fields_(0), resolved_static_fields_(0), unresolved_static_fields_(0) { |
| 73 | for (size_t i = 0; i <= kMaxInvokeType; i++) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 74 | resolved_methods_[i] = 0; |
| 75 | unresolved_methods_[i] = 0; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 76 | virtual_made_direct_[i] = 0; |
| 77 | direct_calls_to_boot_[i] = 0; |
| 78 | direct_methods_to_boot_[i] = 0; |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 79 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void Dump() { |
| 83 | DumpStat(types_in_dex_cache_, types_not_in_dex_cache_, "types known to be in dex cache"); |
| 84 | DumpStat(strings_in_dex_cache_, strings_not_in_dex_cache_, "strings known to be in dex cache"); |
| 85 | DumpStat(resolved_types_, unresolved_types_, "types resolved"); |
| 86 | DumpStat(resolved_instance_fields_, unresolved_instance_fields_, "instance fields resolved"); |
| 87 | DumpStat(resolved_local_static_fields_ + resolved_static_fields_, unresolved_static_fields_, |
| 88 | "static fields resolved"); |
| 89 | DumpStat(resolved_local_static_fields_, resolved_static_fields_ + unresolved_static_fields_, |
| 90 | "static fields local to a class"); |
| 91 | |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 92 | for (size_t i = 0; i <= kMaxInvokeType; i++) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 93 | std::ostringstream oss; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 94 | oss << static_cast<InvokeType>(i) << " methods were AOT resolved"; |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 95 | DumpStat(resolved_methods_[i], unresolved_methods_[i], oss.str().c_str()); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 96 | if (virtual_made_direct_[i] > 0) { |
| 97 | std::ostringstream oss2; |
| 98 | oss2 << static_cast<InvokeType>(i) << " methods made direct"; |
| 99 | DumpStat(virtual_made_direct_[i], |
| 100 | resolved_methods_[i] + unresolved_methods_[i] - virtual_made_direct_[i], |
| 101 | oss2.str().c_str()); |
| 102 | } |
| 103 | if (direct_calls_to_boot_[i] > 0) { |
| 104 | std::ostringstream oss2; |
| 105 | oss2 << static_cast<InvokeType>(i) << " method calls are direct into boot"; |
| 106 | DumpStat(direct_calls_to_boot_[i], |
| 107 | resolved_methods_[i] + unresolved_methods_[i] - direct_calls_to_boot_[i], |
| 108 | oss2.str().c_str()); |
| 109 | } |
| 110 | if (direct_methods_to_boot_[i] > 0) { |
| 111 | std::ostringstream oss2; |
| 112 | oss2 << static_cast<InvokeType>(i) << " method calls have methods in boot"; |
| 113 | DumpStat(direct_methods_to_boot_[i], |
| 114 | resolved_methods_[i] + unresolved_methods_[i] - direct_methods_to_boot_[i], |
| 115 | oss2.str().c_str()); |
| 116 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 117 | } |
| 118 | } |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 119 | |
| 120 | // Allow lossy statistics in non-debug builds |
| 121 | #ifndef NDEBUG |
| 122 | #define STATS_LOCK() MutexLock mu(stats_lock_) |
| 123 | #else |
| 124 | #define STATS_LOCK() |
| 125 | #endif |
| 126 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 127 | void TypeInDexCache() { |
| 128 | STATS_LOCK(); |
| 129 | types_in_dex_cache_++; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 130 | } |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 131 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 132 | void TypeNotInDexCache() { |
| 133 | STATS_LOCK(); |
| 134 | types_not_in_dex_cache_++; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 135 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 136 | |
| 137 | void StringInDexCache() { |
| 138 | STATS_LOCK(); |
| 139 | strings_in_dex_cache_++; |
| 140 | } |
| 141 | |
| 142 | void StringNotInDexCache() { |
| 143 | STATS_LOCK(); |
| 144 | strings_not_in_dex_cache_++; |
| 145 | } |
| 146 | |
| 147 | void TypeDoesntNeedAccessCheck() { |
| 148 | STATS_LOCK(); |
| 149 | resolved_types_++; |
| 150 | } |
| 151 | |
| 152 | void TypeNeedsAccessCheck() { |
| 153 | STATS_LOCK(); |
| 154 | unresolved_types_++; |
| 155 | } |
| 156 | |
| 157 | void ResolvedInstanceField() { |
| 158 | STATS_LOCK(); |
| 159 | resolved_instance_fields_++; |
| 160 | } |
| 161 | |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 162 | void UnresolvedInstanceField() { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 163 | STATS_LOCK(); |
| 164 | unresolved_instance_fields_++; |
| 165 | } |
| 166 | |
| 167 | void ResolvedLocalStaticField() { |
| 168 | STATS_LOCK(); |
| 169 | resolved_local_static_fields_++; |
| 170 | } |
| 171 | |
| 172 | void ResolvedStaticField() { |
| 173 | STATS_LOCK(); |
| 174 | resolved_static_fields_++; |
| 175 | } |
| 176 | |
| 177 | void UnresolvedStaticField() { |
| 178 | STATS_LOCK(); |
| 179 | unresolved_static_fields_++; |
| 180 | } |
| 181 | |
| 182 | void ResolvedMethod(InvokeType type) { |
| 183 | DCHECK_LE(type, kMaxInvokeType); |
| 184 | STATS_LOCK(); |
| 185 | resolved_methods_[type]++; |
| 186 | } |
| 187 | |
| 188 | void UnresolvedMethod(InvokeType type) { |
| 189 | DCHECK_LE(type, kMaxInvokeType); |
| 190 | STATS_LOCK(); |
| 191 | unresolved_methods_[type]++; |
| 192 | } |
| 193 | |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 194 | void VirtualMadeDirect(InvokeType type) { |
| 195 | DCHECK_LE(type, kMaxInvokeType); |
Ian Rogers | fb6adba | 2012-03-04 21:51:51 -0800 | [diff] [blame] | 196 | STATS_LOCK(); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 197 | virtual_made_direct_[type]++; |
Ian Rogers | fb6adba | 2012-03-04 21:51:51 -0800 | [diff] [blame] | 198 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 199 | |
| 200 | void DirectCallsToBoot(InvokeType type) { |
| 201 | DCHECK_LE(type, kMaxInvokeType); |
| 202 | STATS_LOCK(); |
| 203 | direct_calls_to_boot_[type]++; |
| 204 | } |
| 205 | |
| 206 | void DirectMethodsToBoot(InvokeType type) { |
| 207 | DCHECK_LE(type, kMaxInvokeType); |
| 208 | STATS_LOCK(); |
| 209 | direct_methods_to_boot_[type]++; |
| 210 | } |
| 211 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 212 | private: |
| 213 | Mutex stats_lock_; |
| 214 | |
| 215 | size_t types_in_dex_cache_; |
| 216 | size_t types_not_in_dex_cache_; |
| 217 | |
| 218 | size_t strings_in_dex_cache_; |
| 219 | size_t strings_not_in_dex_cache_; |
| 220 | |
| 221 | size_t resolved_types_; |
| 222 | size_t unresolved_types_; |
| 223 | |
| 224 | size_t resolved_instance_fields_; |
| 225 | size_t unresolved_instance_fields_; |
| 226 | |
| 227 | size_t resolved_local_static_fields_; |
| 228 | size_t resolved_static_fields_; |
| 229 | size_t unresolved_static_fields_; |
| 230 | |
| 231 | size_t resolved_methods_[kMaxInvokeType + 1]; |
| 232 | size_t unresolved_methods_[kMaxInvokeType + 1]; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 233 | size_t virtual_made_direct_[kMaxInvokeType + 1]; |
| 234 | size_t direct_calls_to_boot_[kMaxInvokeType + 1]; |
| 235 | size_t direct_methods_to_boot_[kMaxInvokeType + 1]; |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 236 | |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 237 | DISALLOW_COPY_AND_ASSIGN(AOTCompilationStats); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 238 | }; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 239 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 240 | static std::string MakeCompilerSoName(InstructionSet instruction_set) { |
| 241 | // TODO: is the ARM/Thumb2 instruction set distinction really buying us anything, |
| 242 | // or just causing hassle like this? |
| 243 | if (instruction_set == kThumb2) { |
| 244 | instruction_set = kArm; |
| 245 | } |
| 246 | |
Elliott Hughes | 059d5c1 | 2012-03-12 17:39:18 -0700 | [diff] [blame] | 247 | // Capitalize the instruction set, because that's what we do in the build system. |
Elliott Hughes | 6fcce30 | 2012-06-19 16:54:19 -0700 | [diff] [blame] | 248 | std::string instruction_set_name(ToStr<InstructionSet>(instruction_set).str()); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 249 | for (size_t i = 0; i < instruction_set_name.size(); ++i) { |
| 250 | instruction_set_name[i] = toupper(instruction_set_name[i]); |
| 251 | } |
Elliott Hughes | 059d5c1 | 2012-03-12 17:39:18 -0700 | [diff] [blame] | 252 | |
| 253 | // Bad things happen if we pull in the libartd-compiler to a libart dex2oat or vice versa, |
| 254 | // because we end up with both libart and libartd in the same address space! |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 255 | const char* suffix = (kIsDebugBuild ? "d" : ""); |
Elliott Hughes | 059d5c1 | 2012-03-12 17:39:18 -0700 | [diff] [blame] | 256 | |
| 257 | // Work out the filename for the compiler library. |
Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 258 | #if defined(ART_USE_LLVM_COMPILER) |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 259 | std::string library_name(StringPrintf("art%s-compiler-llvm", suffix)); |
Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 260 | #elif defined(ART_USE_GREENLAND_COMPILER) |
| 261 | std::string library_name(StringPrintf("art%s-compiler-greenland", suffix)); |
| 262 | #else |
| 263 | std::string library_name(StringPrintf("art%s-compiler-%s", suffix, instruction_set_name.c_str())); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 264 | #endif |
Elliott Hughes | 059d5c1 | 2012-03-12 17:39:18 -0700 | [diff] [blame] | 265 | std::string filename(StringPrintf(OS_SHARED_LIB_FORMAT_STR, library_name.c_str())); |
| 266 | |
| 267 | #if defined(__APPLE__) |
| 268 | // On Linux, dex2oat will have been built with an RPATH of $ORIGIN/../lib, so dlopen(3) will find |
| 269 | // the .so by itself. On Mac OS, there isn't really an equivalent, so we have to manually do the |
| 270 | // same work. |
Elliott Hughes | 059d5c1 | 2012-03-12 17:39:18 -0700 | [diff] [blame] | 271 | uint32_t executable_path_length = 0; |
Elliott Hughes | 448e93c | 2012-03-28 22:30:06 -0700 | [diff] [blame] | 272 | _NSGetExecutablePath(NULL, &executable_path_length); |
| 273 | std::string path(executable_path_length, static_cast<char>(0)); |
| 274 | CHECK_EQ(_NSGetExecutablePath(&path[0], &executable_path_length), 0); |
Elliott Hughes | 059d5c1 | 2012-03-12 17:39:18 -0700 | [diff] [blame] | 275 | |
| 276 | // Strip the "/dex2oat". |
| 277 | size_t last_slash = path.find_last_of('/'); |
| 278 | CHECK_NE(last_slash, std::string::npos) << path; |
| 279 | path.resize(last_slash); |
| 280 | |
| 281 | // Strip the "/bin". |
| 282 | last_slash = path.find_last_of('/'); |
| 283 | path.resize(last_slash); |
| 284 | |
| 285 | filename = path + "/lib/" + filename; |
| 286 | #endif |
| 287 | return filename; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Elliott Hughes | 46f060a | 2012-03-09 17:36:50 -0800 | [diff] [blame] | 290 | template<typename Fn> |
| 291 | static Fn FindFunction(const std::string& compiler_so_name, void* library, const char* name) { |
| 292 | Fn fn = reinterpret_cast<Fn>(dlsym(library, name)); |
| 293 | if (fn == NULL) { |
| 294 | LOG(FATAL) << "Couldn't find \"" << name << "\" in compiler library " << compiler_so_name << ": " << dlerror(); |
| 295 | } |
Elliott Hughes | 059d5c1 | 2012-03-12 17:39:18 -0700 | [diff] [blame] | 296 | VLOG(compiler) << "Found \"" << name << "\" at " << reinterpret_cast<void*>(fn); |
Elliott Hughes | 46f060a | 2012-03-09 17:36:50 -0800 | [diff] [blame] | 297 | return fn; |
| 298 | } |
| 299 | |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 300 | Compiler::Compiler(InstructionSet instruction_set, bool image, size_t thread_count, |
Brian Carlstrom | ba0668e | 2012-03-26 13:14:07 -0700 | [diff] [blame] | 301 | bool support_debugging, const std::set<std::string>* image_classes, |
| 302 | bool dump_stats, bool dump_timings) |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 303 | : instruction_set_(instruction_set), |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 304 | compiled_classes_lock_("compiled classes lock"), |
| 305 | compiled_methods_lock_("compiled method lock"), |
| 306 | compiled_invoke_stubs_lock_("compiled invoke stubs lock"), |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 307 | #if defined(ART_USE_LLVM_COMPILER) |
| 308 | compiled_proxy_stubs_lock_("compiled proxy stubs lock"), |
| 309 | #endif |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 310 | image_(image), |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 311 | thread_count_(thread_count), |
Elliott Hughes | de6e4cf | 2012-02-27 14:46:06 -0800 | [diff] [blame] | 312 | support_debugging_(support_debugging), |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 313 | stats_(new AOTCompilationStats), |
Brian Carlstrom | ba0668e | 2012-03-26 13:14:07 -0700 | [diff] [blame] | 314 | dump_stats_(dump_stats), |
| 315 | dump_timings_(dump_timings), |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 316 | image_classes_(image_classes), |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 317 | compiler_library_(NULL), |
Elliott Hughes | 46f060a | 2012-03-09 17:36:50 -0800 | [diff] [blame] | 318 | compiler_(NULL), |
Elliott Hughes | 6f4976c | 2012-03-13 21:19:01 -0700 | [diff] [blame] | 319 | compiler_context_(NULL), |
Elliott Hughes | 46f060a | 2012-03-09 17:36:50 -0800 | [diff] [blame] | 320 | jni_compiler_(NULL), |
Elliott Hughes | 5ddbe0b | 2012-06-01 12:58:24 -0700 | [diff] [blame] | 321 | #if !defined(ART_USE_LLVM_COMPILER) |
| 322 | create_invoke_stub_(NULL) { |
| 323 | #else |
| 324 | create_invoke_stub_(NULL), |
| 325 | compiler_enable_auto_elf_loading_(NULL), |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 326 | compiler_get_method_code_addr_(NULL), |
Elliott Hughes | 5ddbe0b | 2012-06-01 12:58:24 -0700 | [diff] [blame] | 327 | compiler_get_method_invoke_stub_addr_(NULL) { |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 328 | #endif |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 329 | std::string compiler_so_name(MakeCompilerSoName(instruction_set_)); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 330 | compiler_library_ = dlopen(compiler_so_name.c_str(), RTLD_LAZY); |
| 331 | if (compiler_library_ == NULL) { |
| 332 | LOG(FATAL) << "Couldn't find compiler library " << compiler_so_name << ": " << dlerror(); |
| 333 | } |
| 334 | VLOG(compiler) << "dlopen(\"" << compiler_so_name << "\", RTLD_LAZY) returned " << compiler_library_; |
| 335 | |
Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 336 | #if defined(ART_USE_LLVM_COMPILER) || defined(ART_USE_GREENLAND_COMPILER) |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 337 | // Initialize compiler_context_ |
| 338 | typedef void (*InitCompilerContextFn)(Compiler&); |
| 339 | |
| 340 | InitCompilerContextFn init_compiler_context = |
| 341 | FindFunction<void (*)(Compiler&)>(compiler_so_name, |
| 342 | compiler_library_, |
| 343 | "ArtInitCompilerContext"); |
| 344 | |
| 345 | init_compiler_context(*this); |
| 346 | #endif |
| 347 | |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame] | 348 | compiler_ = FindFunction<CompilerFn>(compiler_so_name, compiler_library_, "ArtCompileMethod"); |
Elliott Hughes | 46f060a | 2012-03-09 17:36:50 -0800 | [diff] [blame] | 349 | jni_compiler_ = FindFunction<JniCompilerFn>(compiler_so_name, compiler_library_, "ArtJniCompileMethod"); |
| 350 | create_invoke_stub_ = FindFunction<CreateInvokeStubFn>(compiler_so_name, compiler_library_, "ArtCreateInvokeStub"); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 351 | |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 352 | #if defined(ART_USE_LLVM_COMPILER) |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 353 | create_proxy_stub_ = FindFunction<CreateProxyStubFn>( |
| 354 | compiler_so_name, compiler_library_, "ArtCreateProxyStub"); |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 355 | compiler_enable_auto_elf_loading_ = FindFunction<CompilerEnableAutoElfLoadingFn>( |
| 356 | compiler_so_name, compiler_library_, "compilerLLVMEnableAutoElfLoading"); |
| 357 | compiler_get_method_code_addr_ = FindFunction<CompilerGetMethodCodeAddrFn>( |
| 358 | compiler_so_name, compiler_library_, "compilerLLVMGetMethodCodeAddr"); |
| 359 | compiler_get_method_invoke_stub_addr_ = FindFunction<CompilerGetMethodInvokeStubAddrFn>( |
| 360 | compiler_so_name, compiler_library_, "compilerLLVMGetMethodInvokeStubAddr"); |
| 361 | #endif |
| 362 | |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 363 | CHECK(!Runtime::Current()->IsStarted()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 364 | if (!image_) { |
| 365 | CHECK(image_classes_ == NULL); |
| 366 | } |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 369 | Compiler::~Compiler() { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 370 | { |
| 371 | MutexLock mu(compiled_classes_lock_); |
| 372 | STLDeleteValues(&compiled_classes_); |
| 373 | } |
| 374 | { |
| 375 | MutexLock mu(compiled_methods_lock_); |
| 376 | STLDeleteValues(&compiled_methods_); |
| 377 | } |
| 378 | { |
| 379 | MutexLock mu(compiled_invoke_stubs_lock_); |
| 380 | STLDeleteValues(&compiled_invoke_stubs_); |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 381 | } |
Brian Carlstrom | d06dfe7 | 2012-06-06 22:15:39 -0700 | [diff] [blame] | 382 | #if defined(ART_USE_LLVM_COMPILER) |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 383 | { |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 384 | MutexLock mu(compiled_proxy_stubs_lock_); |
| 385 | STLDeleteValues(&compiled_proxy_stubs_); |
| 386 | } |
Brian Carlstrom | d06dfe7 | 2012-06-06 22:15:39 -0700 | [diff] [blame] | 387 | #endif |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 388 | { |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 389 | MutexLock mu(compiled_methods_lock_); |
| 390 | STLDeleteElements(&code_to_patch_); |
| 391 | } |
| 392 | { |
| 393 | MutexLock mu(compiled_methods_lock_); |
| 394 | STLDeleteElements(&methods_to_patch_); |
| 395 | } |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 396 | #if defined(ART_USE_LLVM_COMPILER) |
| 397 | CompilerCallbackFn f = FindFunction<CompilerCallbackFn>(MakeCompilerSoName(instruction_set_), |
| 398 | compiler_library_, |
| 399 | "compilerLLVMDispose"); |
| 400 | (*f)(*this); |
| 401 | #endif |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 402 | if (compiler_library_ != NULL) { |
| 403 | VLOG(compiler) << "dlclose(" << compiler_library_ << ")"; |
| 404 | dlclose(compiler_library_); |
| 405 | } |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 408 | ByteArray* Compiler::CreateResolutionStub(InstructionSet instruction_set, |
| 409 | Runtime::TrampolineType type) { |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 410 | if (instruction_set == kX86) { |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 411 | return x86::X86CreateResolutionTrampoline(type); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 412 | } else { |
| 413 | CHECK(instruction_set == kArm || instruction_set == kThumb2); |
| 414 | // Generates resolution stub using ARM instruction set |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 415 | return arm::ArmCreateResolutionTrampoline(type); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 419 | ByteArray* Compiler::CreateJniDlsymLookupStub(InstructionSet instruction_set) { |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 420 | switch (instruction_set) { |
| 421 | case kArm: |
| 422 | case kThumb2: |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 423 | return arm::CreateJniDlsymLookupStub(); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 424 | case kX86: |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 425 | return x86::CreateJniDlsymLookupStub(); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 426 | default: |
Ian Rogers | 49c4894 | 2012-03-11 15:15:37 -0700 | [diff] [blame] | 427 | LOG(FATAL) << "Unknown InstructionSet: " << instruction_set; |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 428 | return NULL; |
| 429 | } |
| 430 | } |
| 431 | |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 432 | ByteArray* Compiler::CreateAbstractMethodErrorStub(InstructionSet instruction_set) { |
| 433 | if (instruction_set == kX86) { |
| 434 | return x86::CreateAbstractMethodErrorStub(); |
| 435 | } else { |
| 436 | CHECK(instruction_set == kArm || instruction_set == kThumb2); |
| 437 | // Generates resolution stub using ARM instruction set |
| 438 | return arm::CreateAbstractMethodErrorStub(); |
| 439 | } |
| 440 | } |
| 441 | |
Jesse Wilson | 254db0f | 2011-11-16 16:44:11 -0500 | [diff] [blame] | 442 | void Compiler::CompileAll(const ClassLoader* class_loader, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 443 | const std::vector<const DexFile*>& dex_files) { |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 444 | DCHECK(!Runtime::Current()->IsStarted()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 445 | |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 446 | TimingLogger timings("compiler"); |
| 447 | |
Elliott Hughes | 4909ba4 | 2012-06-14 13:33:49 -0700 | [diff] [blame] | 448 | // TODO: make the verifier thread-safe and remove this workaround. |
| 449 | size_t thread_count = thread_count_; |
| 450 | thread_count_ = 1; |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 451 | PreCompile(class_loader, dex_files, timings); |
Elliott Hughes | 4909ba4 | 2012-06-14 13:33:49 -0700 | [diff] [blame] | 452 | thread_count_ = thread_count; |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 453 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 454 | Compile(class_loader, dex_files); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 455 | timings.AddSplit("Compile"); |
| 456 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 457 | PostCompile(class_loader, dex_files); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 458 | timings.AddSplit("PostCompile"); |
| 459 | |
Brian Carlstrom | ba0668e | 2012-03-26 13:14:07 -0700 | [diff] [blame] | 460 | if (dump_timings_ && timings.GetTotalNs() > MsToNs(1000)) { |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 461 | timings.Dump(); |
| 462 | } |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 463 | |
Brian Carlstrom | ba0668e | 2012-03-26 13:14:07 -0700 | [diff] [blame] | 464 | if (dump_stats_) { |
| 465 | stats_->Dump(); |
| 466 | } |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 469 | void Compiler::CompileOne(const Method* method) { |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 470 | DCHECK(!Runtime::Current()->IsStarted()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 471 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 472 | const ClassLoader* class_loader = method->GetDeclaringClass()->GetClassLoader(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 473 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 474 | // Find the dex_file |
| 475 | const DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache(); |
| 476 | const DexFile& dex_file = Runtime::Current()->GetClassLinker()->FindDexFile(dex_cache); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 477 | std::vector<const DexFile*> dex_files; |
| 478 | dex_files.push_back(&dex_file); |
| 479 | |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 480 | TimingLogger timings("CompileOne"); |
| 481 | PreCompile(class_loader, dex_files, timings); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 482 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 483 | uint32_t method_idx = method->GetDexMethodIndex(); |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 484 | const DexFile::CodeItem* code_item = dex_file.GetCodeItem(method->GetCodeItemOffset()); |
| 485 | CompileMethod(code_item, method->GetAccessFlags(), method_idx, class_loader, dex_file); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 486 | |
| 487 | PostCompile(class_loader, dex_files); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 490 | void Compiler::Resolve(const ClassLoader* class_loader, |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 491 | const std::vector<const DexFile*>& dex_files, TimingLogger& timings) { |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 492 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 493 | const DexFile* dex_file = dex_files[i]; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 494 | CHECK(dex_file != NULL); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 495 | ResolveDexFile(class_loader, *dex_file, timings); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 499 | void Compiler::PreCompile(const ClassLoader* class_loader, |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 500 | const std::vector<const DexFile*>& dex_files, TimingLogger& timings) { |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 501 | Resolve(class_loader, dex_files, timings); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 502 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 503 | Verify(class_loader, dex_files); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 504 | timings.AddSplit("PreCompile.Verify"); |
| 505 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 506 | InitializeClassesWithoutClinit(class_loader, dex_files); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 507 | timings.AddSplit("PreCompile.InitializeClassesWithoutClinit"); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void Compiler::PostCompile(const ClassLoader* class_loader, |
| 511 | const std::vector<const DexFile*>& dex_files) { |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 512 | SetGcMaps(class_loader, dex_files); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 513 | #if defined(ART_USE_LLVM_COMPILER) |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 514 | CompilerCallbackFn f = FindFunction<CompilerCallbackFn>(MakeCompilerSoName(instruction_set_), |
| 515 | compiler_library_, |
| 516 | "compilerLLVMMaterializeRemainder"); |
| 517 | (*f)(*this); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 518 | #endif |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | bool Compiler::IsImageClass(const std::string& descriptor) const { |
| 522 | if (image_classes_ == NULL) { |
| 523 | return true; |
| 524 | } |
| 525 | return image_classes_->find(descriptor) != image_classes_->end(); |
| 526 | } |
| 527 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 528 | bool Compiler::CanAssumeTypeIsPresentInDexCache(const DexCache* dex_cache, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 529 | uint32_t type_idx) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 530 | if (!IsImage()) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 531 | stats_->TypeNotInDexCache(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 532 | return false; |
| 533 | } |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 534 | Class* resolved_class = dex_cache->GetResolvedType(type_idx); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 535 | if (resolved_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 536 | stats_->TypeNotInDexCache(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 537 | return false; |
| 538 | } |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 539 | bool result = IsImageClass(ClassHelper(resolved_class).GetDescriptor()); |
| 540 | if (result) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 541 | stats_->TypeInDexCache(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 542 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 543 | stats_->TypeNotInDexCache(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 544 | } |
| 545 | return result; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 548 | bool Compiler::CanAssumeStringIsPresentInDexCache(const DexCache* dex_cache, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 549 | uint32_t string_idx) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 550 | // TODO: Add support for loading strings referenced by image_classes_ |
| 551 | // See also Compiler::ResolveDexFile |
| 552 | |
| 553 | // The following is a test saying that if we're building the image without a restricted set of |
| 554 | // image classes then we can assume the string is present in the dex cache if it is there now |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 555 | bool result = IsImage() && image_classes_ == NULL && dex_cache->GetResolvedString(string_idx) != NULL; |
| 556 | if (result) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 557 | stats_->StringInDexCache(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 558 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 559 | stats_->StringNotInDexCache(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 560 | } |
| 561 | return result; |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | bool Compiler::CanAccessTypeWithoutChecks(uint32_t referrer_idx, const DexCache* dex_cache, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 565 | const DexFile& dex_file, uint32_t type_idx) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 566 | // Get type from dex cache assuming it was populated by the verifier |
| 567 | Class* resolved_class = dex_cache->GetResolvedType(type_idx); |
| 568 | if (resolved_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 569 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 570 | return false; // Unknown class needs access checks. |
| 571 | } |
| 572 | const DexFile::MethodId& method_id = dex_file.GetMethodId(referrer_idx); |
| 573 | Class* referrer_class = dex_cache->GetResolvedType(method_id.class_idx_); |
| 574 | if (referrer_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 575 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 576 | return false; // Incomplete referrer knowledge needs access check. |
| 577 | } |
| 578 | // Perform access check, will return true if access is ok or false if we're going to have to |
| 579 | // check this at runtime (for example for class loaders). |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 580 | bool result = referrer_class->CanAccess(resolved_class); |
| 581 | if (result) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 582 | stats_->TypeDoesntNeedAccessCheck(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 583 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 584 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 585 | } |
| 586 | return result; |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | bool Compiler::CanAccessInstantiableTypeWithoutChecks(uint32_t referrer_idx, |
| 590 | const DexCache* dex_cache, |
| 591 | const DexFile& dex_file, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 592 | uint32_t type_idx) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 593 | // Get type from dex cache assuming it was populated by the verifier. |
| 594 | Class* resolved_class = dex_cache->GetResolvedType(type_idx); |
| 595 | if (resolved_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 596 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 597 | return false; // Unknown class needs access checks. |
| 598 | } |
| 599 | const DexFile::MethodId& method_id = dex_file.GetMethodId(referrer_idx); |
| 600 | Class* referrer_class = dex_cache->GetResolvedType(method_id.class_idx_); |
| 601 | if (referrer_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 602 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 603 | return false; // Incomplete referrer knowledge needs access check. |
| 604 | } |
| 605 | // Perform access and instantiable checks, will return true if access is ok or false if we're |
| 606 | // going to have to check this at runtime (for example for class loaders). |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 607 | bool result = referrer_class->CanAccess(resolved_class) && resolved_class->IsInstantiable(); |
| 608 | if (result) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 609 | stats_->TypeDoesntNeedAccessCheck(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 610 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 611 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 612 | } |
| 613 | return result; |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 616 | static Class* ComputeReferrerClass(OatCompilationUnit* mUnit) { |
| 617 | const DexFile::MethodId& referrer_method_id = |
| 618 | mUnit->dex_file_->GetMethodId(mUnit->method_idx_); |
| 619 | |
| 620 | return mUnit->class_linker_->ResolveType( |
| 621 | *mUnit->dex_file_, referrer_method_id.class_idx_, |
| 622 | mUnit->dex_cache_, mUnit->class_loader_); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 623 | } |
| 624 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 625 | static Field* ComputeReferrerField(OatCompilationUnit* mUnit, uint32_t field_idx) { |
| 626 | return mUnit->class_linker_->ResolveField( |
| 627 | *mUnit->dex_file_, field_idx, mUnit->dex_cache_, |
| 628 | mUnit->class_loader_, false); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 629 | } |
| 630 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 631 | static Method* ComputeReferrerMethod(OatCompilationUnit* mUnit, uint32_t method_idx) { |
| 632 | return mUnit->class_linker_->ResolveMethod( |
| 633 | *mUnit->dex_file_, method_idx, mUnit->dex_cache_, |
| 634 | mUnit->class_loader_, true); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 637 | bool Compiler::ComputeInstanceFieldInfo(uint32_t field_idx, OatCompilationUnit* mUnit, |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 638 | int& field_offset, bool& is_volatile, bool is_put) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 639 | // Conservative defaults |
| 640 | field_offset = -1; |
| 641 | is_volatile = true; |
| 642 | // Try to resolve field |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 643 | Field* resolved_field = ComputeReferrerField(mUnit, field_idx); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 644 | if (resolved_field != NULL) { |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 645 | Class* referrer_class = ComputeReferrerClass(mUnit); |
Ian Rogers | e2645d3 | 2012-04-11 14:42:42 -0700 | [diff] [blame] | 646 | if (referrer_class != NULL) { |
| 647 | Class* fields_class = resolved_field->GetDeclaringClass(); |
| 648 | bool access_ok = referrer_class->CanAccess(fields_class) && |
| 649 | referrer_class->CanAccessMember(fields_class, |
| 650 | resolved_field->GetAccessFlags()); |
| 651 | if (!access_ok) { |
| 652 | // The referring class can't access the resolved field, this may occur as a result of a |
| 653 | // protected field being made public by a sub-class. Resort to the dex file to determine |
| 654 | // the correct class for the access check. |
| 655 | const DexFile& dex_file = mUnit->class_linker_->FindDexFile(referrer_class->GetDexCache()); |
| 656 | Class* dex_fields_class = mUnit->class_linker_->ResolveType(dex_file, |
| 657 | dex_file.GetFieldId(field_idx).class_idx_, |
| 658 | referrer_class); |
| 659 | access_ok = referrer_class->CanAccess(dex_fields_class) && |
| 660 | referrer_class->CanAccessMember(dex_fields_class, |
| 661 | resolved_field->GetAccessFlags()); |
| 662 | } |
| 663 | bool is_write_to_final_from_wrong_class = is_put && resolved_field->IsFinal() && |
| 664 | fields_class != referrer_class; |
| 665 | if (access_ok && !is_write_to_final_from_wrong_class) { |
| 666 | field_offset = resolved_field->GetOffset().Int32Value(); |
| 667 | is_volatile = resolved_field->IsVolatile(); |
| 668 | stats_->ResolvedInstanceField(); |
| 669 | return true; // Fast path. |
| 670 | } |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | // Clean up any exception left by field/type resolution |
| 674 | Thread* thread = Thread::Current(); |
| 675 | if (thread->IsExceptionPending()) { |
| 676 | thread->ClearException(); |
| 677 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 678 | stats_->UnresolvedInstanceField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 679 | return false; // Incomplete knowledge needs slow path. |
| 680 | } |
| 681 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 682 | bool Compiler::ComputeStaticFieldInfo(uint32_t field_idx, OatCompilationUnit* mUnit, |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 683 | int& field_offset, int& ssb_index, |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 684 | bool& is_referrers_class, bool& is_volatile, bool is_put) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 685 | // Conservative defaults |
| 686 | field_offset = -1; |
| 687 | ssb_index = -1; |
| 688 | is_referrers_class = false; |
| 689 | is_volatile = true; |
| 690 | // Try to resolve field |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 691 | Field* resolved_field = ComputeReferrerField(mUnit, field_idx); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 692 | if (resolved_field != NULL) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 693 | DCHECK(resolved_field->IsStatic()); |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 694 | Class* referrer_class = ComputeReferrerClass(mUnit); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 695 | if (referrer_class != NULL) { |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 696 | Class* fields_class = resolved_field->GetDeclaringClass(); |
| 697 | if (fields_class == referrer_class) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 698 | is_referrers_class = true; // implies no worrying about class initialization |
| 699 | field_offset = resolved_field->GetOffset().Int32Value(); |
| 700 | is_volatile = resolved_field->IsVolatile(); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 701 | stats_->ResolvedLocalStaticField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 702 | return true; // fast path |
| 703 | } else { |
Ian Rogers | e2645d3 | 2012-04-11 14:42:42 -0700 | [diff] [blame] | 704 | bool access_ok = referrer_class->CanAccess(fields_class) && |
| 705 | referrer_class->CanAccessMember(fields_class, |
| 706 | resolved_field->GetAccessFlags()); |
| 707 | if (!access_ok) { |
| 708 | // The referring class can't access the resolved field, this may occur as a result of a |
| 709 | // protected field being made public by a sub-class. Resort to the dex file to determine |
| 710 | // the correct class for the access check. Don't change the field's class as that is |
| 711 | // used to identify the SSB. |
| 712 | const DexFile& dex_file = mUnit->class_linker_->FindDexFile(referrer_class->GetDexCache()); |
| 713 | Class* dex_fields_class = |
| 714 | mUnit->class_linker_->ResolveType(dex_file, |
| 715 | dex_file.GetFieldId(field_idx).class_idx_, |
| 716 | referrer_class); |
| 717 | access_ok = referrer_class->CanAccess(dex_fields_class) && |
| 718 | referrer_class->CanAccessMember(dex_fields_class, |
| 719 | resolved_field->GetAccessFlags()); |
| 720 | } |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 721 | bool is_write_to_final_from_wrong_class = is_put && resolved_field->IsFinal(); |
Ian Rogers | e2645d3 | 2012-04-11 14:42:42 -0700 | [diff] [blame] | 722 | if (access_ok && !is_write_to_final_from_wrong_class) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 723 | // We have the resolved field, we must make it into a ssbIndex for the referrer |
| 724 | // in its static storage base (which may fail if it doesn't have a slot for it) |
Ian Rogers | 4103ad2 | 2012-02-06 09:18:25 -0800 | [diff] [blame] | 725 | // TODO: for images we can elide the static storage base null check |
| 726 | // if we know there's a non-null entry in the image |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 727 | if (fields_class->GetDexCache() == mUnit->dex_cache_) { |
Ian Rogers | 4103ad2 | 2012-02-06 09:18:25 -0800 | [diff] [blame] | 728 | // common case where the dex cache of both the referrer and the field are the same, |
| 729 | // no need to search the dex file |
| 730 | ssb_index = fields_class->GetDexTypeIndex(); |
| 731 | field_offset = resolved_field->GetOffset().Int32Value(); |
| 732 | is_volatile = resolved_field->IsVolatile(); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 733 | stats_->ResolvedStaticField(); |
Ian Rogers | 4103ad2 | 2012-02-06 09:18:25 -0800 | [diff] [blame] | 734 | return true; |
| 735 | } |
Ian Rogers | e2645d3 | 2012-04-11 14:42:42 -0700 | [diff] [blame] | 736 | // Search dex file for localized ssb index, may fail if field's class is a parent |
| 737 | // of the class mentioned in the dex file and there is no dex cache entry. |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 738 | std::string descriptor(FieldHelper(resolved_field).GetDeclaringClassDescriptor()); |
| 739 | const DexFile::StringId* string_id = |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 740 | mUnit->dex_file_->FindStringId(descriptor); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 741 | if (string_id != NULL) { |
| 742 | const DexFile::TypeId* type_id = |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 743 | mUnit->dex_file_->FindTypeId(mUnit->dex_file_->GetIndexForStringId(*string_id)); |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 744 | if (type_id != NULL) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 745 | // medium path, needs check of static storage base being initialized |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 746 | ssb_index = mUnit->dex_file_->GetIndexForTypeId(*type_id); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 747 | field_offset = resolved_field->GetOffset().Int32Value(); |
| 748 | is_volatile = resolved_field->IsVolatile(); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 749 | stats_->ResolvedStaticField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 750 | return true; |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | // Clean up any exception left by field/type resolution |
| 758 | Thread* thread = Thread::Current(); |
| 759 | if (thread->IsExceptionPending()) { |
| 760 | thread->ClearException(); |
| 761 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 762 | stats_->UnresolvedStaticField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 763 | return false; // Incomplete knowledge needs slow path. |
| 764 | } |
| 765 | |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 766 | void Compiler::GetCodeAndMethodForDirectCall(InvokeType type, InvokeType sharp_type, Method* method, |
| 767 | uintptr_t& direct_code, uintptr_t& direct_method) { |
| 768 | direct_code = 0; |
| 769 | direct_method = 0; |
| 770 | if (sharp_type != kStatic && sharp_type != kDirect) { |
| 771 | return; |
| 772 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 773 | bool method_code_in_boot = method->GetDeclaringClass()->GetClassLoader() == NULL; |
| 774 | if (!method_code_in_boot) { |
| 775 | return; |
| 776 | } |
| 777 | bool has_clinit_trampoline = method->IsStatic() && !method->GetDeclaringClass()->IsInitialized(); |
| 778 | if (has_clinit_trampoline) { |
| 779 | return; |
| 780 | } |
| 781 | stats_->DirectCallsToBoot(type); |
| 782 | stats_->DirectMethodsToBoot(type); |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 783 | bool compiling_boot = Runtime::Current()->GetHeap()->GetSpaces().size() == 1; |
| 784 | if (compiling_boot) { |
Brian Carlstrom | 0637e27 | 2012-03-20 01:07:52 -0700 | [diff] [blame] | 785 | const bool kSupportBootImageFixup = true; |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 786 | if (kSupportBootImageFixup) { |
| 787 | MethodHelper mh(method); |
| 788 | if (IsImageClass(mh.GetDeclaringClassDescriptor())) { |
Brian Carlstrom | 0637e27 | 2012-03-20 01:07:52 -0700 | [diff] [blame] | 789 | // We can only branch directly to Methods that are resolved in the DexCache. |
| 790 | // Otherwise we won't invoke the resolution trampoline. |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 791 | direct_method = -1; |
Brian Carlstrom | 0637e27 | 2012-03-20 01:07:52 -0700 | [diff] [blame] | 792 | direct_code = -1; |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 793 | } |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 794 | } |
| 795 | } else { |
| 796 | if (Runtime::Current()->GetHeap()->GetImageSpace()->Contains(method)) { |
| 797 | direct_method = reinterpret_cast<uintptr_t>(method); |
| 798 | } |
| 799 | direct_code = reinterpret_cast<uintptr_t>(method->GetCode()); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 800 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Ian Rogers | fb6adba | 2012-03-04 21:51:51 -0800 | [diff] [blame] | 803 | bool Compiler::ComputeInvokeInfo(uint32_t method_idx, OatCompilationUnit* mUnit, InvokeType& type, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 804 | int& vtable_idx, uintptr_t& direct_code, |
| 805 | uintptr_t& direct_method) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 806 | vtable_idx = -1; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 807 | direct_code = 0; |
| 808 | direct_method = 0; |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 809 | Method* resolved_method = ComputeReferrerMethod(mUnit, method_idx); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 810 | if (resolved_method != NULL) { |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 811 | Class* referrer_class = ComputeReferrerClass(mUnit); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 812 | if (referrer_class != NULL) { |
| 813 | Class* methods_class = resolved_method->GetDeclaringClass(); |
| 814 | if (!referrer_class->CanAccess(methods_class) || |
| 815 | !referrer_class->CanAccessMember(methods_class, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 816 | resolved_method->GetAccessFlags())) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 817 | // The referring class can't access the resolved method, this may occur as a result of a |
| 818 | // protected method being made public by implementing an interface that re-declares the |
| 819 | // method public. Resort to the dex file to determine the correct class for the access check |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 820 | const DexFile& dex_file = mUnit->class_linker_->FindDexFile(referrer_class->GetDexCache()); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 821 | methods_class = |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 822 | mUnit->class_linker_->ResolveType(dex_file, |
| 823 | dex_file.GetMethodId(method_idx).class_idx_, |
| 824 | referrer_class); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 825 | } |
| 826 | if (referrer_class->CanAccess(methods_class) && |
| 827 | referrer_class->CanAccessMember(methods_class, |
| 828 | resolved_method->GetAccessFlags())) { |
| 829 | vtable_idx = resolved_method->GetMethodIndex(); |
Ian Rogers | f320b63 | 2012-03-13 18:47:47 -0700 | [diff] [blame] | 830 | const bool kEnableSharpening = true; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 831 | // Sharpen a virtual call into a direct call when the target is known. |
| 832 | bool can_sharpen = type == kVirtual && (resolved_method->IsFinal() || |
| 833 | methods_class->IsFinal()); |
| 834 | // ensure the vtable index will be correct to dispatch in the vtable of the super class |
jeffhao | 4155fcd | 2012-03-21 11:42:12 -0700 | [diff] [blame] | 835 | can_sharpen = can_sharpen || (type == kSuper && referrer_class != methods_class && |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 836 | referrer_class->IsSubClass(methods_class) && |
jeffhao | 4155fcd | 2012-03-21 11:42:12 -0700 | [diff] [blame] | 837 | vtable_idx < methods_class->GetVTable()->GetLength() && |
| 838 | methods_class->GetVTable()->Get(vtable_idx) == resolved_method); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 839 | if (kEnableSharpening && can_sharpen) { |
| 840 | stats_->ResolvedMethod(type); |
Ian Rogers | fb6adba | 2012-03-04 21:51:51 -0800 | [diff] [blame] | 841 | // Sharpen a virtual call into a direct call. The method_idx is into referrer's |
| 842 | // dex cache, check that this resolved method is where we expect it. |
| 843 | CHECK(referrer_class->GetDexCache()->GetResolvedMethod(method_idx) == resolved_method) |
| 844 | << PrettyMethod(resolved_method); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 845 | stats_->VirtualMadeDirect(type); |
| 846 | GetCodeAndMethodForDirectCall(type, kDirect, resolved_method, direct_code, direct_method); |
| 847 | type = kDirect; |
| 848 | return true; |
| 849 | } else if (type == kSuper) { |
| 850 | // Unsharpened super calls are suspicious so go slowpath. |
| 851 | } else { |
| 852 | stats_->ResolvedMethod(type); |
| 853 | GetCodeAndMethodForDirectCall(type, type, resolved_method, direct_code, direct_method); |
| 854 | return true; |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | // Clean up any exception left by method/type resolution |
| 860 | Thread* thread = Thread::Current(); |
| 861 | if (thread->IsExceptionPending()) { |
| 862 | thread->ClearException(); |
| 863 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 864 | stats_->UnresolvedMethod(type); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 865 | return false; // Incomplete knowledge needs slow path. |
| 866 | } |
| 867 | |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 868 | void Compiler::AddCodePatch(DexCache* dex_cache, |
| 869 | const DexFile* dex_file, |
| 870 | uint32_t referrer_method_idx, |
| 871 | uint32_t referrer_access_flags, |
| 872 | uint32_t target_method_idx, |
| 873 | bool target_is_direct, |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 874 | size_t literal_offset) { |
| 875 | MutexLock mu(compiled_methods_lock_); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 876 | code_to_patch_.push_back(new PatchInformation(dex_cache, |
| 877 | dex_file, |
| 878 | referrer_method_idx, |
| 879 | referrer_access_flags, |
| 880 | target_method_idx, |
| 881 | target_is_direct, |
| 882 | literal_offset)); |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 883 | } |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 884 | void Compiler::AddMethodPatch(DexCache* dex_cache, |
| 885 | const DexFile* dex_file, |
| 886 | uint32_t referrer_method_idx, |
| 887 | uint32_t referrer_access_flags, |
| 888 | uint32_t target_method_idx, |
| 889 | bool target_is_direct, |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 890 | size_t literal_offset) { |
| 891 | MutexLock mu(compiled_methods_lock_); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 892 | methods_to_patch_.push_back(new PatchInformation(dex_cache, |
| 893 | dex_file, |
| 894 | referrer_method_idx, |
| 895 | referrer_access_flags, |
| 896 | target_method_idx, |
| 897 | target_is_direct, |
| 898 | literal_offset)); |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Brian Carlstrom | 5ead095 | 2011-11-28 22:55:52 -0800 | [diff] [blame] | 901 | // Return true if the class should be skipped during compilation. We |
| 902 | // never skip classes in the boot class loader. However, if we have a |
| 903 | // non-boot class loader and we can resolve the class in the boot |
| 904 | // class loader, we do skip the class. This happens if an app bundles |
| 905 | // classes found in the boot classpath. Since at runtime we will |
| 906 | // select the class from the boot classpath, do not attempt to resolve |
| 907 | // or compile it now. |
| 908 | static bool SkipClass(const ClassLoader* class_loader, |
| 909 | const DexFile& dex_file, |
| 910 | const DexFile::ClassDef& class_def) { |
| 911 | if (class_loader == NULL) { |
| 912 | return false; |
| 913 | } |
| 914 | const char* descriptor = dex_file.GetClassDescriptor(class_def); |
| 915 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 916 | Class* klass = class_linker->FindClass(descriptor, NULL); |
| 917 | if (klass == NULL) { |
| 918 | Thread* self = Thread::Current(); |
| 919 | CHECK(self->IsExceptionPending()); |
| 920 | self->ClearException(); |
| 921 | return false; |
| 922 | } |
| 923 | return true; |
| 924 | } |
| 925 | |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 926 | class Context { |
| 927 | public: |
| 928 | Context(ClassLinker* class_linker, |
| 929 | const ClassLoader* class_loader, |
| 930 | Compiler* compiler, |
| 931 | DexCache* dex_cache, |
| 932 | const DexFile* dex_file) |
| 933 | : class_linker_(class_linker), |
| 934 | class_loader_(class_loader), |
| 935 | compiler_(compiler), |
| 936 | dex_cache_(dex_cache), |
| 937 | dex_file_(dex_file) {} |
| 938 | |
| 939 | ClassLinker* GetClassLinker() { |
| 940 | CHECK(class_linker_ != NULL); |
| 941 | return class_linker_; |
| 942 | } |
| 943 | const ClassLoader* GetClassLoader() { |
| 944 | return class_loader_; |
| 945 | } |
| 946 | Compiler* GetCompiler() { |
| 947 | CHECK(compiler_ != NULL); |
| 948 | return compiler_; |
| 949 | } |
| 950 | DexCache* GetDexCache() { |
| 951 | CHECK(dex_cache_ != NULL); |
| 952 | return dex_cache_; |
| 953 | } |
| 954 | const DexFile* GetDexFile() { |
| 955 | CHECK(dex_file_ != NULL); |
| 956 | return dex_file_; |
| 957 | } |
| 958 | |
| 959 | private: |
| 960 | ClassLinker* class_linker_; |
| 961 | const ClassLoader* class_loader_; |
| 962 | Compiler* compiler_; |
| 963 | DexCache* dex_cache_; |
| 964 | const DexFile* dex_file_; |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 965 | }; |
| 966 | |
| 967 | typedef void Callback(Context* context, size_t index); |
| 968 | |
| 969 | class WorkerThread { |
| 970 | public: |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 971 | WorkerThread(Context* context, size_t begin, size_t end, Callback callback, size_t stripe, bool spawn) |
| 972 | : spawn_(spawn), context_(context), begin_(begin), end_(end), callback_(callback), stripe_(stripe) { |
| 973 | if (spawn_) { |
Elliott Hughes | bf1b457 | 2012-05-24 19:11:39 -0700 | [diff] [blame] | 974 | // Mac OS stacks are only 512KiB. Make sure we have the same stack size on all platforms. |
| 975 | pthread_attr_t attr; |
| 976 | CHECK_PTHREAD_CALL(pthread_attr_init, (&attr), "new compiler worker thread"); |
| 977 | CHECK_PTHREAD_CALL(pthread_attr_setstacksize, (&attr, 1*MB), "new compiler worker thread"); |
| 978 | CHECK_PTHREAD_CALL(pthread_create, (&pthread_, &attr, &Go, this), "new compiler worker thread"); |
| 979 | CHECK_PTHREAD_CALL(pthread_attr_destroy, (&attr), "new compiler worker thread"); |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 980 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | ~WorkerThread() { |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 984 | if (spawn_) { |
| 985 | CHECK_PTHREAD_CALL(pthread_join, (pthread_, NULL), "compiler worker shutdown"); |
| 986 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | private: |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 990 | static void* Go(void* arg) { |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 991 | WorkerThread* worker = reinterpret_cast<WorkerThread*>(arg); |
| 992 | Runtime* runtime = Runtime::Current(); |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 993 | if (worker->spawn_) { |
Elliott Hughes | 462c944 | 2012-03-23 18:47:50 -0700 | [diff] [blame] | 994 | runtime->AttachCurrentThread("Compiler Worker", true, NULL); |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 995 | } |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 996 | Thread::Current()->SetState(kRunnable); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 997 | worker->Run(); |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 998 | if (worker->spawn_) { |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 999 | Thread::Current()->SetState(kNative); |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 1000 | runtime->DetachCurrentThread(); |
| 1001 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1002 | return NULL; |
| 1003 | } |
| 1004 | |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 1005 | void Go() { |
| 1006 | Go(this); |
| 1007 | } |
| 1008 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1009 | void Run() { |
Brian Carlstrom | 64277f3 | 2012-03-26 23:53:34 -0700 | [diff] [blame] | 1010 | Thread* self = Thread::Current(); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1011 | for (size_t i = begin_; i < end_; i += stripe_) { |
| 1012 | callback_(context_, i); |
Brian Carlstrom | 64277f3 | 2012-03-26 23:53:34 -0700 | [diff] [blame] | 1013 | CHECK(!self->IsExceptionPending()) << PrettyTypeOf(self->GetException()) << " " << i; |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | pthread_t pthread_; |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 1018 | bool spawn_; |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1019 | |
| 1020 | Context* context_; |
| 1021 | size_t begin_; |
| 1022 | size_t end_; |
| 1023 | Callback* callback_; |
| 1024 | size_t stripe_; |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 1025 | |
| 1026 | friend void ForAll(Context*, size_t, size_t, Callback, size_t); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1027 | }; |
| 1028 | |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 1029 | void ForAll(Context* context, size_t begin, size_t end, Callback callback, size_t thread_count) { |
Brian Carlstrom | 64277f3 | 2012-03-26 23:53:34 -0700 | [diff] [blame] | 1030 | Thread* self = Thread::Current(); |
| 1031 | CHECK(!self->IsExceptionPending()) << PrettyTypeOf(self->GetException()); |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 1032 | CHECK_GT(thread_count, 0U); |
Elliott Hughes | 81d9151 | 2012-02-03 16:38:43 -0800 | [diff] [blame] | 1033 | |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 1034 | std::vector<WorkerThread*> threads; |
Elliott Hughes | 81d9151 | 2012-02-03 16:38:43 -0800 | [diff] [blame] | 1035 | for (size_t i = 0; i < thread_count; ++i) { |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 1036 | threads.push_back(new WorkerThread(context, begin + i, end, callback, thread_count, (i != 0))); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1037 | } |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 1038 | threads[0]->Go(); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1039 | |
Elliott Hughes | 81d9151 | 2012-02-03 16:38:43 -0800 | [diff] [blame] | 1040 | // Switch to kVmWait while we're blocked waiting for the other threads to finish. |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 1041 | ScopedThreadStateChange tsc(self, kVmWait); |
Elliott Hughes | 81d9151 | 2012-02-03 16:38:43 -0800 | [diff] [blame] | 1042 | STLDeleteElements(&threads); |
| 1043 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1044 | |
| 1045 | static void ResolveClassFieldsAndMethods(Context* context, size_t class_def_index) { |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1046 | const DexFile& dex_file = *context->GetDexFile(); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1047 | |
| 1048 | // Method and Field are the worst. We can't resolve without either |
| 1049 | // context from the code use (to disambiguate virtual vs direct |
| 1050 | // method and instance vs static field) or from class |
| 1051 | // definitions. While the compiler will resolve what it can as it |
| 1052 | // needs it, here we try to resolve fields and methods used in class |
| 1053 | // definitions, since many of them many never be referenced by |
| 1054 | // generated code. |
| 1055 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1056 | if (SkipClass(context->GetClassLoader(), dex_file, class_def)) { |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1057 | return; |
| 1058 | } |
| 1059 | |
| 1060 | // Note the class_data pointer advances through the headers, |
| 1061 | // static fields, instance fields, direct methods, and virtual |
| 1062 | // methods. |
| 1063 | const byte* class_data = dex_file.GetClassData(class_def); |
| 1064 | if (class_data == NULL) { |
| 1065 | // empty class such as a marker interface |
| 1066 | return; |
| 1067 | } |
Brian Carlstrom | 5ead095 | 2011-11-28 22:55:52 -0800 | [diff] [blame] | 1068 | Thread* self = Thread::Current(); |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1069 | ClassLinker* class_linker = context->GetClassLinker(); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1070 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
| 1071 | ClassDataItemIterator it(dex_file, class_data); |
| 1072 | while (it.HasNextStaticField()) { |
| 1073 | Field* field = class_linker->ResolveField(dex_file, it.GetMemberIndex(), dex_cache, |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1074 | context->GetClassLoader(), true); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1075 | if (field == NULL) { |
| 1076 | CHECK(self->IsExceptionPending()); |
| 1077 | self->ClearException(); |
| 1078 | } |
| 1079 | it.Next(); |
| 1080 | } |
| 1081 | while (it.HasNextInstanceField()) { |
| 1082 | Field* field = class_linker->ResolveField(dex_file, it.GetMemberIndex(), dex_cache, |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1083 | context->GetClassLoader(), false); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1084 | if (field == NULL) { |
| 1085 | CHECK(self->IsExceptionPending()); |
| 1086 | self->ClearException(); |
| 1087 | } |
| 1088 | it.Next(); |
| 1089 | } |
| 1090 | while (it.HasNextDirectMethod()) { |
| 1091 | Method* method = class_linker->ResolveMethod(dex_file, it.GetMemberIndex(), dex_cache, |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1092 | context->GetClassLoader(), true); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1093 | if (method == NULL) { |
| 1094 | CHECK(self->IsExceptionPending()); |
| 1095 | self->ClearException(); |
| 1096 | } |
| 1097 | it.Next(); |
| 1098 | } |
| 1099 | while (it.HasNextVirtualMethod()) { |
| 1100 | Method* method = class_linker->ResolveMethod(dex_file, it.GetMemberIndex(), dex_cache, |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1101 | context->GetClassLoader(), false); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1102 | if (method == NULL) { |
| 1103 | CHECK(self->IsExceptionPending()); |
| 1104 | self->ClearException(); |
| 1105 | } |
| 1106 | it.Next(); |
| 1107 | } |
| 1108 | DCHECK(!it.HasNext()); |
| 1109 | } |
| 1110 | |
| 1111 | static void ResolveType(Context* context, size_t type_idx) { |
| 1112 | // Class derived values are more complicated, they require the linker and loader. |
| 1113 | Thread* self = Thread::Current(); |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1114 | Class* klass = context->GetClassLinker()->ResolveType(*context->GetDexFile(), |
| 1115 | type_idx, |
| 1116 | context->GetDexCache(), |
| 1117 | context->GetClassLoader()); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1118 | if (klass == NULL) { |
| 1119 | CHECK(self->IsExceptionPending()); |
| 1120 | Thread::Current()->ClearException(); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | void Compiler::ResolveDexFile(const ClassLoader* class_loader, const DexFile& dex_file, TimingLogger& timings) { |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1125 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1126 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1127 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 1128 | // Strings are easy in that they always are simply resolved to literals in the same file |
| 1129 | if (image_ && image_classes_ == NULL) { |
| 1130 | // TODO: Add support for loading strings referenced by image_classes_ |
| 1131 | // See also Compiler::CanAssumeTypeIsPresentInDexCache. |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1132 | for (size_t string_idx = 0; string_idx < dex_cache->NumStrings(); string_idx++) { |
| 1133 | class_linker->ResolveString(dex_file, string_idx, dex_cache); |
| 1134 | } |
Elliott Hughes | ff73806 | 2012-02-03 15:00:42 -0800 | [diff] [blame] | 1135 | timings.AddSplit("Resolve " + dex_file.GetLocation() + " Strings"); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1138 | Context context(class_linker, class_loader, this, dex_cache, &dex_file); |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 1139 | ForAll(&context, 0, dex_cache->NumResolvedTypes(), ResolveType, thread_count_); |
Elliott Hughes | ff73806 | 2012-02-03 15:00:42 -0800 | [diff] [blame] | 1140 | timings.AddSplit("Resolve " + dex_file.GetLocation() + " Types"); |
Brian Carlstrom | 845490b | 2011-09-19 15:56:53 -0700 | [diff] [blame] | 1141 | |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 1142 | ForAll(&context, 0, dex_file.NumClassDefs(), ResolveClassFieldsAndMethods, thread_count_); |
Elliott Hughes | ff73806 | 2012-02-03 15:00:42 -0800 | [diff] [blame] | 1143 | timings.AddSplit("Resolve " + dex_file.GetLocation() + " MethodsAndFields"); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 1146 | void Compiler::Verify(const ClassLoader* class_loader, |
| 1147 | const std::vector<const DexFile*>& dex_files) { |
| 1148 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 1149 | const DexFile* dex_file = dex_files[i]; |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 1150 | CHECK(dex_file != NULL); |
| 1151 | VerifyDexFile(class_loader, *dex_file); |
| 1152 | } |
| 1153 | } |
| 1154 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1155 | static void VerifyClass(Context* context, size_t class_def_index) { |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1156 | const DexFile::ClassDef& class_def = context->GetDexFile()->GetClassDef(class_def_index); |
| 1157 | const char* descriptor = context->GetDexFile()->GetClassDescriptor(class_def); |
| 1158 | Class* klass = context->GetClassLinker()->FindClass(descriptor, context->GetClassLoader()); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1159 | if (klass == NULL) { |
| 1160 | Thread* self = Thread::Current(); |
| 1161 | CHECK(self->IsExceptionPending()); |
| 1162 | self->ClearException(); |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 1163 | |
| 1164 | /* |
| 1165 | * At compile time, we can still structurally verify the class even if FindClass fails. |
| 1166 | * This is to ensure the class is structurally sound for compilation. An unsound class |
| 1167 | * will be rejected by the verifier and later skipped during compilation in the compiler. |
| 1168 | */ |
| 1169 | std::string error_msg; |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 1170 | if (verifier::MethodVerifier::VerifyClass(context->GetDexFile(), context->GetDexCache(), |
| 1171 | context->GetClassLoader(), class_def_index, error_msg) == verifier::MethodVerifier::kHardFailure) { |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1172 | const DexFile::ClassDef& class_def = context->GetDexFile()->GetClassDef(class_def_index); |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 1173 | LOG(ERROR) << "Verification failed on class " |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1174 | << PrettyDescriptor(context->GetDexFile()->GetClassDescriptor(class_def)) |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 1175 | << " because: " << error_msg; |
| 1176 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1177 | return; |
| 1178 | } |
| 1179 | CHECK(klass->IsResolved()) << PrettyClass(klass); |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1180 | context->GetClassLinker()->VerifyClass(klass); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1181 | |
| 1182 | if (klass->IsErroneous()) { |
| 1183 | // ClassLinker::VerifyClass throws, which isn't useful in the compiler. |
| 1184 | CHECK(Thread::Current()->IsExceptionPending()); |
| 1185 | Thread::Current()->ClearException(); |
jeffhao | 1ac2944 | 2012-03-26 11:37:32 -0700 | [diff] [blame] | 1186 | art::Compiler::ClassReference ref(context->GetDexFile(), class_def_index); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1187 | } |
| 1188 | |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 1189 | CHECK(klass->IsCompileTimeVerified() || klass->IsErroneous()) << PrettyClass(klass); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 1190 | CHECK(!Thread::Current()->IsExceptionPending()) << PrettyTypeOf(Thread::Current()->GetException()); |
| 1191 | } |
| 1192 | |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 1193 | void Compiler::VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file) { |
jeffhao | b4df514 | 2011-09-19 20:25:32 -0700 | [diff] [blame] | 1194 | dex_file.ChangePermissions(PROT_READ | PROT_WRITE); |
Elliott Hughes | d9cdfe9 | 2011-10-06 16:09:04 -0700 | [diff] [blame] | 1195 | |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1196 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 1197 | Context context(class_linker, class_loader, this, class_linker->FindDexCache(dex_file), &dex_file); |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 1198 | ForAll(&context, 0, dex_file.NumClassDefs(), VerifyClass, thread_count_); |
Elliott Hughes | d9cdfe9 | 2011-10-06 16:09:04 -0700 | [diff] [blame] | 1199 | |
jeffhao | b4df514 | 2011-09-19 20:25:32 -0700 | [diff] [blame] | 1200 | dex_file.ChangePermissions(PROT_READ); |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 1203 | void Compiler::InitializeClassesWithoutClinit(const ClassLoader* class_loader, |
| 1204 | const std::vector<const DexFile*>& dex_files) { |
| 1205 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 1206 | const DexFile* dex_file = dex_files[i]; |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 1207 | CHECK(dex_file != NULL); |
| 1208 | InitializeClassesWithoutClinit(class_loader, *dex_file); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | void Compiler::InitializeClassesWithoutClinit(const ClassLoader* class_loader, const DexFile& dex_file) { |
| 1213 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Brian Carlstrom | ffca45d | 2011-09-16 12:10:49 -0700 | [diff] [blame] | 1214 | for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); class_def_index++) { |
| 1215 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 1216 | const char* descriptor = dex_file.GetClassDescriptor(class_def); |
| 1217 | Class* klass = class_linker->FindClass(descriptor, class_loader); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1218 | if (klass != NULL) { |
jeffhao | 1ac2944 | 2012-03-26 11:37:32 -0700 | [diff] [blame] | 1219 | if (klass->IsVerified()) { |
| 1220 | // Only try to initialize classes that were successfully verified. |
Ian Rogers | 0045a29 | 2012-03-31 21:08:41 -0700 | [diff] [blame] | 1221 | bool compiling_boot = Runtime::Current()->GetHeap()->GetSpaces().size() == 1; |
| 1222 | bool can_init_static_fields = compiling_boot && |
| 1223 | IsImageClass(descriptor); |
| 1224 | class_linker->EnsureInitialized(klass, false, can_init_static_fields); |
jeffhao | 1ac2944 | 2012-03-26 11:37:32 -0700 | [diff] [blame] | 1225 | } |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1226 | // record the final class status if necessary |
| 1227 | Class::Status status = klass->GetStatus(); |
| 1228 | ClassReference ref(&dex_file, class_def_index); |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1229 | MutexLock mu(compiled_classes_lock_); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1230 | CompiledClass* compiled_class = GetCompiledClass(ref); |
| 1231 | if (compiled_class == NULL) { |
| 1232 | compiled_class = new CompiledClass(status); |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1233 | compiled_classes_.Put(ref, compiled_class); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1234 | } else { |
| 1235 | DCHECK_EQ(status, compiled_class->GetStatus()); |
| 1236 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1237 | } |
| 1238 | // clear any class not found or verification exceptions |
| 1239 | Thread::Current()->ClearException(); |
Brian Carlstrom | ffca45d | 2011-09-16 12:10:49 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
| 1243 | for (size_t type_idx = 0; type_idx < dex_cache->NumResolvedTypes(); type_idx++) { |
| 1244 | Class* klass = class_linker->ResolveType(dex_file, type_idx, dex_cache, class_loader); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1245 | if (klass == NULL) { |
| 1246 | Thread::Current()->ClearException(); |
| 1247 | } else if (klass->IsInitialized()) { |
Brian Carlstrom | ffca45d | 2011-09-16 12:10:49 -0700 | [diff] [blame] | 1248 | dex_cache->GetInitializedStaticStorage()->Set(type_idx, klass); |
| 1249 | } |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | |
Shih-wei Liao | 90dc30f | 2012-04-23 02:03:30 -0700 | [diff] [blame] | 1253 | // TODO: This class shares some implementation with WorkerThread. We don't want |
| 1254 | // to perturb the non-LLVM side at the same time. Staging the refactoring for |
| 1255 | // the future. |
| 1256 | class DexFilesWorkerThread { |
| 1257 | public: |
| 1258 | DexFilesWorkerThread(Context *worker_context, Callback class_callback, |
| 1259 | const std::vector<const DexFile*>& dex_files, |
| 1260 | volatile int32_t* shared_class_index, bool spawn) |
| 1261 | : spawn_(spawn), worker_context_(worker_context), |
| 1262 | class_callback_(class_callback), dex_files_(dex_files), |
| 1263 | context_(NULL), shared_class_index_(shared_class_index) { |
| 1264 | if (spawn_) { |
TDYa127 | 8cea5fd | 2012-05-29 22:22:32 -0700 | [diff] [blame] | 1265 | pthread_attr_t attr; |
| 1266 | CHECK_PTHREAD_CALL(pthread_attr_init, (&attr), "new compiler worker thread"); |
TDYa127 | 61b409c | 2012-06-05 23:54:30 -0700 | [diff] [blame] | 1267 | CHECK_PTHREAD_CALL(pthread_attr_setstacksize, (&attr, 1*MB), "new compiler worker thread"); |
TDYa127 | 8cea5fd | 2012-05-29 22:22:32 -0700 | [diff] [blame] | 1268 | CHECK_PTHREAD_CALL(pthread_create, (&pthread_, &attr, &Go, this), "new compiler worker thread"); |
| 1269 | CHECK_PTHREAD_CALL(pthread_attr_destroy, (&attr), "new compiler worker thread"); |
Shih-wei Liao | 90dc30f | 2012-04-23 02:03:30 -0700 | [diff] [blame] | 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | ~DexFilesWorkerThread() { |
| 1274 | if (spawn_) { |
| 1275 | CHECK_PTHREAD_CALL(pthread_join, (pthread_, NULL), "compiler worker shutdown"); |
| 1276 | } |
| 1277 | delete context_; |
| 1278 | } |
| 1279 | |
| 1280 | private: |
| 1281 | static void* Go(void* arg) { |
| 1282 | DexFilesWorkerThread* worker = reinterpret_cast<DexFilesWorkerThread*>(arg); |
| 1283 | Runtime* runtime = Runtime::Current(); |
| 1284 | if (worker->spawn_) { |
| 1285 | runtime->AttachCurrentThread("Compiler Worker", true, NULL); |
| 1286 | } |
| 1287 | Thread::Current()->SetState(kRunnable); |
| 1288 | worker->Run(); |
| 1289 | if (worker->spawn_) { |
| 1290 | Thread::Current()->SetState(kNative); |
| 1291 | runtime->DetachCurrentThread(); |
| 1292 | } |
| 1293 | return NULL; |
| 1294 | } |
| 1295 | |
| 1296 | void Go() { |
| 1297 | Go(this); |
| 1298 | } |
| 1299 | |
| 1300 | void SwitchToDexFile(size_t dex_file_index) { |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 1301 | CHECK_LT(dex_file_index, dex_files_.size()); |
Shih-wei Liao | 90dc30f | 2012-04-23 02:03:30 -0700 | [diff] [blame] | 1302 | |
| 1303 | const DexFile* dex_file = dex_files_[dex_file_index]; |
| 1304 | CHECK(dex_file != NULL); |
| 1305 | |
| 1306 | // Destroy the old context |
| 1307 | delete context_; |
| 1308 | |
| 1309 | // TODO: Add a callback to let the client specify the class_linker and |
| 1310 | // dex_cache in the context for the current working dex file. |
| 1311 | context_ = new Context(/* class_linker */NULL, |
| 1312 | worker_context_->GetClassLoader(), |
| 1313 | worker_context_->GetCompiler(), |
| 1314 | /* dex_cache */NULL, dex_file); |
| 1315 | |
| 1316 | CHECK(context_ != NULL); |
| 1317 | } |
| 1318 | |
| 1319 | void Run() { |
| 1320 | Thread* self = Thread::Current(); |
| 1321 | size_t cur_dex_file_index = 0; |
| 1322 | size_t class_index_base = 0; |
| 1323 | |
| 1324 | SwitchToDexFile(0); |
| 1325 | |
| 1326 | while (true) { |
| 1327 | size_t class_index = |
| 1328 | static_cast<size_t>(android_atomic_inc(shared_class_index_)); |
| 1329 | |
| 1330 | const DexFile* dex_file; |
| 1331 | do { |
| 1332 | dex_file = dex_files_[cur_dex_file_index]; |
| 1333 | |
| 1334 | if (class_index < (class_index_base + dex_file->NumClassDefs())) { |
| 1335 | break; |
| 1336 | } |
| 1337 | class_index_base += dex_file->NumClassDefs(); |
| 1338 | |
| 1339 | cur_dex_file_index++; |
| 1340 | } while (cur_dex_file_index < dex_files_.size()); |
| 1341 | |
| 1342 | if (cur_dex_file_index >= dex_files_.size()) { |
| 1343 | return; |
| 1344 | } |
| 1345 | |
| 1346 | if (dex_file != context_->GetDexFile()) { |
| 1347 | SwitchToDexFile(cur_dex_file_index); |
| 1348 | } |
| 1349 | |
| 1350 | class_index -= class_index_base; |
| 1351 | class_callback_(context_, class_index); |
| 1352 | CHECK(!self->IsExceptionPending()) << PrettyTypeOf(self->GetException()); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | pthread_t pthread_; |
| 1357 | bool spawn_; |
| 1358 | |
| 1359 | Context* worker_context_; |
| 1360 | Callback* class_callback_; |
| 1361 | const std::vector<const DexFile*>& dex_files_; |
| 1362 | |
| 1363 | Context* context_; |
| 1364 | volatile int32_t* shared_class_index_; |
| 1365 | |
| 1366 | friend void ForClassesInAllDexFiles(Context*, |
| 1367 | const std::vector<const DexFile*>&, |
| 1368 | Callback, size_t); |
| 1369 | }; |
| 1370 | |
| 1371 | void ForClassesInAllDexFiles(Context* worker_context, |
| 1372 | const std::vector<const DexFile*>& dex_files, |
| 1373 | Callback class_callback, size_t thread_count) { |
| 1374 | Thread* self = Thread::Current(); |
| 1375 | CHECK(!self->IsExceptionPending()) << PrettyTypeOf(self->GetException()); |
| 1376 | CHECK_GT(thread_count, 0U); |
| 1377 | |
| 1378 | std::vector<DexFilesWorkerThread*> threads; |
| 1379 | volatile int32_t shared_class_index = 0; |
| 1380 | |
| 1381 | for (size_t i = 0; i < thread_count; ++i) { |
| 1382 | threads.push_back(new DexFilesWorkerThread(worker_context, class_callback, |
| 1383 | dex_files, &shared_class_index, |
| 1384 | /* spawn */ (i != 0))); |
| 1385 | } |
| 1386 | threads[0]->Go(); |
| 1387 | |
| 1388 | // Switch to kVmWait while we're blocked waiting for the other threads to finish. |
| 1389 | ScopedThreadStateChange tsc(self, kVmWait); |
| 1390 | STLDeleteElements(&threads); |
| 1391 | } |
| 1392 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 1393 | void Compiler::Compile(const ClassLoader* class_loader, |
| 1394 | const std::vector<const DexFile*>& dex_files) { |
Shih-wei Liao | 90dc30f | 2012-04-23 02:03:30 -0700 | [diff] [blame] | 1395 | #if defined(ART_USE_LLVM_COMPILER) |
| 1396 | if (dex_files.size() <= 0) { |
| 1397 | return; // No dex file |
| 1398 | } |
| 1399 | Context context(NULL, class_loader, this, NULL, NULL); |
| 1400 | ForClassesInAllDexFiles(&context, dex_files, Compiler::CompileClass, thread_count_); |
| 1401 | #else |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 1402 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 1403 | const DexFile* dex_file = dex_files[i]; |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 1404 | CHECK(dex_file != NULL); |
| 1405 | CompileDexFile(class_loader, *dex_file); |
| 1406 | } |
Shih-wei Liao | 90dc30f | 2012-04-23 02:03:30 -0700 | [diff] [blame] | 1407 | #endif |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1410 | void Compiler::CompileClass(Context* context, size_t class_def_index) { |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1411 | const ClassLoader* class_loader = context->GetClassLoader(); |
| 1412 | const DexFile& dex_file = *context->GetDexFile(); |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1413 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
Brian Carlstrom | 5ead095 | 2011-11-28 22:55:52 -0800 | [diff] [blame] | 1414 | if (SkipClass(class_loader, dex_file, class_def)) { |
| 1415 | return; |
| 1416 | } |
jeffhao | d1224c7 | 2012-02-29 13:43:08 -0800 | [diff] [blame] | 1417 | ClassReference ref(&dex_file, class_def_index); |
| 1418 | // Skip compiling classes with generic verifier failures since they will still fail at runtime |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1419 | if (verifier::MethodVerifier::IsClassRejected(ref)) { |
jeffhao | d1224c7 | 2012-02-29 13:43:08 -0800 | [diff] [blame] | 1420 | return; |
| 1421 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1422 | const byte* class_data = dex_file.GetClassData(class_def); |
| 1423 | if (class_data == NULL) { |
| 1424 | // empty class, probably a marker interface |
| 1425 | return; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1426 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1427 | ClassDataItemIterator it(dex_file, class_data); |
| 1428 | // Skip fields |
| 1429 | while (it.HasNextStaticField()) { |
| 1430 | it.Next(); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1431 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1432 | while (it.HasNextInstanceField()) { |
| 1433 | it.Next(); |
| 1434 | } |
| 1435 | // Compile direct methods |
Brian Carlstrom | 68adbe4 | 2012-05-11 17:18:08 -0700 | [diff] [blame] | 1436 | int64_t previous_direct_method_idx = -1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1437 | while (it.HasNextDirectMethod()) { |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 1438 | uint32_t method_idx = it.GetMemberIndex(); |
| 1439 | if (method_idx == previous_direct_method_idx) { |
| 1440 | // smali can create dex files with two encoded_methods sharing the same method_idx |
| 1441 | // http://code.google.com/p/smali/issues/detail?id=119 |
| 1442 | it.Next(); |
| 1443 | continue; |
| 1444 | } |
| 1445 | previous_direct_method_idx = method_idx; |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1446 | context->GetCompiler()->CompileMethod(it.GetMethodCodeItem(), it.GetMemberAccessFlags(), |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 1447 | method_idx, class_loader, dex_file); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1448 | it.Next(); |
| 1449 | } |
| 1450 | // Compile virtual methods |
Brian Carlstrom | 68adbe4 | 2012-05-11 17:18:08 -0700 | [diff] [blame] | 1451 | int64_t previous_virtual_method_idx = -1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1452 | while (it.HasNextVirtualMethod()) { |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 1453 | uint32_t method_idx = it.GetMemberIndex(); |
| 1454 | if (method_idx == previous_virtual_method_idx) { |
| 1455 | // smali can create dex files with two encoded_methods sharing the same method_idx |
| 1456 | // http://code.google.com/p/smali/issues/detail?id=119 |
| 1457 | it.Next(); |
| 1458 | continue; |
| 1459 | } |
| 1460 | previous_virtual_method_idx = method_idx; |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1461 | context->GetCompiler()->CompileMethod(it.GetMethodCodeItem(), it.GetMemberAccessFlags(), |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 1462 | method_idx, class_loader, dex_file); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1463 | it.Next(); |
| 1464 | } |
| 1465 | DCHECK(!it.HasNext()); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1468 | void Compiler::CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file) { |
Brian Carlstrom | 731b2ab | 2012-03-06 16:53:35 -0800 | [diff] [blame] | 1469 | Context context(NULL, class_loader, this, NULL, &dex_file); |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 1470 | ForAll(&context, 0, dex_file.NumClassDefs(), Compiler::CompileClass, thread_count_); |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1471 | } |
| 1472 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1473 | static std::string MakeInvokeStubKey(bool is_static, const char* shorty) { |
| 1474 | std::string key(shorty); |
| 1475 | if (is_static) { |
| 1476 | key += "$"; // Must not be a shorty type character. |
| 1477 | } |
| 1478 | return key; |
| 1479 | } |
| 1480 | |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 1481 | void Compiler::CompileMethod(const DexFile::CodeItem* code_item, uint32_t access_flags, |
| 1482 | uint32_t method_idx, const ClassLoader* class_loader, |
| 1483 | const DexFile& dex_file) { |
Elliott Hughes | f09afe8 | 2011-10-16 14:24:21 -0700 | [diff] [blame] | 1484 | CompiledMethod* compiled_method = NULL; |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 1485 | uint64_t start_ns = NanoTime(); |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 1486 | |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 1487 | if ((access_flags & kAccNative) != 0) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 1488 | compiled_method = (*jni_compiler_)(*this, access_flags, method_idx, dex_file); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1489 | CHECK(compiled_method != NULL); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 1490 | } else if ((access_flags & kAccAbstract) != 0) { |
Brian Carlstrom | 2cc022b | 2011-08-25 10:05:39 -0700 | [diff] [blame] | 1491 | } else { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1492 | compiled_method = (*compiler_)(*this, code_item, access_flags, method_idx, class_loader, |
| 1493 | dex_file); |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 1494 | CHECK(compiled_method != NULL) << PrettyMethod(method_idx, dex_file); |
| 1495 | } |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 1496 | uint64_t duration_ns = NanoTime() - start_ns; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1497 | if (duration_ns > MsToNs(100)) { |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 1498 | LOG(WARNING) << "Compilation of " << PrettyMethod(method_idx, dex_file) |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 1499 | << " took " << PrettyDuration(duration_ns); |
Elliott Hughes | f09afe8 | 2011-10-16 14:24:21 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | if (compiled_method != NULL) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1503 | MethodReference ref(&dex_file, method_idx); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1504 | CHECK(GetCompiledMethod(ref) == NULL) << PrettyMethod(method_idx, dex_file); |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1505 | MutexLock mu(compiled_methods_lock_); |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1506 | compiled_methods_.Put(ref, compiled_method); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1507 | DCHECK(GetCompiledMethod(ref) != NULL) << PrettyMethod(method_idx, dex_file); |
Brian Carlstrom | 2cc022b | 2011-08-25 10:05:39 -0700 | [diff] [blame] | 1508 | } |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 1509 | |
Ian Rogers | 45619fc | 2012-02-29 11:15:25 -0800 | [diff] [blame] | 1510 | uint32_t shorty_len; |
| 1511 | const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx), &shorty_len); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 1512 | bool is_static = (access_flags & kAccStatic) != 0; |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1513 | std::string key(MakeInvokeStubKey(is_static, shorty)); |
| 1514 | const CompiledInvokeStub* compiled_invoke_stub = FindInvokeStub(key); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1515 | if (compiled_invoke_stub == NULL) { |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 1516 | compiled_invoke_stub = (*create_invoke_stub_)(*this, is_static, shorty, shorty_len); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1517 | CHECK(compiled_invoke_stub != NULL); |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1518 | InsertInvokeStub(key, compiled_invoke_stub); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1519 | } |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 1520 | |
| 1521 | #if defined(ART_USE_LLVM_COMPILER) |
| 1522 | if (!is_static) { |
| 1523 | const CompiledInvokeStub* compiled_proxy_stub = FindProxyStub(shorty); |
| 1524 | if (compiled_proxy_stub == NULL) { |
| 1525 | compiled_proxy_stub = (*create_proxy_stub_)(*this, shorty, shorty_len); |
| 1526 | CHECK(compiled_proxy_stub != NULL); |
| 1527 | InsertProxyStub(shorty, compiled_proxy_stub); |
| 1528 | } |
| 1529 | } |
| 1530 | #endif |
| 1531 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1532 | CHECK(!Thread::Current()->IsExceptionPending()) << PrettyMethod(method_idx, dex_file); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1535 | const CompiledInvokeStub* Compiler::FindInvokeStub(bool is_static, const char* shorty) const { |
| 1536 | const std::string key(MakeInvokeStubKey(is_static, shorty)); |
| 1537 | return FindInvokeStub(key); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1540 | const CompiledInvokeStub* Compiler::FindInvokeStub(const std::string& key) const { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1541 | MutexLock mu(compiled_invoke_stubs_lock_); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1542 | InvokeStubTable::const_iterator it = compiled_invoke_stubs_.find(key); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1543 | if (it == compiled_invoke_stubs_.end()) { |
| 1544 | return NULL; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1545 | } else { |
| 1546 | DCHECK(it->second != NULL); |
| 1547 | return it->second; |
| 1548 | } |
| 1549 | } |
| 1550 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1551 | void Compiler::InsertInvokeStub(const std::string& key, |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1552 | const CompiledInvokeStub* compiled_invoke_stub) { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1553 | MutexLock mu(compiled_invoke_stubs_lock_); |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1554 | InvokeStubTable::iterator it = compiled_invoke_stubs_.find(key); |
| 1555 | if (it != compiled_invoke_stubs_.end()) { |
| 1556 | // Someone else won the race. |
| 1557 | delete compiled_invoke_stub; |
| 1558 | } else { |
| 1559 | compiled_invoke_stubs_.Put(key, compiled_invoke_stub); |
| 1560 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Logan Chien | 7a2a23a | 2012-06-06 11:01:00 +0800 | [diff] [blame] | 1563 | #if defined(ART_USE_LLVM_COMPILER) |
| 1564 | const CompiledInvokeStub* Compiler::FindProxyStub(const char* shorty) const { |
| 1565 | MutexLock mu(compiled_proxy_stubs_lock_); |
| 1566 | ProxyStubTable::const_iterator it = compiled_proxy_stubs_.find(shorty); |
| 1567 | if (it == compiled_proxy_stubs_.end()) { |
| 1568 | return NULL; |
| 1569 | } else { |
| 1570 | DCHECK(it->second != NULL); |
| 1571 | return it->second; |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | void Compiler::InsertProxyStub(const char* shorty, |
| 1576 | const CompiledInvokeStub* compiled_proxy_stub) { |
| 1577 | MutexLock mu(compiled_proxy_stubs_lock_); |
| 1578 | InvokeStubTable::iterator it = compiled_proxy_stubs_.find(shorty); |
| 1579 | if (it != compiled_proxy_stubs_.end()) { |
| 1580 | // Someone else won the race. |
| 1581 | delete compiled_proxy_stub; |
| 1582 | } else { |
| 1583 | compiled_proxy_stubs_.Put(shorty, compiled_proxy_stub); |
| 1584 | } |
| 1585 | } |
| 1586 | #endif |
| 1587 | |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1588 | CompiledClass* Compiler::GetCompiledClass(ClassReference ref) const { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1589 | MutexLock mu(compiled_classes_lock_); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1590 | ClassTable::const_iterator it = compiled_classes_.find(ref); |
| 1591 | if (it == compiled_classes_.end()) { |
| 1592 | return NULL; |
| 1593 | } |
| 1594 | CHECK(it->second != NULL); |
| 1595 | return it->second; |
| 1596 | } |
| 1597 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1598 | CompiledMethod* Compiler::GetCompiledMethod(MethodReference ref) const { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1599 | MutexLock mu(compiled_methods_lock_); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1600 | MethodTable::const_iterator it = compiled_methods_.find(ref); |
| 1601 | if (it == compiled_methods_.end()) { |
| 1602 | return NULL; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1603 | } |
| 1604 | CHECK(it->second != NULL); |
| 1605 | return it->second; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 1608 | void Compiler::SetGcMaps(const ClassLoader* class_loader, const std::vector<const DexFile*>& dex_files) { |
| 1609 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 1610 | const DexFile* dex_file = dex_files[i]; |
| 1611 | CHECK(dex_file != NULL); |
| 1612 | SetGcMapsDexFile(class_loader, *dex_file); |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | void Compiler::SetGcMapsDexFile(const ClassLoader* class_loader, const DexFile& dex_file) { |
| 1617 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 1618 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
| 1619 | for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); class_def_index++) { |
| 1620 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
| 1621 | const char* descriptor = dex_file.GetClassDescriptor(class_def); |
| 1622 | Class* klass = class_linker->FindClass(descriptor, class_loader); |
| 1623 | if (klass == NULL || !klass->IsVerified()) { |
| 1624 | Thread::Current()->ClearException(); |
| 1625 | continue; |
| 1626 | } |
| 1627 | const byte* class_data = dex_file.GetClassData(class_def); |
| 1628 | if (class_data == NULL) { |
| 1629 | // empty class such as a marker interface |
| 1630 | continue; |
| 1631 | } |
| 1632 | ClassDataItemIterator it(dex_file, class_data); |
| 1633 | while (it.HasNextStaticField()) { |
| 1634 | it.Next(); |
| 1635 | } |
| 1636 | while (it.HasNextInstanceField()) { |
| 1637 | it.Next(); |
| 1638 | } |
| 1639 | while (it.HasNextDirectMethod()) { |
| 1640 | Method* method = class_linker->ResolveMethod(dex_file, it.GetMemberIndex(), dex_cache, |
| 1641 | class_loader, true); |
| 1642 | SetGcMapsMethod(dex_file, method); |
| 1643 | it.Next(); |
| 1644 | } |
| 1645 | while (it.HasNextVirtualMethod()) { |
| 1646 | Method* method = class_linker->ResolveMethod(dex_file, it.GetMemberIndex(), dex_cache, |
| 1647 | class_loader, false); |
| 1648 | SetGcMapsMethod(dex_file, method); |
| 1649 | it.Next(); |
| 1650 | } |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | void Compiler::SetGcMapsMethod(const DexFile& dex_file, Method* method) { |
| 1655 | if (method == NULL) { |
| 1656 | Thread::Current()->ClearException(); |
| 1657 | return; |
| 1658 | } |
| 1659 | uint16_t method_idx = method->GetDexMethodIndex(); |
| 1660 | MethodReference ref(&dex_file, method_idx); |
| 1661 | CompiledMethod* compiled_method = GetCompiledMethod(ref); |
| 1662 | if (compiled_method == NULL) { |
| 1663 | return; |
| 1664 | } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1665 | const std::vector<uint8_t>* gc_map = verifier::MethodVerifier::GetGcMap(ref); |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 1666 | if (gc_map == NULL) { |
| 1667 | return; |
| 1668 | } |
| 1669 | compiled_method->SetGcMap(*gc_map); |
| 1670 | } |
| 1671 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1672 | #if defined(ART_USE_LLVM_COMPILER) || defined(ART_USE_QUICK_COMPILER) |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 1673 | void Compiler::SetBitcodeFileName(std::string const& filename) { |
Logan Chien | 106b2a0 | 2012-03-18 04:41:38 +0800 | [diff] [blame] | 1674 | typedef void (*SetBitcodeFileNameFn)(Compiler&, std::string const&); |
| 1675 | |
| 1676 | SetBitcodeFileNameFn set_bitcode_file_name = |
| 1677 | FindFunction<SetBitcodeFileNameFn>(MakeCompilerSoName(instruction_set_), |
| 1678 | compiler_library_, |
| 1679 | "compilerLLVMSetBitcodeFileName"); |
| 1680 | |
| 1681 | set_bitcode_file_name(*this, filename); |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 1682 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1683 | #endif |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 1684 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1685 | #if defined(ART_USE_LLVM_COMPILER) |
Logan Chien | f7015fd | 2012-03-18 01:19:37 +0800 | [diff] [blame] | 1686 | void Compiler::EnableAutoElfLoading() { |
| 1687 | compiler_enable_auto_elf_loading_(*this); |
| 1688 | } |
| 1689 | |
| 1690 | const void* Compiler::GetMethodCodeAddr(const CompiledMethod* cm, |
| 1691 | const Method* method) const { |
| 1692 | return compiler_get_method_code_addr_(*this, cm, method); |
| 1693 | } |
| 1694 | |
| 1695 | const Method::InvokeStub* Compiler::GetMethodInvokeStubAddr(const CompiledInvokeStub* cm, |
| 1696 | const Method* method) const { |
| 1697 | return compiler_get_method_invoke_stub_addr_(*this, cm, method); |
| 1698 | } |
Logan Chien | df57614 | 2012-03-20 17:36:32 +0800 | [diff] [blame] | 1699 | |
| 1700 | std::vector<ElfImage> Compiler::GetElfImages() const { |
| 1701 | typedef std::vector<ElfImage> (*GetElfImagesFn)(const Compiler&); |
| 1702 | |
| 1703 | GetElfImagesFn get_elf_images = |
| 1704 | FindFunction<GetElfImagesFn>(MakeCompilerSoName(instruction_set_), |
| 1705 | compiler_library_, |
| 1706 | "compilerLLVMGetElfImages"); |
| 1707 | |
| 1708 | return get_elf_images(*this); |
| 1709 | } |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 1710 | #endif |
| 1711 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1712 | } // namespace art |