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