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