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