1 /* 2 * Copyright 2014 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 */ 16 17 #ifndef ART_RUNTIME_JIT_JIT_CODE_CACHE_H_ 18 #define ART_RUNTIME_JIT_JIT_CODE_CACHE_H_ 19 20 #include <cstdint> 21 #include <iosfwd> 22 #include <memory> 23 #include <set> 24 #include <string> 25 #include <unordered_set> 26 #include <vector> 27 28 #include "base/arena_containers.h" 29 #include "base/array_ref.h" 30 #include "base/atomic.h" 31 #include "base/histogram.h" 32 #include "base/macros.h" 33 #include "base/mem_map.h" 34 #include "base/mutex.h" 35 #include "base/safe_map.h" 36 #include "compilation_kind.h" 37 #include "jit_memory_region.h" 38 #include "profiling_info.h" 39 40 namespace art HIDDEN { 41 42 class ArtMethod; 43 template<class T> class Handle; 44 class LinearAlloc; 45 class InlineCache; 46 class IsMarkedVisitor; 47 class JitJniStubTestHelper; 48 class OatQuickMethodHeader; 49 struct ProfileMethodInfo; 50 class ProfilingInfo; 51 class Thread; 52 53 namespace gc { 54 namespace accounting { 55 template<size_t kAlignment> class MemoryRangeBitmap; 56 } // namespace accounting 57 } // namespace gc 58 59 namespace mirror { 60 class Class; 61 class Object; 62 template<class T> class ObjectArray; 63 } // namespace mirror 64 65 namespace gc { 66 namespace accounting { 67 template<size_t kAlignment> class MemoryRangeBitmap; 68 } // namespace accounting 69 } // namespace gc 70 71 namespace mirror { 72 class Class; 73 class Object; 74 template<class T> class ObjectArray; 75 } // namespace mirror 76 77 namespace jit { 78 79 class MarkCodeClosure; 80 81 // Type of bitmap used for tracking live functions in the JIT code cache for the purposes 82 // of garbage collecting code. 83 using CodeCacheBitmap = gc::accounting::MemoryRangeBitmap<kJitCodeAccountingBytes>; 84 85 // The state of profile-based compilation in the zygote. 86 // - kInProgress: JIT compilation is happening 87 // - kDone: JIT compilation is finished, and the zygote is preparing notifying 88 // the other processes. 89 // - kNotifiedOk: the zygote has notified the other processes, which can start 90 // sharing the boot image method mappings. 91 // - kNotifiedFailure: the zygote has notified the other processes, but they 92 // cannot share the boot image method mappings due to 93 // unexpected errors 94 enum class ZygoteCompilationState : uint8_t { 95 kInProgress = 0, 96 kDone = 1, 97 kNotifiedOk = 2, 98 kNotifiedFailure = 3, 99 }; 100 101 // Class abstraction over a map of ArtMethod -> compiled code, where the 102 // ArtMethod are compiled by the zygote, and the map acts as a communication 103 // channel between the zygote and the other processes. 104 // For the zygote process, this map is the only map it is placing the compiled 105 // code. JitCodeCache.method_code_map_ is empty. 106 // 107 // This map is writable only by the zygote, and readable by all children. 108 class ZygoteMap { 109 public: 110 struct Entry { 111 ArtMethod* method; 112 // Note we currently only allocate code in the low 4g, so we could just reserve 4 bytes 113 // for the code pointer. For simplicity and in the case we move to 64bit 114 // addresses for code, just keep it void* for now. 115 const void* code_ptr; 116 }; 117 ZygoteMap(JitMemoryRegion * region)118 explicit ZygoteMap(JitMemoryRegion* region) 119 : map_(), region_(region), compilation_state_(nullptr) {} 120 121 // Initialize the data structure so it can hold `number_of_methods` mappings. 122 // Note that the map is fixed size and never grows. 123 void Initialize(uint32_t number_of_methods) REQUIRES(!Locks::jit_lock_); 124 125 // Add the mapping method -> code. 126 void Put(const void* code, ArtMethod* method) REQUIRES(Locks::jit_lock_); 127 128 // Return the code pointer for the given method. If pc is not zero, check that 129 // the pc falls into that code range. Return null otherwise. 130 const void* GetCodeFor(ArtMethod* method, uintptr_t pc = 0) const; 131 132 // Return whether the map has associated code for the given method. ContainsMethod(ArtMethod * method)133 bool ContainsMethod(ArtMethod* method) const { 134 return GetCodeFor(method) != nullptr; 135 } 136 SetCompilationState(ZygoteCompilationState state)137 void SetCompilationState(ZygoteCompilationState state) { 138 DCHECK_LT(static_cast<uint8_t>(*compilation_state_), static_cast<uint8_t>(state)); 139 region_->WriteData(compilation_state_, state); 140 } 141 IsCompilationDoneButNotNotified()142 bool IsCompilationDoneButNotNotified() const { 143 return compilation_state_ != nullptr && *compilation_state_ == ZygoteCompilationState::kDone; 144 } 145 IsCompilationNotified()146 bool IsCompilationNotified() const { 147 return compilation_state_ != nullptr && *compilation_state_ > ZygoteCompilationState::kDone; 148 } 149 CanMapBootImageMethods()150 bool CanMapBootImageMethods() const { 151 return compilation_state_ != nullptr && 152 *compilation_state_ == ZygoteCompilationState::kNotifiedOk; 153 } 154 cbegin()155 ArrayRef<const Entry>::const_iterator cbegin() const { 156 return map_.cbegin(); 157 } begin()158 ArrayRef<const Entry>::iterator begin() { 159 return map_.begin(); 160 } cend()161 ArrayRef<const Entry>::const_iterator cend() const { 162 return map_.cend(); 163 } end()164 ArrayRef<const Entry>::iterator end() { 165 return map_.end(); 166 } 167 168 private: 169 // The map allocated with `region_`. 170 ArrayRef<const Entry> map_; 171 172 // The region in which the map is allocated. 173 JitMemoryRegion* const region_; 174 175 // The current state of compilation in the zygote. Starts with kInProgress, 176 // and should end with kNotifiedOk or kNotifiedFailure. 177 const ZygoteCompilationState* compilation_state_; 178 179 DISALLOW_COPY_AND_ASSIGN(ZygoteMap); 180 }; 181 182 class JitCodeCache { 183 public: 184 static constexpr size_t kMaxCapacity = 64 * MB; 185 186 // Default initial capacity of the JIT code cache. GetInitialCapacity()187 static size_t GetInitialCapacity() { 188 // This function is called during static initialization 189 // when gPageSize might not be available yet. 190 const size_t page_size = GetPageSizeSlow(); 191 192 // Put the default to a very low amount for debug builds to stress the code cache 193 // collection. It should be at least two pages, however, as the storage is split 194 // into data and code sections with sizes that should be aligned to page size each 195 // as that's the unit mspaces use. See also: JitMemoryRegion::Initialize. 196 return std::max(kIsDebugBuild ? 8 * KB : 64 * KB, 2 * page_size); 197 } 198 199 // Create the code cache with a code + data capacity equal to "capacity", error message is passed 200 // in the out arg error_msg. 201 static JitCodeCache* Create(bool used_only_for_profile_data, 202 bool rwx_memory_allowed, 203 bool is_zygote, 204 std::string* error_msg); 205 ~JitCodeCache(); 206 207 bool NotifyCompilationOf(ArtMethod* method, 208 Thread* self, 209 CompilationKind compilation_kind, 210 bool prejit) 211 REQUIRES_SHARED(Locks::mutator_lock_) 212 REQUIRES(!Locks::jit_lock_); 213 214 EXPORT void NotifyMethodRedefined(ArtMethod* method) 215 REQUIRES(Locks::mutator_lock_) 216 REQUIRES(!Locks::jit_lock_); 217 218 // Notify to the code cache that the compiler wants to use the 219 // profiling info of `method` to drive optimizations, 220 // and therefore ensure the returned profiling info object is not 221 // collected. 222 ProfilingInfo* NotifyCompilerUse(ArtMethod* method, Thread* self) 223 REQUIRES_SHARED(Locks::mutator_lock_) 224 REQUIRES(!Locks::jit_lock_); 225 226 void DoneCompiling(ArtMethod* method, Thread* self) 227 REQUIRES_SHARED(Locks::mutator_lock_) 228 REQUIRES(!Locks::jit_lock_); 229 230 void DoneCompilerUse(ArtMethod* method, Thread* self) 231 REQUIRES_SHARED(Locks::mutator_lock_) 232 REQUIRES(!Locks::jit_lock_); 233 234 // Return true if the code cache contains this pc. 235 EXPORT bool ContainsPc(const void* pc) const; 236 237 // Return true if the code cache contains this pc in the private region (i.e. not from zygote). 238 bool PrivateRegionContainsPc(const void* pc) const; 239 240 // Return true if the code cache contains this method. 241 EXPORT bool ContainsMethod(ArtMethod* method) 242 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::jit_lock_); 243 244 // Return the code pointer for a JNI-compiled stub if the method is in the cache, null otherwise. 245 const void* GetJniStubCode(ArtMethod* method) 246 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::jit_lock_); 247 248 // Allocate a region for both code and data in the JIT code cache. 249 // The reserved memory is left completely uninitialized. 250 bool Reserve(Thread* self, 251 JitMemoryRegion* region, 252 size_t code_size, 253 size_t stack_map_size, 254 size_t number_of_roots, 255 ArtMethod* method, 256 /*out*/ArrayRef<const uint8_t>* reserved_code, 257 /*out*/ArrayRef<const uint8_t>* reserved_data) 258 REQUIRES_SHARED(Locks::mutator_lock_) 259 REQUIRES(!Locks::jit_lock_); 260 261 // Initialize code and data of previously allocated memory. 262 // 263 // `cha_single_implementation_list` needs to be registered via CHA (if it's 264 // still valid), since the compiled code still needs to be invalidated if the 265 // single-implementation assumptions are violated later. This needs to be done 266 // even if `has_should_deoptimize_flag` is false, which can happen due to CHA 267 // guard elimination. 268 bool Commit(Thread* self, 269 JitMemoryRegion* region, 270 ArtMethod* method, 271 ArrayRef<const uint8_t> reserved_code, // Uninitialized destination. 272 ArrayRef<const uint8_t> code, // Compiler output (source). 273 ArrayRef<const uint8_t> reserved_data, // Uninitialized destination. 274 const std::vector<Handle<mirror::Object>>& roots, 275 ArrayRef<const uint8_t> stack_map, // Compiler output (source). 276 const std::vector<uint8_t>& debug_info, 277 bool is_full_debug_info, 278 CompilationKind compilation_kind, 279 const ArenaSet<ArtMethod*>& cha_single_implementation_list) 280 REQUIRES_SHARED(Locks::mutator_lock_) 281 REQUIRES(!Locks::jit_lock_); 282 283 // Free the previously allocated memory regions. 284 void Free(Thread* self, JitMemoryRegion* region, const uint8_t* code, const uint8_t* data) 285 REQUIRES_SHARED(Locks::mutator_lock_) 286 REQUIRES(!Locks::jit_lock_); 287 void FreeLocked(JitMemoryRegion* region, const uint8_t* code, const uint8_t* data) 288 REQUIRES(Locks::jit_lock_); 289 290 void IncreaseCodeCacheCapacity(Thread* self) 291 REQUIRES(!Locks::jit_lock_) 292 REQUIRES_SHARED(Locks::mutator_lock_); 293 294 // Given the 'pc', try to find the JIT compiled code associated with it. 'method' may be null 295 // when LookupMethodHeader is called from MarkCodeClosure::Run() in debug builds. Return null 296 // if 'pc' is not in the code cache. 297 OatQuickMethodHeader* LookupMethodHeader(uintptr_t pc, ArtMethod* method) 298 REQUIRES(!Locks::jit_lock_) 299 REQUIRES_SHARED(Locks::mutator_lock_); 300 301 EXPORT OatQuickMethodHeader* LookupOsrMethodHeader(ArtMethod* method) 302 REQUIRES(!Locks::jit_lock_) 303 REQUIRES_SHARED(Locks::mutator_lock_); 304 305 // Removes method from the cache for testing purposes. The caller 306 // must ensure that all threads are suspended and the method should 307 // not be in any thread's stack. 308 EXPORT bool RemoveMethod(ArtMethod* method, bool release_memory) 309 REQUIRES(!Locks::jit_lock_) 310 REQUIRES(Locks::mutator_lock_); 311 312 // Remove all methods in our cache that were allocated by 'alloc'. 313 void RemoveMethodsIn(Thread* self, const LinearAlloc& alloc) 314 REQUIRES(!Locks::jit_lock_) 315 REQUIRES_SHARED(Locks::mutator_lock_); 316 317 void CopyInlineCacheInto(const InlineCache& ic, 318 /*out*/StackHandleScope<InlineCache::kIndividualCacheSize>* classes) 319 REQUIRES(!Locks::jit_lock_) 320 REQUIRES_SHARED(Locks::mutator_lock_); 321 322 // Create a 'ProfileInfo' for 'method'. 323 ProfilingInfo* AddProfilingInfo(Thread* self, 324 ArtMethod* method, 325 const std::vector<uint32_t>& inline_cache_entries, 326 const std::vector<uint32_t>& branch_cache_entries) 327 REQUIRES(!Locks::jit_lock_) 328 REQUIRES_SHARED(Locks::mutator_lock_); 329 OwnsSpace(const void * mspace)330 bool OwnsSpace(const void* mspace) const NO_THREAD_SAFETY_ANALYSIS { 331 return private_region_.OwnsSpace(mspace) || shared_region_.OwnsSpace(mspace); 332 } 333 334 void* MoreCore(const void* mspace, intptr_t increment); 335 336 // Adds to `methods` all profiled methods which are part of any of the given dex locations. 337 // Saves inline caches for a method if its hotness meets `inline_cache_threshold` after being 338 // baseline compiled. 339 EXPORT void GetProfiledMethods(const std::set<std::string>& dex_base_locations, 340 std::vector<ProfileMethodInfo>& methods, 341 uint16_t inline_cache_threshold) REQUIRES(!Locks::jit_lock_) 342 REQUIRES_SHARED(Locks::mutator_lock_); 343 344 EXPORT void InvalidateAllCompiledCode() 345 REQUIRES(!Locks::jit_lock_) 346 REQUIRES_SHARED(Locks::mutator_lock_); 347 348 void InvalidateCompiledCodeFor(ArtMethod* method, const OatQuickMethodHeader* code) 349 REQUIRES(!Locks::jit_lock_) 350 REQUIRES_SHARED(Locks::mutator_lock_); 351 352 void Dump(std::ostream& os) REQUIRES(!Locks::jit_lock_); 353 void DumpAllCompiledMethods(std::ostream& os) 354 REQUIRES(!Locks::jit_lock_) 355 REQUIRES_SHARED(Locks::mutator_lock_); 356 357 bool IsOsrCompiled(ArtMethod* method) REQUIRES(!Locks::jit_lock_); 358 359 void SweepRootTables(IsMarkedVisitor* visitor) 360 REQUIRES(!Locks::jit_lock_) 361 REQUIRES_SHARED(Locks::mutator_lock_); 362 363 // The GC needs to disallow the reading of inline caches when it processes them, 364 // to avoid having a class being used while it is being deleted. 365 void AllowInlineCacheAccess() REQUIRES(!Locks::jit_lock_); 366 void DisallowInlineCacheAccess() REQUIRES(!Locks::jit_lock_); 367 void BroadcastForInlineCacheAccess() REQUIRES(!Locks::jit_lock_); 368 369 // Notify the code cache that the method at the pointer 'old_method' is being moved to the pointer 370 // 'new_method' since it is being made obsolete. 371 EXPORT void MoveObsoleteMethod(ArtMethod* old_method, ArtMethod* new_method) 372 REQUIRES(!Locks::jit_lock_) REQUIRES(Locks::mutator_lock_); 373 374 // Dynamically change whether we want to garbage collect code. 375 EXPORT void SetGarbageCollectCode(bool value) REQUIRES(!Locks::jit_lock_); 376 377 bool GetGarbageCollectCode() REQUIRES(!Locks::jit_lock_); 378 379 // Unsafe variant for debug checks. GetGarbageCollectCodeUnsafe()380 bool GetGarbageCollectCodeUnsafe() const NO_THREAD_SAFETY_ANALYSIS { 381 return garbage_collect_code_; 382 } GetZygoteMap()383 ZygoteMap* GetZygoteMap() { 384 return &zygote_map_; 385 } 386 387 // Fetch the code of a method that was JITted, but the JIT could not 388 // update its entrypoint due to the resolution trampoline. 389 const void* GetSavedEntryPointOfPreCompiledMethod(ArtMethod* method) 390 REQUIRES(!Locks::jit_lock_) 391 REQUIRES_SHARED(Locks::mutator_lock_); 392 393 EXPORT void PostForkChildAction(bool is_system_server, bool is_zygote); 394 395 // Clear the entrypoints of JIT compiled methods that belong in the zygote space. 396 // This is used for removing non-debuggable JIT code at the point we realize the runtime 397 // is debuggable. Also clear the Precompiled flag from all methods so the non-debuggable code 398 // doesn't come back. 399 EXPORT void TransitionToDebuggable() REQUIRES(!Locks::jit_lock_) REQUIRES(Locks::mutator_lock_); 400 401 JitMemoryRegion* GetCurrentRegion(); IsSharedRegion(const JitMemoryRegion & region)402 bool IsSharedRegion(const JitMemoryRegion& region) const { return ®ion == &shared_region_; } CanAllocateProfilingInfo()403 bool CanAllocateProfilingInfo() { 404 // If we don't have a private region, we cannot allocate a profiling info. 405 // A shared region doesn't support in general GC objects, which a profiling info 406 // can reference. 407 JitMemoryRegion* region = GetCurrentRegion(); 408 return region->IsValid() && !IsSharedRegion(*region); 409 } 410 411 // Return whether the given `ptr` is in the zygote executable memory space. IsInZygoteExecSpace(const void * ptr)412 bool IsInZygoteExecSpace(const void* ptr) const { 413 return shared_region_.IsInExecSpace(ptr); 414 } 415 416 ProfilingInfo* GetProfilingInfo(ArtMethod* method, Thread* self); 417 void MaybeUpdateInlineCache(ArtMethod* method, 418 uint32_t dex_pc, 419 ObjPtr<mirror::Class> cls, 420 Thread* self) 421 REQUIRES_SHARED(Locks::mutator_lock_); 422 423 // NO_THREAD_SAFETY_ANALYSIS because we may be called with the JIT lock held 424 // or not. The implementation of this method handles the two cases. 425 void AddZombieCode(ArtMethod* method, const void* code_ptr) NO_THREAD_SAFETY_ANALYSIS; 426 427 EXPORT void DoCollection(Thread* self) 428 REQUIRES(!Locks::jit_lock_); 429 430 private: 431 JitCodeCache(); 432 433 void AddZombieCodeInternal(ArtMethod* method, const void* code_ptr) 434 REQUIRES(Locks::jit_lock_) 435 REQUIRES_SHARED(Locks::mutator_lock_); 436 437 ProfilingInfo* AddProfilingInfoInternal(Thread* self, 438 ArtMethod* method, 439 const std::vector<uint32_t>& inline_cache_entries, 440 const std::vector<uint32_t>& branch_cache_entries) 441 REQUIRES(Locks::jit_lock_) 442 REQUIRES_SHARED(Locks::mutator_lock_); 443 444 // If a collection is in progress, wait for it to finish. Return 445 // whether the thread actually waited. 446 bool WaitForPotentialCollectionToComplete(Thread* self) 447 REQUIRES(Locks::jit_lock_) REQUIRES_SHARED(!Locks::mutator_lock_); 448 449 // Notify all waiting threads that a collection is done. 450 void NotifyCollectionDone(Thread* self) REQUIRES(Locks::jit_lock_); 451 452 // Remove CHA dependents and underlying allocations for entries in `method_headers`. 453 void FreeAllMethodHeaders(const std::unordered_set<OatQuickMethodHeader*>& method_headers) 454 REQUIRES(Locks::jit_lock_) 455 REQUIRES(!Locks::cha_lock_); 456 457 // Removes method from the cache. The caller must ensure that all threads 458 // are suspended and the method should not be in any thread's stack. 459 bool RemoveMethodLocked(ArtMethod* method, bool release_memory) 460 REQUIRES(Locks::jit_lock_) 461 REQUIRES(Locks::mutator_lock_); 462 463 // Call given callback for every compiled method in the code cache. 464 void VisitAllMethods(const std::function<void(const void*, ArtMethod*)>& cb) 465 REQUIRES(Locks::jit_lock_); 466 467 // Free code and data allocations for `code_ptr`. 468 void FreeCodeAndData(const void* code_ptr) 469 REQUIRES(Locks::jit_lock_); 470 471 // Number of bytes allocated in the code cache. 472 size_t CodeCacheSize() REQUIRES(!Locks::jit_lock_); 473 474 // Number of bytes allocated in the data cache. 475 size_t DataCacheSize() REQUIRES(!Locks::jit_lock_); 476 477 // Number of bytes allocated in the code cache. 478 size_t CodeCacheSizeLocked() REQUIRES(Locks::jit_lock_); 479 480 // Number of bytes allocated in the data cache. 481 size_t DataCacheSizeLocked() REQUIRES(Locks::jit_lock_); 482 483 // Return whether the code cache's capacity is at its maximum. 484 bool IsAtMaxCapacity() const REQUIRES(Locks::jit_lock_); 485 486 void RemoveUnmarkedCode(Thread* self) 487 REQUIRES(!Locks::jit_lock_) 488 REQUIRES_SHARED(Locks::mutator_lock_); 489 490 void MarkCompiledCodeOnThreadStacks(Thread* self) 491 REQUIRES(!Locks::jit_lock_) 492 REQUIRES_SHARED(Locks::mutator_lock_); 493 GetLiveBitmap()494 CodeCacheBitmap* GetLiveBitmap() const { 495 return live_bitmap_.get(); 496 } 497 IsInZygoteDataSpace(const void * ptr)498 bool IsInZygoteDataSpace(const void* ptr) const { 499 return shared_region_.IsInDataSpace(ptr); 500 } 501 GetReservedCapacity()502 size_t GetReservedCapacity() { 503 return reserved_capacity_; 504 } 505 506 bool IsWeakAccessEnabled(Thread* self) const; 507 void WaitUntilInlineCacheAccessible(Thread* self) 508 REQUIRES(!Locks::jit_lock_) 509 REQUIRES_SHARED(Locks::mutator_lock_); 510 511 class JniStubKey; 512 class JniStubData; 513 514 // Whether the GC allows accessing weaks in inline caches. Note that this 515 // is not used by the concurrent collector, which uses 516 // Thread::SetWeakRefAccessEnabled instead. 517 Atomic<bool> is_weak_access_enabled_; 518 519 // Condition to wait on for accessing inline caches. 520 ConditionVariable inline_cache_cond_ GUARDED_BY(Locks::jit_lock_); 521 522 // Reserved capacity of the JIT code cache. 523 const size_t reserved_capacity_; 524 525 // By default, do not GC until reaching four times the initial capacity. 526 static constexpr size_t kReservedCapacityMultiplier = 4; 527 528 // -------------- JIT memory regions ------------------------------------- // 529 530 // Shared region, inherited from the zygote. 531 JitMemoryRegion shared_region_; 532 533 // Process's own region. 534 JitMemoryRegion private_region_; 535 536 // -------------- Global JIT maps --------------------------------------- // 537 538 // Note: The methods held in these maps may be dead, so we must ensure that we do not use 539 // read barriers on their declaring classes as that could unnecessarily keep them alive or 540 // crash the GC, depending on the GC phase and particular GC's details. Asserting that we 541 // do not emit read barriers for these methods can be tricky as we're allowed to emit read 542 // barriers for other methods that are known to be alive, such as the method being compiled. 543 // The GC must ensure that methods in these maps are cleaned up with `RemoveMethodsIn()` 544 // before the declaring class memory is freed. 545 546 // Holds compiled code associated with the shorty for a JNI stub. 547 SafeMap<JniStubKey, JniStubData> jni_stubs_map_ GUARDED_BY(Locks::jit_lock_); 548 549 // Holds compiled code associated to the ArtMethod. 550 SafeMap<const void*, ArtMethod*> method_code_map_ GUARDED_BY(Locks::jit_lock_); 551 552 // Holds compiled code associated to the ArtMethod. Used when pre-jitting 553 // methods whose entrypoints have the resolution stub. 554 SafeMap<ArtMethod*, const void*> saved_compiled_methods_map_ GUARDED_BY(Locks::jit_lock_); 555 556 // Holds osr compiled code associated to the ArtMethod. 557 SafeMap<ArtMethod*, const void*> osr_code_map_ GUARDED_BY(Locks::jit_lock_); 558 559 // ProfilingInfo objects we have allocated. 560 SafeMap<ArtMethod*, ProfilingInfo*> profiling_infos_ GUARDED_BY(Locks::jit_lock_); 561 562 // Zombie code and JNI methods to consider for collection. 563 std::set<const void*> zombie_code_ GUARDED_BY(Locks::jit_lock_); 564 std::set<ArtMethod*> zombie_jni_code_ GUARDED_BY(Locks::jit_lock_); 565 566 std::set<const void*> processed_zombie_code_ GUARDED_BY(Locks::jit_lock_); 567 std::set<ArtMethod*> processed_zombie_jni_code_ GUARDED_BY(Locks::jit_lock_); 568 569 // Methods that the zygote has compiled and can be shared across processes 570 // forked from the zygote. 571 ZygoteMap zygote_map_; 572 573 // -------------- JIT GC related data structures ----------------------- // 574 575 // Condition to wait on during collection and for accessing weak references in inline caches. 576 ConditionVariable lock_cond_ GUARDED_BY(Locks::jit_lock_); 577 578 // Whether there is a code cache collection in progress. 579 bool collection_in_progress_ GUARDED_BY(Locks::jit_lock_); 580 581 // Whether a GC task is already scheduled. 582 bool gc_task_scheduled_ GUARDED_BY(Locks::jit_lock_); 583 584 // Bitmap for collecting code and data. 585 std::unique_ptr<CodeCacheBitmap> live_bitmap_; 586 587 // Whether we can do garbage collection. Not 'const' as tests may override this. 588 bool garbage_collect_code_ GUARDED_BY(Locks::jit_lock_); 589 590 // ---------------- JIT statistics -------------------------------------- // 591 592 // Number of baseline compilations done throughout the lifetime of the JIT. 593 size_t number_of_baseline_compilations_ GUARDED_BY(Locks::jit_lock_); 594 595 // Number of optimized compilations done throughout the lifetime of the JIT. 596 size_t number_of_optimized_compilations_ GUARDED_BY(Locks::jit_lock_); 597 598 // Number of compilations for on-stack-replacement done throughout the lifetime of the JIT. 599 size_t number_of_osr_compilations_ GUARDED_BY(Locks::jit_lock_); 600 601 // Number of code cache collections done throughout the lifetime of the JIT. 602 size_t number_of_collections_ GUARDED_BY(Locks::jit_lock_); 603 604 // Histograms for keeping track of stack map size statistics. 605 Histogram<uint64_t> histogram_stack_map_memory_use_ GUARDED_BY(Locks::jit_lock_); 606 607 // Histograms for keeping track of code size statistics. 608 Histogram<uint64_t> histogram_code_memory_use_ GUARDED_BY(Locks::jit_lock_); 609 610 // Histograms for keeping track of profiling info statistics. 611 Histogram<uint64_t> histogram_profiling_info_memory_use_ GUARDED_BY(Locks::jit_lock_); 612 613 friend class ScopedCodeCacheWrite; 614 friend class MarkCodeClosure; 615 616 DISALLOW_COPY_AND_ASSIGN(JitCodeCache); 617 }; 618 619 } // namespace jit 620 } // namespace art 621 622 #endif // ART_RUNTIME_JIT_JIT_CODE_CACHE_H_ 623