blob: 388a51751e7ac4c828894d9fcbab67e4218cb038 [file] [log] [blame]
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001/*
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#include "jit_code_cache.h"
18
19#include <sstream>
20
Andreas Gampe5629d2d2017-05-15 16:28:13 -070021#include "arch/context.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070022#include "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070023#include "base/enums.h"
Calin Juravle66f55232015-12-08 15:09:10 +000024#include "base/stl_util.h"
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -080025#include "base/systrace.h"
Calin Juravle31f2c152015-10-23 17:56:15 +010026#include "base/time_utils.h"
Mingyao Yang063fc772016-08-02 11:02:54 -070027#include "cha.h"
David Srbecky5cc349f2015-12-18 15:04:48 +000028#include "debugger_interface.h"
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +010029#include "entrypoints/runtime_asm_entrypoints.h"
30#include "gc/accounting/bitmap-inl.h"
Nicolas Geoffraycf48fa02016-07-30 22:49:11 +010031#include "gc/scoped_gc_critical_section.h"
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +000032#include "jit/jit.h"
Nicolas Geoffray26705e22015-10-28 12:50:11 +000033#include "jit/profiling_info.h"
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +010034#include "linear_alloc.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080035#include "mem_map.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080036#include "oat_file-inl.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070037#include "oat_quick_method_header.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070038#include "scoped_thread_state_change-inl.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070039#include "stack.h"
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +010040#include "thread_list.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080041
42namespace art {
43namespace jit {
44
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010045static constexpr int kProtAll = PROT_READ | PROT_WRITE | PROT_EXEC;
46static constexpr int kProtData = PROT_READ | PROT_WRITE;
47static constexpr int kProtCode = PROT_READ | PROT_EXEC;
48
Nicolas Geoffray933330a2016-03-16 14:20:06 +000049static constexpr size_t kCodeSizeLogThreshold = 50 * KB;
50static constexpr size_t kStackMapSizeLogThreshold = 50 * KB;
51
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010052#define CHECKED_MPROTECT(memory, size, prot) \
53 do { \
54 int rc = mprotect(memory, size, prot); \
55 if (UNLIKELY(rc != 0)) { \
56 errno = rc; \
57 PLOG(FATAL) << "Failed to mprotect jit code cache"; \
58 } \
59 } while (false) \
60
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000061JitCodeCache* JitCodeCache::Create(size_t initial_capacity,
62 size_t max_capacity,
Nicolas Geoffraya25dce92016-01-12 16:41:10 +000063 bool generate_debug_info,
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000064 std::string* error_msg) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -080065 ScopedTrace trace(__PRETTY_FUNCTION__);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000066 CHECK_GE(max_capacity, initial_capacity);
Nicolas Geoffraya25dce92016-01-12 16:41:10 +000067
68 // Generating debug information is mostly for using the 'perf' tool, which does
69 // not work with ashmem.
70 bool use_ashmem = !generate_debug_info;
71 // With 'perf', we want a 1-1 mapping between an address and a method.
72 bool garbage_collect_code = !generate_debug_info;
73
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000074 // We need to have 32 bit offsets from method headers in code cache which point to things
75 // in the data cache. If the maps are more than 4G apart, having multiple maps wouldn't work.
76 // Ensure we're below 1 GB to be safe.
77 if (max_capacity > 1 * GB) {
78 std::ostringstream oss;
79 oss << "Maxium code cache capacity is limited to 1 GB, "
80 << PrettySize(max_capacity) << " is too big";
81 *error_msg = oss.str();
82 return nullptr;
83 }
84
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080085 std::string error_str;
86 // Map name specific for android_os_Debug.cpp accounting.
Nicolas Geoffray132d8362016-11-16 09:19:42 +000087 // Map in low 4gb to simplify accessing root tables for x86_64.
88 // We could do PC-relative addressing to avoid this problem, but that
89 // would require reserving code and data area before submitting, which
90 // means more windows for the code memory to be RWX.
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010091 MemMap* data_map = MemMap::MapAnonymous(
Nicolas Geoffray132d8362016-11-16 09:19:42 +000092 "data-code-cache", nullptr,
93 max_capacity,
94 kProtAll,
95 /* low_4gb */ true,
96 /* reuse */ false,
97 &error_str,
98 use_ashmem);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010099 if (data_map == nullptr) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800100 std::ostringstream oss;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000101 oss << "Failed to create read write execute cache: " << error_str << " size=" << max_capacity;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800102 *error_msg = oss.str();
103 return nullptr;
104 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100105
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000106 // Align both capacities to page size, as that's the unit mspaces use.
107 initial_capacity = RoundDown(initial_capacity, 2 * kPageSize);
108 max_capacity = RoundDown(max_capacity, 2 * kPageSize);
109
Nicolas Geoffray4e915fb2015-10-28 17:39:47 +0000110 // Data cache is 1 / 2 of the map.
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100111 // TODO: Make this variable?
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000112 size_t data_size = max_capacity / 2;
113 size_t code_size = max_capacity - data_size;
114 DCHECK_EQ(code_size + data_size, max_capacity);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100115 uint8_t* divider = data_map->Begin() + data_size;
116
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000117 MemMap* code_map =
118 data_map->RemapAtEnd(divider, "jit-code-cache", kProtAll, &error_str, use_ashmem);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100119 if (code_map == nullptr) {
120 std::ostringstream oss;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000121 oss << "Failed to create read write execute cache: " << error_str << " size=" << max_capacity;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100122 *error_msg = oss.str();
123 return nullptr;
124 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100125 DCHECK_EQ(code_map->Begin(), divider);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000126 data_size = initial_capacity / 2;
127 code_size = initial_capacity - data_size;
128 DCHECK_EQ(code_size + data_size, initial_capacity);
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000129 return new JitCodeCache(
Nicolas Geoffrayc3fec4c2016-01-14 16:16:35 +0000130 code_map, data_map, code_size, data_size, max_capacity, garbage_collect_code);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800131}
132
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000133JitCodeCache::JitCodeCache(MemMap* code_map,
134 MemMap* data_map,
135 size_t initial_code_capacity,
136 size_t initial_data_capacity,
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000137 size_t max_capacity,
138 bool garbage_collect_code)
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100139 : lock_("Jit code cache", kJitCodeCacheLock),
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000140 lock_cond_("Jit code cache condition variable", lock_),
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100141 collection_in_progress_(false),
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100142 code_map_(code_map),
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000143 data_map_(data_map),
144 max_capacity_(max_capacity),
145 current_capacity_(initial_code_capacity + initial_data_capacity),
146 code_end_(initial_code_capacity),
147 data_end_(initial_data_capacity),
Nicolas Geoffray35122442016-03-02 12:05:30 +0000148 last_collection_increased_code_cache_(false),
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000149 last_update_time_ns_(0),
Nicolas Geoffray0a522232016-01-19 09:34:58 +0000150 garbage_collect_code_(garbage_collect_code),
Nicolas Geoffrayb0d22082016-02-24 17:18:25 +0000151 used_memory_for_data_(0),
152 used_memory_for_code_(0),
Nicolas Geoffrayfcdd7292016-02-25 13:27:47 +0000153 number_of_compilations_(0),
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000154 number_of_osr_compilations_(0),
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000155 number_of_collections_(0),
156 histogram_stack_map_memory_use_("Memory used for stack maps", 16),
157 histogram_code_memory_use_("Memory used for compiled code", 16),
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000158 histogram_profiling_info_memory_use_("Memory used for profiling info", 16),
159 is_weak_access_enabled_(true),
160 inline_cache_cond_("Jit inline cache condition variable", lock_) {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100161
Nicolas Geoffrayc3fec4c2016-01-14 16:16:35 +0000162 DCHECK_GE(max_capacity, initial_code_capacity + initial_data_capacity);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000163 code_mspace_ = create_mspace_with_base(code_map_->Begin(), code_end_, false /*locked*/);
164 data_mspace_ = create_mspace_with_base(data_map_->Begin(), data_end_, false /*locked*/);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100165
166 if (code_mspace_ == nullptr || data_mspace_ == nullptr) {
167 PLOG(FATAL) << "create_mspace_with_base failed";
168 }
169
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000170 SetFootprintLimit(current_capacity_);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100171
172 CHECKED_MPROTECT(code_map_->Begin(), code_map_->Size(), kProtCode);
173 CHECKED_MPROTECT(data_map_->Begin(), data_map_->Size(), kProtData);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100174
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000175 VLOG(jit) << "Created jit code cache: initial data size="
176 << PrettySize(initial_data_capacity)
177 << ", initial code size="
178 << PrettySize(initial_code_capacity);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800179}
180
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100181bool JitCodeCache::ContainsPc(const void* ptr) const {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100182 return code_map_->Begin() <= ptr && ptr < code_map_->End();
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800183}
184
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000185bool JitCodeCache::ContainsMethod(ArtMethod* method) {
186 MutexLock mu(Thread::Current(), lock_);
187 for (auto& it : method_code_map_) {
188 if (it.second == method) {
189 return true;
190 }
191 }
192 return false;
193}
194
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800195class ScopedCodeCacheWrite : ScopedTrace {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100196 public:
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100197 explicit ScopedCodeCacheWrite(MemMap* code_map, bool only_for_tlb_shootdown = false)
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800198 : ScopedTrace("ScopedCodeCacheWrite"),
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100199 code_map_(code_map),
200 only_for_tlb_shootdown_(only_for_tlb_shootdown) {
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800201 ScopedTrace trace("mprotect all");
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100202 CHECKED_MPROTECT(
203 code_map_->Begin(), only_for_tlb_shootdown_ ? kPageSize : code_map_->Size(), kProtAll);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800204 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100205 ~ScopedCodeCacheWrite() {
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800206 ScopedTrace trace("mprotect code");
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100207 CHECKED_MPROTECT(
208 code_map_->Begin(), only_for_tlb_shootdown_ ? kPageSize : code_map_->Size(), kProtCode);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100209 }
210 private:
211 MemMap* const code_map_;
212
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100213 // If we're using ScopedCacheWrite only for TLB shootdown, we limit the scope of mprotect to
214 // one page.
215 const bool only_for_tlb_shootdown_;
216
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100217 DISALLOW_COPY_AND_ASSIGN(ScopedCodeCacheWrite);
218};
219
220uint8_t* JitCodeCache::CommitCode(Thread* self,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100221 ArtMethod* method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000222 uint8_t* stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700223 uint8_t* method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000224 uint8_t* roots_data,
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100225 size_t frame_size_in_bytes,
226 size_t core_spill_mask,
227 size_t fp_spill_mask,
228 const uint8_t* code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000229 size_t code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000230 size_t data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000231 bool osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700232 Handle<mirror::ObjectArray<mirror::Object>> roots,
233 bool has_should_deoptimize_flag,
234 const ArenaSet<ArtMethod*>& cha_single_implementation_list) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100235 uint8_t* result = CommitCodeInternal(self,
236 method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000237 stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700238 method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000239 roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100240 frame_size_in_bytes,
241 core_spill_mask,
242 fp_spill_mask,
243 code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000244 code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000245 data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000246 osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700247 roots,
248 has_should_deoptimize_flag,
249 cha_single_implementation_list);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100250 if (result == nullptr) {
251 // Retry.
252 GarbageCollectCache(self);
253 result = CommitCodeInternal(self,
254 method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000255 stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700256 method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000257 roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100258 frame_size_in_bytes,
259 core_spill_mask,
260 fp_spill_mask,
261 code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000262 code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000263 data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000264 osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700265 roots,
266 has_should_deoptimize_flag,
267 cha_single_implementation_list);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100268 }
269 return result;
270}
271
272bool JitCodeCache::WaitForPotentialCollectionToComplete(Thread* self) {
273 bool in_collection = false;
274 while (collection_in_progress_) {
275 in_collection = true;
276 lock_cond_.Wait(self);
277 }
278 return in_collection;
279}
280
281static uintptr_t FromCodeToAllocation(const void* code) {
282 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
283 return reinterpret_cast<uintptr_t>(code) - RoundUp(sizeof(OatQuickMethodHeader), alignment);
284}
285
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000286static uint32_t ComputeRootTableSize(uint32_t number_of_roots) {
287 return sizeof(uint32_t) + number_of_roots * sizeof(GcRoot<mirror::Object>);
288}
289
290static uint32_t GetNumberOfRoots(const uint8_t* stack_map) {
291 // The length of the table is stored just before the stack map (and therefore at the end of
292 // the table itself), in order to be able to fetch it from a `stack_map` pointer.
293 return reinterpret_cast<const uint32_t*>(stack_map)[-1];
294}
295
Mathieu Chartier7a704be2016-11-22 13:24:40 -0800296static void FillRootTableLength(uint8_t* roots_data, uint32_t length) {
297 // Store the length of the table at the end. This will allow fetching it from a `stack_map`
298 // pointer.
299 reinterpret_cast<uint32_t*>(roots_data)[length] = length;
300}
301
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000302static const uint8_t* FromStackMapToRoots(const uint8_t* stack_map_data) {
303 return stack_map_data - ComputeRootTableSize(GetNumberOfRoots(stack_map_data));
304}
305
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000306static void FillRootTable(uint8_t* roots_data, Handle<mirror::ObjectArray<mirror::Object>> roots)
307 REQUIRES_SHARED(Locks::mutator_lock_) {
308 GcRoot<mirror::Object>* gc_roots = reinterpret_cast<GcRoot<mirror::Object>*>(roots_data);
Mathieu Chartier7a704be2016-11-22 13:24:40 -0800309 const uint32_t length = roots->GetLength();
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000310 // Put all roots in `roots_data`.
311 for (uint32_t i = 0; i < length; ++i) {
312 ObjPtr<mirror::Object> object = roots->Get(i);
313 if (kIsDebugBuild) {
314 // Ensure the string is strongly interned. b/32995596
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000315 if (object->IsString()) {
316 ObjPtr<mirror::String> str = reinterpret_cast<mirror::String*>(object.Ptr());
317 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
318 CHECK(class_linker->GetInternTable()->LookupStrong(Thread::Current(), str) != nullptr);
319 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000320 }
321 gc_roots[i] = GcRoot<mirror::Object>(object);
322 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000323}
324
325static uint8_t* GetRootTable(const void* code_ptr, uint32_t* number_of_roots = nullptr) {
326 OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
327 uint8_t* data = method_header->GetOptimizedCodeInfoPtr();
328 uint32_t roots = GetNumberOfRoots(data);
329 if (number_of_roots != nullptr) {
330 *number_of_roots = roots;
331 }
332 return data - ComputeRootTableSize(roots);
333}
334
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100335// Use a sentinel for marking entries in the JIT table that have been cleared.
336// This helps diagnosing in case the compiled code tries to wrongly access such
337// entries.
Andreas Gampe5629d2d2017-05-15 16:28:13 -0700338static mirror::Class* const weak_sentinel =
339 reinterpret_cast<mirror::Class*>(Context::kBadGprBase + 0xff);
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100340
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000341// Helper for the GC to process a weak class in a JIT root table.
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100342static inline void ProcessWeakClass(GcRoot<mirror::Class>* root_ptr,
343 IsMarkedVisitor* visitor,
344 mirror::Class* update)
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000345 REQUIRES_SHARED(Locks::mutator_lock_) {
346 // This does not need a read barrier because this is called by GC.
347 mirror::Class* cls = root_ptr->Read<kWithoutReadBarrier>();
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100348 if (cls != nullptr && cls != weak_sentinel) {
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000349 DCHECK((cls->IsClass<kDefaultVerifyFlags, kWithoutReadBarrier>()));
350 // Look at the classloader of the class to know if it has been unloaded.
351 // This does not need a read barrier because this is called by GC.
352 mirror::Object* class_loader =
353 cls->GetClassLoader<kDefaultVerifyFlags, kWithoutReadBarrier>();
354 if (class_loader == nullptr || visitor->IsMarked(class_loader) != nullptr) {
355 // The class loader is live, update the entry if the class has moved.
356 mirror::Class* new_cls = down_cast<mirror::Class*>(visitor->IsMarked(cls));
357 // Note that new_object can be null for CMS and newly allocated objects.
358 if (new_cls != nullptr && new_cls != cls) {
359 *root_ptr = GcRoot<mirror::Class>(new_cls);
360 }
361 } else {
362 // The class loader is not live, clear the entry.
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100363 *root_ptr = GcRoot<mirror::Class>(update);
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000364 }
365 }
366}
367
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000368void JitCodeCache::SweepRootTables(IsMarkedVisitor* visitor) {
369 MutexLock mu(Thread::Current(), lock_);
370 for (const auto& entry : method_code_map_) {
371 uint32_t number_of_roots = 0;
372 uint8_t* roots_data = GetRootTable(entry.first, &number_of_roots);
373 GcRoot<mirror::Object>* roots = reinterpret_cast<GcRoot<mirror::Object>*>(roots_data);
374 for (uint32_t i = 0; i < number_of_roots; ++i) {
375 // This does not need a read barrier because this is called by GC.
376 mirror::Object* object = roots[i].Read<kWithoutReadBarrier>();
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100377 if (object == nullptr || object == weak_sentinel) {
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000378 // entry got deleted in a previous sweep.
379 } else if (object->IsString<kDefaultVerifyFlags, kWithoutReadBarrier>()) {
380 mirror::Object* new_object = visitor->IsMarked(object);
381 // We know the string is marked because it's a strongly-interned string that
382 // is always alive. The IsMarked implementation of the CMS collector returns
383 // null for newly allocated objects, but we know those haven't moved. Therefore,
384 // only update the entry if we get a different non-null string.
385 // TODO: Do not use IsMarked for j.l.Class, and adjust once we move this method
386 // out of the weak access/creation pause. b/32167580
387 if (new_object != nullptr && new_object != object) {
388 DCHECK(new_object->IsString());
389 roots[i] = GcRoot<mirror::Object>(new_object);
390 }
391 } else {
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100392 ProcessWeakClass(
393 reinterpret_cast<GcRoot<mirror::Class>*>(&roots[i]), visitor, weak_sentinel);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000394 }
395 }
396 }
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000397 // Walk over inline caches to clear entries containing unloaded classes.
398 for (ProfilingInfo* info : profiling_infos_) {
399 for (size_t i = 0; i < info->number_of_inline_caches_; ++i) {
400 InlineCache* cache = &info->cache_[i];
401 for (size_t j = 0; j < InlineCache::kIndividualCacheSize; ++j) {
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100402 ProcessWeakClass(&cache->classes_[j], visitor, nullptr);
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000403 }
404 }
405 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000406}
407
Mingyao Yang063fc772016-08-02 11:02:54 -0700408void JitCodeCache::FreeCode(const void* code_ptr) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100409 uintptr_t allocation = FromCodeToAllocation(code_ptr);
David Srbecky5cc349f2015-12-18 15:04:48 +0000410 // Notify native debugger that we are about to remove the code.
411 // It does nothing if we are not using native debugger.
412 DeleteJITCodeEntryForAddress(reinterpret_cast<uintptr_t>(code_ptr));
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000413 FreeData(GetRootTable(code_ptr));
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000414 FreeCode(reinterpret_cast<uint8_t*>(allocation));
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100415}
416
Mingyao Yang063fc772016-08-02 11:02:54 -0700417void JitCodeCache::FreeAllMethodHeaders(
418 const std::unordered_set<OatQuickMethodHeader*>& method_headers) {
419 {
420 MutexLock mu(Thread::Current(), *Locks::cha_lock_);
421 Runtime::Current()->GetClassHierarchyAnalysis()
422 ->RemoveDependentsWithMethodHeaders(method_headers);
423 }
424
425 // We need to remove entries in method_headers from CHA dependencies
426 // first since once we do FreeCode() below, the memory can be reused
427 // so it's possible for the same method_header to start representing
428 // different compile code.
429 MutexLock mu(Thread::Current(), lock_);
430 ScopedCodeCacheWrite scc(code_map_.get());
431 for (const OatQuickMethodHeader* method_header : method_headers) {
432 FreeCode(method_header->GetCode());
433 }
434}
435
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100436void JitCodeCache::RemoveMethodsIn(Thread* self, const LinearAlloc& alloc) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800437 ScopedTrace trace(__PRETTY_FUNCTION__);
Mingyao Yang063fc772016-08-02 11:02:54 -0700438 // We use a set to first collect all method_headers whose code need to be
439 // removed. We need to free the underlying code after we remove CHA dependencies
440 // for entries in this set. And it's more efficient to iterate through
441 // the CHA dependency map just once with an unordered_set.
442 std::unordered_set<OatQuickMethodHeader*> method_headers;
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000443 {
Mingyao Yang063fc772016-08-02 11:02:54 -0700444 MutexLock mu(self, lock_);
445 // We do not check if a code cache GC is in progress, as this method comes
446 // with the classlinker_classes_lock_ held, and suspending ourselves could
447 // lead to a deadlock.
448 {
449 ScopedCodeCacheWrite scc(code_map_.get());
450 for (auto it = method_code_map_.begin(); it != method_code_map_.end();) {
451 if (alloc.ContainsUnsafe(it->second)) {
452 method_headers.insert(OatQuickMethodHeader::FromCodePointer(it->first));
453 it = method_code_map_.erase(it);
454 } else {
455 ++it;
456 }
457 }
458 }
459 for (auto it = osr_code_map_.begin(); it != osr_code_map_.end();) {
460 if (alloc.ContainsUnsafe(it->first)) {
461 // Note that the code has already been pushed to method_headers in the loop
462 // above and is going to be removed in FreeCode() below.
463 it = osr_code_map_.erase(it);
464 } else {
465 ++it;
466 }
467 }
468 for (auto it = profiling_infos_.begin(); it != profiling_infos_.end();) {
469 ProfilingInfo* info = *it;
470 if (alloc.ContainsUnsafe(info->GetMethod())) {
471 info->GetMethod()->SetProfilingInfo(nullptr);
472 FreeData(reinterpret_cast<uint8_t*>(info));
473 it = profiling_infos_.erase(it);
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000474 } else {
475 ++it;
476 }
477 }
478 }
Mingyao Yang063fc772016-08-02 11:02:54 -0700479 FreeAllMethodHeaders(method_headers);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100480}
481
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000482bool JitCodeCache::IsWeakAccessEnabled(Thread* self) const {
483 return kUseReadBarrier
484 ? self->GetWeakRefAccessEnabled()
485 : is_weak_access_enabled_.LoadSequentiallyConsistent();
486}
487
488void JitCodeCache::WaitUntilInlineCacheAccessible(Thread* self) {
489 if (IsWeakAccessEnabled(self)) {
490 return;
491 }
492 ScopedThreadSuspension sts(self, kWaitingWeakGcRootRead);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +0000493 MutexLock mu(self, lock_);
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000494 while (!IsWeakAccessEnabled(self)) {
495 inline_cache_cond_.Wait(self);
496 }
497}
498
499void JitCodeCache::BroadcastForInlineCacheAccess() {
500 Thread* self = Thread::Current();
501 MutexLock mu(self, lock_);
502 inline_cache_cond_.Broadcast(self);
503}
504
505void JitCodeCache::AllowInlineCacheAccess() {
506 DCHECK(!kUseReadBarrier);
507 is_weak_access_enabled_.StoreSequentiallyConsistent(true);
508 BroadcastForInlineCacheAccess();
509}
510
511void JitCodeCache::DisallowInlineCacheAccess() {
512 DCHECK(!kUseReadBarrier);
513 is_weak_access_enabled_.StoreSequentiallyConsistent(false);
514}
515
516void JitCodeCache::CopyInlineCacheInto(const InlineCache& ic,
517 Handle<mirror::ObjectArray<mirror::Class>> array) {
518 WaitUntilInlineCacheAccessible(Thread::Current());
519 // Note that we don't need to lock `lock_` here, the compiler calling
520 // this method has already ensured the inline cache will not be deleted.
521 for (size_t in_cache = 0, in_array = 0;
522 in_cache < InlineCache::kIndividualCacheSize;
523 ++in_cache) {
524 mirror::Class* object = ic.classes_[in_cache].Read();
525 if (object != nullptr) {
526 array->Set(in_array++, object);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +0000527 }
528 }
529}
530
Mathieu Chartierf044c222017-05-31 15:27:54 -0700531static void ClearMethodCounter(ArtMethod* method, bool was_warm) {
532 if (was_warm) {
533 method->AddAccessFlags(kAccPreviouslyWarm);
534 }
535 // We reset the counter to 1 so that the profile knows that the method was executed at least once.
536 // This is required for layout purposes.
537 method->SetCounter(1);
538}
539
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100540uint8_t* JitCodeCache::CommitCodeInternal(Thread* self,
541 ArtMethod* method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000542 uint8_t* stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700543 uint8_t* method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000544 uint8_t* roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100545 size_t frame_size_in_bytes,
546 size_t core_spill_mask,
547 size_t fp_spill_mask,
548 const uint8_t* code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000549 size_t code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000550 size_t data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000551 bool osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700552 Handle<mirror::ObjectArray<mirror::Object>> roots,
553 bool has_should_deoptimize_flag,
554 const ArenaSet<ArtMethod*>&
555 cha_single_implementation_list) {
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000556 DCHECK(stack_map != nullptr);
Nicolas Geoffray1e7de6c2015-10-21 12:07:31 +0100557 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
558 // Ensure the header ends up at expected instruction alignment.
559 size_t header_size = RoundUp(sizeof(OatQuickMethodHeader), alignment);
560 size_t total_size = header_size + code_size;
561
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100562 OatQuickMethodHeader* method_header = nullptr;
Nicolas Geoffray1e7de6c2015-10-21 12:07:31 +0100563 uint8_t* code_ptr = nullptr;
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000564 uint8_t* memory = nullptr;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100565 {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000566 ScopedThreadSuspension sts(self, kSuspended);
567 MutexLock mu(self, lock_);
568 WaitForPotentialCollectionToComplete(self);
569 {
570 ScopedCodeCacheWrite scc(code_map_.get());
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000571 memory = AllocateCode(total_size);
572 if (memory == nullptr) {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000573 return nullptr;
574 }
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000575 code_ptr = memory + header_size;
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000576
577 std::copy(code, code + code_size, code_ptr);
578 method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
579 new (method_header) OatQuickMethodHeader(
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000580 code_ptr - stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700581 code_ptr - method_info,
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000582 frame_size_in_bytes,
583 core_spill_mask,
584 fp_spill_mask,
585 code_size);
Kevin Brodskyb93ce182016-12-15 14:23:09 +0000586 // Flush caches before we remove write permission because some ARMv8 Qualcomm kernels may
587 // trigger a segfault if a page fault occurs when requesting a cache maintenance operation.
588 // This is a kernel bug that we need to work around until affected devices (e.g. Nexus 5X and
589 // 6P) stop being supported or their kernels are fixed.
Artem Udovichenkob18a6692016-11-17 10:51:58 +0300590 //
Kevin Brodskyb93ce182016-12-15 14:23:09 +0000591 // For reference, this behavior is caused by this commit:
592 // https://android.googlesource.com/kernel/msm/+/3fbe6bc28a6b9939d0650f2f17eb5216c719950c
Artem Udovichenkob18a6692016-11-17 10:51:58 +0300593 FlushInstructionCache(reinterpret_cast<char*>(code_ptr),
594 reinterpret_cast<char*>(code_ptr + code_size));
Mingyao Yang063fc772016-08-02 11:02:54 -0700595 DCHECK(!Runtime::Current()->IsAotCompiler());
596 if (has_should_deoptimize_flag) {
597 method_header->SetHasShouldDeoptimizeFlag();
598 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100599 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100600
Nicolas Geoffray0a522232016-01-19 09:34:58 +0000601 number_of_compilations_++;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100602 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000603 // We need to update the entry point in the runnable state for the instrumentation.
604 {
Mingyao Yang063fc772016-08-02 11:02:54 -0700605 // Need cha_lock_ for checking all single-implementation flags and register
606 // dependencies.
607 MutexLock cha_mu(self, *Locks::cha_lock_);
608 bool single_impl_still_valid = true;
609 for (ArtMethod* single_impl : cha_single_implementation_list) {
610 if (!single_impl->HasSingleImplementation()) {
Jeff Hao00286db2017-05-30 16:53:07 -0700611 // Simply discard the compiled code. Clear the counter so that it may be recompiled later.
612 // Hopefully the class hierarchy will be more stable when compilation is retried.
Mingyao Yang063fc772016-08-02 11:02:54 -0700613 single_impl_still_valid = false;
Mathieu Chartierf044c222017-05-31 15:27:54 -0700614 ClearMethodCounter(method, /*was_warm*/ false);
Mingyao Yang063fc772016-08-02 11:02:54 -0700615 break;
616 }
617 }
618
619 // Discard the code if any single-implementation assumptions are now invalid.
620 if (!single_impl_still_valid) {
621 VLOG(jit) << "JIT discarded jitted code due to invalid single-implementation assumptions.";
622 return nullptr;
623 }
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000624 DCHECK(cha_single_implementation_list.empty() || !Runtime::Current()->IsJavaDebuggable())
Alex Lightdba61482016-12-21 08:20:29 -0800625 << "Should not be using cha on debuggable apps/runs!";
626
Mingyao Yang063fc772016-08-02 11:02:54 -0700627 for (ArtMethod* single_impl : cha_single_implementation_list) {
628 Runtime::Current()->GetClassHierarchyAnalysis()->AddDependency(
629 single_impl, method, method_header);
630 }
631
632 // The following needs to be guarded by cha_lock_ also. Otherwise it's
633 // possible that the compiled code is considered invalidated by some class linking,
634 // but below we still make the compiled code valid for the method.
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000635 MutexLock mu(self, lock_);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000636 // Fill the root table before updating the entry point.
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000637 DCHECK_EQ(FromStackMapToRoots(stack_map), roots_data);
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100638 DCHECK_LE(roots_data, stack_map);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000639 FillRootTable(roots_data, roots);
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100640 {
641 // Flush data cache, as compiled code references literals in it.
642 // We also need a TLB shootdown to act as memory barrier across cores.
643 ScopedCodeCacheWrite ccw(code_map_.get(), /* only_for_tlb_shootdown */ true);
644 FlushDataCache(reinterpret_cast<char*>(roots_data),
645 reinterpret_cast<char*>(roots_data + data_size));
646 }
647 method_code_map_.Put(code_ptr, method);
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000648 if (osr) {
Nicolas Geoffrayfcdd7292016-02-25 13:27:47 +0000649 number_of_osr_compilations_++;
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000650 osr_code_map_.Put(method, code_ptr);
Nicolas Geoffray480d5102016-04-18 12:09:30 +0100651 } else {
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000652 Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
653 method, method_header->GetEntryPoint());
654 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000655 if (collection_in_progress_) {
656 // We need to update the live bitmap if there is a GC to ensure it sees this new
657 // code.
658 GetLiveBitmap()->AtomicTestAndSet(FromCodeToAllocation(code_ptr));
659 }
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000660 last_update_time_ns_.StoreRelease(NanoTime());
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000661 VLOG(jit)
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100662 << "JIT added (osr=" << std::boolalpha << osr << std::noboolalpha << ") "
David Sehr709b0702016-10-13 09:12:37 -0700663 << ArtMethod::PrettyMethod(method) << "@" << method
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000664 << " ccache_size=" << PrettySize(CodeCacheSizeLocked()) << ": "
665 << " dcache_size=" << PrettySize(DataCacheSizeLocked()) << ": "
666 << reinterpret_cast<const void*>(method_header->GetEntryPoint()) << ","
Mingyao Yang063fc772016-08-02 11:02:54 -0700667 << reinterpret_cast<const void*>(method_header->GetEntryPoint() +
668 method_header->GetCodeSize());
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000669 histogram_code_memory_use_.AddValue(code_size);
670 if (code_size > kCodeSizeLogThreshold) {
671 LOG(INFO) << "JIT allocated "
672 << PrettySize(code_size)
673 << " for compiled code of "
David Sehr709b0702016-10-13 09:12:37 -0700674 << ArtMethod::PrettyMethod(method);
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000675 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000676 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100677
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100678 return reinterpret_cast<uint8_t*>(method_header);
679}
680
681size_t JitCodeCache::CodeCacheSize() {
682 MutexLock mu(Thread::Current(), lock_);
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000683 return CodeCacheSizeLocked();
684}
685
Alex Lightdba61482016-12-21 08:20:29 -0800686// This notifies the code cache that the given method has been redefined and that it should remove
687// any cached information it has on the method. All threads must be suspended before calling this
688// method. The compiled code for the method (if there is any) must not be in any threads call stack.
689void JitCodeCache::NotifyMethodRedefined(ArtMethod* method) {
690 MutexLock mu(Thread::Current(), lock_);
691 if (method->IsNative()) {
692 return;
693 }
694 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
695 if (info != nullptr) {
696 auto profile = std::find(profiling_infos_.begin(), profiling_infos_.end(), info);
697 DCHECK(profile != profiling_infos_.end());
698 profiling_infos_.erase(profile);
699 }
700 method->SetProfilingInfo(nullptr);
701 ScopedCodeCacheWrite ccw(code_map_.get());
Andreas Gampe39e67382017-05-15 19:26:38 -0700702 for (auto code_iter = method_code_map_.begin(); code_iter != method_code_map_.end();) {
Alex Lightdba61482016-12-21 08:20:29 -0800703 if (code_iter->second == method) {
704 FreeCode(code_iter->first);
Andreas Gampe39e67382017-05-15 19:26:38 -0700705 code_iter = method_code_map_.erase(code_iter);
706 continue;
Alex Lightdba61482016-12-21 08:20:29 -0800707 }
Andreas Gampe39e67382017-05-15 19:26:38 -0700708 ++code_iter;
Alex Lightdba61482016-12-21 08:20:29 -0800709 }
710 auto code_map = osr_code_map_.find(method);
711 if (code_map != osr_code_map_.end()) {
712 osr_code_map_.erase(code_map);
713 }
714}
715
716// This invalidates old_method. Once this function returns one can no longer use old_method to
717// execute code unless it is fixed up. This fixup will happen later in the process of installing a
718// class redefinition.
719// TODO We should add some info to ArtMethod to note that 'old_method' has been invalidated and
720// shouldn't be used since it is no longer logically in the jit code cache.
721// TODO We should add DCHECKS that validate that the JIT is paused when this method is entered.
722void JitCodeCache::MoveObsoleteMethod(ArtMethod* old_method, ArtMethod* new_method) {
Alex Lighteee0bd42017-02-14 15:31:45 +0000723 // Native methods have no profiling info and need no special handling from the JIT code cache.
724 if (old_method->IsNative()) {
725 return;
726 }
Alex Lightdba61482016-12-21 08:20:29 -0800727 MutexLock mu(Thread::Current(), lock_);
728 // Update ProfilingInfo to the new one and remove it from the old_method.
729 if (old_method->GetProfilingInfo(kRuntimePointerSize) != nullptr) {
730 DCHECK_EQ(old_method->GetProfilingInfo(kRuntimePointerSize)->GetMethod(), old_method);
731 ProfilingInfo* info = old_method->GetProfilingInfo(kRuntimePointerSize);
732 old_method->SetProfilingInfo(nullptr);
733 // Since the JIT should be paused and all threads suspended by the time this is called these
734 // checks should always pass.
735 DCHECK(!info->IsInUseByCompiler());
736 new_method->SetProfilingInfo(info);
737 info->method_ = new_method;
738 }
739 // Update method_code_map_ to point to the new method.
740 for (auto& it : method_code_map_) {
741 if (it.second == old_method) {
742 it.second = new_method;
743 }
744 }
745 // Update osr_code_map_ to point to the new method.
746 auto code_map = osr_code_map_.find(old_method);
747 if (code_map != osr_code_map_.end()) {
748 osr_code_map_.Put(new_method, code_map->second);
749 osr_code_map_.erase(old_method);
750 }
751}
752
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000753size_t JitCodeCache::CodeCacheSizeLocked() {
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000754 return used_memory_for_code_;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100755}
756
757size_t JitCodeCache::DataCacheSize() {
758 MutexLock mu(Thread::Current(), lock_);
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000759 return DataCacheSizeLocked();
760}
761
762size_t JitCodeCache::DataCacheSizeLocked() {
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000763 return used_memory_for_data_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800764}
765
Nicolas Geoffrayf46501c2016-11-22 13:45:36 +0000766void JitCodeCache::ClearData(Thread* self,
767 uint8_t* stack_map_data,
768 uint8_t* roots_data) {
769 DCHECK_EQ(FromStackMapToRoots(stack_map_data), roots_data);
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000770 MutexLock mu(self, lock_);
Nicolas Geoffrayf46501c2016-11-22 13:45:36 +0000771 FreeData(reinterpret_cast<uint8_t*>(roots_data));
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000772}
773
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000774size_t JitCodeCache::ReserveData(Thread* self,
775 size_t stack_map_size,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700776 size_t method_info_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000777 size_t number_of_roots,
778 ArtMethod* method,
779 uint8_t** stack_map_data,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700780 uint8_t** method_info_data,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000781 uint8_t** roots_data) {
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000782 size_t table_size = ComputeRootTableSize(number_of_roots);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700783 size_t size = RoundUp(stack_map_size + method_info_size + table_size, sizeof(void*));
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100784 uint8_t* result = nullptr;
785
786 {
787 ScopedThreadSuspension sts(self, kSuspended);
788 MutexLock mu(self, lock_);
789 WaitForPotentialCollectionToComplete(self);
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000790 result = AllocateData(size);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100791 }
792
793 if (result == nullptr) {
794 // Retry.
795 GarbageCollectCache(self);
796 ScopedThreadSuspension sts(self, kSuspended);
797 MutexLock mu(self, lock_);
798 WaitForPotentialCollectionToComplete(self);
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000799 result = AllocateData(size);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100800 }
801
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000802 MutexLock mu(self, lock_);
803 histogram_stack_map_memory_use_.AddValue(size);
804 if (size > kStackMapSizeLogThreshold) {
805 LOG(INFO) << "JIT allocated "
806 << PrettySize(size)
807 << " for stack maps of "
David Sehr709b0702016-10-13 09:12:37 -0700808 << ArtMethod::PrettyMethod(method);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800809 }
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000810 if (result != nullptr) {
811 *roots_data = result;
812 *stack_map_data = result + table_size;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700813 *method_info_data = *stack_map_data + stack_map_size;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000814 FillRootTableLength(*roots_data, number_of_roots);
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000815 return size;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000816 } else {
817 *roots_data = nullptr;
818 *stack_map_data = nullptr;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700819 *method_info_data = nullptr;
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000820 return 0;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000821 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800822}
823
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100824class MarkCodeVisitor FINAL : public StackVisitor {
825 public:
826 MarkCodeVisitor(Thread* thread_in, JitCodeCache* code_cache_in)
827 : StackVisitor(thread_in, nullptr, StackVisitor::StackWalkKind::kSkipInlinedFrames),
828 code_cache_(code_cache_in),
829 bitmap_(code_cache_->GetLiveBitmap()) {}
830
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700831 bool VisitFrame() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100832 const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader();
833 if (method_header == nullptr) {
834 return true;
835 }
836 const void* code = method_header->GetCode();
837 if (code_cache_->ContainsPc(code)) {
838 // Use the atomic set version, as multiple threads are executing this code.
839 bitmap_->AtomicTestAndSet(FromCodeToAllocation(code));
840 }
841 return true;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800842 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100843
844 private:
845 JitCodeCache* const code_cache_;
846 CodeCacheBitmap* const bitmap_;
847};
848
849class MarkCodeClosure FINAL : public Closure {
850 public:
851 MarkCodeClosure(JitCodeCache* code_cache, Barrier* barrier)
852 : code_cache_(code_cache), barrier_(barrier) {}
853
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700854 void Run(Thread* thread) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800855 ScopedTrace trace(__PRETTY_FUNCTION__);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100856 DCHECK(thread == Thread::Current() || thread->IsSuspended());
857 MarkCodeVisitor visitor(thread, code_cache_);
858 visitor.WalkStack();
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +0000859 if (kIsDebugBuild) {
860 // The stack walking code queries the side instrumentation stack if it
861 // sees an instrumentation exit pc, so the JIT code of methods in that stack
862 // must have been seen. We sanity check this below.
863 for (const instrumentation::InstrumentationStackFrame& frame
864 : *thread->GetInstrumentationStack()) {
865 // The 'method_' in InstrumentationStackFrame is the one that has return_pc_ in
866 // its stack frame, it is not the method owning return_pc_. We just pass null to
867 // LookupMethodHeader: the method is only checked against in debug builds.
868 OatQuickMethodHeader* method_header =
869 code_cache_->LookupMethodHeader(frame.return_pc_, nullptr);
870 if (method_header != nullptr) {
871 const void* code = method_header->GetCode();
872 CHECK(code_cache_->GetLiveBitmap()->Test(FromCodeToAllocation(code)));
873 }
874 }
875 }
Mathieu Chartier10d25082015-10-28 18:36:09 -0700876 barrier_->Pass(Thread::Current());
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800877 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100878
879 private:
880 JitCodeCache* const code_cache_;
881 Barrier* const barrier_;
882};
883
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000884void JitCodeCache::NotifyCollectionDone(Thread* self) {
885 collection_in_progress_ = false;
886 lock_cond_.Broadcast(self);
887}
888
889void JitCodeCache::SetFootprintLimit(size_t new_footprint) {
890 size_t per_space_footprint = new_footprint / 2;
891 DCHECK(IsAlignedParam(per_space_footprint, kPageSize));
892 DCHECK_EQ(per_space_footprint * 2, new_footprint);
893 mspace_set_footprint_limit(data_mspace_, per_space_footprint);
894 {
895 ScopedCodeCacheWrite scc(code_map_.get());
896 mspace_set_footprint_limit(code_mspace_, per_space_footprint);
897 }
898}
899
900bool JitCodeCache::IncreaseCodeCacheCapacity() {
901 if (current_capacity_ == max_capacity_) {
902 return false;
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100903 }
904
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000905 // Double the capacity if we're below 1MB, or increase it by 1MB if
906 // we're above.
907 if (current_capacity_ < 1 * MB) {
908 current_capacity_ *= 2;
909 } else {
910 current_capacity_ += 1 * MB;
911 }
912 if (current_capacity_ > max_capacity_) {
913 current_capacity_ = max_capacity_;
914 }
915
916 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
917 LOG(INFO) << "Increasing code cache capacity to " << PrettySize(current_capacity_);
918 }
919
920 SetFootprintLimit(current_capacity_);
921
922 return true;
923}
924
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000925void JitCodeCache::MarkCompiledCodeOnThreadStacks(Thread* self) {
926 Barrier barrier(0);
927 size_t threads_running_checkpoint = 0;
928 MarkCodeClosure closure(this, &barrier);
929 threads_running_checkpoint = Runtime::Current()->GetThreadList()->RunCheckpoint(&closure);
930 // Now that we have run our checkpoint, move to a suspended state and wait
931 // for other threads to run the checkpoint.
932 ScopedThreadSuspension sts(self, kSuspended);
933 if (threads_running_checkpoint != 0) {
934 barrier.Increment(self, threads_running_checkpoint);
935 }
936}
937
Nicolas Geoffray35122442016-03-02 12:05:30 +0000938bool JitCodeCache::ShouldDoFullCollection() {
939 if (current_capacity_ == max_capacity_) {
940 // Always do a full collection when the code cache is full.
941 return true;
942 } else if (current_capacity_ < kReservedCapacity) {
943 // Always do partial collection when the code cache size is below the reserved
944 // capacity.
945 return false;
946 } else if (last_collection_increased_code_cache_) {
947 // This time do a full collection.
948 return true;
949 } else {
950 // This time do a partial collection.
951 return false;
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000952 }
953}
954
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000955void JitCodeCache::GarbageCollectCache(Thread* self) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800956 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000957 if (!garbage_collect_code_) {
958 MutexLock mu(self, lock_);
959 IncreaseCodeCacheCapacity();
960 return;
961 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100962
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000963 // Wait for an existing collection, or let everyone know we are starting one.
964 {
965 ScopedThreadSuspension sts(self, kSuspended);
966 MutexLock mu(self, lock_);
967 if (WaitForPotentialCollectionToComplete(self)) {
968 return;
969 } else {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000970 number_of_collections_++;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000971 live_bitmap_.reset(CodeCacheBitmap::Create(
972 "code-cache-bitmap",
973 reinterpret_cast<uintptr_t>(code_map_->Begin()),
974 reinterpret_cast<uintptr_t>(code_map_->Begin() + current_capacity_ / 2)));
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000975 collection_in_progress_ = true;
976 }
977 }
978
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000979 TimingLogger logger("JIT code cache timing logger", true, VLOG_IS_ON(jit));
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000980 {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000981 TimingLogger::ScopedTiming st("Code cache collection", &logger);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000982
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000983 bool do_full_collection = false;
984 {
985 MutexLock mu(self, lock_);
986 do_full_collection = ShouldDoFullCollection();
Nicolas Geoffraya96917a2016-03-01 22:18:02 +0000987 }
988
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000989 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
990 LOG(INFO) << "Do "
991 << (do_full_collection ? "full" : "partial")
992 << " code cache collection, code="
993 << PrettySize(CodeCacheSize())
994 << ", data=" << PrettySize(DataCacheSize());
995 }
Nicolas Geoffray35122442016-03-02 12:05:30 +0000996
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000997 DoCollection(self, /* collect_profiling_info */ do_full_collection);
998
999 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
1000 LOG(INFO) << "After code cache collection, code="
1001 << PrettySize(CodeCacheSize())
1002 << ", data=" << PrettySize(DataCacheSize());
1003 }
1004
1005 {
1006 MutexLock mu(self, lock_);
1007
1008 // Increase the code cache only when we do partial collections.
1009 // TODO: base this strategy on how full the code cache is?
1010 if (do_full_collection) {
1011 last_collection_increased_code_cache_ = false;
1012 } else {
1013 last_collection_increased_code_cache_ = true;
1014 IncreaseCodeCacheCapacity();
Nicolas Geoffray35122442016-03-02 12:05:30 +00001015 }
1016
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001017 bool next_collection_will_be_full = ShouldDoFullCollection();
1018
1019 // Start polling the liveness of compiled code to prepare for the next full collection.
Nicolas Geoffray480d5102016-04-18 12:09:30 +01001020 if (next_collection_will_be_full) {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001021 // Save the entry point of methods we have compiled, and update the entry
1022 // point of those methods to the interpreter. If the method is invoked, the
1023 // interpreter will update its entry point to the compiled code and call it.
1024 for (ProfilingInfo* info : profiling_infos_) {
1025 const void* entry_point = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
1026 if (ContainsPc(entry_point)) {
1027 info->SetSavedEntryPoint(entry_point);
Nicolas Geoffray3b1a7f42017-02-22 10:21:00 +00001028 // Don't call Instrumentation::UpdateMethods, as it can check the declaring
1029 // class of the method. We may be concurrently running a GC which makes accessing
1030 // the class unsafe. We know it is OK to bypass the instrumentation as we've just
1031 // checked that the current entry point is JIT compiled code.
1032 info->GetMethod()->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001033 }
1034 }
1035
1036 DCHECK(CheckLiveCompiledCodeHasProfilingInfo());
1037 }
1038 live_bitmap_.reset(nullptr);
1039 NotifyCollectionDone(self);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001040 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001041 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001042 Runtime::Current()->GetJit()->AddTimingLogger(logger);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001043}
1044
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001045void JitCodeCache::RemoveUnmarkedCode(Thread* self) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001046 ScopedTrace trace(__FUNCTION__);
Mingyao Yang063fc772016-08-02 11:02:54 -07001047 std::unordered_set<OatQuickMethodHeader*> method_headers;
1048 {
1049 MutexLock mu(self, lock_);
1050 ScopedCodeCacheWrite scc(code_map_.get());
1051 // Iterate over all compiled code and remove entries that are not marked.
1052 for (auto it = method_code_map_.begin(); it != method_code_map_.end();) {
1053 const void* code_ptr = it->first;
1054 uintptr_t allocation = FromCodeToAllocation(code_ptr);
1055 if (GetLiveBitmap()->Test(allocation)) {
1056 ++it;
1057 } else {
1058 method_headers.insert(OatQuickMethodHeader::FromCodePointer(it->first));
1059 it = method_code_map_.erase(it);
1060 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001061 }
1062 }
Mingyao Yang063fc772016-08-02 11:02:54 -07001063 FreeAllMethodHeaders(method_headers);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001064}
1065
1066void JitCodeCache::DoCollection(Thread* self, bool collect_profiling_info) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001067 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001068 {
1069 MutexLock mu(self, lock_);
1070 if (collect_profiling_info) {
1071 // Clear the profiling info of methods that do not have compiled code as entrypoint.
1072 // Also remove the saved entry point from the ProfilingInfo objects.
1073 for (ProfilingInfo* info : profiling_infos_) {
1074 const void* ptr = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001075 if (!ContainsPc(ptr) && !info->IsInUseByCompiler()) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001076 info->GetMethod()->SetProfilingInfo(nullptr);
1077 }
Nicolas Geoffrayb9a639d2016-03-22 11:25:20 +00001078
1079 if (info->GetSavedEntryPoint() != nullptr) {
1080 info->SetSavedEntryPoint(nullptr);
1081 // We are going to move this method back to interpreter. Clear the counter now to
Mathieu Chartierf044c222017-05-31 15:27:54 -07001082 // give it a chance to be hot again.
1083 ClearMethodCounter(info->GetMethod(), /*was_warm*/ true);
Nicolas Geoffrayb9a639d2016-03-22 11:25:20 +00001084 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001085 }
1086 } else if (kIsDebugBuild) {
1087 // Sanity check that the profiling infos do not have a dangling entry point.
1088 for (ProfilingInfo* info : profiling_infos_) {
1089 DCHECK(info->GetSavedEntryPoint() == nullptr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001090 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001091 }
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001092
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001093 // Mark compiled code that are entrypoints of ArtMethods. Compiled code that is not
1094 // an entry point is either:
1095 // - an osr compiled code, that will be removed if not in a thread call stack.
1096 // - discarded compiled code, that will be removed if not in a thread call stack.
1097 for (const auto& it : method_code_map_) {
1098 ArtMethod* method = it.second;
1099 const void* code_ptr = it.first;
1100 const OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1101 if (method_header->GetEntryPoint() == method->GetEntryPointFromQuickCompiledCode()) {
1102 GetLiveBitmap()->AtomicTestAndSet(FromCodeToAllocation(code_ptr));
1103 }
1104 }
1105
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +00001106 // Empty osr method map, as osr compiled code will be deleted (except the ones
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001107 // on thread stacks).
1108 osr_code_map_.clear();
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001109 }
1110
1111 // Run a checkpoint on all threads to mark the JIT compiled code they are running.
Nicolas Geoffray8d372502016-02-23 13:56:43 +00001112 MarkCompiledCodeOnThreadStacks(self);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001113
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001114 // At this point, mutator threads are still running, and entrypoints of methods can
1115 // change. We do know they cannot change to a code cache entry that is not marked,
1116 // therefore we can safely remove those entries.
1117 RemoveUnmarkedCode(self);
Nicolas Geoffraya96917a2016-03-01 22:18:02 +00001118
Nicolas Geoffray35122442016-03-02 12:05:30 +00001119 if (collect_profiling_info) {
Nicolas Geoffraycf48fa02016-07-30 22:49:11 +01001120 ScopedThreadSuspension sts(self, kSuspended);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001121 MutexLock mu(self, lock_);
1122 // Free all profiling infos of methods not compiled nor being compiled.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001123 auto profiling_kept_end = std::remove_if(profiling_infos_.begin(), profiling_infos_.end(),
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001124 [this] (ProfilingInfo* info) NO_THREAD_SAFETY_ANALYSIS {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001125 const void* ptr = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
Nicolas Geoffray511e41b2016-03-02 17:09:35 +00001126 // We have previously cleared the ProfilingInfo pointer in the ArtMethod in the hope
1127 // that the compiled code would not get revived. As mutator threads run concurrently,
1128 // they may have revived the compiled code, and now we are in the situation where
1129 // a method has compiled code but no ProfilingInfo.
1130 // We make sure compiled methods have a ProfilingInfo object. It is needed for
1131 // code cache collection.
Andreas Gampe542451c2016-07-26 09:02:02 -07001132 if (ContainsPc(ptr) &&
1133 info->GetMethod()->GetProfilingInfo(kRuntimePointerSize) == nullptr) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001134 info->GetMethod()->SetProfilingInfo(info);
Andreas Gampe542451c2016-07-26 09:02:02 -07001135 } else if (info->GetMethod()->GetProfilingInfo(kRuntimePointerSize) != info) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001136 // No need for this ProfilingInfo object anymore.
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001137 FreeData(reinterpret_cast<uint8_t*>(info));
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001138 return true;
1139 }
1140 return false;
1141 });
1142 profiling_infos_.erase(profiling_kept_end, profiling_infos_.end());
Nicolas Geoffray35122442016-03-02 12:05:30 +00001143 DCHECK(CheckLiveCompiledCodeHasProfilingInfo());
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001144 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001145}
1146
Nicolas Geoffray35122442016-03-02 12:05:30 +00001147bool JitCodeCache::CheckLiveCompiledCodeHasProfilingInfo() {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001148 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001149 // Check that methods we have compiled do have a ProfilingInfo object. We would
1150 // have memory leaks of compiled code otherwise.
1151 for (const auto& it : method_code_map_) {
1152 ArtMethod* method = it.second;
Andreas Gampe542451c2016-07-26 09:02:02 -07001153 if (method->GetProfilingInfo(kRuntimePointerSize) == nullptr) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001154 const void* code_ptr = it.first;
1155 const OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1156 if (method_header->GetEntryPoint() == method->GetEntryPointFromQuickCompiledCode()) {
1157 // If the code is not dead, then we have a problem. Note that this can even
1158 // happen just after a collection, as mutator threads are running in parallel
1159 // and could deoptimize an existing compiled code.
1160 return false;
1161 }
1162 }
1163 }
1164 return true;
1165}
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001166
1167OatQuickMethodHeader* JitCodeCache::LookupMethodHeader(uintptr_t pc, ArtMethod* method) {
1168 static_assert(kRuntimeISA != kThumb2, "kThumb2 cannot be a runtime ISA");
1169 if (kRuntimeISA == kArm) {
1170 // On Thumb-2, the pc is offset by one.
1171 --pc;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001172 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001173 if (!ContainsPc(reinterpret_cast<const void*>(pc))) {
1174 return nullptr;
1175 }
1176
1177 MutexLock mu(Thread::Current(), lock_);
1178 if (method_code_map_.empty()) {
1179 return nullptr;
1180 }
1181 auto it = method_code_map_.lower_bound(reinterpret_cast<const void*>(pc));
1182 --it;
1183
1184 const void* code_ptr = it->first;
1185 OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1186 if (!method_header->Contains(pc)) {
1187 return nullptr;
1188 }
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +00001189 if (kIsDebugBuild && method != nullptr) {
Alex Light1ebe4fe2017-01-30 14:57:11 -08001190 // When we are walking the stack to redefine classes and creating obsolete methods it is
1191 // possible that we might have updated the method_code_map by making this method obsolete in a
1192 // previous frame. Therefore we should just check that the non-obsolete version of this method
1193 // is the one we expect. We change to the non-obsolete versions in the error message since the
1194 // obsolete version of the method might not be fully initialized yet. This situation can only
1195 // occur when we are in the process of allocating and setting up obsolete methods. Otherwise
1196 // method and it->second should be identical. (See runtime/openjdkjvmti/ti_redefine.cc for more
1197 // information.)
1198 DCHECK_EQ(it->second->GetNonObsoleteMethod(), method->GetNonObsoleteMethod())
1199 << ArtMethod::PrettyMethod(method->GetNonObsoleteMethod()) << " "
1200 << ArtMethod::PrettyMethod(it->second->GetNonObsoleteMethod()) << " "
David Sehr709b0702016-10-13 09:12:37 -07001201 << std::hex << pc;
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +00001202 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001203 return method_header;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001204}
1205
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001206OatQuickMethodHeader* JitCodeCache::LookupOsrMethodHeader(ArtMethod* method) {
1207 MutexLock mu(Thread::Current(), lock_);
1208 auto it = osr_code_map_.find(method);
1209 if (it == osr_code_map_.end()) {
1210 return nullptr;
1211 }
1212 return OatQuickMethodHeader::FromCodePointer(it->second);
1213}
1214
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001215ProfilingInfo* JitCodeCache::AddProfilingInfo(Thread* self,
1216 ArtMethod* method,
1217 const std::vector<uint32_t>& entries,
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001218 bool retry_allocation)
1219 // No thread safety analysis as we are using TryLock/Unlock explicitly.
1220 NO_THREAD_SAFETY_ANALYSIS {
1221 ProfilingInfo* info = nullptr;
1222 if (!retry_allocation) {
1223 // If we are allocating for the interpreter, just try to lock, to avoid
1224 // lock contention with the JIT.
1225 if (lock_.ExclusiveTryLock(self)) {
1226 info = AddProfilingInfoInternal(self, method, entries);
1227 lock_.ExclusiveUnlock(self);
1228 }
1229 } else {
1230 {
1231 MutexLock mu(self, lock_);
1232 info = AddProfilingInfoInternal(self, method, entries);
1233 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001234
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001235 if (info == nullptr) {
1236 GarbageCollectCache(self);
1237 MutexLock mu(self, lock_);
1238 info = AddProfilingInfoInternal(self, method, entries);
1239 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001240 }
1241 return info;
1242}
1243
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001244ProfilingInfo* JitCodeCache::AddProfilingInfoInternal(Thread* self ATTRIBUTE_UNUSED,
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001245 ArtMethod* method,
1246 const std::vector<uint32_t>& entries) {
1247 size_t profile_info_size = RoundUp(
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001248 sizeof(ProfilingInfo) + sizeof(InlineCache) * entries.size(),
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001249 sizeof(void*));
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001250
1251 // Check whether some other thread has concurrently created it.
Andreas Gampe542451c2016-07-26 09:02:02 -07001252 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001253 if (info != nullptr) {
1254 return info;
1255 }
1256
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001257 uint8_t* data = AllocateData(profile_info_size);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001258 if (data == nullptr) {
1259 return nullptr;
1260 }
1261 info = new (data) ProfilingInfo(method, entries);
Nicolas Geoffray07f35642016-01-04 16:06:51 +00001262
1263 // Make sure other threads see the data in the profiling info object before the
1264 // store in the ArtMethod's ProfilingInfo pointer.
1265 QuasiAtomic::ThreadFenceRelease();
1266
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001267 method->SetProfilingInfo(info);
1268 profiling_infos_.push_back(info);
Nicolas Geoffray933330a2016-03-16 14:20:06 +00001269 histogram_profiling_info_memory_use_.AddValue(profile_info_size);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001270 return info;
1271}
1272
Nicolas Geoffray0a3be162015-11-18 11:15:22 +00001273// NO_THREAD_SAFETY_ANALYSIS as this is called from mspace code, at which point the lock
1274// is already held.
1275void* JitCodeCache::MoreCore(const void* mspace, intptr_t increment) NO_THREAD_SAFETY_ANALYSIS {
1276 if (code_mspace_ == mspace) {
1277 size_t result = code_end_;
1278 code_end_ += increment;
1279 return reinterpret_cast<void*>(result + code_map_->Begin());
1280 } else {
1281 DCHECK_EQ(data_mspace_, mspace);
1282 size_t result = data_end_;
1283 data_end_ += increment;
1284 return reinterpret_cast<void*>(result + data_map_->Begin());
1285 }
1286}
1287
Calin Juravle99629622016-04-19 16:33:46 +01001288void JitCodeCache::GetProfiledMethods(const std::set<std::string>& dex_base_locations,
Calin Juravle940eb0c2017-01-30 19:30:44 -08001289 std::vector<ProfileMethodInfo>& methods) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001290 ScopedTrace trace(__FUNCTION__);
Calin Juravle31f2c152015-10-23 17:56:15 +01001291 MutexLock mu(Thread::Current(), lock_);
Calin Juravlea39fd982017-05-18 10:15:52 -07001292 uint16_t jit_compile_threshold = Runtime::Current()->GetJITOptions()->GetCompileThreshold();
Calin Juravle99629622016-04-19 16:33:46 +01001293 for (const ProfilingInfo* info : profiling_infos_) {
1294 ArtMethod* method = info->GetMethod();
1295 const DexFile* dex_file = method->GetDexFile();
Calin Juravle940eb0c2017-01-30 19:30:44 -08001296 if (!ContainsElement(dex_base_locations, dex_file->GetBaseLocation())) {
1297 // Skip dex files which are not profiled.
1298 continue;
Calin Juravle31f2c152015-10-23 17:56:15 +01001299 }
Calin Juravle940eb0c2017-01-30 19:30:44 -08001300 std::vector<ProfileMethodInfo::ProfileInlineCache> inline_caches;
Calin Juravlea39fd982017-05-18 10:15:52 -07001301
1302 // If the method didn't reach the compilation threshold don't save the inline caches.
1303 // They might be incomplete and cause unnecessary deoptimizations.
1304 // If the inline cache is empty the compiler will generate a regular invoke virtual/interface.
1305 if (method->GetCounter() < jit_compile_threshold) {
1306 methods.emplace_back(/*ProfileMethodInfo*/
1307 dex_file, method->GetDexMethodIndex(), inline_caches);
1308 continue;
1309 }
1310
Calin Juravle940eb0c2017-01-30 19:30:44 -08001311 for (size_t i = 0; i < info->number_of_inline_caches_; ++i) {
Mathieu Chartierdbddc222017-05-24 12:04:13 -07001312 std::vector<TypeReference> profile_classes;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001313 const InlineCache& cache = info->cache_[i];
Calin Juravle13439f02017-02-21 01:17:21 -08001314 ArtMethod* caller = info->GetMethod();
Calin Juravle589e71e2017-03-03 16:05:05 -08001315 bool is_missing_types = false;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001316 for (size_t k = 0; k < InlineCache::kIndividualCacheSize; k++) {
1317 mirror::Class* cls = cache.classes_[k].Read();
1318 if (cls == nullptr) {
1319 break;
1320 }
Calin Juravle4ca70a32017-02-21 16:22:24 -08001321
Calin Juravle13439f02017-02-21 01:17:21 -08001322 // Check if the receiver is in the boot class path or if it's in the
1323 // same class loader as the caller. If not, skip it, as there is not
1324 // much we can do during AOT.
1325 if (!cls->IsBootStrapClassLoaded() &&
1326 caller->GetClassLoader() != cls->GetClassLoader()) {
1327 is_missing_types = true;
1328 continue;
1329 }
1330
Calin Juravle4ca70a32017-02-21 16:22:24 -08001331 const DexFile* class_dex_file = nullptr;
1332 dex::TypeIndex type_index;
1333
1334 if (cls->GetDexCache() == nullptr) {
1335 DCHECK(cls->IsArrayClass()) << cls->PrettyClass();
Calin Juravlee21806f2017-02-22 11:49:43 -08001336 // Make a best effort to find the type index in the method's dex file.
1337 // We could search all open dex files but that might turn expensive
1338 // and probably not worth it.
Calin Juravle4ca70a32017-02-21 16:22:24 -08001339 class_dex_file = dex_file;
1340 type_index = cls->FindTypeIndexInOtherDexFile(*dex_file);
1341 } else {
1342 class_dex_file = &(cls->GetDexFile());
1343 type_index = cls->GetDexTypeIndex();
1344 }
1345 if (!type_index.IsValid()) {
1346 // Could be a proxy class or an array for which we couldn't find the type index.
Calin Juravle589e71e2017-03-03 16:05:05 -08001347 is_missing_types = true;
Calin Juravle4ca70a32017-02-21 16:22:24 -08001348 continue;
1349 }
1350 if (ContainsElement(dex_base_locations, class_dex_file->GetBaseLocation())) {
Calin Juravle940eb0c2017-01-30 19:30:44 -08001351 // Only consider classes from the same apk (including multidex).
1352 profile_classes.emplace_back(/*ProfileMethodInfo::ProfileClassReference*/
Calin Juravle4ca70a32017-02-21 16:22:24 -08001353 class_dex_file, type_index);
Calin Juravle589e71e2017-03-03 16:05:05 -08001354 } else {
1355 is_missing_types = true;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001356 }
1357 }
1358 if (!profile_classes.empty()) {
1359 inline_caches.emplace_back(/*ProfileMethodInfo::ProfileInlineCache*/
Calin Juravle589e71e2017-03-03 16:05:05 -08001360 cache.dex_pc_, is_missing_types, profile_classes);
Calin Juravle940eb0c2017-01-30 19:30:44 -08001361 }
1362 }
1363 methods.emplace_back(/*ProfileMethodInfo*/
1364 dex_file, method->GetDexMethodIndex(), inline_caches);
Calin Juravle31f2c152015-10-23 17:56:15 +01001365 }
1366}
1367
Calin Juravle4d77b6a2015-12-01 18:38:09 +00001368uint64_t JitCodeCache::GetLastUpdateTimeNs() const {
1369 return last_update_time_ns_.LoadAcquire();
Calin Juravle31f2c152015-10-23 17:56:15 +01001370}
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001371
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +01001372bool JitCodeCache::IsOsrCompiled(ArtMethod* method) {
1373 MutexLock mu(Thread::Current(), lock_);
1374 return osr_code_map_.find(method) != osr_code_map_.end();
1375}
1376
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001377bool JitCodeCache::NotifyCompilationOf(ArtMethod* method, Thread* self, bool osr) {
1378 if (!osr && ContainsPc(method->GetEntryPointFromQuickCompiledCode())) {
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001379 return false;
1380 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00001381
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00001382 MutexLock mu(self, lock_);
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001383 if (osr && (osr_code_map_.find(method) != osr_code_map_.end())) {
1384 return false;
1385 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001386
Andreas Gampe542451c2016-07-26 09:02:02 -07001387 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001388 if (info == nullptr) {
David Sehr709b0702016-10-13 09:12:37 -07001389 VLOG(jit) << method->PrettyMethod() << " needs a ProfilingInfo to be compiled";
Jeff Hao00286db2017-05-30 16:53:07 -07001390 // Because the counter is not atomic, there are some rare cases where we may not hit the
1391 // threshold for creating the ProfilingInfo. Reset the counter now to "correct" this.
Mathieu Chartierf044c222017-05-31 15:27:54 -07001392 ClearMethodCounter(method, /*was_warm*/ false);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001393 return false;
1394 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001395
buzbee454b3b62016-04-07 14:42:47 -07001396 if (info->IsMethodBeingCompiled(osr)) {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001397 return false;
1398 }
1399
buzbee454b3b62016-04-07 14:42:47 -07001400 info->SetIsMethodBeingCompiled(true, osr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001401 return true;
1402}
1403
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001404ProfilingInfo* JitCodeCache::NotifyCompilerUse(ArtMethod* method, Thread* self) {
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001405 MutexLock mu(self, lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -07001406 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001407 if (info != nullptr) {
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +00001408 if (!info->IncrementInlineUse()) {
1409 // Overflow of inlining uses, just bail.
1410 return nullptr;
1411 }
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001412 }
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001413 return info;
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001414}
1415
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001416void JitCodeCache::DoneCompilerUse(ArtMethod* method, Thread* self) {
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001417 MutexLock mu(self, lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -07001418 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001419 DCHECK(info != nullptr);
1420 info->DecrementInlineUse();
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001421}
1422
buzbee454b3b62016-04-07 14:42:47 -07001423void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self ATTRIBUTE_UNUSED, bool osr) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001424 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
buzbee454b3b62016-04-07 14:42:47 -07001425 DCHECK(info->IsMethodBeingCompiled(osr));
1426 info->SetIsMethodBeingCompiled(false, osr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001427}
1428
Nicolas Geoffraya25dce92016-01-12 16:41:10 +00001429size_t JitCodeCache::GetMemorySizeOfCodePointer(const void* ptr) {
1430 MutexLock mu(Thread::Current(), lock_);
1431 return mspace_usable_size(reinterpret_cast<const void*>(FromCodeToAllocation(ptr)));
1432}
1433
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001434void JitCodeCache::InvalidateCompiledCodeFor(ArtMethod* method,
1435 const OatQuickMethodHeader* header) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001436 ProfilingInfo* profiling_info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001437 if ((profiling_info != nullptr) &&
1438 (profiling_info->GetSavedEntryPoint() == header->GetEntryPoint())) {
1439 // Prevent future uses of the compiled code.
1440 profiling_info->SetSavedEntryPoint(nullptr);
1441 }
1442
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001443 if (method->GetEntryPointFromQuickCompiledCode() == header->GetEntryPoint()) {
Jeff Hao00286db2017-05-30 16:53:07 -07001444 // The entrypoint is the one to invalidate, so we just update it to the interpreter entry point
Mathieu Chartierf044c222017-05-31 15:27:54 -07001445 // and clear the counter to get the method Jitted again.
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001446 Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
1447 method, GetQuickToInterpreterBridge());
Mathieu Chartierf044c222017-05-31 15:27:54 -07001448 ClearMethodCounter(method, /*was_warm*/ profiling_info != nullptr);
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001449 } else {
1450 MutexLock mu(Thread::Current(), lock_);
1451 auto it = osr_code_map_.find(method);
1452 if (it != osr_code_map_.end() && OatQuickMethodHeader::FromCodePointer(it->second) == header) {
1453 // Remove the OSR method, to avoid using it again.
1454 osr_code_map_.erase(it);
1455 }
1456 }
1457}
1458
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001459uint8_t* JitCodeCache::AllocateCode(size_t code_size) {
1460 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
1461 uint8_t* result = reinterpret_cast<uint8_t*>(
1462 mspace_memalign(code_mspace_, alignment, code_size));
1463 size_t header_size = RoundUp(sizeof(OatQuickMethodHeader), alignment);
1464 // Ensure the header ends up at expected instruction alignment.
1465 DCHECK_ALIGNED_PARAM(reinterpret_cast<uintptr_t>(result + header_size), alignment);
1466 used_memory_for_code_ += mspace_usable_size(result);
1467 return result;
1468}
1469
1470void JitCodeCache::FreeCode(uint8_t* code) {
1471 used_memory_for_code_ -= mspace_usable_size(code);
1472 mspace_free(code_mspace_, code);
1473}
1474
1475uint8_t* JitCodeCache::AllocateData(size_t data_size) {
1476 void* result = mspace_malloc(data_mspace_, data_size);
1477 used_memory_for_data_ += mspace_usable_size(result);
1478 return reinterpret_cast<uint8_t*>(result);
1479}
1480
1481void JitCodeCache::FreeData(uint8_t* data) {
1482 used_memory_for_data_ -= mspace_usable_size(data);
1483 mspace_free(data_mspace_, data);
1484}
1485
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001486void JitCodeCache::Dump(std::ostream& os) {
1487 MutexLock mu(Thread::Current(), lock_);
1488 os << "Current JIT code cache size: " << PrettySize(used_memory_for_code_) << "\n"
1489 << "Current JIT data cache size: " << PrettySize(used_memory_for_data_) << "\n"
1490 << "Current JIT capacity: " << PrettySize(current_capacity_) << "\n"
1491 << "Current number of JIT code cache entries: " << method_code_map_.size() << "\n"
1492 << "Total number of JIT compilations: " << number_of_compilations_ << "\n"
1493 << "Total number of JIT compilations for on stack replacement: "
1494 << number_of_osr_compilations_ << "\n"
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001495 << "Total number of JIT code cache collections: " << number_of_collections_ << std::endl;
Nicolas Geoffray933330a2016-03-16 14:20:06 +00001496 histogram_stack_map_memory_use_.PrintMemoryUse(os);
1497 histogram_code_memory_use_.PrintMemoryUse(os);
1498 histogram_profiling_info_memory_use_.PrintMemoryUse(os);
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001499}
1500
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001501} // namespace jit
1502} // namespace art