blob: 0cafac7380d3a28d48a0a24ee9c04508d286b264 [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"
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070038#include "object_callbacks.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070039#include "scoped_thread_state_change-inl.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070040#include "stack.h"
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +010041#include "thread_list.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080042
43namespace art {
44namespace jit {
45
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010046static constexpr int kProtAll = PROT_READ | PROT_WRITE | PROT_EXEC;
47static constexpr int kProtData = PROT_READ | PROT_WRITE;
48static constexpr int kProtCode = PROT_READ | PROT_EXEC;
49
Nicolas Geoffray933330a2016-03-16 14:20:06 +000050static constexpr size_t kCodeSizeLogThreshold = 50 * KB;
51static constexpr size_t kStackMapSizeLogThreshold = 50 * KB;
52
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010053#define CHECKED_MPROTECT(memory, size, prot) \
54 do { \
55 int rc = mprotect(memory, size, prot); \
56 if (UNLIKELY(rc != 0)) { \
57 errno = rc; \
58 PLOG(FATAL) << "Failed to mprotect jit code cache"; \
59 } \
60 } while (false) \
61
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000062JitCodeCache* JitCodeCache::Create(size_t initial_capacity,
63 size_t max_capacity,
Nicolas Geoffraya25dce92016-01-12 16:41:10 +000064 bool generate_debug_info,
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000065 std::string* error_msg) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -080066 ScopedTrace trace(__PRETTY_FUNCTION__);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000067 CHECK_GE(max_capacity, initial_capacity);
Nicolas Geoffraya25dce92016-01-12 16:41:10 +000068
69 // Generating debug information is mostly for using the 'perf' tool, which does
70 // not work with ashmem.
71 bool use_ashmem = !generate_debug_info;
72 // With 'perf', we want a 1-1 mapping between an address and a method.
73 bool garbage_collect_code = !generate_debug_info;
74
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000075 // We need to have 32 bit offsets from method headers in code cache which point to things
76 // in the data cache. If the maps are more than 4G apart, having multiple maps wouldn't work.
77 // Ensure we're below 1 GB to be safe.
78 if (max_capacity > 1 * GB) {
79 std::ostringstream oss;
80 oss << "Maxium code cache capacity is limited to 1 GB, "
81 << PrettySize(max_capacity) << " is too big";
82 *error_msg = oss.str();
83 return nullptr;
84 }
85
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080086 std::string error_str;
87 // Map name specific for android_os_Debug.cpp accounting.
Nicolas Geoffray132d8362016-11-16 09:19:42 +000088 // Map in low 4gb to simplify accessing root tables for x86_64.
89 // We could do PC-relative addressing to avoid this problem, but that
90 // would require reserving code and data area before submitting, which
91 // means more windows for the code memory to be RWX.
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010092 MemMap* data_map = MemMap::MapAnonymous(
Nicolas Geoffray132d8362016-11-16 09:19:42 +000093 "data-code-cache", nullptr,
94 max_capacity,
95 kProtAll,
96 /* low_4gb */ true,
97 /* reuse */ false,
98 &error_str,
99 use_ashmem);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100100 if (data_map == nullptr) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800101 std::ostringstream oss;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000102 oss << "Failed to create read write execute cache: " << error_str << " size=" << max_capacity;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800103 *error_msg = oss.str();
104 return nullptr;
105 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100106
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000107 // Align both capacities to page size, as that's the unit mspaces use.
108 initial_capacity = RoundDown(initial_capacity, 2 * kPageSize);
109 max_capacity = RoundDown(max_capacity, 2 * kPageSize);
110
Nicolas Geoffray4e915fb2015-10-28 17:39:47 +0000111 // Data cache is 1 / 2 of the map.
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100112 // TODO: Make this variable?
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000113 size_t data_size = max_capacity / 2;
114 size_t code_size = max_capacity - data_size;
115 DCHECK_EQ(code_size + data_size, max_capacity);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100116 uint8_t* divider = data_map->Begin() + data_size;
117
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000118 MemMap* code_map =
119 data_map->RemapAtEnd(divider, "jit-code-cache", kProtAll, &error_str, use_ashmem);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100120 if (code_map == nullptr) {
121 std::ostringstream oss;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000122 oss << "Failed to create read write execute cache: " << error_str << " size=" << max_capacity;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100123 *error_msg = oss.str();
124 return nullptr;
125 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100126 DCHECK_EQ(code_map->Begin(), divider);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000127 data_size = initial_capacity / 2;
128 code_size = initial_capacity - data_size;
129 DCHECK_EQ(code_size + data_size, initial_capacity);
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000130 return new JitCodeCache(
Nicolas Geoffrayc3fec4c2016-01-14 16:16:35 +0000131 code_map, data_map, code_size, data_size, max_capacity, garbage_collect_code);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800132}
133
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000134JitCodeCache::JitCodeCache(MemMap* code_map,
135 MemMap* data_map,
136 size_t initial_code_capacity,
137 size_t initial_data_capacity,
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000138 size_t max_capacity,
139 bool garbage_collect_code)
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100140 : lock_("Jit code cache", kJitCodeCacheLock),
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000141 lock_cond_("Jit code cache condition variable", lock_),
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100142 collection_in_progress_(false),
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100143 code_map_(code_map),
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000144 data_map_(data_map),
145 max_capacity_(max_capacity),
146 current_capacity_(initial_code_capacity + initial_data_capacity),
147 code_end_(initial_code_capacity),
148 data_end_(initial_data_capacity),
Nicolas Geoffray35122442016-03-02 12:05:30 +0000149 last_collection_increased_code_cache_(false),
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000150 last_update_time_ns_(0),
Nicolas Geoffray0a522232016-01-19 09:34:58 +0000151 garbage_collect_code_(garbage_collect_code),
Nicolas Geoffrayb0d22082016-02-24 17:18:25 +0000152 used_memory_for_data_(0),
153 used_memory_for_code_(0),
Nicolas Geoffrayfcdd7292016-02-25 13:27:47 +0000154 number_of_compilations_(0),
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000155 number_of_osr_compilations_(0),
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000156 number_of_collections_(0),
157 histogram_stack_map_memory_use_("Memory used for stack maps", 16),
158 histogram_code_memory_use_("Memory used for compiled code", 16),
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000159 histogram_profiling_info_memory_use_("Memory used for profiling info", 16),
160 is_weak_access_enabled_(true),
161 inline_cache_cond_("Jit inline cache condition variable", lock_) {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100162
Nicolas Geoffrayc3fec4c2016-01-14 16:16:35 +0000163 DCHECK_GE(max_capacity, initial_code_capacity + initial_data_capacity);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000164 code_mspace_ = create_mspace_with_base(code_map_->Begin(), code_end_, false /*locked*/);
165 data_mspace_ = create_mspace_with_base(data_map_->Begin(), data_end_, false /*locked*/);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100166
167 if (code_mspace_ == nullptr || data_mspace_ == nullptr) {
168 PLOG(FATAL) << "create_mspace_with_base failed";
169 }
170
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000171 SetFootprintLimit(current_capacity_);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100172
173 CHECKED_MPROTECT(code_map_->Begin(), code_map_->Size(), kProtCode);
174 CHECKED_MPROTECT(data_map_->Begin(), data_map_->Size(), kProtData);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100175
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000176 VLOG(jit) << "Created jit code cache: initial data size="
177 << PrettySize(initial_data_capacity)
178 << ", initial code size="
179 << PrettySize(initial_code_capacity);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800180}
181
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100182bool JitCodeCache::ContainsPc(const void* ptr) const {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100183 return code_map_->Begin() <= ptr && ptr < code_map_->End();
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800184}
185
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000186bool JitCodeCache::ContainsMethod(ArtMethod* method) {
187 MutexLock mu(Thread::Current(), lock_);
188 for (auto& it : method_code_map_) {
189 if (it.second == method) {
190 return true;
191 }
192 }
193 return false;
194}
195
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800196class ScopedCodeCacheWrite : ScopedTrace {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100197 public:
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100198 explicit ScopedCodeCacheWrite(MemMap* code_map, bool only_for_tlb_shootdown = false)
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800199 : ScopedTrace("ScopedCodeCacheWrite"),
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100200 code_map_(code_map),
201 only_for_tlb_shootdown_(only_for_tlb_shootdown) {
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800202 ScopedTrace trace("mprotect all");
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100203 CHECKED_MPROTECT(
204 code_map_->Begin(), only_for_tlb_shootdown_ ? kPageSize : code_map_->Size(), kProtAll);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800205 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100206 ~ScopedCodeCacheWrite() {
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800207 ScopedTrace trace("mprotect code");
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100208 CHECKED_MPROTECT(
209 code_map_->Begin(), only_for_tlb_shootdown_ ? kPageSize : code_map_->Size(), kProtCode);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100210 }
211 private:
212 MemMap* const code_map_;
213
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100214 // If we're using ScopedCacheWrite only for TLB shootdown, we limit the scope of mprotect to
215 // one page.
216 const bool only_for_tlb_shootdown_;
217
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100218 DISALLOW_COPY_AND_ASSIGN(ScopedCodeCacheWrite);
219};
220
221uint8_t* JitCodeCache::CommitCode(Thread* self,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100222 ArtMethod* method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000223 uint8_t* stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700224 uint8_t* method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000225 uint8_t* roots_data,
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100226 size_t frame_size_in_bytes,
227 size_t core_spill_mask,
228 size_t fp_spill_mask,
229 const uint8_t* code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000230 size_t code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000231 size_t data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000232 bool osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700233 Handle<mirror::ObjectArray<mirror::Object>> roots,
234 bool has_should_deoptimize_flag,
235 const ArenaSet<ArtMethod*>& cha_single_implementation_list) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100236 uint8_t* result = CommitCodeInternal(self,
237 method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000238 stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700239 method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000240 roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100241 frame_size_in_bytes,
242 core_spill_mask,
243 fp_spill_mask,
244 code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000245 code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000246 data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000247 osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700248 roots,
249 has_should_deoptimize_flag,
250 cha_single_implementation_list);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100251 if (result == nullptr) {
252 // Retry.
253 GarbageCollectCache(self);
254 result = CommitCodeInternal(self,
255 method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000256 stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700257 method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000258 roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100259 frame_size_in_bytes,
260 core_spill_mask,
261 fp_spill_mask,
262 code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000263 code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000264 data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000265 osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700266 roots,
267 has_should_deoptimize_flag,
268 cha_single_implementation_list);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100269 }
270 return result;
271}
272
273bool JitCodeCache::WaitForPotentialCollectionToComplete(Thread* self) {
274 bool in_collection = false;
275 while (collection_in_progress_) {
276 in_collection = true;
277 lock_cond_.Wait(self);
278 }
279 return in_collection;
280}
281
282static uintptr_t FromCodeToAllocation(const void* code) {
283 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
284 return reinterpret_cast<uintptr_t>(code) - RoundUp(sizeof(OatQuickMethodHeader), alignment);
285}
286
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000287static uint32_t ComputeRootTableSize(uint32_t number_of_roots) {
288 return sizeof(uint32_t) + number_of_roots * sizeof(GcRoot<mirror::Object>);
289}
290
291static uint32_t GetNumberOfRoots(const uint8_t* stack_map) {
292 // The length of the table is stored just before the stack map (and therefore at the end of
293 // the table itself), in order to be able to fetch it from a `stack_map` pointer.
294 return reinterpret_cast<const uint32_t*>(stack_map)[-1];
295}
296
Mathieu Chartier7a704be2016-11-22 13:24:40 -0800297static void FillRootTableLength(uint8_t* roots_data, uint32_t length) {
298 // Store the length of the table at the end. This will allow fetching it from a `stack_map`
299 // pointer.
300 reinterpret_cast<uint32_t*>(roots_data)[length] = length;
301}
302
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000303static const uint8_t* FromStackMapToRoots(const uint8_t* stack_map_data) {
304 return stack_map_data - ComputeRootTableSize(GetNumberOfRoots(stack_map_data));
305}
306
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000307static void FillRootTable(uint8_t* roots_data, Handle<mirror::ObjectArray<mirror::Object>> roots)
308 REQUIRES_SHARED(Locks::mutator_lock_) {
309 GcRoot<mirror::Object>* gc_roots = reinterpret_cast<GcRoot<mirror::Object>*>(roots_data);
Mathieu Chartier7a704be2016-11-22 13:24:40 -0800310 const uint32_t length = roots->GetLength();
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000311 // Put all roots in `roots_data`.
312 for (uint32_t i = 0; i < length; ++i) {
313 ObjPtr<mirror::Object> object = roots->Get(i);
314 if (kIsDebugBuild) {
315 // Ensure the string is strongly interned. b/32995596
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000316 if (object->IsString()) {
317 ObjPtr<mirror::String> str = reinterpret_cast<mirror::String*>(object.Ptr());
318 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
319 CHECK(class_linker->GetInternTable()->LookupStrong(Thread::Current(), str) != nullptr);
320 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000321 }
322 gc_roots[i] = GcRoot<mirror::Object>(object);
323 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000324}
325
326static uint8_t* GetRootTable(const void* code_ptr, uint32_t* number_of_roots = nullptr) {
327 OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
328 uint8_t* data = method_header->GetOptimizedCodeInfoPtr();
329 uint32_t roots = GetNumberOfRoots(data);
330 if (number_of_roots != nullptr) {
331 *number_of_roots = roots;
332 }
333 return data - ComputeRootTableSize(roots);
334}
335
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100336// Use a sentinel for marking entries in the JIT table that have been cleared.
337// This helps diagnosing in case the compiled code tries to wrongly access such
338// entries.
Andreas Gampe5629d2d2017-05-15 16:28:13 -0700339static mirror::Class* const weak_sentinel =
340 reinterpret_cast<mirror::Class*>(Context::kBadGprBase + 0xff);
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100341
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000342// Helper for the GC to process a weak class in a JIT root table.
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100343static inline void ProcessWeakClass(GcRoot<mirror::Class>* root_ptr,
344 IsMarkedVisitor* visitor,
345 mirror::Class* update)
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000346 REQUIRES_SHARED(Locks::mutator_lock_) {
347 // This does not need a read barrier because this is called by GC.
348 mirror::Class* cls = root_ptr->Read<kWithoutReadBarrier>();
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100349 if (cls != nullptr && cls != weak_sentinel) {
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000350 DCHECK((cls->IsClass<kDefaultVerifyFlags, kWithoutReadBarrier>()));
351 // Look at the classloader of the class to know if it has been unloaded.
352 // This does not need a read barrier because this is called by GC.
353 mirror::Object* class_loader =
354 cls->GetClassLoader<kDefaultVerifyFlags, kWithoutReadBarrier>();
355 if (class_loader == nullptr || visitor->IsMarked(class_loader) != nullptr) {
356 // The class loader is live, update the entry if the class has moved.
357 mirror::Class* new_cls = down_cast<mirror::Class*>(visitor->IsMarked(cls));
358 // Note that new_object can be null for CMS and newly allocated objects.
359 if (new_cls != nullptr && new_cls != cls) {
360 *root_ptr = GcRoot<mirror::Class>(new_cls);
361 }
362 } else {
363 // The class loader is not live, clear the entry.
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100364 *root_ptr = GcRoot<mirror::Class>(update);
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000365 }
366 }
367}
368
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000369void JitCodeCache::SweepRootTables(IsMarkedVisitor* visitor) {
370 MutexLock mu(Thread::Current(), lock_);
371 for (const auto& entry : method_code_map_) {
372 uint32_t number_of_roots = 0;
373 uint8_t* roots_data = GetRootTable(entry.first, &number_of_roots);
374 GcRoot<mirror::Object>* roots = reinterpret_cast<GcRoot<mirror::Object>*>(roots_data);
375 for (uint32_t i = 0; i < number_of_roots; ++i) {
376 // This does not need a read barrier because this is called by GC.
377 mirror::Object* object = roots[i].Read<kWithoutReadBarrier>();
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100378 if (object == nullptr || object == weak_sentinel) {
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000379 // entry got deleted in a previous sweep.
380 } else if (object->IsString<kDefaultVerifyFlags, kWithoutReadBarrier>()) {
381 mirror::Object* new_object = visitor->IsMarked(object);
382 // We know the string is marked because it's a strongly-interned string that
383 // is always alive. The IsMarked implementation of the CMS collector returns
384 // null for newly allocated objects, but we know those haven't moved. Therefore,
385 // only update the entry if we get a different non-null string.
386 // TODO: Do not use IsMarked for j.l.Class, and adjust once we move this method
387 // out of the weak access/creation pause. b/32167580
388 if (new_object != nullptr && new_object != object) {
389 DCHECK(new_object->IsString());
390 roots[i] = GcRoot<mirror::Object>(new_object);
391 }
392 } else {
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100393 ProcessWeakClass(
394 reinterpret_cast<GcRoot<mirror::Class>*>(&roots[i]), visitor, weak_sentinel);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000395 }
396 }
397 }
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000398 // Walk over inline caches to clear entries containing unloaded classes.
399 for (ProfilingInfo* info : profiling_infos_) {
400 for (size_t i = 0; i < info->number_of_inline_caches_; ++i) {
401 InlineCache* cache = &info->cache_[i];
402 for (size_t j = 0; j < InlineCache::kIndividualCacheSize; ++j) {
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100403 ProcessWeakClass(&cache->classes_[j], visitor, nullptr);
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000404 }
405 }
406 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000407}
408
Mingyao Yang063fc772016-08-02 11:02:54 -0700409void JitCodeCache::FreeCode(const void* code_ptr) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100410 uintptr_t allocation = FromCodeToAllocation(code_ptr);
David Srbecky5cc349f2015-12-18 15:04:48 +0000411 // Notify native debugger that we are about to remove the code.
412 // It does nothing if we are not using native debugger.
413 DeleteJITCodeEntryForAddress(reinterpret_cast<uintptr_t>(code_ptr));
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000414 FreeData(GetRootTable(code_ptr));
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000415 FreeCode(reinterpret_cast<uint8_t*>(allocation));
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100416}
417
Mingyao Yang063fc772016-08-02 11:02:54 -0700418void JitCodeCache::FreeAllMethodHeaders(
419 const std::unordered_set<OatQuickMethodHeader*>& method_headers) {
420 {
421 MutexLock mu(Thread::Current(), *Locks::cha_lock_);
422 Runtime::Current()->GetClassHierarchyAnalysis()
423 ->RemoveDependentsWithMethodHeaders(method_headers);
424 }
425
426 // We need to remove entries in method_headers from CHA dependencies
427 // first since once we do FreeCode() below, the memory can be reused
428 // so it's possible for the same method_header to start representing
429 // different compile code.
430 MutexLock mu(Thread::Current(), lock_);
431 ScopedCodeCacheWrite scc(code_map_.get());
432 for (const OatQuickMethodHeader* method_header : method_headers) {
433 FreeCode(method_header->GetCode());
434 }
435}
436
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100437void JitCodeCache::RemoveMethodsIn(Thread* self, const LinearAlloc& alloc) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800438 ScopedTrace trace(__PRETTY_FUNCTION__);
Mingyao Yang063fc772016-08-02 11:02:54 -0700439 // We use a set to first collect all method_headers whose code need to be
440 // removed. We need to free the underlying code after we remove CHA dependencies
441 // for entries in this set. And it's more efficient to iterate through
442 // the CHA dependency map just once with an unordered_set.
443 std::unordered_set<OatQuickMethodHeader*> method_headers;
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000444 {
Mingyao Yang063fc772016-08-02 11:02:54 -0700445 MutexLock mu(self, lock_);
446 // We do not check if a code cache GC is in progress, as this method comes
447 // with the classlinker_classes_lock_ held, and suspending ourselves could
448 // lead to a deadlock.
449 {
450 ScopedCodeCacheWrite scc(code_map_.get());
451 for (auto it = method_code_map_.begin(); it != method_code_map_.end();) {
452 if (alloc.ContainsUnsafe(it->second)) {
453 method_headers.insert(OatQuickMethodHeader::FromCodePointer(it->first));
454 it = method_code_map_.erase(it);
455 } else {
456 ++it;
457 }
458 }
459 }
460 for (auto it = osr_code_map_.begin(); it != osr_code_map_.end();) {
461 if (alloc.ContainsUnsafe(it->first)) {
462 // Note that the code has already been pushed to method_headers in the loop
463 // above and is going to be removed in FreeCode() below.
464 it = osr_code_map_.erase(it);
465 } else {
466 ++it;
467 }
468 }
469 for (auto it = profiling_infos_.begin(); it != profiling_infos_.end();) {
470 ProfilingInfo* info = *it;
471 if (alloc.ContainsUnsafe(info->GetMethod())) {
472 info->GetMethod()->SetProfilingInfo(nullptr);
473 FreeData(reinterpret_cast<uint8_t*>(info));
474 it = profiling_infos_.erase(it);
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000475 } else {
476 ++it;
477 }
478 }
479 }
Mingyao Yang063fc772016-08-02 11:02:54 -0700480 FreeAllMethodHeaders(method_headers);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100481}
482
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000483bool JitCodeCache::IsWeakAccessEnabled(Thread* self) const {
484 return kUseReadBarrier
485 ? self->GetWeakRefAccessEnabled()
486 : is_weak_access_enabled_.LoadSequentiallyConsistent();
487}
488
489void JitCodeCache::WaitUntilInlineCacheAccessible(Thread* self) {
490 if (IsWeakAccessEnabled(self)) {
491 return;
492 }
493 ScopedThreadSuspension sts(self, kWaitingWeakGcRootRead);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +0000494 MutexLock mu(self, lock_);
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000495 while (!IsWeakAccessEnabled(self)) {
496 inline_cache_cond_.Wait(self);
497 }
498}
499
500void JitCodeCache::BroadcastForInlineCacheAccess() {
501 Thread* self = Thread::Current();
502 MutexLock mu(self, lock_);
503 inline_cache_cond_.Broadcast(self);
504}
505
506void JitCodeCache::AllowInlineCacheAccess() {
507 DCHECK(!kUseReadBarrier);
508 is_weak_access_enabled_.StoreSequentiallyConsistent(true);
509 BroadcastForInlineCacheAccess();
510}
511
512void JitCodeCache::DisallowInlineCacheAccess() {
513 DCHECK(!kUseReadBarrier);
514 is_weak_access_enabled_.StoreSequentiallyConsistent(false);
515}
516
517void JitCodeCache::CopyInlineCacheInto(const InlineCache& ic,
518 Handle<mirror::ObjectArray<mirror::Class>> array) {
519 WaitUntilInlineCacheAccessible(Thread::Current());
520 // Note that we don't need to lock `lock_` here, the compiler calling
521 // this method has already ensured the inline cache will not be deleted.
522 for (size_t in_cache = 0, in_array = 0;
523 in_cache < InlineCache::kIndividualCacheSize;
524 ++in_cache) {
525 mirror::Class* object = ic.classes_[in_cache].Read();
526 if (object != nullptr) {
527 array->Set(in_array++, object);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +0000528 }
529 }
530}
531
Mathieu Chartierf044c222017-05-31 15:27:54 -0700532static void ClearMethodCounter(ArtMethod* method, bool was_warm) {
533 if (was_warm) {
534 method->AddAccessFlags(kAccPreviouslyWarm);
535 }
536 // We reset the counter to 1 so that the profile knows that the method was executed at least once.
537 // This is required for layout purposes.
538 method->SetCounter(1);
539}
540
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100541uint8_t* JitCodeCache::CommitCodeInternal(Thread* self,
542 ArtMethod* method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000543 uint8_t* stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700544 uint8_t* method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000545 uint8_t* roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100546 size_t frame_size_in_bytes,
547 size_t core_spill_mask,
548 size_t fp_spill_mask,
549 const uint8_t* code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000550 size_t code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000551 size_t data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000552 bool osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700553 Handle<mirror::ObjectArray<mirror::Object>> roots,
554 bool has_should_deoptimize_flag,
555 const ArenaSet<ArtMethod*>&
556 cha_single_implementation_list) {
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000557 DCHECK(stack_map != nullptr);
Nicolas Geoffray1e7de6c2015-10-21 12:07:31 +0100558 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
559 // Ensure the header ends up at expected instruction alignment.
560 size_t header_size = RoundUp(sizeof(OatQuickMethodHeader), alignment);
561 size_t total_size = header_size + code_size;
562
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100563 OatQuickMethodHeader* method_header = nullptr;
Nicolas Geoffray1e7de6c2015-10-21 12:07:31 +0100564 uint8_t* code_ptr = nullptr;
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000565 uint8_t* memory = nullptr;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100566 {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000567 ScopedThreadSuspension sts(self, kSuspended);
568 MutexLock mu(self, lock_);
569 WaitForPotentialCollectionToComplete(self);
570 {
571 ScopedCodeCacheWrite scc(code_map_.get());
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000572 memory = AllocateCode(total_size);
573 if (memory == nullptr) {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000574 return nullptr;
575 }
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000576 code_ptr = memory + header_size;
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000577
578 std::copy(code, code + code_size, code_ptr);
579 method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
580 new (method_header) OatQuickMethodHeader(
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000581 code_ptr - stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700582 code_ptr - method_info,
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000583 frame_size_in_bytes,
584 core_spill_mask,
585 fp_spill_mask,
586 code_size);
Kevin Brodskyb93ce182016-12-15 14:23:09 +0000587 // Flush caches before we remove write permission because some ARMv8 Qualcomm kernels may
588 // trigger a segfault if a page fault occurs when requesting a cache maintenance operation.
589 // This is a kernel bug that we need to work around until affected devices (e.g. Nexus 5X and
590 // 6P) stop being supported or their kernels are fixed.
Artem Udovichenkob18a6692016-11-17 10:51:58 +0300591 //
Kevin Brodskyb93ce182016-12-15 14:23:09 +0000592 // For reference, this behavior is caused by this commit:
593 // https://android.googlesource.com/kernel/msm/+/3fbe6bc28a6b9939d0650f2f17eb5216c719950c
Artem Udovichenkob18a6692016-11-17 10:51:58 +0300594 FlushInstructionCache(reinterpret_cast<char*>(code_ptr),
595 reinterpret_cast<char*>(code_ptr + code_size));
Mingyao Yang063fc772016-08-02 11:02:54 -0700596 DCHECK(!Runtime::Current()->IsAotCompiler());
597 if (has_should_deoptimize_flag) {
598 method_header->SetHasShouldDeoptimizeFlag();
599 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100600 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100601
Nicolas Geoffray0a522232016-01-19 09:34:58 +0000602 number_of_compilations_++;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100603 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000604 // We need to update the entry point in the runnable state for the instrumentation.
605 {
Mingyao Yang063fc772016-08-02 11:02:54 -0700606 // Need cha_lock_ for checking all single-implementation flags and register
607 // dependencies.
608 MutexLock cha_mu(self, *Locks::cha_lock_);
609 bool single_impl_still_valid = true;
610 for (ArtMethod* single_impl : cha_single_implementation_list) {
611 if (!single_impl->HasSingleImplementation()) {
Jeff Hao00286db2017-05-30 16:53:07 -0700612 // Simply discard the compiled code. Clear the counter so that it may be recompiled later.
613 // Hopefully the class hierarchy will be more stable when compilation is retried.
Mingyao Yang063fc772016-08-02 11:02:54 -0700614 single_impl_still_valid = false;
Mathieu Chartierf044c222017-05-31 15:27:54 -0700615 ClearMethodCounter(method, /*was_warm*/ false);
Mingyao Yang063fc772016-08-02 11:02:54 -0700616 break;
617 }
618 }
619
620 // Discard the code if any single-implementation assumptions are now invalid.
621 if (!single_impl_still_valid) {
622 VLOG(jit) << "JIT discarded jitted code due to invalid single-implementation assumptions.";
623 return nullptr;
624 }
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000625 DCHECK(cha_single_implementation_list.empty() || !Runtime::Current()->IsJavaDebuggable())
Alex Lightdba61482016-12-21 08:20:29 -0800626 << "Should not be using cha on debuggable apps/runs!";
627
Mingyao Yang063fc772016-08-02 11:02:54 -0700628 for (ArtMethod* single_impl : cha_single_implementation_list) {
629 Runtime::Current()->GetClassHierarchyAnalysis()->AddDependency(
630 single_impl, method, method_header);
631 }
632
633 // The following needs to be guarded by cha_lock_ also. Otherwise it's
634 // possible that the compiled code is considered invalidated by some class linking,
635 // but below we still make the compiled code valid for the method.
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000636 MutexLock mu(self, lock_);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000637 // Fill the root table before updating the entry point.
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000638 DCHECK_EQ(FromStackMapToRoots(stack_map), roots_data);
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100639 DCHECK_LE(roots_data, stack_map);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000640 FillRootTable(roots_data, roots);
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100641 {
642 // Flush data cache, as compiled code references literals in it.
643 // We also need a TLB shootdown to act as memory barrier across cores.
644 ScopedCodeCacheWrite ccw(code_map_.get(), /* only_for_tlb_shootdown */ true);
645 FlushDataCache(reinterpret_cast<char*>(roots_data),
646 reinterpret_cast<char*>(roots_data + data_size));
647 }
648 method_code_map_.Put(code_ptr, method);
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000649 if (osr) {
Nicolas Geoffrayfcdd7292016-02-25 13:27:47 +0000650 number_of_osr_compilations_++;
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000651 osr_code_map_.Put(method, code_ptr);
Nicolas Geoffray480d5102016-04-18 12:09:30 +0100652 } else {
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000653 Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
654 method, method_header->GetEntryPoint());
655 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000656 if (collection_in_progress_) {
657 // We need to update the live bitmap if there is a GC to ensure it sees this new
658 // code.
659 GetLiveBitmap()->AtomicTestAndSet(FromCodeToAllocation(code_ptr));
660 }
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000661 last_update_time_ns_.StoreRelease(NanoTime());
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000662 VLOG(jit)
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100663 << "JIT added (osr=" << std::boolalpha << osr << std::noboolalpha << ") "
David Sehr709b0702016-10-13 09:12:37 -0700664 << ArtMethod::PrettyMethod(method) << "@" << method
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000665 << " ccache_size=" << PrettySize(CodeCacheSizeLocked()) << ": "
666 << " dcache_size=" << PrettySize(DataCacheSizeLocked()) << ": "
667 << reinterpret_cast<const void*>(method_header->GetEntryPoint()) << ","
Mingyao Yang063fc772016-08-02 11:02:54 -0700668 << reinterpret_cast<const void*>(method_header->GetEntryPoint() +
669 method_header->GetCodeSize());
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000670 histogram_code_memory_use_.AddValue(code_size);
671 if (code_size > kCodeSizeLogThreshold) {
672 LOG(INFO) << "JIT allocated "
673 << PrettySize(code_size)
674 << " for compiled code of "
David Sehr709b0702016-10-13 09:12:37 -0700675 << ArtMethod::PrettyMethod(method);
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000676 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000677 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100678
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100679 return reinterpret_cast<uint8_t*>(method_header);
680}
681
682size_t JitCodeCache::CodeCacheSize() {
683 MutexLock mu(Thread::Current(), lock_);
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000684 return CodeCacheSizeLocked();
685}
686
Alex Lightdba61482016-12-21 08:20:29 -0800687// This notifies the code cache that the given method has been redefined and that it should remove
688// any cached information it has on the method. All threads must be suspended before calling this
689// method. The compiled code for the method (if there is any) must not be in any threads call stack.
690void JitCodeCache::NotifyMethodRedefined(ArtMethod* method) {
691 MutexLock mu(Thread::Current(), lock_);
692 if (method->IsNative()) {
693 return;
694 }
695 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
696 if (info != nullptr) {
697 auto profile = std::find(profiling_infos_.begin(), profiling_infos_.end(), info);
698 DCHECK(profile != profiling_infos_.end());
699 profiling_infos_.erase(profile);
700 }
701 method->SetProfilingInfo(nullptr);
702 ScopedCodeCacheWrite ccw(code_map_.get());
Andreas Gampe39e67382017-05-15 19:26:38 -0700703 for (auto code_iter = method_code_map_.begin(); code_iter != method_code_map_.end();) {
Alex Lightdba61482016-12-21 08:20:29 -0800704 if (code_iter->second == method) {
705 FreeCode(code_iter->first);
Andreas Gampe39e67382017-05-15 19:26:38 -0700706 code_iter = method_code_map_.erase(code_iter);
707 continue;
Alex Lightdba61482016-12-21 08:20:29 -0800708 }
Andreas Gampe39e67382017-05-15 19:26:38 -0700709 ++code_iter;
Alex Lightdba61482016-12-21 08:20:29 -0800710 }
711 auto code_map = osr_code_map_.find(method);
712 if (code_map != osr_code_map_.end()) {
713 osr_code_map_.erase(code_map);
714 }
715}
716
717// This invalidates old_method. Once this function returns one can no longer use old_method to
718// execute code unless it is fixed up. This fixup will happen later in the process of installing a
719// class redefinition.
720// TODO We should add some info to ArtMethod to note that 'old_method' has been invalidated and
721// shouldn't be used since it is no longer logically in the jit code cache.
722// TODO We should add DCHECKS that validate that the JIT is paused when this method is entered.
723void JitCodeCache::MoveObsoleteMethod(ArtMethod* old_method, ArtMethod* new_method) {
Alex Lighteee0bd42017-02-14 15:31:45 +0000724 // Native methods have no profiling info and need no special handling from the JIT code cache.
725 if (old_method->IsNative()) {
726 return;
727 }
Alex Lightdba61482016-12-21 08:20:29 -0800728 MutexLock mu(Thread::Current(), lock_);
729 // Update ProfilingInfo to the new one and remove it from the old_method.
730 if (old_method->GetProfilingInfo(kRuntimePointerSize) != nullptr) {
731 DCHECK_EQ(old_method->GetProfilingInfo(kRuntimePointerSize)->GetMethod(), old_method);
732 ProfilingInfo* info = old_method->GetProfilingInfo(kRuntimePointerSize);
733 old_method->SetProfilingInfo(nullptr);
734 // Since the JIT should be paused and all threads suspended by the time this is called these
735 // checks should always pass.
736 DCHECK(!info->IsInUseByCompiler());
737 new_method->SetProfilingInfo(info);
738 info->method_ = new_method;
739 }
740 // Update method_code_map_ to point to the new method.
741 for (auto& it : method_code_map_) {
742 if (it.second == old_method) {
743 it.second = new_method;
744 }
745 }
746 // Update osr_code_map_ to point to the new method.
747 auto code_map = osr_code_map_.find(old_method);
748 if (code_map != osr_code_map_.end()) {
749 osr_code_map_.Put(new_method, code_map->second);
750 osr_code_map_.erase(old_method);
751 }
752}
753
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000754size_t JitCodeCache::CodeCacheSizeLocked() {
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000755 return used_memory_for_code_;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100756}
757
758size_t JitCodeCache::DataCacheSize() {
759 MutexLock mu(Thread::Current(), lock_);
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000760 return DataCacheSizeLocked();
761}
762
763size_t JitCodeCache::DataCacheSizeLocked() {
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000764 return used_memory_for_data_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800765}
766
Nicolas Geoffrayf46501c2016-11-22 13:45:36 +0000767void JitCodeCache::ClearData(Thread* self,
768 uint8_t* stack_map_data,
769 uint8_t* roots_data) {
770 DCHECK_EQ(FromStackMapToRoots(stack_map_data), roots_data);
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000771 MutexLock mu(self, lock_);
Nicolas Geoffrayf46501c2016-11-22 13:45:36 +0000772 FreeData(reinterpret_cast<uint8_t*>(roots_data));
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000773}
774
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000775size_t JitCodeCache::ReserveData(Thread* self,
776 size_t stack_map_size,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700777 size_t method_info_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000778 size_t number_of_roots,
779 ArtMethod* method,
780 uint8_t** stack_map_data,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700781 uint8_t** method_info_data,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000782 uint8_t** roots_data) {
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000783 size_t table_size = ComputeRootTableSize(number_of_roots);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700784 size_t size = RoundUp(stack_map_size + method_info_size + table_size, sizeof(void*));
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100785 uint8_t* result = nullptr;
786
787 {
788 ScopedThreadSuspension sts(self, kSuspended);
789 MutexLock mu(self, lock_);
790 WaitForPotentialCollectionToComplete(self);
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000791 result = AllocateData(size);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100792 }
793
794 if (result == nullptr) {
795 // Retry.
796 GarbageCollectCache(self);
797 ScopedThreadSuspension sts(self, kSuspended);
798 MutexLock mu(self, lock_);
799 WaitForPotentialCollectionToComplete(self);
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000800 result = AllocateData(size);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100801 }
802
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000803 MutexLock mu(self, lock_);
804 histogram_stack_map_memory_use_.AddValue(size);
805 if (size > kStackMapSizeLogThreshold) {
806 LOG(INFO) << "JIT allocated "
807 << PrettySize(size)
808 << " for stack maps of "
David Sehr709b0702016-10-13 09:12:37 -0700809 << ArtMethod::PrettyMethod(method);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800810 }
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000811 if (result != nullptr) {
812 *roots_data = result;
813 *stack_map_data = result + table_size;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700814 *method_info_data = *stack_map_data + stack_map_size;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000815 FillRootTableLength(*roots_data, number_of_roots);
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000816 return size;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000817 } else {
818 *roots_data = nullptr;
819 *stack_map_data = nullptr;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700820 *method_info_data = nullptr;
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000821 return 0;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000822 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800823}
824
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100825class MarkCodeVisitor FINAL : public StackVisitor {
826 public:
827 MarkCodeVisitor(Thread* thread_in, JitCodeCache* code_cache_in)
828 : StackVisitor(thread_in, nullptr, StackVisitor::StackWalkKind::kSkipInlinedFrames),
829 code_cache_(code_cache_in),
830 bitmap_(code_cache_->GetLiveBitmap()) {}
831
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700832 bool VisitFrame() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100833 const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader();
834 if (method_header == nullptr) {
835 return true;
836 }
837 const void* code = method_header->GetCode();
838 if (code_cache_->ContainsPc(code)) {
839 // Use the atomic set version, as multiple threads are executing this code.
840 bitmap_->AtomicTestAndSet(FromCodeToAllocation(code));
841 }
842 return true;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800843 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100844
845 private:
846 JitCodeCache* const code_cache_;
847 CodeCacheBitmap* const bitmap_;
848};
849
850class MarkCodeClosure FINAL : public Closure {
851 public:
852 MarkCodeClosure(JitCodeCache* code_cache, Barrier* barrier)
853 : code_cache_(code_cache), barrier_(barrier) {}
854
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700855 void Run(Thread* thread) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800856 ScopedTrace trace(__PRETTY_FUNCTION__);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100857 DCHECK(thread == Thread::Current() || thread->IsSuspended());
858 MarkCodeVisitor visitor(thread, code_cache_);
859 visitor.WalkStack();
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +0000860 if (kIsDebugBuild) {
861 // The stack walking code queries the side instrumentation stack if it
862 // sees an instrumentation exit pc, so the JIT code of methods in that stack
863 // must have been seen. We sanity check this below.
864 for (const instrumentation::InstrumentationStackFrame& frame
865 : *thread->GetInstrumentationStack()) {
866 // The 'method_' in InstrumentationStackFrame is the one that has return_pc_ in
867 // its stack frame, it is not the method owning return_pc_. We just pass null to
868 // LookupMethodHeader: the method is only checked against in debug builds.
869 OatQuickMethodHeader* method_header =
870 code_cache_->LookupMethodHeader(frame.return_pc_, nullptr);
871 if (method_header != nullptr) {
872 const void* code = method_header->GetCode();
873 CHECK(code_cache_->GetLiveBitmap()->Test(FromCodeToAllocation(code)));
874 }
875 }
876 }
Mathieu Chartier10d25082015-10-28 18:36:09 -0700877 barrier_->Pass(Thread::Current());
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800878 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100879
880 private:
881 JitCodeCache* const code_cache_;
882 Barrier* const barrier_;
883};
884
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000885void JitCodeCache::NotifyCollectionDone(Thread* self) {
886 collection_in_progress_ = false;
887 lock_cond_.Broadcast(self);
888}
889
890void JitCodeCache::SetFootprintLimit(size_t new_footprint) {
891 size_t per_space_footprint = new_footprint / 2;
892 DCHECK(IsAlignedParam(per_space_footprint, kPageSize));
893 DCHECK_EQ(per_space_footprint * 2, new_footprint);
894 mspace_set_footprint_limit(data_mspace_, per_space_footprint);
895 {
896 ScopedCodeCacheWrite scc(code_map_.get());
897 mspace_set_footprint_limit(code_mspace_, per_space_footprint);
898 }
899}
900
901bool JitCodeCache::IncreaseCodeCacheCapacity() {
902 if (current_capacity_ == max_capacity_) {
903 return false;
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100904 }
905
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000906 // Double the capacity if we're below 1MB, or increase it by 1MB if
907 // we're above.
908 if (current_capacity_ < 1 * MB) {
909 current_capacity_ *= 2;
910 } else {
911 current_capacity_ += 1 * MB;
912 }
913 if (current_capacity_ > max_capacity_) {
914 current_capacity_ = max_capacity_;
915 }
916
917 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
918 LOG(INFO) << "Increasing code cache capacity to " << PrettySize(current_capacity_);
919 }
920
921 SetFootprintLimit(current_capacity_);
922
923 return true;
924}
925
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000926void JitCodeCache::MarkCompiledCodeOnThreadStacks(Thread* self) {
927 Barrier barrier(0);
928 size_t threads_running_checkpoint = 0;
929 MarkCodeClosure closure(this, &barrier);
930 threads_running_checkpoint = Runtime::Current()->GetThreadList()->RunCheckpoint(&closure);
931 // Now that we have run our checkpoint, move to a suspended state and wait
932 // for other threads to run the checkpoint.
933 ScopedThreadSuspension sts(self, kSuspended);
934 if (threads_running_checkpoint != 0) {
935 barrier.Increment(self, threads_running_checkpoint);
936 }
937}
938
Nicolas Geoffray35122442016-03-02 12:05:30 +0000939bool JitCodeCache::ShouldDoFullCollection() {
940 if (current_capacity_ == max_capacity_) {
941 // Always do a full collection when the code cache is full.
942 return true;
943 } else if (current_capacity_ < kReservedCapacity) {
944 // Always do partial collection when the code cache size is below the reserved
945 // capacity.
946 return false;
947 } else if (last_collection_increased_code_cache_) {
948 // This time do a full collection.
949 return true;
950 } else {
951 // This time do a partial collection.
952 return false;
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000953 }
954}
955
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000956void JitCodeCache::GarbageCollectCache(Thread* self) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800957 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000958 if (!garbage_collect_code_) {
959 MutexLock mu(self, lock_);
960 IncreaseCodeCacheCapacity();
961 return;
962 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100963
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000964 // Wait for an existing collection, or let everyone know we are starting one.
965 {
966 ScopedThreadSuspension sts(self, kSuspended);
967 MutexLock mu(self, lock_);
968 if (WaitForPotentialCollectionToComplete(self)) {
969 return;
970 } else {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000971 number_of_collections_++;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000972 live_bitmap_.reset(CodeCacheBitmap::Create(
973 "code-cache-bitmap",
974 reinterpret_cast<uintptr_t>(code_map_->Begin()),
975 reinterpret_cast<uintptr_t>(code_map_->Begin() + current_capacity_ / 2)));
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000976 collection_in_progress_ = true;
977 }
978 }
979
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000980 TimingLogger logger("JIT code cache timing logger", true, VLOG_IS_ON(jit));
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000981 {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000982 TimingLogger::ScopedTiming st("Code cache collection", &logger);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000983
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000984 bool do_full_collection = false;
985 {
986 MutexLock mu(self, lock_);
987 do_full_collection = ShouldDoFullCollection();
Nicolas Geoffraya96917a2016-03-01 22:18:02 +0000988 }
989
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000990 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
991 LOG(INFO) << "Do "
992 << (do_full_collection ? "full" : "partial")
993 << " code cache collection, code="
994 << PrettySize(CodeCacheSize())
995 << ", data=" << PrettySize(DataCacheSize());
996 }
Nicolas Geoffray35122442016-03-02 12:05:30 +0000997
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000998 DoCollection(self, /* collect_profiling_info */ do_full_collection);
999
1000 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
1001 LOG(INFO) << "After code cache collection, code="
1002 << PrettySize(CodeCacheSize())
1003 << ", data=" << PrettySize(DataCacheSize());
1004 }
1005
1006 {
1007 MutexLock mu(self, lock_);
1008
1009 // Increase the code cache only when we do partial collections.
1010 // TODO: base this strategy on how full the code cache is?
1011 if (do_full_collection) {
1012 last_collection_increased_code_cache_ = false;
1013 } else {
1014 last_collection_increased_code_cache_ = true;
1015 IncreaseCodeCacheCapacity();
Nicolas Geoffray35122442016-03-02 12:05:30 +00001016 }
1017
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001018 bool next_collection_will_be_full = ShouldDoFullCollection();
1019
1020 // Start polling the liveness of compiled code to prepare for the next full collection.
Nicolas Geoffray480d5102016-04-18 12:09:30 +01001021 if (next_collection_will_be_full) {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001022 // Save the entry point of methods we have compiled, and update the entry
1023 // point of those methods to the interpreter. If the method is invoked, the
1024 // interpreter will update its entry point to the compiled code and call it.
1025 for (ProfilingInfo* info : profiling_infos_) {
1026 const void* entry_point = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
1027 if (ContainsPc(entry_point)) {
1028 info->SetSavedEntryPoint(entry_point);
Nicolas Geoffray3b1a7f42017-02-22 10:21:00 +00001029 // Don't call Instrumentation::UpdateMethods, as it can check the declaring
1030 // class of the method. We may be concurrently running a GC which makes accessing
1031 // the class unsafe. We know it is OK to bypass the instrumentation as we've just
1032 // checked that the current entry point is JIT compiled code.
1033 info->GetMethod()->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001034 }
1035 }
1036
1037 DCHECK(CheckLiveCompiledCodeHasProfilingInfo());
1038 }
1039 live_bitmap_.reset(nullptr);
1040 NotifyCollectionDone(self);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001041 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001042 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001043 Runtime::Current()->GetJit()->AddTimingLogger(logger);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001044}
1045
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001046void JitCodeCache::RemoveUnmarkedCode(Thread* self) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001047 ScopedTrace trace(__FUNCTION__);
Mingyao Yang063fc772016-08-02 11:02:54 -07001048 std::unordered_set<OatQuickMethodHeader*> method_headers;
1049 {
1050 MutexLock mu(self, lock_);
1051 ScopedCodeCacheWrite scc(code_map_.get());
1052 // Iterate over all compiled code and remove entries that are not marked.
1053 for (auto it = method_code_map_.begin(); it != method_code_map_.end();) {
1054 const void* code_ptr = it->first;
1055 uintptr_t allocation = FromCodeToAllocation(code_ptr);
1056 if (GetLiveBitmap()->Test(allocation)) {
1057 ++it;
1058 } else {
1059 method_headers.insert(OatQuickMethodHeader::FromCodePointer(it->first));
1060 it = method_code_map_.erase(it);
1061 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001062 }
1063 }
Mingyao Yang063fc772016-08-02 11:02:54 -07001064 FreeAllMethodHeaders(method_headers);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001065}
1066
1067void JitCodeCache::DoCollection(Thread* self, bool collect_profiling_info) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001068 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001069 {
1070 MutexLock mu(self, lock_);
1071 if (collect_profiling_info) {
1072 // Clear the profiling info of methods that do not have compiled code as entrypoint.
1073 // Also remove the saved entry point from the ProfilingInfo objects.
1074 for (ProfilingInfo* info : profiling_infos_) {
1075 const void* ptr = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001076 if (!ContainsPc(ptr) && !info->IsInUseByCompiler()) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001077 info->GetMethod()->SetProfilingInfo(nullptr);
1078 }
Nicolas Geoffrayb9a639d2016-03-22 11:25:20 +00001079
1080 if (info->GetSavedEntryPoint() != nullptr) {
1081 info->SetSavedEntryPoint(nullptr);
1082 // We are going to move this method back to interpreter. Clear the counter now to
Mathieu Chartierf044c222017-05-31 15:27:54 -07001083 // give it a chance to be hot again.
1084 ClearMethodCounter(info->GetMethod(), /*was_warm*/ true);
Nicolas Geoffrayb9a639d2016-03-22 11:25:20 +00001085 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001086 }
1087 } else if (kIsDebugBuild) {
1088 // Sanity check that the profiling infos do not have a dangling entry point.
1089 for (ProfilingInfo* info : profiling_infos_) {
1090 DCHECK(info->GetSavedEntryPoint() == nullptr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001091 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001092 }
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001093
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001094 // Mark compiled code that are entrypoints of ArtMethods. Compiled code that is not
1095 // an entry point is either:
1096 // - an osr compiled code, that will be removed if not in a thread call stack.
1097 // - discarded compiled code, that will be removed if not in a thread call stack.
1098 for (const auto& it : method_code_map_) {
1099 ArtMethod* method = it.second;
1100 const void* code_ptr = it.first;
1101 const OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1102 if (method_header->GetEntryPoint() == method->GetEntryPointFromQuickCompiledCode()) {
1103 GetLiveBitmap()->AtomicTestAndSet(FromCodeToAllocation(code_ptr));
1104 }
1105 }
1106
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +00001107 // Empty osr method map, as osr compiled code will be deleted (except the ones
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001108 // on thread stacks).
1109 osr_code_map_.clear();
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001110 }
1111
1112 // Run a checkpoint on all threads to mark the JIT compiled code they are running.
Nicolas Geoffray8d372502016-02-23 13:56:43 +00001113 MarkCompiledCodeOnThreadStacks(self);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001114
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001115 // At this point, mutator threads are still running, and entrypoints of methods can
1116 // change. We do know they cannot change to a code cache entry that is not marked,
1117 // therefore we can safely remove those entries.
1118 RemoveUnmarkedCode(self);
Nicolas Geoffraya96917a2016-03-01 22:18:02 +00001119
Nicolas Geoffray35122442016-03-02 12:05:30 +00001120 if (collect_profiling_info) {
Nicolas Geoffraycf48fa02016-07-30 22:49:11 +01001121 ScopedThreadSuspension sts(self, kSuspended);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001122 MutexLock mu(self, lock_);
1123 // Free all profiling infos of methods not compiled nor being compiled.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001124 auto profiling_kept_end = std::remove_if(profiling_infos_.begin(), profiling_infos_.end(),
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001125 [this] (ProfilingInfo* info) NO_THREAD_SAFETY_ANALYSIS {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001126 const void* ptr = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
Nicolas Geoffray511e41b2016-03-02 17:09:35 +00001127 // We have previously cleared the ProfilingInfo pointer in the ArtMethod in the hope
1128 // that the compiled code would not get revived. As mutator threads run concurrently,
1129 // they may have revived the compiled code, and now we are in the situation where
1130 // a method has compiled code but no ProfilingInfo.
1131 // We make sure compiled methods have a ProfilingInfo object. It is needed for
1132 // code cache collection.
Andreas Gampe542451c2016-07-26 09:02:02 -07001133 if (ContainsPc(ptr) &&
1134 info->GetMethod()->GetProfilingInfo(kRuntimePointerSize) == nullptr) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001135 info->GetMethod()->SetProfilingInfo(info);
Andreas Gampe542451c2016-07-26 09:02:02 -07001136 } else if (info->GetMethod()->GetProfilingInfo(kRuntimePointerSize) != info) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001137 // No need for this ProfilingInfo object anymore.
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001138 FreeData(reinterpret_cast<uint8_t*>(info));
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001139 return true;
1140 }
1141 return false;
1142 });
1143 profiling_infos_.erase(profiling_kept_end, profiling_infos_.end());
Nicolas Geoffray35122442016-03-02 12:05:30 +00001144 DCHECK(CheckLiveCompiledCodeHasProfilingInfo());
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001145 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001146}
1147
Nicolas Geoffray35122442016-03-02 12:05:30 +00001148bool JitCodeCache::CheckLiveCompiledCodeHasProfilingInfo() {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001149 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001150 // Check that methods we have compiled do have a ProfilingInfo object. We would
1151 // have memory leaks of compiled code otherwise.
1152 for (const auto& it : method_code_map_) {
1153 ArtMethod* method = it.second;
Andreas Gampe542451c2016-07-26 09:02:02 -07001154 if (method->GetProfilingInfo(kRuntimePointerSize) == nullptr) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001155 const void* code_ptr = it.first;
1156 const OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1157 if (method_header->GetEntryPoint() == method->GetEntryPointFromQuickCompiledCode()) {
1158 // If the code is not dead, then we have a problem. Note that this can even
1159 // happen just after a collection, as mutator threads are running in parallel
1160 // and could deoptimize an existing compiled code.
1161 return false;
1162 }
1163 }
1164 }
1165 return true;
1166}
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001167
1168OatQuickMethodHeader* JitCodeCache::LookupMethodHeader(uintptr_t pc, ArtMethod* method) {
1169 static_assert(kRuntimeISA != kThumb2, "kThumb2 cannot be a runtime ISA");
1170 if (kRuntimeISA == kArm) {
1171 // On Thumb-2, the pc is offset by one.
1172 --pc;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001173 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001174 if (!ContainsPc(reinterpret_cast<const void*>(pc))) {
1175 return nullptr;
1176 }
1177
1178 MutexLock mu(Thread::Current(), lock_);
1179 if (method_code_map_.empty()) {
1180 return nullptr;
1181 }
1182 auto it = method_code_map_.lower_bound(reinterpret_cast<const void*>(pc));
1183 --it;
1184
1185 const void* code_ptr = it->first;
1186 OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1187 if (!method_header->Contains(pc)) {
1188 return nullptr;
1189 }
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +00001190 if (kIsDebugBuild && method != nullptr) {
Alex Light1ebe4fe2017-01-30 14:57:11 -08001191 // When we are walking the stack to redefine classes and creating obsolete methods it is
1192 // possible that we might have updated the method_code_map by making this method obsolete in a
1193 // previous frame. Therefore we should just check that the non-obsolete version of this method
1194 // is the one we expect. We change to the non-obsolete versions in the error message since the
1195 // obsolete version of the method might not be fully initialized yet. This situation can only
1196 // occur when we are in the process of allocating and setting up obsolete methods. Otherwise
1197 // method and it->second should be identical. (See runtime/openjdkjvmti/ti_redefine.cc for more
1198 // information.)
1199 DCHECK_EQ(it->second->GetNonObsoleteMethod(), method->GetNonObsoleteMethod())
1200 << ArtMethod::PrettyMethod(method->GetNonObsoleteMethod()) << " "
1201 << ArtMethod::PrettyMethod(it->second->GetNonObsoleteMethod()) << " "
David Sehr709b0702016-10-13 09:12:37 -07001202 << std::hex << pc;
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +00001203 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001204 return method_header;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001205}
1206
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001207OatQuickMethodHeader* JitCodeCache::LookupOsrMethodHeader(ArtMethod* method) {
1208 MutexLock mu(Thread::Current(), lock_);
1209 auto it = osr_code_map_.find(method);
1210 if (it == osr_code_map_.end()) {
1211 return nullptr;
1212 }
1213 return OatQuickMethodHeader::FromCodePointer(it->second);
1214}
1215
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001216ProfilingInfo* JitCodeCache::AddProfilingInfo(Thread* self,
1217 ArtMethod* method,
1218 const std::vector<uint32_t>& entries,
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001219 bool retry_allocation)
1220 // No thread safety analysis as we are using TryLock/Unlock explicitly.
1221 NO_THREAD_SAFETY_ANALYSIS {
1222 ProfilingInfo* info = nullptr;
1223 if (!retry_allocation) {
1224 // If we are allocating for the interpreter, just try to lock, to avoid
1225 // lock contention with the JIT.
1226 if (lock_.ExclusiveTryLock(self)) {
1227 info = AddProfilingInfoInternal(self, method, entries);
1228 lock_.ExclusiveUnlock(self);
1229 }
1230 } else {
1231 {
1232 MutexLock mu(self, lock_);
1233 info = AddProfilingInfoInternal(self, method, entries);
1234 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001235
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001236 if (info == nullptr) {
1237 GarbageCollectCache(self);
1238 MutexLock mu(self, lock_);
1239 info = AddProfilingInfoInternal(self, method, entries);
1240 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001241 }
1242 return info;
1243}
1244
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001245ProfilingInfo* JitCodeCache::AddProfilingInfoInternal(Thread* self ATTRIBUTE_UNUSED,
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001246 ArtMethod* method,
1247 const std::vector<uint32_t>& entries) {
1248 size_t profile_info_size = RoundUp(
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001249 sizeof(ProfilingInfo) + sizeof(InlineCache) * entries.size(),
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001250 sizeof(void*));
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001251
1252 // Check whether some other thread has concurrently created it.
Andreas Gampe542451c2016-07-26 09:02:02 -07001253 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001254 if (info != nullptr) {
1255 return info;
1256 }
1257
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001258 uint8_t* data = AllocateData(profile_info_size);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001259 if (data == nullptr) {
1260 return nullptr;
1261 }
1262 info = new (data) ProfilingInfo(method, entries);
Nicolas Geoffray07f35642016-01-04 16:06:51 +00001263
1264 // Make sure other threads see the data in the profiling info object before the
1265 // store in the ArtMethod's ProfilingInfo pointer.
1266 QuasiAtomic::ThreadFenceRelease();
1267
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001268 method->SetProfilingInfo(info);
1269 profiling_infos_.push_back(info);
Nicolas Geoffray933330a2016-03-16 14:20:06 +00001270 histogram_profiling_info_memory_use_.AddValue(profile_info_size);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001271 return info;
1272}
1273
Nicolas Geoffray0a3be162015-11-18 11:15:22 +00001274// NO_THREAD_SAFETY_ANALYSIS as this is called from mspace code, at which point the lock
1275// is already held.
1276void* JitCodeCache::MoreCore(const void* mspace, intptr_t increment) NO_THREAD_SAFETY_ANALYSIS {
1277 if (code_mspace_ == mspace) {
1278 size_t result = code_end_;
1279 code_end_ += increment;
1280 return reinterpret_cast<void*>(result + code_map_->Begin());
1281 } else {
1282 DCHECK_EQ(data_mspace_, mspace);
1283 size_t result = data_end_;
1284 data_end_ += increment;
1285 return reinterpret_cast<void*>(result + data_map_->Begin());
1286 }
1287}
1288
Calin Juravle99629622016-04-19 16:33:46 +01001289void JitCodeCache::GetProfiledMethods(const std::set<std::string>& dex_base_locations,
Calin Juravle940eb0c2017-01-30 19:30:44 -08001290 std::vector<ProfileMethodInfo>& methods) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001291 ScopedTrace trace(__FUNCTION__);
Calin Juravle31f2c152015-10-23 17:56:15 +01001292 MutexLock mu(Thread::Current(), lock_);
Calin Juravlea39fd982017-05-18 10:15:52 -07001293 uint16_t jit_compile_threshold = Runtime::Current()->GetJITOptions()->GetCompileThreshold();
Calin Juravle99629622016-04-19 16:33:46 +01001294 for (const ProfilingInfo* info : profiling_infos_) {
1295 ArtMethod* method = info->GetMethod();
1296 const DexFile* dex_file = method->GetDexFile();
Calin Juravle940eb0c2017-01-30 19:30:44 -08001297 if (!ContainsElement(dex_base_locations, dex_file->GetBaseLocation())) {
1298 // Skip dex files which are not profiled.
1299 continue;
Calin Juravle31f2c152015-10-23 17:56:15 +01001300 }
Calin Juravle940eb0c2017-01-30 19:30:44 -08001301 std::vector<ProfileMethodInfo::ProfileInlineCache> inline_caches;
Calin Juravlea39fd982017-05-18 10:15:52 -07001302
1303 // If the method didn't reach the compilation threshold don't save the inline caches.
1304 // They might be incomplete and cause unnecessary deoptimizations.
1305 // If the inline cache is empty the compiler will generate a regular invoke virtual/interface.
1306 if (method->GetCounter() < jit_compile_threshold) {
1307 methods.emplace_back(/*ProfileMethodInfo*/
1308 dex_file, method->GetDexMethodIndex(), inline_caches);
1309 continue;
1310 }
1311
Calin Juravle940eb0c2017-01-30 19:30:44 -08001312 for (size_t i = 0; i < info->number_of_inline_caches_; ++i) {
Mathieu Chartierdbddc222017-05-24 12:04:13 -07001313 std::vector<TypeReference> profile_classes;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001314 const InlineCache& cache = info->cache_[i];
Calin Juravle13439f02017-02-21 01:17:21 -08001315 ArtMethod* caller = info->GetMethod();
Calin Juravle589e71e2017-03-03 16:05:05 -08001316 bool is_missing_types = false;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001317 for (size_t k = 0; k < InlineCache::kIndividualCacheSize; k++) {
1318 mirror::Class* cls = cache.classes_[k].Read();
1319 if (cls == nullptr) {
1320 break;
1321 }
Calin Juravle4ca70a32017-02-21 16:22:24 -08001322
Calin Juravle13439f02017-02-21 01:17:21 -08001323 // Check if the receiver is in the boot class path or if it's in the
1324 // same class loader as the caller. If not, skip it, as there is not
1325 // much we can do during AOT.
1326 if (!cls->IsBootStrapClassLoaded() &&
1327 caller->GetClassLoader() != cls->GetClassLoader()) {
1328 is_missing_types = true;
1329 continue;
1330 }
1331
Calin Juravle4ca70a32017-02-21 16:22:24 -08001332 const DexFile* class_dex_file = nullptr;
1333 dex::TypeIndex type_index;
1334
1335 if (cls->GetDexCache() == nullptr) {
1336 DCHECK(cls->IsArrayClass()) << cls->PrettyClass();
Calin Juravlee21806f2017-02-22 11:49:43 -08001337 // Make a best effort to find the type index in the method's dex file.
1338 // We could search all open dex files but that might turn expensive
1339 // and probably not worth it.
Calin Juravle4ca70a32017-02-21 16:22:24 -08001340 class_dex_file = dex_file;
1341 type_index = cls->FindTypeIndexInOtherDexFile(*dex_file);
1342 } else {
1343 class_dex_file = &(cls->GetDexFile());
1344 type_index = cls->GetDexTypeIndex();
1345 }
1346 if (!type_index.IsValid()) {
1347 // Could be a proxy class or an array for which we couldn't find the type index.
Calin Juravle589e71e2017-03-03 16:05:05 -08001348 is_missing_types = true;
Calin Juravle4ca70a32017-02-21 16:22:24 -08001349 continue;
1350 }
1351 if (ContainsElement(dex_base_locations, class_dex_file->GetBaseLocation())) {
Calin Juravle940eb0c2017-01-30 19:30:44 -08001352 // Only consider classes from the same apk (including multidex).
1353 profile_classes.emplace_back(/*ProfileMethodInfo::ProfileClassReference*/
Calin Juravle4ca70a32017-02-21 16:22:24 -08001354 class_dex_file, type_index);
Calin Juravle589e71e2017-03-03 16:05:05 -08001355 } else {
1356 is_missing_types = true;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001357 }
1358 }
1359 if (!profile_classes.empty()) {
1360 inline_caches.emplace_back(/*ProfileMethodInfo::ProfileInlineCache*/
Calin Juravle589e71e2017-03-03 16:05:05 -08001361 cache.dex_pc_, is_missing_types, profile_classes);
Calin Juravle940eb0c2017-01-30 19:30:44 -08001362 }
1363 }
1364 methods.emplace_back(/*ProfileMethodInfo*/
1365 dex_file, method->GetDexMethodIndex(), inline_caches);
Calin Juravle31f2c152015-10-23 17:56:15 +01001366 }
1367}
1368
Calin Juravle4d77b6a2015-12-01 18:38:09 +00001369uint64_t JitCodeCache::GetLastUpdateTimeNs() const {
1370 return last_update_time_ns_.LoadAcquire();
Calin Juravle31f2c152015-10-23 17:56:15 +01001371}
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001372
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +01001373bool JitCodeCache::IsOsrCompiled(ArtMethod* method) {
1374 MutexLock mu(Thread::Current(), lock_);
1375 return osr_code_map_.find(method) != osr_code_map_.end();
1376}
1377
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001378bool JitCodeCache::NotifyCompilationOf(ArtMethod* method, Thread* self, bool osr) {
1379 if (!osr && ContainsPc(method->GetEntryPointFromQuickCompiledCode())) {
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001380 return false;
1381 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00001382
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00001383 MutexLock mu(self, lock_);
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001384 if (osr && (osr_code_map_.find(method) != osr_code_map_.end())) {
1385 return false;
1386 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001387
Andreas Gampe542451c2016-07-26 09:02:02 -07001388 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001389 if (info == nullptr) {
David Sehr709b0702016-10-13 09:12:37 -07001390 VLOG(jit) << method->PrettyMethod() << " needs a ProfilingInfo to be compiled";
Jeff Hao00286db2017-05-30 16:53:07 -07001391 // Because the counter is not atomic, there are some rare cases where we may not hit the
1392 // threshold for creating the ProfilingInfo. Reset the counter now to "correct" this.
Mathieu Chartierf044c222017-05-31 15:27:54 -07001393 ClearMethodCounter(method, /*was_warm*/ false);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001394 return false;
1395 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001396
buzbee454b3b62016-04-07 14:42:47 -07001397 if (info->IsMethodBeingCompiled(osr)) {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001398 return false;
1399 }
1400
buzbee454b3b62016-04-07 14:42:47 -07001401 info->SetIsMethodBeingCompiled(true, osr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001402 return true;
1403}
1404
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001405ProfilingInfo* JitCodeCache::NotifyCompilerUse(ArtMethod* method, Thread* self) {
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001406 MutexLock mu(self, lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -07001407 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001408 if (info != nullptr) {
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +00001409 if (!info->IncrementInlineUse()) {
1410 // Overflow of inlining uses, just bail.
1411 return nullptr;
1412 }
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001413 }
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001414 return info;
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001415}
1416
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001417void JitCodeCache::DoneCompilerUse(ArtMethod* method, Thread* self) {
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001418 MutexLock mu(self, lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -07001419 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001420 DCHECK(info != nullptr);
1421 info->DecrementInlineUse();
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001422}
1423
buzbee454b3b62016-04-07 14:42:47 -07001424void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self ATTRIBUTE_UNUSED, bool osr) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001425 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
buzbee454b3b62016-04-07 14:42:47 -07001426 DCHECK(info->IsMethodBeingCompiled(osr));
1427 info->SetIsMethodBeingCompiled(false, osr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001428}
1429
Nicolas Geoffraya25dce92016-01-12 16:41:10 +00001430size_t JitCodeCache::GetMemorySizeOfCodePointer(const void* ptr) {
1431 MutexLock mu(Thread::Current(), lock_);
1432 return mspace_usable_size(reinterpret_cast<const void*>(FromCodeToAllocation(ptr)));
1433}
1434
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001435void JitCodeCache::InvalidateCompiledCodeFor(ArtMethod* method,
1436 const OatQuickMethodHeader* header) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001437 ProfilingInfo* profiling_info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001438 if ((profiling_info != nullptr) &&
1439 (profiling_info->GetSavedEntryPoint() == header->GetEntryPoint())) {
1440 // Prevent future uses of the compiled code.
1441 profiling_info->SetSavedEntryPoint(nullptr);
1442 }
1443
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001444 if (method->GetEntryPointFromQuickCompiledCode() == header->GetEntryPoint()) {
Jeff Hao00286db2017-05-30 16:53:07 -07001445 // The entrypoint is the one to invalidate, so we just update it to the interpreter entry point
Mathieu Chartierf044c222017-05-31 15:27:54 -07001446 // and clear the counter to get the method Jitted again.
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001447 Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
1448 method, GetQuickToInterpreterBridge());
Mathieu Chartierf044c222017-05-31 15:27:54 -07001449 ClearMethodCounter(method, /*was_warm*/ profiling_info != nullptr);
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001450 } else {
1451 MutexLock mu(Thread::Current(), lock_);
1452 auto it = osr_code_map_.find(method);
1453 if (it != osr_code_map_.end() && OatQuickMethodHeader::FromCodePointer(it->second) == header) {
1454 // Remove the OSR method, to avoid using it again.
1455 osr_code_map_.erase(it);
1456 }
1457 }
1458}
1459
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001460uint8_t* JitCodeCache::AllocateCode(size_t code_size) {
1461 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
1462 uint8_t* result = reinterpret_cast<uint8_t*>(
1463 mspace_memalign(code_mspace_, alignment, code_size));
1464 size_t header_size = RoundUp(sizeof(OatQuickMethodHeader), alignment);
1465 // Ensure the header ends up at expected instruction alignment.
1466 DCHECK_ALIGNED_PARAM(reinterpret_cast<uintptr_t>(result + header_size), alignment);
1467 used_memory_for_code_ += mspace_usable_size(result);
1468 return result;
1469}
1470
1471void JitCodeCache::FreeCode(uint8_t* code) {
1472 used_memory_for_code_ -= mspace_usable_size(code);
1473 mspace_free(code_mspace_, code);
1474}
1475
1476uint8_t* JitCodeCache::AllocateData(size_t data_size) {
1477 void* result = mspace_malloc(data_mspace_, data_size);
1478 used_memory_for_data_ += mspace_usable_size(result);
1479 return reinterpret_cast<uint8_t*>(result);
1480}
1481
1482void JitCodeCache::FreeData(uint8_t* data) {
1483 used_memory_for_data_ -= mspace_usable_size(data);
1484 mspace_free(data_mspace_, data);
1485}
1486
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001487void JitCodeCache::Dump(std::ostream& os) {
1488 MutexLock mu(Thread::Current(), lock_);
1489 os << "Current JIT code cache size: " << PrettySize(used_memory_for_code_) << "\n"
1490 << "Current JIT data cache size: " << PrettySize(used_memory_for_data_) << "\n"
1491 << "Current JIT capacity: " << PrettySize(current_capacity_) << "\n"
1492 << "Current number of JIT code cache entries: " << method_code_map_.size() << "\n"
1493 << "Total number of JIT compilations: " << number_of_compilations_ << "\n"
1494 << "Total number of JIT compilations for on stack replacement: "
1495 << number_of_osr_compilations_ << "\n"
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001496 << "Total number of JIT code cache collections: " << number_of_collections_ << std::endl;
Nicolas Geoffray933330a2016-03-16 14:20:06 +00001497 histogram_stack_map_memory_use_.PrintMemoryUse(os);
1498 histogram_code_memory_use_.PrintMemoryUse(os);
1499 histogram_profiling_info_memory_use_.PrintMemoryUse(os);
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001500}
1501
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001502} // namespace jit
1503} // namespace art