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 | |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 21 | #include <sys/mman.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 | 2cc022b | 2011-08-25 10:05:39 -0700 | [diff] [blame] | 24 | #include "assembler.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 25 | #include "class_linker.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 26 | #include "class_loader.h" |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 27 | #include "compiler/CompilerIR.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 28 | #include "dex_cache.h" |
Brian Carlstrom | 2cc022b | 2011-08-25 10:05:39 -0700 | [diff] [blame] | 29 | #include "jni_compiler.h" |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 30 | #include "jni_internal.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 31 | #include "oat_file.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 32 | #include "object_utils.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 33 | #include "runtime.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 34 | #include "stl_util.h" |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 35 | #include "timing_logger.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 36 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 37 | #if defined(ART_USE_LLVM_COMPILER) |
| 38 | #include "compiler_llvm/compiler_llvm.h" |
| 39 | #endif |
| 40 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 41 | namespace art { |
| 42 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 43 | #if !defined(ART_USE_LLVM_COMPILER) |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 44 | CompiledMethod* oatCompileMethod(Compiler& compiler, const DexFile::CodeItem* code_item, |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 45 | uint32_t access_flags, uint32_t method_idx, |
| 46 | const ClassLoader* class_loader, |
| 47 | const DexFile& dex_file, InstructionSet); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 48 | #endif |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 49 | |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 50 | namespace arm { |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 51 | ByteArray* CreateAbstractMethodErrorStub(); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 52 | CompiledInvokeStub* ArmCreateInvokeStub(bool is_static, const char* shorty); |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 53 | ByteArray* ArmCreateResolutionTrampoline(Runtime::TrampolineType type); |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 54 | ByteArray* CreateJniDlsymLookupStub(); |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 55 | } |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 56 | namespace x86 { |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 57 | ByteArray* CreateAbstractMethodErrorStub(); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 58 | CompiledInvokeStub* X86CreateInvokeStub(bool is_static, const char* shorty); |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 59 | ByteArray* X86CreateResolutionTrampoline(Runtime::TrampolineType type); |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 60 | ByteArray* CreateJniDlsymLookupStub(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 63 | static double Percentage(size_t x, size_t y) { |
| 64 | return 100.0 * ((double)x) / ((double)(x + y)); |
| 65 | } |
| 66 | |
| 67 | static void DumpStat(size_t x, size_t y, const char* str) { |
| 68 | if (x == 0 && y == 0) { |
| 69 | return; |
| 70 | } |
| 71 | LOG(INFO) << Percentage(x, y) << "% of " << str << " for " << (x + y) << " cases"; |
| 72 | } |
| 73 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 74 | class AOTCompilationStats { |
| 75 | public: |
| 76 | AOTCompilationStats() : stats_lock_("AOT compilation statistics lock"), |
| 77 | types_in_dex_cache_(0), types_not_in_dex_cache_(0), |
| 78 | strings_in_dex_cache_(0), strings_not_in_dex_cache_(0), |
| 79 | resolved_types_(0), unresolved_types_(0), |
| 80 | resolved_instance_fields_(0), unresolved_instance_fields_(0), |
| 81 | resolved_local_static_fields_(0), resolved_static_fields_(0), unresolved_static_fields_(0) { |
| 82 | for (size_t i = 0; i < kMaxInvokeType; i++) { |
| 83 | resolved_methods_[i] = 0; |
| 84 | unresolved_methods_[i] = 0; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | void Dump() { |
| 89 | DumpStat(types_in_dex_cache_, types_not_in_dex_cache_, "types known to be in dex cache"); |
| 90 | DumpStat(strings_in_dex_cache_, strings_not_in_dex_cache_, "strings known to be in dex cache"); |
| 91 | DumpStat(resolved_types_, unresolved_types_, "types resolved"); |
| 92 | DumpStat(resolved_instance_fields_, unresolved_instance_fields_, "instance fields resolved"); |
| 93 | DumpStat(resolved_local_static_fields_ + resolved_static_fields_, unresolved_static_fields_, |
| 94 | "static fields resolved"); |
| 95 | DumpStat(resolved_local_static_fields_, resolved_static_fields_ + unresolved_static_fields_, |
| 96 | "static fields local to a class"); |
| 97 | |
| 98 | for (size_t i = 0; i < kMaxInvokeType; i++) { |
| 99 | std::ostringstream oss; |
| 100 | oss << "resolved " << static_cast<InvokeType>(i) << " methods"; |
| 101 | DumpStat(resolved_methods_[i], unresolved_methods_[i], oss.str().c_str()); |
| 102 | } |
| 103 | } |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 104 | |
| 105 | // Allow lossy statistics in non-debug builds |
| 106 | #ifndef NDEBUG |
| 107 | #define STATS_LOCK() MutexLock mu(stats_lock_) |
| 108 | #else |
| 109 | #define STATS_LOCK() |
| 110 | #endif |
| 111 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 112 | void TypeInDexCache() { |
| 113 | STATS_LOCK(); |
| 114 | types_in_dex_cache_++; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 115 | } |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 116 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 117 | void TypeNotInDexCache() { |
| 118 | STATS_LOCK(); |
| 119 | types_not_in_dex_cache_++; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 120 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 121 | |
| 122 | void StringInDexCache() { |
| 123 | STATS_LOCK(); |
| 124 | strings_in_dex_cache_++; |
| 125 | } |
| 126 | |
| 127 | void StringNotInDexCache() { |
| 128 | STATS_LOCK(); |
| 129 | strings_not_in_dex_cache_++; |
| 130 | } |
| 131 | |
| 132 | void TypeDoesntNeedAccessCheck() { |
| 133 | STATS_LOCK(); |
| 134 | resolved_types_++; |
| 135 | } |
| 136 | |
| 137 | void TypeNeedsAccessCheck() { |
| 138 | STATS_LOCK(); |
| 139 | unresolved_types_++; |
| 140 | } |
| 141 | |
| 142 | void ResolvedInstanceField() { |
| 143 | STATS_LOCK(); |
| 144 | resolved_instance_fields_++; |
| 145 | } |
| 146 | |
| 147 | void UnresolvedInstanceField(){ |
| 148 | STATS_LOCK(); |
| 149 | unresolved_instance_fields_++; |
| 150 | } |
| 151 | |
| 152 | void ResolvedLocalStaticField() { |
| 153 | STATS_LOCK(); |
| 154 | resolved_local_static_fields_++; |
| 155 | } |
| 156 | |
| 157 | void ResolvedStaticField() { |
| 158 | STATS_LOCK(); |
| 159 | resolved_static_fields_++; |
| 160 | } |
| 161 | |
| 162 | void UnresolvedStaticField() { |
| 163 | STATS_LOCK(); |
| 164 | unresolved_static_fields_++; |
| 165 | } |
| 166 | |
| 167 | void ResolvedMethod(InvokeType type) { |
| 168 | DCHECK_LE(type, kMaxInvokeType); |
| 169 | STATS_LOCK(); |
| 170 | resolved_methods_[type]++; |
| 171 | } |
| 172 | |
| 173 | void UnresolvedMethod(InvokeType type) { |
| 174 | DCHECK_LE(type, kMaxInvokeType); |
| 175 | STATS_LOCK(); |
| 176 | unresolved_methods_[type]++; |
| 177 | } |
| 178 | |
| 179 | private: |
| 180 | Mutex stats_lock_; |
| 181 | |
| 182 | size_t types_in_dex_cache_; |
| 183 | size_t types_not_in_dex_cache_; |
| 184 | |
| 185 | size_t strings_in_dex_cache_; |
| 186 | size_t strings_not_in_dex_cache_; |
| 187 | |
| 188 | size_t resolved_types_; |
| 189 | size_t unresolved_types_; |
| 190 | |
| 191 | size_t resolved_instance_fields_; |
| 192 | size_t unresolved_instance_fields_; |
| 193 | |
| 194 | size_t resolved_local_static_fields_; |
| 195 | size_t resolved_static_fields_; |
| 196 | size_t unresolved_static_fields_; |
| 197 | |
| 198 | size_t resolved_methods_[kMaxInvokeType + 1]; |
| 199 | size_t unresolved_methods_[kMaxInvokeType + 1]; |
| 200 | |
| 201 | DISALLOW_COPY_AND_ASSIGN(AOTCompilationStats);; |
| 202 | }; |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 203 | |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 204 | Compiler::Compiler(InstructionSet instruction_set, bool image, size_t thread_count, |
Elliott Hughes | de6e4cf | 2012-02-27 14:46:06 -0800 | [diff] [blame^] | 205 | bool support_debugging, const std::set<std::string>* image_classes) |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 206 | : instruction_set_(instruction_set), |
| 207 | jni_compiler_(instruction_set), |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 208 | compiled_classes_lock_("compiled classes lock"), |
| 209 | compiled_methods_lock_("compiled method lock"), |
| 210 | compiled_invoke_stubs_lock_("compiled invoke stubs lock"), |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 211 | image_(image), |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 212 | thread_count_(thread_count), |
Elliott Hughes | de6e4cf | 2012-02-27 14:46:06 -0800 | [diff] [blame^] | 213 | support_debugging_(support_debugging), |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 214 | stats_(new AOTCompilationStats), |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 215 | image_classes_(image_classes) |
| 216 | #if defined(ART_USE_LLVM_COMPILER) |
| 217 | , |
| 218 | compiler_llvm_(new compiler_llvm::CompilerLLVM(this, instruction_set)) |
| 219 | #endif |
| 220 | { |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 221 | CHECK(!Runtime::Current()->IsStarted()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 222 | if (!image_) { |
| 223 | CHECK(image_classes_ == NULL); |
| 224 | } |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 227 | Compiler::~Compiler() { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 228 | { |
| 229 | MutexLock mu(compiled_classes_lock_); |
| 230 | STLDeleteValues(&compiled_classes_); |
| 231 | } |
| 232 | { |
| 233 | MutexLock mu(compiled_methods_lock_); |
| 234 | STLDeleteValues(&compiled_methods_); |
| 235 | } |
| 236 | { |
| 237 | MutexLock mu(compiled_invoke_stubs_lock_); |
| 238 | STLDeleteValues(&compiled_invoke_stubs_); |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 239 | } |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 242 | ByteArray* Compiler::CreateResolutionStub(InstructionSet instruction_set, |
| 243 | Runtime::TrampolineType type) { |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 244 | if (instruction_set == kX86) { |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 245 | return x86::X86CreateResolutionTrampoline(type); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 246 | } else { |
| 247 | CHECK(instruction_set == kArm || instruction_set == kThumb2); |
| 248 | // Generates resolution stub using ARM instruction set |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 249 | return arm::ArmCreateResolutionTrampoline(type); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 253 | ByteArray* Compiler::CreateJniDlsymLookupStub(InstructionSet instruction_set) { |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 254 | switch (instruction_set) { |
| 255 | case kArm: |
| 256 | case kThumb2: |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 257 | return arm::CreateJniDlsymLookupStub(); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 258 | case kX86: |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 259 | return x86::CreateJniDlsymLookupStub(); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 260 | default: |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 261 | LOG(FATAL) << "Unknown InstructionSet: " << static_cast<int>(instruction_set); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 262 | return NULL; |
| 263 | } |
| 264 | } |
| 265 | |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 266 | ByteArray* Compiler::CreateAbstractMethodErrorStub(InstructionSet instruction_set) { |
| 267 | if (instruction_set == kX86) { |
| 268 | return x86::CreateAbstractMethodErrorStub(); |
| 269 | } else { |
| 270 | CHECK(instruction_set == kArm || instruction_set == kThumb2); |
| 271 | // Generates resolution stub using ARM instruction set |
| 272 | return arm::CreateAbstractMethodErrorStub(); |
| 273 | } |
| 274 | } |
| 275 | |
Jesse Wilson | 254db0f | 2011-11-16 16:44:11 -0500 | [diff] [blame] | 276 | void Compiler::CompileAll(const ClassLoader* class_loader, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 277 | const std::vector<const DexFile*>& dex_files) { |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 278 | DCHECK(!Runtime::Current()->IsStarted()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 279 | |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 280 | TimingLogger timings("compiler"); |
| 281 | |
| 282 | PreCompile(class_loader, dex_files, timings); |
| 283 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 284 | Compile(class_loader, dex_files); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 285 | timings.AddSplit("Compile"); |
| 286 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 287 | PostCompile(class_loader, dex_files); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 288 | timings.AddSplit("PostCompile"); |
| 289 | |
| 290 | if (timings.GetTotalNs() > MsToNs(1000)) { |
| 291 | timings.Dump(); |
| 292 | } |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 293 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 294 | stats_->Dump(); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 297 | void Compiler::CompileOne(const Method* method) { |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 298 | DCHECK(!Runtime::Current()->IsStarted()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 299 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 300 | const ClassLoader* class_loader = method->GetDeclaringClass()->GetClassLoader(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 301 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 302 | // Find the dex_file |
| 303 | const DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache(); |
| 304 | const DexFile& dex_file = Runtime::Current()->GetClassLinker()->FindDexFile(dex_cache); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 305 | std::vector<const DexFile*> dex_files; |
| 306 | dex_files.push_back(&dex_file); |
| 307 | |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 308 | TimingLogger timings("CompileOne"); |
| 309 | PreCompile(class_loader, dex_files, timings); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 310 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 311 | uint32_t method_idx = method->GetDexMethodIndex(); |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 312 | const DexFile::CodeItem* code_item = dex_file.GetCodeItem(method->GetCodeItemOffset()); |
| 313 | CompileMethod(code_item, method->GetAccessFlags(), method_idx, class_loader, dex_file); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 314 | |
| 315 | PostCompile(class_loader, dex_files); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 318 | void Compiler::Resolve(const ClassLoader* class_loader, |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 319 | const std::vector<const DexFile*>& dex_files, TimingLogger& timings) { |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 320 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 321 | const DexFile* dex_file = dex_files[i]; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 322 | CHECK(dex_file != NULL); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 323 | ResolveDexFile(class_loader, *dex_file, timings); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 327 | void Compiler::PreCompile(const ClassLoader* class_loader, |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 328 | const std::vector<const DexFile*>& dex_files, TimingLogger& timings) { |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 329 | Resolve(class_loader, dex_files, timings); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 330 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 331 | Verify(class_loader, dex_files); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 332 | timings.AddSplit("PreCompile.Verify"); |
| 333 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 334 | InitializeClassesWithoutClinit(class_loader, dex_files); |
Elliott Hughes | 601a123 | 2012-02-02 17:47:38 -0800 | [diff] [blame] | 335 | timings.AddSplit("PreCompile.InitializeClassesWithoutClinit"); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | void Compiler::PostCompile(const ClassLoader* class_loader, |
| 339 | const std::vector<const DexFile*>& dex_files) { |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 340 | SetGcMaps(class_loader, dex_files); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 341 | #if defined(ART_USE_LLVM_COMPILER) |
| 342 | compiler_llvm_->MaterializeLLVMModule(); |
| 343 | #endif |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 344 | SetCodeAndDirectMethods(dex_files); |
| 345 | } |
| 346 | |
| 347 | bool Compiler::IsImageClass(const std::string& descriptor) const { |
| 348 | if (image_classes_ == NULL) { |
| 349 | return true; |
| 350 | } |
| 351 | return image_classes_->find(descriptor) != image_classes_->end(); |
| 352 | } |
| 353 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 354 | bool Compiler::CanAssumeTypeIsPresentInDexCache(const DexCache* dex_cache, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 355 | uint32_t type_idx) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 356 | if (!IsImage()) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 357 | stats_->TypeNotInDexCache(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 358 | return false; |
| 359 | } |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 360 | Class* resolved_class = dex_cache->GetResolvedType(type_idx); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 361 | if (resolved_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 362 | stats_->TypeNotInDexCache(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 363 | return false; |
| 364 | } |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 365 | bool result = IsImageClass(ClassHelper(resolved_class).GetDescriptor()); |
| 366 | if (result) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 367 | stats_->TypeInDexCache(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 368 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 369 | stats_->TypeNotInDexCache(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 370 | } |
| 371 | return result; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 372 | } |
| 373 | |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 374 | bool Compiler::CanAssumeStringIsPresentInDexCache(const DexCache* dex_cache, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 375 | uint32_t string_idx) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 376 | // TODO: Add support for loading strings referenced by image_classes_ |
| 377 | // See also Compiler::ResolveDexFile |
| 378 | |
| 379 | // The following is a test saying that if we're building the image without a restricted set of |
| 380 | // image classes then we can assume the string is present in the dex cache if it is there now |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 381 | bool result = IsImage() && image_classes_ == NULL && dex_cache->GetResolvedString(string_idx) != NULL; |
| 382 | if (result) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 383 | stats_->StringInDexCache(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 384 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 385 | stats_->StringNotInDexCache(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 386 | } |
| 387 | return result; |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | bool Compiler::CanAccessTypeWithoutChecks(uint32_t referrer_idx, const DexCache* dex_cache, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 391 | const DexFile& dex_file, uint32_t type_idx) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 392 | // Get type from dex cache assuming it was populated by the verifier |
| 393 | Class* resolved_class = dex_cache->GetResolvedType(type_idx); |
| 394 | if (resolved_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 395 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 396 | return false; // Unknown class needs access checks. |
| 397 | } |
| 398 | const DexFile::MethodId& method_id = dex_file.GetMethodId(referrer_idx); |
| 399 | Class* referrer_class = dex_cache->GetResolvedType(method_id.class_idx_); |
| 400 | if (referrer_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 401 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 402 | return false; // Incomplete referrer knowledge needs access check. |
| 403 | } |
| 404 | // Perform access check, will return true if access is ok or false if we're going to have to |
| 405 | // check this at runtime (for example for class loaders). |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 406 | bool result = referrer_class->CanAccess(resolved_class); |
| 407 | if (result) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 408 | stats_->TypeDoesntNeedAccessCheck(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 409 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 410 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 411 | } |
| 412 | return result; |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | bool Compiler::CanAccessInstantiableTypeWithoutChecks(uint32_t referrer_idx, |
| 416 | const DexCache* dex_cache, |
| 417 | const DexFile& dex_file, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 418 | uint32_t type_idx) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 419 | // Get type from dex cache assuming it was populated by the verifier. |
| 420 | Class* resolved_class = dex_cache->GetResolvedType(type_idx); |
| 421 | if (resolved_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 422 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 423 | return false; // Unknown class needs access checks. |
| 424 | } |
| 425 | const DexFile::MethodId& method_id = dex_file.GetMethodId(referrer_idx); |
| 426 | Class* referrer_class = dex_cache->GetResolvedType(method_id.class_idx_); |
| 427 | if (referrer_class == NULL) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 428 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 429 | return false; // Incomplete referrer knowledge needs access check. |
| 430 | } |
| 431 | // Perform access and instantiable checks, will return true if access is ok or false if we're |
| 432 | // 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] | 433 | bool result = referrer_class->CanAccess(resolved_class) && resolved_class->IsInstantiable(); |
| 434 | if (result) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 435 | stats_->TypeDoesntNeedAccessCheck(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 436 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 437 | stats_->TypeNeedsAccessCheck(); |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 438 | } |
| 439 | return result; |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 442 | static Class* ComputeReferrerClass(CompilationUnit* cUnit) { |
| 443 | const DexFile::MethodId& referrer_method_id = cUnit->dex_file->GetMethodId(cUnit->method_idx); |
| 444 | return cUnit->class_linker->ResolveType(*cUnit->dex_file, referrer_method_id.class_idx_, |
| 445 | cUnit->dex_cache, cUnit->class_loader); |
| 446 | } |
| 447 | |
| 448 | static Field* ComputeReferrerField(CompilationUnit* cUnit, uint32_t field_idx) { |
| 449 | return cUnit->class_linker->ResolveField(*cUnit->dex_file, field_idx, cUnit->dex_cache, |
| 450 | cUnit->class_loader, false); |
| 451 | |
| 452 | } |
| 453 | |
| 454 | static Method* ComputeReferrerMethod(CompilationUnit* cUnit, uint32_t method_idx) { |
| 455 | return cUnit->class_linker->ResolveMethod(*cUnit->dex_file, method_idx, cUnit->dex_cache, |
| 456 | cUnit->class_loader, true); |
| 457 | } |
| 458 | |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 459 | bool Compiler::ComputeInstanceFieldInfo(uint32_t field_idx, CompilationUnit* cUnit, |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 460 | int& field_offset, bool& is_volatile, bool is_put) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 461 | // Conservative defaults |
| 462 | field_offset = -1; |
| 463 | is_volatile = true; |
| 464 | // Try to resolve field |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 465 | Field* resolved_field = ComputeReferrerField(cUnit, field_idx); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 466 | if (resolved_field != NULL) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 467 | Class* referrer_class = ComputeReferrerClass(cUnit); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 468 | // Try to resolve referring class then access check, failure to pass the |
| 469 | Class* fields_class = resolved_field->GetDeclaringClass(); |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 470 | bool is_write_to_final_from_wrong_class = is_put && resolved_field->IsFinal() && |
| 471 | fields_class != referrer_class; |
| 472 | if (referrer_class != NULL && referrer_class->CanAccess(fields_class) && |
| 473 | referrer_class->CanAccessMember(fields_class, resolved_field->GetAccessFlags()) && |
| 474 | !is_write_to_final_from_wrong_class) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 475 | field_offset = resolved_field->GetOffset().Int32Value(); |
| 476 | is_volatile = resolved_field->IsVolatile(); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 477 | stats_->ResolvedInstanceField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 478 | return true; // Fast path. |
| 479 | } |
| 480 | } |
| 481 | // Clean up any exception left by field/type resolution |
| 482 | Thread* thread = Thread::Current(); |
| 483 | if (thread->IsExceptionPending()) { |
| 484 | thread->ClearException(); |
| 485 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 486 | stats_->UnresolvedInstanceField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 487 | return false; // Incomplete knowledge needs slow path. |
| 488 | } |
| 489 | |
| 490 | bool Compiler::ComputeStaticFieldInfo(uint32_t field_idx, CompilationUnit* cUnit, |
| 491 | int& field_offset, int& ssb_index, |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 492 | bool& is_referrers_class, bool& is_volatile, bool is_put) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 493 | // Conservative defaults |
| 494 | field_offset = -1; |
| 495 | ssb_index = -1; |
| 496 | is_referrers_class = false; |
| 497 | is_volatile = true; |
| 498 | // Try to resolve field |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 499 | Field* resolved_field = ComputeReferrerField(cUnit, field_idx); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 500 | if (resolved_field != NULL) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 501 | DCHECK(resolved_field->IsStatic()); |
| 502 | Class* referrer_class = ComputeReferrerClass(cUnit); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 503 | if (referrer_class != NULL) { |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 504 | Class* fields_class = resolved_field->GetDeclaringClass(); |
| 505 | if (fields_class == referrer_class) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 506 | is_referrers_class = true; // implies no worrying about class initialization |
| 507 | field_offset = resolved_field->GetOffset().Int32Value(); |
| 508 | is_volatile = resolved_field->IsVolatile(); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 509 | stats_->ResolvedLocalStaticField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 510 | return true; // fast path |
| 511 | } else { |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 512 | bool is_write_to_final_from_wrong_class = is_put && resolved_field->IsFinal(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 513 | if (referrer_class->CanAccess(fields_class) && |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 514 | referrer_class->CanAccessMember(fields_class, resolved_field->GetAccessFlags()) && |
| 515 | !is_write_to_final_from_wrong_class) { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 516 | // We have the resolved field, we must make it into a ssbIndex for the referrer |
| 517 | // 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] | 518 | // TODO: for images we can elide the static storage base null check |
| 519 | // if we know there's a non-null entry in the image |
| 520 | if (fields_class->GetDexCache() == cUnit->dex_cache) { |
| 521 | // common case where the dex cache of both the referrer and the field are the same, |
| 522 | // no need to search the dex file |
| 523 | ssb_index = fields_class->GetDexTypeIndex(); |
| 524 | field_offset = resolved_field->GetOffset().Int32Value(); |
| 525 | is_volatile = resolved_field->IsVolatile(); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 526 | stats_->ResolvedStaticField(); |
Ian Rogers | 4103ad2 | 2012-02-06 09:18:25 -0800 | [diff] [blame] | 527 | return true; |
| 528 | } |
| 529 | // Search dex file for localized ssb index |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 530 | std::string descriptor(FieldHelper(resolved_field).GetDeclaringClassDescriptor()); |
| 531 | const DexFile::StringId* string_id = |
| 532 | cUnit->dex_file->FindStringId(descriptor); |
| 533 | if (string_id != NULL) { |
| 534 | const DexFile::TypeId* type_id = |
| 535 | cUnit->dex_file->FindTypeId(cUnit->dex_file->GetIndexForStringId(*string_id)); |
| 536 | if(type_id != NULL) { |
| 537 | // medium path, needs check of static storage base being initialized |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 538 | ssb_index = cUnit->dex_file->GetIndexForTypeId(*type_id); |
| 539 | field_offset = resolved_field->GetOffset().Int32Value(); |
| 540 | is_volatile = resolved_field->IsVolatile(); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 541 | stats_->ResolvedStaticField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 542 | return true; |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | // Clean up any exception left by field/type resolution |
| 550 | Thread* thread = Thread::Current(); |
| 551 | if (thread->IsExceptionPending()) { |
| 552 | thread->ClearException(); |
| 553 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 554 | stats_->UnresolvedStaticField(); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 555 | return false; // Incomplete knowledge needs slow path. |
| 556 | } |
| 557 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 558 | bool Compiler::ComputeInvokeInfo(uint32_t method_idx, CompilationUnit* cUnit, InvokeType type, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 559 | int& vtable_idx) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 560 | vtable_idx = -1; |
| 561 | Method* resolved_method = ComputeReferrerMethod(cUnit, method_idx); |
| 562 | if (resolved_method != NULL) { |
| 563 | Class* referrer_class = ComputeReferrerClass(cUnit); |
| 564 | if (referrer_class != NULL) { |
| 565 | Class* methods_class = resolved_method->GetDeclaringClass(); |
| 566 | if (!referrer_class->CanAccess(methods_class) || |
| 567 | !referrer_class->CanAccessMember(methods_class, |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 568 | resolved_method->GetAccessFlags())) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 569 | // The referring class can't access the resolved method, this may occur as a result of a |
| 570 | // protected method being made public by implementing an interface that re-declares the |
| 571 | // method public. Resort to the dex file to determine the correct class for the access check |
| 572 | const DexFile& dex_file = cUnit->class_linker->FindDexFile(referrer_class->GetDexCache()); |
| 573 | methods_class = |
| 574 | cUnit->class_linker->ResolveType(dex_file, |
| 575 | dex_file.GetMethodId(method_idx).class_idx_, |
| 576 | referrer_class); |
| 577 | |
| 578 | } |
| 579 | if (referrer_class->CanAccess(methods_class) && |
| 580 | referrer_class->CanAccessMember(methods_class, |
| 581 | resolved_method->GetAccessFlags())) { |
| 582 | vtable_idx = resolved_method->GetMethodIndex(); |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 583 | if (type != kSuper) { |
| 584 | // nothing left to do for static/direct/virtual/interface dispatch |
| 585 | stats_->ResolvedMethod(type); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 586 | return true; |
| 587 | } else { |
| 588 | // ensure the vtable index will be correct to dispatch in the vtable of the super class |
Ian Rogers | 996cc58 | 2012-02-14 22:23:29 -0800 | [diff] [blame] | 589 | if (referrer_class->IsSubClass(methods_class) && |
| 590 | vtable_idx < methods_class->GetVTable()->GetLength()) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 591 | stats_->ResolvedMethod(type); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 592 | return true; |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | // Clean up any exception left by method/type resolution |
| 599 | Thread* thread = Thread::Current(); |
| 600 | if (thread->IsExceptionPending()) { |
| 601 | thread->ClearException(); |
| 602 | } |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 603 | stats_->UnresolvedMethod(type); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 604 | return false; // Incomplete knowledge needs slow path. |
| 605 | } |
| 606 | |
Brian Carlstrom | 5ead095 | 2011-11-28 22:55:52 -0800 | [diff] [blame] | 607 | // Return true if the class should be skipped during compilation. We |
| 608 | // never skip classes in the boot class loader. However, if we have a |
| 609 | // non-boot class loader and we can resolve the class in the boot |
| 610 | // class loader, we do skip the class. This happens if an app bundles |
| 611 | // classes found in the boot classpath. Since at runtime we will |
| 612 | // select the class from the boot classpath, do not attempt to resolve |
| 613 | // or compile it now. |
| 614 | static bool SkipClass(const ClassLoader* class_loader, |
| 615 | const DexFile& dex_file, |
| 616 | const DexFile::ClassDef& class_def) { |
| 617 | if (class_loader == NULL) { |
| 618 | return false; |
| 619 | } |
| 620 | const char* descriptor = dex_file.GetClassDescriptor(class_def); |
| 621 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 622 | Class* klass = class_linker->FindClass(descriptor, NULL); |
| 623 | if (klass == NULL) { |
| 624 | Thread* self = Thread::Current(); |
| 625 | CHECK(self->IsExceptionPending()); |
| 626 | self->ClearException(); |
| 627 | return false; |
| 628 | } |
| 629 | return true; |
| 630 | } |
| 631 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 632 | struct Context { |
| 633 | ClassLinker* class_linker; |
| 634 | const ClassLoader* class_loader; |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 635 | Compiler* compiler; |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 636 | DexCache* dex_cache; |
| 637 | const DexFile* dex_file; |
| 638 | }; |
| 639 | |
| 640 | typedef void Callback(Context* context, size_t index); |
| 641 | |
| 642 | class WorkerThread { |
| 643 | public: |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 644 | WorkerThread(Context* context, size_t begin, size_t end, Callback callback, size_t stripe, bool spawn) |
| 645 | : spawn_(spawn), context_(context), begin_(begin), end_(end), callback_(callback), stripe_(stripe) { |
| 646 | if (spawn_) { |
| 647 | CHECK_PTHREAD_CALL(pthread_create, (&pthread_, NULL, &Go, this), "compiler worker thread"); |
| 648 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | ~WorkerThread() { |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 652 | if (spawn_) { |
| 653 | CHECK_PTHREAD_CALL(pthread_join, (pthread_, NULL), "compiler worker shutdown"); |
| 654 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | private: |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 658 | static void* Go(void* arg) { |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 659 | WorkerThread* worker = reinterpret_cast<WorkerThread*>(arg); |
| 660 | Runtime* runtime = Runtime::Current(); |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 661 | if (worker->spawn_) { |
| 662 | runtime->AttachCurrentThread("Compiler Worker", true); |
| 663 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 664 | Thread::Current()->SetState(Thread::kRunnable); |
| 665 | worker->Run(); |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 666 | if (worker->spawn_) { |
| 667 | Thread::Current()->SetState(Thread::kNative); |
| 668 | runtime->DetachCurrentThread(); |
| 669 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 670 | return NULL; |
| 671 | } |
| 672 | |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 673 | void Go() { |
| 674 | Go(this); |
| 675 | } |
| 676 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 677 | void Run() { |
| 678 | for (size_t i = begin_; i < end_; i += stripe_) { |
| 679 | callback_(context_, i); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | pthread_t pthread_; |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 684 | bool spawn_; |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 685 | |
| 686 | Context* context_; |
| 687 | size_t begin_; |
| 688 | size_t end_; |
| 689 | Callback* callback_; |
| 690 | size_t stripe_; |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 691 | |
| 692 | friend void ForAll(Context*, size_t, size_t, Callback, size_t); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 693 | }; |
| 694 | |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 695 | void ForAll(Context* context, size_t begin, size_t end, Callback callback, size_t thread_count) { |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 696 | CHECK_GT(thread_count, 0U); |
Elliott Hughes | 81d9151 | 2012-02-03 16:38:43 -0800 | [diff] [blame] | 697 | |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 698 | std::vector<WorkerThread*> threads; |
Elliott Hughes | 81d9151 | 2012-02-03 16:38:43 -0800 | [diff] [blame] | 699 | for (size_t i = 0; i < thread_count; ++i) { |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 700 | threads.push_back(new WorkerThread(context, begin + i, end, callback, thread_count, (i != 0))); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 701 | } |
Elliott Hughes | 1e40925 | 2012-02-06 11:21:27 -0800 | [diff] [blame] | 702 | threads[0]->Go(); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 703 | |
Elliott Hughes | 81d9151 | 2012-02-03 16:38:43 -0800 | [diff] [blame] | 704 | // Switch to kVmWait while we're blocked waiting for the other threads to finish. |
| 705 | ScopedThreadStateChange tsc(Thread::Current(), Thread::kVmWait); |
| 706 | STLDeleteElements(&threads); |
| 707 | } |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 708 | |
| 709 | static void ResolveClassFieldsAndMethods(Context* context, size_t class_def_index) { |
| 710 | const DexFile& dex_file = *context->dex_file; |
| 711 | |
| 712 | // Method and Field are the worst. We can't resolve without either |
| 713 | // context from the code use (to disambiguate virtual vs direct |
| 714 | // method and instance vs static field) or from class |
| 715 | // definitions. While the compiler will resolve what it can as it |
| 716 | // needs it, here we try to resolve fields and methods used in class |
| 717 | // definitions, since many of them many never be referenced by |
| 718 | // generated code. |
| 719 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
| 720 | if (SkipClass(context->class_loader, dex_file, class_def)) { |
| 721 | return; |
| 722 | } |
| 723 | |
| 724 | // Note the class_data pointer advances through the headers, |
| 725 | // static fields, instance fields, direct methods, and virtual |
| 726 | // methods. |
| 727 | const byte* class_data = dex_file.GetClassData(class_def); |
| 728 | if (class_data == NULL) { |
| 729 | // empty class such as a marker interface |
| 730 | return; |
| 731 | } |
Brian Carlstrom | 5ead095 | 2011-11-28 22:55:52 -0800 | [diff] [blame] | 732 | Thread* self = Thread::Current(); |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 733 | ClassLinker* class_linker = context->class_linker; |
| 734 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
| 735 | ClassDataItemIterator it(dex_file, class_data); |
| 736 | while (it.HasNextStaticField()) { |
| 737 | Field* field = class_linker->ResolveField(dex_file, it.GetMemberIndex(), dex_cache, |
| 738 | context->class_loader, true); |
| 739 | if (field == NULL) { |
| 740 | CHECK(self->IsExceptionPending()); |
| 741 | self->ClearException(); |
| 742 | } |
| 743 | it.Next(); |
| 744 | } |
| 745 | while (it.HasNextInstanceField()) { |
| 746 | Field* field = class_linker->ResolveField(dex_file, it.GetMemberIndex(), dex_cache, |
| 747 | context->class_loader, false); |
| 748 | if (field == NULL) { |
| 749 | CHECK(self->IsExceptionPending()); |
| 750 | self->ClearException(); |
| 751 | } |
| 752 | it.Next(); |
| 753 | } |
| 754 | while (it.HasNextDirectMethod()) { |
| 755 | Method* method = class_linker->ResolveMethod(dex_file, it.GetMemberIndex(), dex_cache, |
| 756 | context->class_loader, true); |
| 757 | if (method == NULL) { |
| 758 | CHECK(self->IsExceptionPending()); |
| 759 | self->ClearException(); |
| 760 | } |
| 761 | it.Next(); |
| 762 | } |
| 763 | while (it.HasNextVirtualMethod()) { |
| 764 | Method* method = class_linker->ResolveMethod(dex_file, it.GetMemberIndex(), dex_cache, |
| 765 | context->class_loader, false); |
| 766 | if (method == NULL) { |
| 767 | CHECK(self->IsExceptionPending()); |
| 768 | self->ClearException(); |
| 769 | } |
| 770 | it.Next(); |
| 771 | } |
| 772 | DCHECK(!it.HasNext()); |
| 773 | } |
| 774 | |
| 775 | static void ResolveType(Context* context, size_t type_idx) { |
| 776 | // Class derived values are more complicated, they require the linker and loader. |
| 777 | Thread* self = Thread::Current(); |
| 778 | ClassLinker* class_linker = context->class_linker; |
| 779 | const DexFile& dex_file = *context->dex_file; |
| 780 | Class* klass = class_linker->ResolveType(dex_file, type_idx, context->dex_cache, context->class_loader); |
| 781 | if (klass == NULL) { |
| 782 | CHECK(self->IsExceptionPending()); |
| 783 | Thread::Current()->ClearException(); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | void Compiler::ResolveDexFile(const ClassLoader* class_loader, const DexFile& dex_file, TimingLogger& timings) { |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 788 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 789 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 790 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 791 | // Strings are easy in that they always are simply resolved to literals in the same file |
| 792 | if (image_ && image_classes_ == NULL) { |
| 793 | // TODO: Add support for loading strings referenced by image_classes_ |
| 794 | // See also Compiler::CanAssumeTypeIsPresentInDexCache. |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 795 | for (size_t string_idx = 0; string_idx < dex_cache->NumStrings(); string_idx++) { |
| 796 | class_linker->ResolveString(dex_file, string_idx, dex_cache); |
| 797 | } |
Elliott Hughes | ff73806 | 2012-02-03 15:00:42 -0800 | [diff] [blame] | 798 | timings.AddSplit("Resolve " + dex_file.GetLocation() + " Strings"); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 801 | Context context; |
| 802 | context.class_linker = class_linker; |
| 803 | context.class_loader = class_loader; |
| 804 | context.dex_cache = dex_cache; |
| 805 | context.dex_file = &dex_file; |
| 806 | |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 807 | ForAll(&context, 0, dex_cache->NumResolvedTypes(), ResolveType, thread_count_); |
Elliott Hughes | ff73806 | 2012-02-03 15:00:42 -0800 | [diff] [blame] | 808 | timings.AddSplit("Resolve " + dex_file.GetLocation() + " Types"); |
Brian Carlstrom | 845490b | 2011-09-19 15:56:53 -0700 | [diff] [blame] | 809 | |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 810 | ForAll(&context, 0, dex_file.NumClassDefs(), ResolveClassFieldsAndMethods, thread_count_); |
Elliott Hughes | ff73806 | 2012-02-03 15:00:42 -0800 | [diff] [blame] | 811 | timings.AddSplit("Resolve " + dex_file.GetLocation() + " MethodsAndFields"); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 814 | void Compiler::Verify(const ClassLoader* class_loader, |
| 815 | const std::vector<const DexFile*>& dex_files) { |
| 816 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 817 | const DexFile* dex_file = dex_files[i]; |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 818 | CHECK(dex_file != NULL); |
| 819 | VerifyDexFile(class_loader, *dex_file); |
| 820 | } |
| 821 | } |
| 822 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 823 | static void VerifyClass(Context* context, size_t class_def_index) { |
| 824 | const DexFile::ClassDef& class_def = context->dex_file->GetClassDef(class_def_index); |
| 825 | const char* descriptor = context->dex_file->GetClassDescriptor(class_def); |
| 826 | Class* klass = context->class_linker->FindClass(descriptor, context->class_loader); |
| 827 | if (klass == NULL) { |
| 828 | Thread* self = Thread::Current(); |
| 829 | CHECK(self->IsExceptionPending()); |
| 830 | self->ClearException(); |
| 831 | return; |
| 832 | } |
| 833 | CHECK(klass->IsResolved()) << PrettyClass(klass); |
| 834 | context->class_linker->VerifyClass(klass); |
| 835 | |
| 836 | if (klass->IsErroneous()) { |
| 837 | // ClassLinker::VerifyClass throws, which isn't useful in the compiler. |
| 838 | CHECK(Thread::Current()->IsExceptionPending()); |
| 839 | Thread::Current()->ClearException(); |
| 840 | // We want to try verification again at run-time, so move back into the resolved state. |
| 841 | klass->SetStatus(Class::kStatusResolved); |
| 842 | } |
| 843 | |
| 844 | CHECK(klass->IsVerified() || klass->IsResolved()) << PrettyClass(klass); |
| 845 | CHECK(!Thread::Current()->IsExceptionPending()) << PrettyTypeOf(Thread::Current()->GetException()); |
| 846 | } |
| 847 | |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 848 | void Compiler::VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file) { |
jeffhao | b4df514 | 2011-09-19 20:25:32 -0700 | [diff] [blame] | 849 | dex_file.ChangePermissions(PROT_READ | PROT_WRITE); |
Elliott Hughes | d9cdfe9 | 2011-10-06 16:09:04 -0700 | [diff] [blame] | 850 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 851 | Context context; |
| 852 | context.class_linker = Runtime::Current()->GetClassLinker(); |
| 853 | context.class_loader = class_loader; |
| 854 | context.dex_file = &dex_file; |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 855 | ForAll(&context, 0, dex_file.NumClassDefs(), VerifyClass, thread_count_); |
Elliott Hughes | d9cdfe9 | 2011-10-06 16:09:04 -0700 | [diff] [blame] | 856 | |
jeffhao | b4df514 | 2011-09-19 20:25:32 -0700 | [diff] [blame] | 857 | dex_file.ChangePermissions(PROT_READ); |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 860 | void Compiler::InitializeClassesWithoutClinit(const ClassLoader* class_loader, |
| 861 | const std::vector<const DexFile*>& dex_files) { |
| 862 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 863 | const DexFile* dex_file = dex_files[i]; |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 864 | CHECK(dex_file != NULL); |
| 865 | InitializeClassesWithoutClinit(class_loader, *dex_file); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | void Compiler::InitializeClassesWithoutClinit(const ClassLoader* class_loader, const DexFile& dex_file) { |
| 870 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Brian Carlstrom | ffca45d | 2011-09-16 12:10:49 -0700 | [diff] [blame] | 871 | for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); class_def_index++) { |
| 872 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
Brian Carlstrom | a5a97a2 | 2011-09-15 14:08:49 -0700 | [diff] [blame] | 873 | const char* descriptor = dex_file.GetClassDescriptor(class_def); |
| 874 | Class* klass = class_linker->FindClass(descriptor, class_loader); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 875 | if (klass != NULL) { |
| 876 | class_linker->EnsureInitialized(klass, false); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 877 | // record the final class status if necessary |
| 878 | Class::Status status = klass->GetStatus(); |
| 879 | ClassReference ref(&dex_file, class_def_index); |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 880 | MutexLock mu(compiled_classes_lock_); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 881 | CompiledClass* compiled_class = GetCompiledClass(ref); |
| 882 | if (compiled_class == NULL) { |
| 883 | compiled_class = new CompiledClass(status); |
| 884 | compiled_classes_[ref] = compiled_class; |
| 885 | } else { |
| 886 | DCHECK_EQ(status, compiled_class->GetStatus()); |
| 887 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 888 | } |
| 889 | // clear any class not found or verification exceptions |
| 890 | Thread::Current()->ClearException(); |
Brian Carlstrom | ffca45d | 2011-09-16 12:10:49 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
| 894 | for (size_t type_idx = 0; type_idx < dex_cache->NumResolvedTypes(); type_idx++) { |
| 895 | Class* klass = class_linker->ResolveType(dex_file, type_idx, dex_cache, class_loader); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 896 | if (klass == NULL) { |
| 897 | Thread::Current()->ClearException(); |
| 898 | } else if (klass->IsInitialized()) { |
Brian Carlstrom | ffca45d | 2011-09-16 12:10:49 -0700 | [diff] [blame] | 899 | dex_cache->GetInitializedStaticStorage()->Set(type_idx, klass); |
| 900 | } |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 904 | void Compiler::Compile(const ClassLoader* class_loader, |
| 905 | const std::vector<const DexFile*>& dex_files) { |
| 906 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 907 | const DexFile* dex_file = dex_files[i]; |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 908 | CHECK(dex_file != NULL); |
| 909 | CompileDexFile(class_loader, *dex_file); |
| 910 | } |
| 911 | } |
| 912 | |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 913 | void Compiler::CompileClass(Context* context, size_t class_def_index) { |
| 914 | const ClassLoader* class_loader = context->class_loader; |
| 915 | const DexFile& dex_file = *context->dex_file; |
| 916 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
Brian Carlstrom | 5ead095 | 2011-11-28 22:55:52 -0800 | [diff] [blame] | 917 | if (SkipClass(class_loader, dex_file, class_def)) { |
| 918 | return; |
| 919 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 920 | const byte* class_data = dex_file.GetClassData(class_def); |
| 921 | if (class_data == NULL) { |
| 922 | // empty class, probably a marker interface |
| 923 | return; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 924 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 925 | ClassDataItemIterator it(dex_file, class_data); |
| 926 | // Skip fields |
| 927 | while (it.HasNextStaticField()) { |
| 928 | it.Next(); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 929 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 930 | while (it.HasNextInstanceField()) { |
| 931 | it.Next(); |
| 932 | } |
| 933 | // Compile direct methods |
| 934 | while (it.HasNextDirectMethod()) { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 935 | context->compiler->CompileMethod(it.GetMethodCodeItem(), it.GetMemberAccessFlags(), |
| 936 | it.GetMemberIndex(), class_loader, dex_file); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 937 | it.Next(); |
| 938 | } |
| 939 | // Compile virtual methods |
| 940 | while (it.HasNextVirtualMethod()) { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 941 | context->compiler->CompileMethod(it.GetMethodCodeItem(), it.GetMemberAccessFlags(), |
| 942 | it.GetMemberIndex(), class_loader, dex_file); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 943 | it.Next(); |
| 944 | } |
| 945 | DCHECK(!it.HasNext()); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 948 | void Compiler::CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file) { |
| 949 | Context context; |
| 950 | context.class_loader = class_loader; |
| 951 | context.compiler = this; |
| 952 | context.dex_file = &dex_file; |
Elliott Hughes | 5523ee0 | 2012-02-03 18:18:34 -0800 | [diff] [blame] | 953 | ForAll(&context, 0, dex_file.NumClassDefs(), Compiler::CompileClass, thread_count_); |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 954 | } |
| 955 | |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 956 | void Compiler::CompileMethod(const DexFile::CodeItem* code_item, uint32_t access_flags, |
| 957 | uint32_t method_idx, const ClassLoader* class_loader, |
| 958 | const DexFile& dex_file) { |
Elliott Hughes | f09afe8 | 2011-10-16 14:24:21 -0700 | [diff] [blame] | 959 | CompiledMethod* compiled_method = NULL; |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 960 | uint64_t start_ns = NanoTime(); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 961 | if ((access_flags & kAccNative) != 0) { |
| 962 | compiled_method = jni_compiler_.Compile(access_flags, method_idx, class_loader, dex_file); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 963 | CHECK(compiled_method != NULL); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 964 | } else if ((access_flags & kAccAbstract) != 0) { |
Brian Carlstrom | 2cc022b | 2011-08-25 10:05:39 -0700 | [diff] [blame] | 965 | } else { |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 966 | #if defined(ART_USE_LLVM_COMPILER) |
| 967 | compiled_method = |
| 968 | compiler_llvm_->CompileDexMethod(code_item, access_flags, method_idx, |
| 969 | class_loader, dex_file); |
| 970 | #else |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 971 | compiled_method = oatCompileMethod(*this, code_item, access_flags, method_idx, class_loader, |
| 972 | dex_file, kThumb2); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 973 | #endif |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 974 | CHECK(compiled_method != NULL) << PrettyMethod(method_idx, dex_file); |
| 975 | } |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 976 | uint64_t duration_ns = NanoTime() - start_ns; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 977 | if (duration_ns > MsToNs(100)) { |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 978 | LOG(WARNING) << "Compilation of " << PrettyMethod(method_idx, dex_file) |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 979 | << " took " << PrettyDuration(duration_ns); |
Elliott Hughes | f09afe8 | 2011-10-16 14:24:21 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | if (compiled_method != NULL) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 983 | MethodReference ref(&dex_file, method_idx); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 984 | CHECK(GetCompiledMethod(ref) == NULL) << PrettyMethod(method_idx, dex_file); |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 985 | MutexLock mu(compiled_methods_lock_); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 986 | compiled_methods_[ref] = compiled_method; |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 987 | DCHECK(GetCompiledMethod(ref) != NULL) << PrettyMethod(method_idx, dex_file); |
Brian Carlstrom | 2cc022b | 2011-08-25 10:05:39 -0700 | [diff] [blame] | 988 | } |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 989 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 990 | const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx)); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 991 | bool is_static = (access_flags & kAccStatic) != 0; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 992 | const CompiledInvokeStub* compiled_invoke_stub = FindInvokeStub(is_static, shorty); |
| 993 | if (compiled_invoke_stub == NULL) { |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 994 | #if defined(ART_USE_LLVM_COMPILER) |
| 995 | compiled_invoke_stub = compiler_llvm_->CreateInvokeStub(is_static, shorty); |
| 996 | #else |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 997 | if (instruction_set_ == kX86) { |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 998 | compiled_invoke_stub = ::art::x86::X86CreateInvokeStub(is_static, shorty); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 999 | } else { |
| 1000 | CHECK(instruction_set_ == kArm || instruction_set_ == kThumb2); |
| 1001 | // Generates invocation stub using ARM instruction set |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 1002 | compiled_invoke_stub = ::art::arm::ArmCreateInvokeStub(is_static, shorty); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1003 | } |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 1004 | #endif |
| 1005 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1006 | CHECK(compiled_invoke_stub != NULL); |
| 1007 | InsertInvokeStub(is_static, shorty, compiled_invoke_stub); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1008 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1009 | CHECK(!Thread::Current()->IsExceptionPending()) << PrettyMethod(method_idx, dex_file); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1012 | static std::string MakeInvokeStubKey(bool is_static, const char* shorty) { |
| 1013 | std::string key(shorty); |
| 1014 | if (is_static) { |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 1015 | key += "$"; // Must not be a shorty type character. |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1016 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1017 | return key; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1020 | const CompiledInvokeStub* Compiler::FindInvokeStub(bool is_static, const char* shorty) const { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1021 | MutexLock mu(compiled_invoke_stubs_lock_); |
Elliott Hughes | 9557241 | 2011-12-13 18:14:20 -0800 | [diff] [blame] | 1022 | const std::string key(MakeInvokeStubKey(is_static, shorty)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1023 | InvokeStubTable::const_iterator it = compiled_invoke_stubs_.find(key); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1024 | if (it == compiled_invoke_stubs_.end()) { |
| 1025 | return NULL; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1026 | } else { |
| 1027 | DCHECK(it->second != NULL); |
| 1028 | return it->second; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | void Compiler::InsertInvokeStub(bool is_static, const char* shorty, |
| 1033 | const CompiledInvokeStub* compiled_invoke_stub) { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1034 | MutexLock mu(compiled_invoke_stubs_lock_); |
Elliott Hughes | 9557241 | 2011-12-13 18:14:20 -0800 | [diff] [blame] | 1035 | std::string key(MakeInvokeStubKey(is_static, shorty)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1036 | compiled_invoke_stubs_[key] = compiled_invoke_stub; |
| 1037 | } |
| 1038 | |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1039 | CompiledClass* Compiler::GetCompiledClass(ClassReference ref) const { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1040 | MutexLock mu(compiled_classes_lock_); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 1041 | ClassTable::const_iterator it = compiled_classes_.find(ref); |
| 1042 | if (it == compiled_classes_.end()) { |
| 1043 | return NULL; |
| 1044 | } |
| 1045 | CHECK(it->second != NULL); |
| 1046 | return it->second; |
| 1047 | } |
| 1048 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1049 | CompiledMethod* Compiler::GetCompiledMethod(MethodReference ref) const { |
Elliott Hughes | c225caa | 2012-02-03 15:43:37 -0800 | [diff] [blame] | 1050 | MutexLock mu(compiled_methods_lock_); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1051 | MethodTable::const_iterator it = compiled_methods_.find(ref); |
| 1052 | if (it == compiled_methods_.end()) { |
| 1053 | return NULL; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1054 | } |
| 1055 | CHECK(it->second != NULL); |
| 1056 | return it->second; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 1059 | void Compiler::SetGcMaps(const ClassLoader* class_loader, const std::vector<const DexFile*>& dex_files) { |
| 1060 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 1061 | const DexFile* dex_file = dex_files[i]; |
| 1062 | CHECK(dex_file != NULL); |
| 1063 | SetGcMapsDexFile(class_loader, *dex_file); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | void Compiler::SetGcMapsDexFile(const ClassLoader* class_loader, const DexFile& dex_file) { |
| 1068 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 1069 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
| 1070 | for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); class_def_index++) { |
| 1071 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
| 1072 | const char* descriptor = dex_file.GetClassDescriptor(class_def); |
| 1073 | Class* klass = class_linker->FindClass(descriptor, class_loader); |
| 1074 | if (klass == NULL || !klass->IsVerified()) { |
| 1075 | Thread::Current()->ClearException(); |
| 1076 | continue; |
| 1077 | } |
| 1078 | const byte* class_data = dex_file.GetClassData(class_def); |
| 1079 | if (class_data == NULL) { |
| 1080 | // empty class such as a marker interface |
| 1081 | continue; |
| 1082 | } |
| 1083 | ClassDataItemIterator it(dex_file, class_data); |
| 1084 | while (it.HasNextStaticField()) { |
| 1085 | it.Next(); |
| 1086 | } |
| 1087 | while (it.HasNextInstanceField()) { |
| 1088 | it.Next(); |
| 1089 | } |
| 1090 | while (it.HasNextDirectMethod()) { |
| 1091 | Method* method = class_linker->ResolveMethod(dex_file, it.GetMemberIndex(), dex_cache, |
| 1092 | class_loader, true); |
| 1093 | SetGcMapsMethod(dex_file, method); |
| 1094 | it.Next(); |
| 1095 | } |
| 1096 | while (it.HasNextVirtualMethod()) { |
| 1097 | Method* method = class_linker->ResolveMethod(dex_file, it.GetMemberIndex(), dex_cache, |
| 1098 | class_loader, false); |
| 1099 | SetGcMapsMethod(dex_file, method); |
| 1100 | it.Next(); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1105 | namespace verifier { |
| 1106 | class DexVerifier { |
| 1107 | public: |
| 1108 | static const std::vector<uint8_t>* GetGcMap(Compiler::MethodReference ref); |
| 1109 | }; |
| 1110 | } |
| 1111 | |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 1112 | void Compiler::SetGcMapsMethod(const DexFile& dex_file, Method* method) { |
| 1113 | if (method == NULL) { |
| 1114 | Thread::Current()->ClearException(); |
| 1115 | return; |
| 1116 | } |
| 1117 | uint16_t method_idx = method->GetDexMethodIndex(); |
| 1118 | MethodReference ref(&dex_file, method_idx); |
| 1119 | CompiledMethod* compiled_method = GetCompiledMethod(ref); |
| 1120 | if (compiled_method == NULL) { |
| 1121 | return; |
| 1122 | } |
| 1123 | const std::vector<uint8_t>* gc_map = verifier::DexVerifier::GetGcMap(ref); |
| 1124 | if (gc_map == NULL) { |
| 1125 | return; |
| 1126 | } |
| 1127 | compiled_method->SetGcMap(*gc_map); |
| 1128 | } |
| 1129 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 1130 | void Compiler::SetCodeAndDirectMethods(const std::vector<const DexFile*>& dex_files) { |
| 1131 | for (size_t i = 0; i != dex_files.size(); ++i) { |
| 1132 | const DexFile* dex_file = dex_files[i]; |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 1133 | CHECK(dex_file != NULL); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 1134 | SetCodeAndDirectMethodsDexFile(*dex_file); |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 1138 | void Compiler::SetCodeAndDirectMethodsDexFile(const DexFile& dex_file) { |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 1139 | Runtime* runtime = Runtime::Current(); |
| 1140 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 1141 | DexCache* dex_cache = class_linker->FindDexCache(dex_file); |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 1142 | CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods(); |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 1143 | for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) { |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 1144 | Method* method = dex_cache->GetResolvedMethod(i); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1145 | if (method == NULL || method->IsDirect()) { |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 1146 | Runtime::TrampolineType type = Runtime::GetTrampolineType(method); |
| 1147 | ByteArray* res_trampoline = runtime->GetResolutionStubArray(type); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 1148 | code_and_direct_methods->SetResolvedDirectMethodTrampoline(i, res_trampoline); |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 1149 | } else { |
| 1150 | // TODO: we currently leave the entry blank for resolved |
| 1151 | // non-direct methods. we could put in an error stub. |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 1156 | } // namespace art |