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