• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, CompilationKind compilation_kind)
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) REQUIRES(!Locks::jit_lock_);
234 
235   // Return the code pointer for a JNI-compiled stub if the method is in the cache, null otherwise.
236   const void* GetJniStubCode(ArtMethod* method) REQUIRES(!Locks::jit_lock_);
237 
238   // Allocate a region for both code and data in the JIT code cache.
239   // The reserved memory is left completely uninitialized.
240   bool Reserve(Thread* self,
241                JitMemoryRegion* region,
242                size_t code_size,
243                size_t stack_map_size,
244                size_t number_of_roots,
245                ArtMethod* method,
246                /*out*/ArrayRef<const uint8_t>* reserved_code,
247                /*out*/ArrayRef<const uint8_t>* reserved_data)
248       REQUIRES_SHARED(Locks::mutator_lock_)
249       REQUIRES(!Locks::jit_lock_);
250 
251   // Initialize code and data of previously allocated memory.
252   //
253   // `cha_single_implementation_list` needs to be registered via CHA (if it's
254   // still valid), since the compiled code still needs to be invalidated if the
255   // single-implementation assumptions are violated later. This needs to be done
256   // even if `has_should_deoptimize_flag` is false, which can happen due to CHA
257   // guard elimination.
258   bool Commit(Thread* self,
259               JitMemoryRegion* region,
260               ArtMethod* method,
261               ArrayRef<const uint8_t> reserved_code,  // Uninitialized destination.
262               ArrayRef<const uint8_t> code,           // Compiler output (source).
263               ArrayRef<const uint8_t> reserved_data,  // Uninitialized destination.
264               const std::vector<Handle<mirror::Object>>& roots,
265               ArrayRef<const uint8_t> stack_map,      // Compiler output (source).
266               const std::vector<uint8_t>& debug_info,
267               bool is_full_debug_info,
268               CompilationKind compilation_kind,
269               bool has_should_deoptimize_flag,
270               const ArenaSet<ArtMethod*>& cha_single_implementation_list)
271       REQUIRES_SHARED(Locks::mutator_lock_)
272       REQUIRES(!Locks::jit_lock_);
273 
274   // Free the previously allocated memory regions.
275   void Free(Thread* self, JitMemoryRegion* region, const uint8_t* code, const uint8_t* data)
276       REQUIRES_SHARED(Locks::mutator_lock_)
277       REQUIRES(!Locks::jit_lock_);
278   void FreeLocked(JitMemoryRegion* region, const uint8_t* code, const uint8_t* data)
279       REQUIRES_SHARED(Locks::mutator_lock_)
280       REQUIRES(Locks::jit_lock_);
281 
282   // Perform a collection on the code cache.
283   void GarbageCollectCache(Thread* self)
284       REQUIRES(!Locks::jit_lock_)
285       REQUIRES_SHARED(Locks::mutator_lock_);
286 
287   // Given the 'pc', try to find the JIT compiled code associated with it.  'method' may be null
288   // when LookupMethodHeader is called from MarkCodeClosure::Run() in debug builds.  Return null
289   // if 'pc' is not in the code cache.
290   OatQuickMethodHeader* LookupMethodHeader(uintptr_t pc, ArtMethod* method)
291       REQUIRES(!Locks::jit_lock_)
292       REQUIRES_SHARED(Locks::mutator_lock_);
293 
294   OatQuickMethodHeader* LookupOsrMethodHeader(ArtMethod* method)
295       REQUIRES(!Locks::jit_lock_)
296       REQUIRES_SHARED(Locks::mutator_lock_);
297 
298   // Removes method from the cache for testing purposes. The caller
299   // must ensure that all threads are suspended and the method should
300   // not be in any thread's stack.
301   bool RemoveMethod(ArtMethod* method, bool release_memory)
302       REQUIRES(!Locks::jit_lock_)
303       REQUIRES(Locks::mutator_lock_);
304 
305   // Remove all methods in our cache that were allocated by 'alloc'.
306   void RemoveMethodsIn(Thread* self, const LinearAlloc& alloc)
307       REQUIRES(!Locks::jit_lock_)
308       REQUIRES_SHARED(Locks::mutator_lock_);
309 
310   void CopyInlineCacheInto(const InlineCache& ic,
311                            /*out*/StackHandleScope<InlineCache::kIndividualCacheSize>* classes)
312       REQUIRES(!Locks::jit_lock_)
313       REQUIRES_SHARED(Locks::mutator_lock_);
314 
315   // Create a 'ProfileInfo' for 'method'.
316   ProfilingInfo* AddProfilingInfo(Thread* self,
317                                   ArtMethod* method,
318                                   const std::vector<uint32_t>& entries)
319       REQUIRES(!Locks::jit_lock_)
320       REQUIRES_SHARED(Locks::mutator_lock_);
321 
OwnsSpace(const void * mspace)322   bool OwnsSpace(const void* mspace) const NO_THREAD_SAFETY_ANALYSIS {
323     return private_region_.OwnsSpace(mspace) || shared_region_.OwnsSpace(mspace);
324   }
325 
326   void* MoreCore(const void* mspace, intptr_t increment);
327 
328   // Adds to `methods` all profiled methods which are part of any of the given dex locations.
329   void GetProfiledMethods(const std::set<std::string>& dex_base_locations,
330                           std::vector<ProfileMethodInfo>& methods)
331       REQUIRES(!Locks::jit_lock_)
332       REQUIRES_SHARED(Locks::mutator_lock_);
333 
334   void InvalidateAllCompiledCode()
335       REQUIRES(!Locks::jit_lock_)
336       REQUIRES_SHARED(Locks::mutator_lock_);
337 
338   void InvalidateCompiledCodeFor(ArtMethod* method, const OatQuickMethodHeader* code)
339       REQUIRES(!Locks::jit_lock_)
340       REQUIRES_SHARED(Locks::mutator_lock_);
341 
342   void Dump(std::ostream& os) REQUIRES(!Locks::jit_lock_);
343 
344   bool IsOsrCompiled(ArtMethod* method) REQUIRES(!Locks::jit_lock_);
345 
346   void SweepRootTables(IsMarkedVisitor* visitor)
347       REQUIRES(!Locks::jit_lock_)
348       REQUIRES_SHARED(Locks::mutator_lock_);
349 
350   // The GC needs to disallow the reading of inline caches when it processes them,
351   // to avoid having a class being used while it is being deleted.
352   void AllowInlineCacheAccess() REQUIRES(!Locks::jit_lock_);
353   void DisallowInlineCacheAccess() REQUIRES(!Locks::jit_lock_);
354   void BroadcastForInlineCacheAccess() REQUIRES(!Locks::jit_lock_);
355 
356   // Notify the code cache that the method at the pointer 'old_method' is being moved to the pointer
357   // 'new_method' since it is being made obsolete.
358   void MoveObsoleteMethod(ArtMethod* old_method, ArtMethod* new_method)
359       REQUIRES(!Locks::jit_lock_) REQUIRES(Locks::mutator_lock_);
360 
361   // Dynamically change whether we want to garbage collect code.
362   void SetGarbageCollectCode(bool value) REQUIRES(!Locks::jit_lock_);
363 
364   bool GetGarbageCollectCode() REQUIRES(!Locks::jit_lock_);
365 
366   // Unsafe variant for debug checks.
GetGarbageCollectCodeUnsafe()367   bool GetGarbageCollectCodeUnsafe() const NO_THREAD_SAFETY_ANALYSIS {
368     return garbage_collect_code_;
369   }
GetZygoteMap()370   ZygoteMap* GetZygoteMap() {
371     return &zygote_map_;
372   }
373 
374   // Fetch the code of a method that was JITted, but the JIT could not
375   // update its entrypoint due to the resolution trampoline.
376   const void* GetSavedEntryPointOfPreCompiledMethod(ArtMethod* method)
377       REQUIRES(!Locks::jit_lock_)
378       REQUIRES_SHARED(Locks::mutator_lock_);
379 
380   void PostForkChildAction(bool is_system_server, bool is_zygote);
381 
382   // Clear the entrypoints of JIT compiled methods that belong in the zygote space.
383   // This is used for removing non-debuggable JIT code at the point we realize the runtime
384   // is debuggable. Also clear the Precompiled flag from all methods so the non-debuggable code
385   // doesn't come back.
386   void TransitionToDebuggable() REQUIRES(!Locks::jit_lock_) REQUIRES(Locks::mutator_lock_);
387 
388   JitMemoryRegion* GetCurrentRegion();
IsSharedRegion(const JitMemoryRegion & region)389   bool IsSharedRegion(const JitMemoryRegion& region) const { return &region == &shared_region_; }
CanAllocateProfilingInfo()390   bool CanAllocateProfilingInfo() {
391     // If we don't have a private region, we cannot allocate a profiling info.
392     // A shared region doesn't support in general GC objects, which a profiling info
393     // can reference.
394     JitMemoryRegion* region = GetCurrentRegion();
395     return region->IsValid() && !IsSharedRegion(*region);
396   }
397 
398   // Return whether the given `ptr` is in the zygote executable memory space.
IsInZygoteExecSpace(const void * ptr)399   bool IsInZygoteExecSpace(const void* ptr) const {
400     return shared_region_.IsInExecSpace(ptr);
401   }
402 
403   ProfilingInfo* GetProfilingInfo(ArtMethod* method, Thread* self);
404   void ResetHotnessCounter(ArtMethod* method, Thread* self);
405 
406  private:
407   JitCodeCache();
408 
409   ProfilingInfo* AddProfilingInfoInternal(Thread* self,
410                                           ArtMethod* method,
411                                           const std::vector<uint32_t>& entries)
412       REQUIRES(Locks::jit_lock_)
413       REQUIRES_SHARED(Locks::mutator_lock_);
414 
415   // If a collection is in progress, wait for it to finish. Must be called with the mutator lock.
416   // The non-mutator lock version should be used if possible. This method will release then
417   // re-acquire the mutator lock.
418   void WaitForPotentialCollectionToCompleteRunnable(Thread* self)
419       REQUIRES(Locks::jit_lock_, !Roles::uninterruptible_) REQUIRES_SHARED(Locks::mutator_lock_);
420 
421   // If a collection is in progress, wait for it to finish. Return
422   // whether the thread actually waited.
423   bool WaitForPotentialCollectionToComplete(Thread* self)
424       REQUIRES(Locks::jit_lock_) REQUIRES(!Locks::mutator_lock_);
425 
426   // Remove CHA dependents and underlying allocations for entries in `method_headers`.
427   void FreeAllMethodHeaders(const std::unordered_set<OatQuickMethodHeader*>& method_headers)
428       REQUIRES_SHARED(Locks::mutator_lock_)
429       REQUIRES(Locks::jit_lock_)
430       REQUIRES(!Locks::cha_lock_);
431 
432   // Removes method from the cache. The caller must ensure that all threads
433   // are suspended and the method should not be in any thread's stack.
434   bool RemoveMethodLocked(ArtMethod* method, bool release_memory)
435       REQUIRES(Locks::jit_lock_)
436       REQUIRES(Locks::mutator_lock_);
437 
438   // Call given callback for every compiled method in the code cache.
439   void VisitAllMethods(const std::function<void(const void*, ArtMethod*)>& cb)
440       REQUIRES(Locks::jit_lock_);
441 
442   // Free code and data allocations for `code_ptr`.
443   void FreeCodeAndData(const void* code_ptr)
444       REQUIRES(Locks::jit_lock_)
445       REQUIRES_SHARED(Locks::mutator_lock_);
446 
447   // Number of bytes allocated in the code cache.
448   size_t CodeCacheSize() REQUIRES(!Locks::jit_lock_);
449 
450   // Number of bytes allocated in the data cache.
451   size_t DataCacheSize() REQUIRES(!Locks::jit_lock_);
452 
453   // Number of bytes allocated in the code cache.
454   size_t CodeCacheSizeLocked() REQUIRES(Locks::jit_lock_);
455 
456   // Number of bytes allocated in the data cache.
457   size_t DataCacheSizeLocked() REQUIRES(Locks::jit_lock_);
458 
459   // Notify all waiting threads that a collection is done.
460   void NotifyCollectionDone(Thread* self) REQUIRES(Locks::jit_lock_);
461 
462   // Return whether the code cache's capacity is at its maximum.
463   bool IsAtMaxCapacity() const REQUIRES(Locks::jit_lock_);
464 
465   // Return whether we should do a full collection given the current state of the cache.
466   bool ShouldDoFullCollection()
467       REQUIRES(Locks::jit_lock_)
468       REQUIRES_SHARED(Locks::mutator_lock_);
469 
470   void DoCollection(Thread* self, bool collect_profiling_info)
471       REQUIRES(!Locks::jit_lock_)
472       REQUIRES_SHARED(Locks::mutator_lock_);
473 
474   void RemoveUnmarkedCode(Thread* self)
475       REQUIRES(!Locks::jit_lock_)
476       REQUIRES_SHARED(Locks::mutator_lock_);
477 
478   void MarkCompiledCodeOnThreadStacks(Thread* self)
479       REQUIRES(!Locks::jit_lock_)
480       REQUIRES_SHARED(Locks::mutator_lock_);
481 
GetLiveBitmap()482   CodeCacheBitmap* GetLiveBitmap() const {
483     return live_bitmap_.get();
484   }
485 
IsInZygoteDataSpace(const void * ptr)486   bool IsInZygoteDataSpace(const void* ptr) const {
487     return shared_region_.IsInDataSpace(ptr);
488   }
489 
490   bool IsWeakAccessEnabled(Thread* self) const;
491   void WaitUntilInlineCacheAccessible(Thread* self)
492       REQUIRES(!Locks::jit_lock_)
493       REQUIRES_SHARED(Locks::mutator_lock_);
494 
495   // Record that `method` is being compiled with the given mode.
496   void AddMethodBeingCompiled(ArtMethod* method, CompilationKind compilation_kind)
497       REQUIRES(Locks::jit_lock_);
498 
499   // Remove `method` from the list of methods meing compiled with the given mode.
500   void RemoveMethodBeingCompiled(ArtMethod* method, CompilationKind compilation_kind)
501       REQUIRES(Locks::jit_lock_);
502 
503   // Return whether `method` is being compiled with the given mode.
504   bool IsMethodBeingCompiled(ArtMethod* method, CompilationKind compilation_kind)
505       REQUIRES(Locks::jit_lock_);
506 
507   // Return whether `method` is being compiled in any mode.
508   bool IsMethodBeingCompiled(ArtMethod* method) REQUIRES(Locks::jit_lock_);
509 
510   class JniStubKey;
511   class JniStubData;
512 
513   // Whether the GC allows accessing weaks in inline caches. Note that this
514   // is not used by the concurrent collector, which uses
515   // Thread::SetWeakRefAccessEnabled instead.
516   Atomic<bool> is_weak_access_enabled_;
517 
518   // Condition to wait on for accessing inline caches.
519   ConditionVariable inline_cache_cond_ GUARDED_BY(Locks::jit_lock_);
520 
521   // -------------- JIT memory regions ------------------------------------- //
522 
523   // Shared region, inherited from the zygote.
524   JitMemoryRegion shared_region_;
525 
526   // Process's own region.
527   JitMemoryRegion private_region_;
528 
529   // -------------- Global JIT maps --------------------------------------- //
530 
531   // Holds compiled code associated with the shorty for a JNI stub.
532   SafeMap<JniStubKey, JniStubData> jni_stubs_map_ GUARDED_BY(Locks::jit_lock_);
533 
534   // Holds compiled code associated to the ArtMethod.
535   SafeMap<const void*, ArtMethod*> method_code_map_ GUARDED_BY(Locks::jit_lock_);
536 
537   // Holds compiled code associated to the ArtMethod. Used when pre-jitting
538   // methods whose entrypoints have the resolution stub.
539   SafeMap<ArtMethod*, const void*> saved_compiled_methods_map_ GUARDED_BY(Locks::jit_lock_);
540 
541   // Holds osr compiled code associated to the ArtMethod.
542   SafeMap<ArtMethod*, const void*> osr_code_map_ GUARDED_BY(Locks::jit_lock_);
543 
544   // ProfilingInfo objects we have allocated.
545   SafeMap<ArtMethod*, ProfilingInfo*> profiling_infos_ GUARDED_BY(Locks::jit_lock_);
546 
547   // Methods we are currently compiling, one set for each kind of compilation.
548   std::set<ArtMethod*> current_optimized_compilations_ GUARDED_BY(Locks::jit_lock_);
549   std::set<ArtMethod*> current_osr_compilations_ GUARDED_BY(Locks::jit_lock_);
550   std::set<ArtMethod*> current_baseline_compilations_ GUARDED_BY(Locks::jit_lock_);
551 
552   // Methods that the zygote has compiled and can be shared across processes
553   // forked from the zygote.
554   ZygoteMap zygote_map_;
555 
556   // -------------- JIT GC related data structures ----------------------- //
557 
558   // Condition to wait on during collection.
559   ConditionVariable lock_cond_ GUARDED_BY(Locks::jit_lock_);
560 
561   // Whether there is a code cache collection in progress.
562   bool collection_in_progress_ GUARDED_BY(Locks::jit_lock_);
563 
564   // Bitmap for collecting code and data.
565   std::unique_ptr<CodeCacheBitmap> live_bitmap_;
566 
567   // Whether the last collection round increased the code cache.
568   bool last_collection_increased_code_cache_ GUARDED_BY(Locks::jit_lock_);
569 
570   // Whether we can do garbage collection. Not 'const' as tests may override this.
571   bool garbage_collect_code_ GUARDED_BY(Locks::jit_lock_);
572 
573   // ---------------- JIT statistics -------------------------------------- //
574 
575   // Number of baseline compilations done throughout the lifetime of the JIT.
576   size_t number_of_baseline_compilations_ GUARDED_BY(Locks::jit_lock_);
577 
578   // Number of optimized compilations done throughout the lifetime of the JIT.
579   size_t number_of_optimized_compilations_ GUARDED_BY(Locks::jit_lock_);
580 
581   // Number of compilations for on-stack-replacement done throughout the lifetime of the JIT.
582   size_t number_of_osr_compilations_ GUARDED_BY(Locks::jit_lock_);
583 
584   // Number of code cache collections done throughout the lifetime of the JIT.
585   size_t number_of_collections_ GUARDED_BY(Locks::jit_lock_);
586 
587   // Histograms for keeping track of stack map size statistics.
588   Histogram<uint64_t> histogram_stack_map_memory_use_ GUARDED_BY(Locks::jit_lock_);
589 
590   // Histograms for keeping track of code size statistics.
591   Histogram<uint64_t> histogram_code_memory_use_ GUARDED_BY(Locks::jit_lock_);
592 
593   // Histograms for keeping track of profiling info statistics.
594   Histogram<uint64_t> histogram_profiling_info_memory_use_ GUARDED_BY(Locks::jit_lock_);
595 
596   friend class art::JitJniStubTestHelper;
597   friend class ScopedCodeCacheWrite;
598   friend class MarkCodeClosure;
599 
600   DISALLOW_COPY_AND_ASSIGN(JitCodeCache);
601 };
602 
603 }  // namespace jit
604 }  // namespace art
605 
606 #endif  // ART_RUNTIME_JIT_JIT_CODE_CACHE_H_
607