blob: fdac24e5a06efde497ad75435cf4633a5dae79fa [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"
Mathieu Chartier0795f232016-09-27 18:43:30 -070037#include "scoped_thread_state_change-inl.h"
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +010038#include "thread_list.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080039
40namespace art {
41namespace jit {
42
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010043static constexpr int kProtAll = PROT_READ | PROT_WRITE | PROT_EXEC;
44static constexpr int kProtData = PROT_READ | PROT_WRITE;
45static constexpr int kProtCode = PROT_READ | PROT_EXEC;
46
Nicolas Geoffray933330a2016-03-16 14:20:06 +000047static constexpr size_t kCodeSizeLogThreshold = 50 * KB;
48static constexpr size_t kStackMapSizeLogThreshold = 50 * KB;
49
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010050#define CHECKED_MPROTECT(memory, size, prot) \
51 do { \
52 int rc = mprotect(memory, size, prot); \
53 if (UNLIKELY(rc != 0)) { \
54 errno = rc; \
55 PLOG(FATAL) << "Failed to mprotect jit code cache"; \
56 } \
57 } while (false) \
58
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000059JitCodeCache* JitCodeCache::Create(size_t initial_capacity,
60 size_t max_capacity,
Nicolas Geoffraya25dce92016-01-12 16:41:10 +000061 bool generate_debug_info,
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000062 std::string* error_msg) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -080063 ScopedTrace trace(__PRETTY_FUNCTION__);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000064 CHECK_GE(max_capacity, initial_capacity);
Nicolas Geoffraya25dce92016-01-12 16:41:10 +000065
66 // Generating debug information is mostly for using the 'perf' tool, which does
67 // not work with ashmem.
68 bool use_ashmem = !generate_debug_info;
69 // With 'perf', we want a 1-1 mapping between an address and a method.
70 bool garbage_collect_code = !generate_debug_info;
71
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000072 // We need to have 32 bit offsets from method headers in code cache which point to things
73 // in the data cache. If the maps are more than 4G apart, having multiple maps wouldn't work.
74 // Ensure we're below 1 GB to be safe.
75 if (max_capacity > 1 * GB) {
76 std::ostringstream oss;
77 oss << "Maxium code cache capacity is limited to 1 GB, "
78 << PrettySize(max_capacity) << " is too big";
79 *error_msg = oss.str();
80 return nullptr;
81 }
82
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080083 std::string error_str;
84 // Map name specific for android_os_Debug.cpp accounting.
Nicolas Geoffray132d8362016-11-16 09:19:42 +000085 // Map in low 4gb to simplify accessing root tables for x86_64.
86 // We could do PC-relative addressing to avoid this problem, but that
87 // would require reserving code and data area before submitting, which
88 // means more windows for the code memory to be RWX.
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010089 MemMap* data_map = MemMap::MapAnonymous(
Nicolas Geoffray132d8362016-11-16 09:19:42 +000090 "data-code-cache", nullptr,
91 max_capacity,
92 kProtAll,
93 /* low_4gb */ true,
94 /* reuse */ false,
95 &error_str,
96 use_ashmem);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +010097 if (data_map == nullptr) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080098 std::ostringstream oss;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +000099 oss << "Failed to create read write execute cache: " << error_str << " size=" << max_capacity;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800100 *error_msg = oss.str();
101 return nullptr;
102 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100103
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000104 // Align both capacities to page size, as that's the unit mspaces use.
105 initial_capacity = RoundDown(initial_capacity, 2 * kPageSize);
106 max_capacity = RoundDown(max_capacity, 2 * kPageSize);
107
Nicolas Geoffray4e915fb2015-10-28 17:39:47 +0000108 // Data cache is 1 / 2 of the map.
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100109 // TODO: Make this variable?
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000110 size_t data_size = max_capacity / 2;
111 size_t code_size = max_capacity - data_size;
112 DCHECK_EQ(code_size + data_size, max_capacity);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100113 uint8_t* divider = data_map->Begin() + data_size;
114
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000115 MemMap* code_map =
116 data_map->RemapAtEnd(divider, "jit-code-cache", kProtAll, &error_str, use_ashmem);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100117 if (code_map == nullptr) {
118 std::ostringstream oss;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000119 oss << "Failed to create read write execute cache: " << error_str << " size=" << max_capacity;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100120 *error_msg = oss.str();
121 return nullptr;
122 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100123 DCHECK_EQ(code_map->Begin(), divider);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000124 data_size = initial_capacity / 2;
125 code_size = initial_capacity - data_size;
126 DCHECK_EQ(code_size + data_size, initial_capacity);
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000127 return new JitCodeCache(
Nicolas Geoffrayc3fec4c2016-01-14 16:16:35 +0000128 code_map, data_map, code_size, data_size, max_capacity, garbage_collect_code);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800129}
130
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000131JitCodeCache::JitCodeCache(MemMap* code_map,
132 MemMap* data_map,
133 size_t initial_code_capacity,
134 size_t initial_data_capacity,
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000135 size_t max_capacity,
136 bool garbage_collect_code)
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100137 : lock_("Jit code cache", kJitCodeCacheLock),
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000138 lock_cond_("Jit code cache condition variable", lock_),
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100139 collection_in_progress_(false),
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100140 code_map_(code_map),
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000141 data_map_(data_map),
142 max_capacity_(max_capacity),
143 current_capacity_(initial_code_capacity + initial_data_capacity),
144 code_end_(initial_code_capacity),
145 data_end_(initial_data_capacity),
Nicolas Geoffray35122442016-03-02 12:05:30 +0000146 last_collection_increased_code_cache_(false),
Nicolas Geoffraya25dce92016-01-12 16:41:10 +0000147 last_update_time_ns_(0),
Nicolas Geoffray0a522232016-01-19 09:34:58 +0000148 garbage_collect_code_(garbage_collect_code),
Nicolas Geoffrayb0d22082016-02-24 17:18:25 +0000149 used_memory_for_data_(0),
150 used_memory_for_code_(0),
Nicolas Geoffrayfcdd7292016-02-25 13:27:47 +0000151 number_of_compilations_(0),
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000152 number_of_osr_compilations_(0),
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000153 number_of_collections_(0),
154 histogram_stack_map_memory_use_("Memory used for stack maps", 16),
155 histogram_code_memory_use_("Memory used for compiled code", 16),
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000156 histogram_profiling_info_memory_use_("Memory used for profiling info", 16),
157 is_weak_access_enabled_(true),
158 inline_cache_cond_("Jit inline cache condition variable", lock_) {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100159
Nicolas Geoffrayc3fec4c2016-01-14 16:16:35 +0000160 DCHECK_GE(max_capacity, initial_code_capacity + initial_data_capacity);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000161 code_mspace_ = create_mspace_with_base(code_map_->Begin(), code_end_, false /*locked*/);
162 data_mspace_ = create_mspace_with_base(data_map_->Begin(), data_end_, false /*locked*/);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100163
164 if (code_mspace_ == nullptr || data_mspace_ == nullptr) {
165 PLOG(FATAL) << "create_mspace_with_base failed";
166 }
167
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000168 SetFootprintLimit(current_capacity_);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100169
170 CHECKED_MPROTECT(code_map_->Begin(), code_map_->Size(), kProtCode);
171 CHECKED_MPROTECT(data_map_->Begin(), data_map_->Size(), kProtData);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100172
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000173 VLOG(jit) << "Created jit code cache: initial data size="
174 << PrettySize(initial_data_capacity)
175 << ", initial code size="
176 << PrettySize(initial_code_capacity);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800177}
178
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100179bool JitCodeCache::ContainsPc(const void* ptr) const {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100180 return code_map_->Begin() <= ptr && ptr < code_map_->End();
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800181}
182
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000183bool JitCodeCache::ContainsMethod(ArtMethod* method) {
184 MutexLock mu(Thread::Current(), lock_);
185 for (auto& it : method_code_map_) {
186 if (it.second == method) {
187 return true;
188 }
189 }
190 return false;
191}
192
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800193class ScopedCodeCacheWrite : ScopedTrace {
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100194 public:
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100195 explicit ScopedCodeCacheWrite(MemMap* code_map, bool only_for_tlb_shootdown = false)
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800196 : ScopedTrace("ScopedCodeCacheWrite"),
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100197 code_map_(code_map),
198 only_for_tlb_shootdown_(only_for_tlb_shootdown) {
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800199 ScopedTrace trace("mprotect all");
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100200 CHECKED_MPROTECT(
201 code_map_->Begin(), only_for_tlb_shootdown_ ? kPageSize : code_map_->Size(), kProtAll);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800202 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100203 ~ScopedCodeCacheWrite() {
Mathieu Chartier33fbf372016-03-07 13:48:08 -0800204 ScopedTrace trace("mprotect code");
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100205 CHECKED_MPROTECT(
206 code_map_->Begin(), only_for_tlb_shootdown_ ? kPageSize : code_map_->Size(), kProtCode);
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100207 }
208 private:
209 MemMap* const code_map_;
210
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100211 // If we're using ScopedCacheWrite only for TLB shootdown, we limit the scope of mprotect to
212 // one page.
213 const bool only_for_tlb_shootdown_;
214
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100215 DISALLOW_COPY_AND_ASSIGN(ScopedCodeCacheWrite);
216};
217
218uint8_t* JitCodeCache::CommitCode(Thread* self,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100219 ArtMethod* method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000220 uint8_t* stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700221 uint8_t* method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000222 uint8_t* roots_data,
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100223 size_t frame_size_in_bytes,
224 size_t core_spill_mask,
225 size_t fp_spill_mask,
226 const uint8_t* code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000227 size_t code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000228 size_t data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000229 bool osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700230 Handle<mirror::ObjectArray<mirror::Object>> roots,
231 bool has_should_deoptimize_flag,
232 const ArenaSet<ArtMethod*>& cha_single_implementation_list) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100233 uint8_t* result = CommitCodeInternal(self,
234 method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000235 stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700236 method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000237 roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100238 frame_size_in_bytes,
239 core_spill_mask,
240 fp_spill_mask,
241 code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000242 code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000243 data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000244 osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700245 roots,
246 has_should_deoptimize_flag,
247 cha_single_implementation_list);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100248 if (result == nullptr) {
249 // Retry.
250 GarbageCollectCache(self);
251 result = CommitCodeInternal(self,
252 method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000253 stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700254 method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000255 roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100256 frame_size_in_bytes,
257 core_spill_mask,
258 fp_spill_mask,
259 code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000260 code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000261 data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000262 osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700263 roots,
264 has_should_deoptimize_flag,
265 cha_single_implementation_list);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100266 }
267 return result;
268}
269
270bool JitCodeCache::WaitForPotentialCollectionToComplete(Thread* self) {
271 bool in_collection = false;
272 while (collection_in_progress_) {
273 in_collection = true;
274 lock_cond_.Wait(self);
275 }
276 return in_collection;
277}
278
279static uintptr_t FromCodeToAllocation(const void* code) {
280 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
281 return reinterpret_cast<uintptr_t>(code) - RoundUp(sizeof(OatQuickMethodHeader), alignment);
282}
283
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000284static uint32_t ComputeRootTableSize(uint32_t number_of_roots) {
285 return sizeof(uint32_t) + number_of_roots * sizeof(GcRoot<mirror::Object>);
286}
287
288static uint32_t GetNumberOfRoots(const uint8_t* stack_map) {
289 // The length of the table is stored just before the stack map (and therefore at the end of
290 // the table itself), in order to be able to fetch it from a `stack_map` pointer.
291 return reinterpret_cast<const uint32_t*>(stack_map)[-1];
292}
293
Mathieu Chartier7a704be2016-11-22 13:24:40 -0800294static void FillRootTableLength(uint8_t* roots_data, uint32_t length) {
295 // Store the length of the table at the end. This will allow fetching it from a `stack_map`
296 // pointer.
297 reinterpret_cast<uint32_t*>(roots_data)[length] = length;
298}
299
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000300static const uint8_t* FromStackMapToRoots(const uint8_t* stack_map_data) {
301 return stack_map_data - ComputeRootTableSize(GetNumberOfRoots(stack_map_data));
302}
303
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000304static void FillRootTable(uint8_t* roots_data, Handle<mirror::ObjectArray<mirror::Object>> roots)
305 REQUIRES_SHARED(Locks::mutator_lock_) {
306 GcRoot<mirror::Object>* gc_roots = reinterpret_cast<GcRoot<mirror::Object>*>(roots_data);
Mathieu Chartier7a704be2016-11-22 13:24:40 -0800307 const uint32_t length = roots->GetLength();
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000308 // Put all roots in `roots_data`.
309 for (uint32_t i = 0; i < length; ++i) {
310 ObjPtr<mirror::Object> object = roots->Get(i);
311 if (kIsDebugBuild) {
312 // Ensure the string is strongly interned. b/32995596
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000313 if (object->IsString()) {
314 ObjPtr<mirror::String> str = reinterpret_cast<mirror::String*>(object.Ptr());
315 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
316 CHECK(class_linker->GetInternTable()->LookupStrong(Thread::Current(), str) != nullptr);
317 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000318 }
319 gc_roots[i] = GcRoot<mirror::Object>(object);
320 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000321}
322
323static uint8_t* GetRootTable(const void* code_ptr, uint32_t* number_of_roots = nullptr) {
324 OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
325 uint8_t* data = method_header->GetOptimizedCodeInfoPtr();
326 uint32_t roots = GetNumberOfRoots(data);
327 if (number_of_roots != nullptr) {
328 *number_of_roots = roots;
329 }
330 return data - ComputeRootTableSize(roots);
331}
332
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100333// Use a sentinel for marking entries in the JIT table that have been cleared.
334// This helps diagnosing in case the compiled code tries to wrongly access such
335// entries.
Andreas Gampe5629d2d2017-05-15 16:28:13 -0700336static mirror::Class* const weak_sentinel =
337 reinterpret_cast<mirror::Class*>(Context::kBadGprBase + 0xff);
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100338
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000339// Helper for the GC to process a weak class in a JIT root table.
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100340static inline void ProcessWeakClass(GcRoot<mirror::Class>* root_ptr,
341 IsMarkedVisitor* visitor,
342 mirror::Class* update)
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000343 REQUIRES_SHARED(Locks::mutator_lock_) {
344 // This does not need a read barrier because this is called by GC.
345 mirror::Class* cls = root_ptr->Read<kWithoutReadBarrier>();
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100346 if (cls != nullptr && cls != weak_sentinel) {
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000347 DCHECK((cls->IsClass<kDefaultVerifyFlags, kWithoutReadBarrier>()));
348 // Look at the classloader of the class to know if it has been unloaded.
349 // This does not need a read barrier because this is called by GC.
350 mirror::Object* class_loader =
351 cls->GetClassLoader<kDefaultVerifyFlags, kWithoutReadBarrier>();
352 if (class_loader == nullptr || visitor->IsMarked(class_loader) != nullptr) {
353 // The class loader is live, update the entry if the class has moved.
354 mirror::Class* new_cls = down_cast<mirror::Class*>(visitor->IsMarked(cls));
355 // Note that new_object can be null for CMS and newly allocated objects.
356 if (new_cls != nullptr && new_cls != cls) {
357 *root_ptr = GcRoot<mirror::Class>(new_cls);
358 }
359 } else {
360 // The class loader is not live, clear the entry.
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100361 *root_ptr = GcRoot<mirror::Class>(update);
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000362 }
363 }
364}
365
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000366void JitCodeCache::SweepRootTables(IsMarkedVisitor* visitor) {
367 MutexLock mu(Thread::Current(), lock_);
368 for (const auto& entry : method_code_map_) {
369 uint32_t number_of_roots = 0;
370 uint8_t* roots_data = GetRootTable(entry.first, &number_of_roots);
371 GcRoot<mirror::Object>* roots = reinterpret_cast<GcRoot<mirror::Object>*>(roots_data);
372 for (uint32_t i = 0; i < number_of_roots; ++i) {
373 // This does not need a read barrier because this is called by GC.
374 mirror::Object* object = roots[i].Read<kWithoutReadBarrier>();
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100375 if (object == nullptr || object == weak_sentinel) {
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000376 // entry got deleted in a previous sweep.
377 } else if (object->IsString<kDefaultVerifyFlags, kWithoutReadBarrier>()) {
378 mirror::Object* new_object = visitor->IsMarked(object);
379 // We know the string is marked because it's a strongly-interned string that
380 // is always alive. The IsMarked implementation of the CMS collector returns
381 // null for newly allocated objects, but we know those haven't moved. Therefore,
382 // only update the entry if we get a different non-null string.
383 // TODO: Do not use IsMarked for j.l.Class, and adjust once we move this method
384 // out of the weak access/creation pause. b/32167580
385 if (new_object != nullptr && new_object != object) {
386 DCHECK(new_object->IsString());
387 roots[i] = GcRoot<mirror::Object>(new_object);
388 }
389 } else {
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100390 ProcessWeakClass(
391 reinterpret_cast<GcRoot<mirror::Class>*>(&roots[i]), visitor, weak_sentinel);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000392 }
393 }
394 }
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000395 // Walk over inline caches to clear entries containing unloaded classes.
396 for (ProfilingInfo* info : profiling_infos_) {
397 for (size_t i = 0; i < info->number_of_inline_caches_; ++i) {
398 InlineCache* cache = &info->cache_[i];
399 for (size_t j = 0; j < InlineCache::kIndividualCacheSize; ++j) {
Nicolas Geoffray6ca115b2017-05-10 15:09:35 +0100400 ProcessWeakClass(&cache->classes_[j], visitor, nullptr);
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000401 }
402 }
403 }
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000404}
405
Mingyao Yang063fc772016-08-02 11:02:54 -0700406void JitCodeCache::FreeCode(const void* code_ptr) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100407 uintptr_t allocation = FromCodeToAllocation(code_ptr);
David Srbecky5cc349f2015-12-18 15:04:48 +0000408 // Notify native debugger that we are about to remove the code.
409 // It does nothing if we are not using native debugger.
410 DeleteJITCodeEntryForAddress(reinterpret_cast<uintptr_t>(code_ptr));
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000411 FreeData(GetRootTable(code_ptr));
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000412 FreeCode(reinterpret_cast<uint8_t*>(allocation));
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100413}
414
Mingyao Yang063fc772016-08-02 11:02:54 -0700415void JitCodeCache::FreeAllMethodHeaders(
416 const std::unordered_set<OatQuickMethodHeader*>& method_headers) {
417 {
418 MutexLock mu(Thread::Current(), *Locks::cha_lock_);
419 Runtime::Current()->GetClassHierarchyAnalysis()
420 ->RemoveDependentsWithMethodHeaders(method_headers);
421 }
422
423 // We need to remove entries in method_headers from CHA dependencies
424 // first since once we do FreeCode() below, the memory can be reused
425 // so it's possible for the same method_header to start representing
426 // different compile code.
427 MutexLock mu(Thread::Current(), lock_);
428 ScopedCodeCacheWrite scc(code_map_.get());
429 for (const OatQuickMethodHeader* method_header : method_headers) {
430 FreeCode(method_header->GetCode());
431 }
432}
433
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100434void JitCodeCache::RemoveMethodsIn(Thread* self, const LinearAlloc& alloc) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800435 ScopedTrace trace(__PRETTY_FUNCTION__);
Mingyao Yang063fc772016-08-02 11:02:54 -0700436 // We use a set to first collect all method_headers whose code need to be
437 // removed. We need to free the underlying code after we remove CHA dependencies
438 // for entries in this set. And it's more efficient to iterate through
439 // the CHA dependency map just once with an unordered_set.
440 std::unordered_set<OatQuickMethodHeader*> method_headers;
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000441 {
Mingyao Yang063fc772016-08-02 11:02:54 -0700442 MutexLock mu(self, lock_);
443 // We do not check if a code cache GC is in progress, as this method comes
444 // with the classlinker_classes_lock_ held, and suspending ourselves could
445 // lead to a deadlock.
446 {
447 ScopedCodeCacheWrite scc(code_map_.get());
448 for (auto it = method_code_map_.begin(); it != method_code_map_.end();) {
449 if (alloc.ContainsUnsafe(it->second)) {
450 method_headers.insert(OatQuickMethodHeader::FromCodePointer(it->first));
451 it = method_code_map_.erase(it);
452 } else {
453 ++it;
454 }
455 }
456 }
457 for (auto it = osr_code_map_.begin(); it != osr_code_map_.end();) {
458 if (alloc.ContainsUnsafe(it->first)) {
459 // Note that the code has already been pushed to method_headers in the loop
460 // above and is going to be removed in FreeCode() below.
461 it = osr_code_map_.erase(it);
462 } else {
463 ++it;
464 }
465 }
466 for (auto it = profiling_infos_.begin(); it != profiling_infos_.end();) {
467 ProfilingInfo* info = *it;
468 if (alloc.ContainsUnsafe(info->GetMethod())) {
469 info->GetMethod()->SetProfilingInfo(nullptr);
470 FreeData(reinterpret_cast<uint8_t*>(info));
471 it = profiling_infos_.erase(it);
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000472 } else {
473 ++it;
474 }
475 }
476 }
Mingyao Yang063fc772016-08-02 11:02:54 -0700477 FreeAllMethodHeaders(method_headers);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100478}
479
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000480bool JitCodeCache::IsWeakAccessEnabled(Thread* self) const {
481 return kUseReadBarrier
482 ? self->GetWeakRefAccessEnabled()
483 : is_weak_access_enabled_.LoadSequentiallyConsistent();
484}
485
486void JitCodeCache::WaitUntilInlineCacheAccessible(Thread* self) {
487 if (IsWeakAccessEnabled(self)) {
488 return;
489 }
490 ScopedThreadSuspension sts(self, kWaitingWeakGcRootRead);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +0000491 MutexLock mu(self, lock_);
Nicolas Geoffraye51ca8b2016-11-22 14:49:31 +0000492 while (!IsWeakAccessEnabled(self)) {
493 inline_cache_cond_.Wait(self);
494 }
495}
496
497void JitCodeCache::BroadcastForInlineCacheAccess() {
498 Thread* self = Thread::Current();
499 MutexLock mu(self, lock_);
500 inline_cache_cond_.Broadcast(self);
501}
502
503void JitCodeCache::AllowInlineCacheAccess() {
504 DCHECK(!kUseReadBarrier);
505 is_weak_access_enabled_.StoreSequentiallyConsistent(true);
506 BroadcastForInlineCacheAccess();
507}
508
509void JitCodeCache::DisallowInlineCacheAccess() {
510 DCHECK(!kUseReadBarrier);
511 is_weak_access_enabled_.StoreSequentiallyConsistent(false);
512}
513
514void JitCodeCache::CopyInlineCacheInto(const InlineCache& ic,
515 Handle<mirror::ObjectArray<mirror::Class>> array) {
516 WaitUntilInlineCacheAccessible(Thread::Current());
517 // Note that we don't need to lock `lock_` here, the compiler calling
518 // this method has already ensured the inline cache will not be deleted.
519 for (size_t in_cache = 0, in_array = 0;
520 in_cache < InlineCache::kIndividualCacheSize;
521 ++in_cache) {
522 mirror::Class* object = ic.classes_[in_cache].Read();
523 if (object != nullptr) {
524 array->Set(in_array++, object);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +0000525 }
526 }
527}
528
Mathieu Chartierf044c222017-05-31 15:27:54 -0700529static void ClearMethodCounter(ArtMethod* method, bool was_warm) {
530 if (was_warm) {
531 method->AddAccessFlags(kAccPreviouslyWarm);
532 }
533 // We reset the counter to 1 so that the profile knows that the method was executed at least once.
534 // This is required for layout purposes.
535 method->SetCounter(1);
536}
537
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100538uint8_t* JitCodeCache::CommitCodeInternal(Thread* self,
539 ArtMethod* method,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000540 uint8_t* stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700541 uint8_t* method_info,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000542 uint8_t* roots_data,
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100543 size_t frame_size_in_bytes,
544 size_t core_spill_mask,
545 size_t fp_spill_mask,
546 const uint8_t* code,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000547 size_t code_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000548 size_t data_size,
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000549 bool osr,
Mingyao Yang063fc772016-08-02 11:02:54 -0700550 Handle<mirror::ObjectArray<mirror::Object>> roots,
551 bool has_should_deoptimize_flag,
552 const ArenaSet<ArtMethod*>&
553 cha_single_implementation_list) {
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000554 DCHECK(stack_map != nullptr);
Nicolas Geoffray1e7de6c2015-10-21 12:07:31 +0100555 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
556 // Ensure the header ends up at expected instruction alignment.
557 size_t header_size = RoundUp(sizeof(OatQuickMethodHeader), alignment);
558 size_t total_size = header_size + code_size;
559
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100560 OatQuickMethodHeader* method_header = nullptr;
Nicolas Geoffray1e7de6c2015-10-21 12:07:31 +0100561 uint8_t* code_ptr = nullptr;
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000562 uint8_t* memory = nullptr;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100563 {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000564 ScopedThreadSuspension sts(self, kSuspended);
565 MutexLock mu(self, lock_);
566 WaitForPotentialCollectionToComplete(self);
567 {
568 ScopedCodeCacheWrite scc(code_map_.get());
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000569 memory = AllocateCode(total_size);
570 if (memory == nullptr) {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000571 return nullptr;
572 }
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000573 code_ptr = memory + header_size;
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000574
575 std::copy(code, code + code_size, code_ptr);
576 method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
577 new (method_header) OatQuickMethodHeader(
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000578 code_ptr - stack_map,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700579 code_ptr - method_info,
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000580 frame_size_in_bytes,
581 core_spill_mask,
582 fp_spill_mask,
583 code_size);
Kevin Brodskyb93ce182016-12-15 14:23:09 +0000584 // Flush caches before we remove write permission because some ARMv8 Qualcomm kernels may
585 // trigger a segfault if a page fault occurs when requesting a cache maintenance operation.
586 // This is a kernel bug that we need to work around until affected devices (e.g. Nexus 5X and
587 // 6P) stop being supported or their kernels are fixed.
Artem Udovichenkob18a6692016-11-17 10:51:58 +0300588 //
Kevin Brodskyb93ce182016-12-15 14:23:09 +0000589 // For reference, this behavior is caused by this commit:
590 // https://android.googlesource.com/kernel/msm/+/3fbe6bc28a6b9939d0650f2f17eb5216c719950c
Artem Udovichenkob18a6692016-11-17 10:51:58 +0300591 FlushInstructionCache(reinterpret_cast<char*>(code_ptr),
592 reinterpret_cast<char*>(code_ptr + code_size));
Mingyao Yang063fc772016-08-02 11:02:54 -0700593 DCHECK(!Runtime::Current()->IsAotCompiler());
594 if (has_should_deoptimize_flag) {
595 method_header->SetHasShouldDeoptimizeFlag();
596 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100597 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100598
Nicolas Geoffray0a522232016-01-19 09:34:58 +0000599 number_of_compilations_++;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100600 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000601 // We need to update the entry point in the runnable state for the instrumentation.
602 {
Mingyao Yang063fc772016-08-02 11:02:54 -0700603 // Need cha_lock_ for checking all single-implementation flags and register
604 // dependencies.
605 MutexLock cha_mu(self, *Locks::cha_lock_);
606 bool single_impl_still_valid = true;
607 for (ArtMethod* single_impl : cha_single_implementation_list) {
608 if (!single_impl->HasSingleImplementation()) {
Jeff Hao00286db2017-05-30 16:53:07 -0700609 // Simply discard the compiled code. Clear the counter so that it may be recompiled later.
610 // Hopefully the class hierarchy will be more stable when compilation is retried.
Mingyao Yang063fc772016-08-02 11:02:54 -0700611 single_impl_still_valid = false;
Mathieu Chartierf044c222017-05-31 15:27:54 -0700612 ClearMethodCounter(method, /*was_warm*/ false);
Mingyao Yang063fc772016-08-02 11:02:54 -0700613 break;
614 }
615 }
616
617 // Discard the code if any single-implementation assumptions are now invalid.
618 if (!single_impl_still_valid) {
619 VLOG(jit) << "JIT discarded jitted code due to invalid single-implementation assumptions.";
620 return nullptr;
621 }
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000622 DCHECK(cha_single_implementation_list.empty() || !Runtime::Current()->IsJavaDebuggable())
Alex Lightdba61482016-12-21 08:20:29 -0800623 << "Should not be using cha on debuggable apps/runs!";
624
Mingyao Yang063fc772016-08-02 11:02:54 -0700625 for (ArtMethod* single_impl : cha_single_implementation_list) {
626 Runtime::Current()->GetClassHierarchyAnalysis()->AddDependency(
627 single_impl, method, method_header);
628 }
629
630 // The following needs to be guarded by cha_lock_ also. Otherwise it's
631 // possible that the compiled code is considered invalidated by some class linking,
632 // but below we still make the compiled code valid for the method.
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000633 MutexLock mu(self, lock_);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000634 // Fill the root table before updating the entry point.
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000635 DCHECK_EQ(FromStackMapToRoots(stack_map), roots_data);
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100636 DCHECK_LE(roots_data, stack_map);
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000637 FillRootTable(roots_data, roots);
Nicolas Geoffray352b17a2017-05-25 12:54:31 +0100638 {
639 // Flush data cache, as compiled code references literals in it.
640 // We also need a TLB shootdown to act as memory barrier across cores.
641 ScopedCodeCacheWrite ccw(code_map_.get(), /* only_for_tlb_shootdown */ true);
642 FlushDataCache(reinterpret_cast<char*>(roots_data),
643 reinterpret_cast<char*>(roots_data + data_size));
644 }
645 method_code_map_.Put(code_ptr, method);
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000646 if (osr) {
Nicolas Geoffrayfcdd7292016-02-25 13:27:47 +0000647 number_of_osr_compilations_++;
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000648 osr_code_map_.Put(method, code_ptr);
Nicolas Geoffray480d5102016-04-18 12:09:30 +0100649 } else {
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000650 Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
651 method, method_header->GetEntryPoint());
652 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000653 if (collection_in_progress_) {
654 // We need to update the live bitmap if there is a GC to ensure it sees this new
655 // code.
656 GetLiveBitmap()->AtomicTestAndSet(FromCodeToAllocation(code_ptr));
657 }
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000658 last_update_time_ns_.StoreRelease(NanoTime());
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000659 VLOG(jit)
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100660 << "JIT added (osr=" << std::boolalpha << osr << std::noboolalpha << ") "
David Sehr709b0702016-10-13 09:12:37 -0700661 << ArtMethod::PrettyMethod(method) << "@" << method
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000662 << " ccache_size=" << PrettySize(CodeCacheSizeLocked()) << ": "
663 << " dcache_size=" << PrettySize(DataCacheSizeLocked()) << ": "
664 << reinterpret_cast<const void*>(method_header->GetEntryPoint()) << ","
Mingyao Yang063fc772016-08-02 11:02:54 -0700665 << reinterpret_cast<const void*>(method_header->GetEntryPoint() +
666 method_header->GetCodeSize());
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000667 histogram_code_memory_use_.AddValue(code_size);
668 if (code_size > kCodeSizeLogThreshold) {
669 LOG(INFO) << "JIT allocated "
670 << PrettySize(code_size)
671 << " for compiled code of "
David Sehr709b0702016-10-13 09:12:37 -0700672 << ArtMethod::PrettyMethod(method);
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000673 }
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000674 }
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100675
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100676 return reinterpret_cast<uint8_t*>(method_header);
677}
678
679size_t JitCodeCache::CodeCacheSize() {
680 MutexLock mu(Thread::Current(), lock_);
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000681 return CodeCacheSizeLocked();
682}
683
Alex Lightdba61482016-12-21 08:20:29 -0800684// This notifies the code cache that the given method has been redefined and that it should remove
685// any cached information it has on the method. All threads must be suspended before calling this
686// method. The compiled code for the method (if there is any) must not be in any threads call stack.
687void JitCodeCache::NotifyMethodRedefined(ArtMethod* method) {
688 MutexLock mu(Thread::Current(), lock_);
689 if (method->IsNative()) {
690 return;
691 }
692 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
693 if (info != nullptr) {
694 auto profile = std::find(profiling_infos_.begin(), profiling_infos_.end(), info);
695 DCHECK(profile != profiling_infos_.end());
696 profiling_infos_.erase(profile);
697 }
698 method->SetProfilingInfo(nullptr);
699 ScopedCodeCacheWrite ccw(code_map_.get());
Andreas Gampe39e67382017-05-15 19:26:38 -0700700 for (auto code_iter = method_code_map_.begin(); code_iter != method_code_map_.end();) {
Alex Lightdba61482016-12-21 08:20:29 -0800701 if (code_iter->second == method) {
702 FreeCode(code_iter->first);
Andreas Gampe39e67382017-05-15 19:26:38 -0700703 code_iter = method_code_map_.erase(code_iter);
704 continue;
Alex Lightdba61482016-12-21 08:20:29 -0800705 }
Andreas Gampe39e67382017-05-15 19:26:38 -0700706 ++code_iter;
Alex Lightdba61482016-12-21 08:20:29 -0800707 }
708 auto code_map = osr_code_map_.find(method);
709 if (code_map != osr_code_map_.end()) {
710 osr_code_map_.erase(code_map);
711 }
712}
713
714// This invalidates old_method. Once this function returns one can no longer use old_method to
715// execute code unless it is fixed up. This fixup will happen later in the process of installing a
716// class redefinition.
717// TODO We should add some info to ArtMethod to note that 'old_method' has been invalidated and
718// shouldn't be used since it is no longer logically in the jit code cache.
719// TODO We should add DCHECKS that validate that the JIT is paused when this method is entered.
720void JitCodeCache::MoveObsoleteMethod(ArtMethod* old_method, ArtMethod* new_method) {
Alex Lighteee0bd42017-02-14 15:31:45 +0000721 // Native methods have no profiling info and need no special handling from the JIT code cache.
722 if (old_method->IsNative()) {
723 return;
724 }
Alex Lightdba61482016-12-21 08:20:29 -0800725 MutexLock mu(Thread::Current(), lock_);
726 // Update ProfilingInfo to the new one and remove it from the old_method.
727 if (old_method->GetProfilingInfo(kRuntimePointerSize) != nullptr) {
728 DCHECK_EQ(old_method->GetProfilingInfo(kRuntimePointerSize)->GetMethod(), old_method);
729 ProfilingInfo* info = old_method->GetProfilingInfo(kRuntimePointerSize);
730 old_method->SetProfilingInfo(nullptr);
731 // Since the JIT should be paused and all threads suspended by the time this is called these
732 // checks should always pass.
733 DCHECK(!info->IsInUseByCompiler());
734 new_method->SetProfilingInfo(info);
735 info->method_ = new_method;
736 }
737 // Update method_code_map_ to point to the new method.
738 for (auto& it : method_code_map_) {
739 if (it.second == old_method) {
740 it.second = new_method;
741 }
742 }
743 // Update osr_code_map_ to point to the new method.
744 auto code_map = osr_code_map_.find(old_method);
745 if (code_map != osr_code_map_.end()) {
746 osr_code_map_.Put(new_method, code_map->second);
747 osr_code_map_.erase(old_method);
748 }
749}
750
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000751size_t JitCodeCache::CodeCacheSizeLocked() {
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000752 return used_memory_for_code_;
Nicolas Geoffray0c3c2662015-10-15 13:53:04 +0100753}
754
755size_t JitCodeCache::DataCacheSize() {
756 MutexLock mu(Thread::Current(), lock_);
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000757 return DataCacheSizeLocked();
758}
759
760size_t JitCodeCache::DataCacheSizeLocked() {
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000761 return used_memory_for_data_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800762}
763
Nicolas Geoffrayf46501c2016-11-22 13:45:36 +0000764void JitCodeCache::ClearData(Thread* self,
765 uint8_t* stack_map_data,
766 uint8_t* roots_data) {
767 DCHECK_EQ(FromStackMapToRoots(stack_map_data), roots_data);
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000768 MutexLock mu(self, lock_);
Nicolas Geoffrayf46501c2016-11-22 13:45:36 +0000769 FreeData(reinterpret_cast<uint8_t*>(roots_data));
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000770}
771
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000772size_t JitCodeCache::ReserveData(Thread* self,
773 size_t stack_map_size,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700774 size_t method_info_size,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000775 size_t number_of_roots,
776 ArtMethod* method,
777 uint8_t** stack_map_data,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700778 uint8_t** method_info_data,
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000779 uint8_t** roots_data) {
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000780 size_t table_size = ComputeRootTableSize(number_of_roots);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700781 size_t size = RoundUp(stack_map_size + method_info_size + table_size, sizeof(void*));
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100782 uint8_t* result = nullptr;
783
784 {
785 ScopedThreadSuspension sts(self, kSuspended);
786 MutexLock mu(self, lock_);
787 WaitForPotentialCollectionToComplete(self);
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000788 result = AllocateData(size);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100789 }
790
791 if (result == nullptr) {
792 // Retry.
793 GarbageCollectCache(self);
794 ScopedThreadSuspension sts(self, kSuspended);
795 MutexLock mu(self, lock_);
796 WaitForPotentialCollectionToComplete(self);
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +0000797 result = AllocateData(size);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100798 }
799
Nicolas Geoffray933330a2016-03-16 14:20:06 +0000800 MutexLock mu(self, lock_);
801 histogram_stack_map_memory_use_.AddValue(size);
802 if (size > kStackMapSizeLogThreshold) {
803 LOG(INFO) << "JIT allocated "
804 << PrettySize(size)
805 << " for stack maps of "
David Sehr709b0702016-10-13 09:12:37 -0700806 << ArtMethod::PrettyMethod(method);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800807 }
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000808 if (result != nullptr) {
809 *roots_data = result;
810 *stack_map_data = result + table_size;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700811 *method_info_data = *stack_map_data + stack_map_size;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000812 FillRootTableLength(*roots_data, number_of_roots);
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000813 return size;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000814 } else {
815 *roots_data = nullptr;
816 *stack_map_data = nullptr;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700817 *method_info_data = nullptr;
Nicolas Geoffrayed015ac2016-12-15 17:58:48 +0000818 return 0;
Nicolas Geoffrayf4b94422016-12-05 00:10:09 +0000819 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800820}
821
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100822class MarkCodeVisitor FINAL : public StackVisitor {
823 public:
824 MarkCodeVisitor(Thread* thread_in, JitCodeCache* code_cache_in)
825 : StackVisitor(thread_in, nullptr, StackVisitor::StackWalkKind::kSkipInlinedFrames),
826 code_cache_(code_cache_in),
827 bitmap_(code_cache_->GetLiveBitmap()) {}
828
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700829 bool VisitFrame() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100830 const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader();
831 if (method_header == nullptr) {
832 return true;
833 }
834 const void* code = method_header->GetCode();
835 if (code_cache_->ContainsPc(code)) {
836 // Use the atomic set version, as multiple threads are executing this code.
837 bitmap_->AtomicTestAndSet(FromCodeToAllocation(code));
838 }
839 return true;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800840 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100841
842 private:
843 JitCodeCache* const code_cache_;
844 CodeCacheBitmap* const bitmap_;
845};
846
847class MarkCodeClosure FINAL : public Closure {
848 public:
849 MarkCodeClosure(JitCodeCache* code_cache, Barrier* barrier)
850 : code_cache_(code_cache), barrier_(barrier) {}
851
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700852 void Run(Thread* thread) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800853 ScopedTrace trace(__PRETTY_FUNCTION__);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100854 DCHECK(thread == Thread::Current() || thread->IsSuspended());
855 MarkCodeVisitor visitor(thread, code_cache_);
856 visitor.WalkStack();
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +0000857 if (kIsDebugBuild) {
858 // The stack walking code queries the side instrumentation stack if it
859 // sees an instrumentation exit pc, so the JIT code of methods in that stack
860 // must have been seen. We sanity check this below.
861 for (const instrumentation::InstrumentationStackFrame& frame
862 : *thread->GetInstrumentationStack()) {
863 // The 'method_' in InstrumentationStackFrame is the one that has return_pc_ in
864 // its stack frame, it is not the method owning return_pc_. We just pass null to
865 // LookupMethodHeader: the method is only checked against in debug builds.
866 OatQuickMethodHeader* method_header =
867 code_cache_->LookupMethodHeader(frame.return_pc_, nullptr);
868 if (method_header != nullptr) {
869 const void* code = method_header->GetCode();
870 CHECK(code_cache_->GetLiveBitmap()->Test(FromCodeToAllocation(code)));
871 }
872 }
873 }
Mathieu Chartier10d25082015-10-28 18:36:09 -0700874 barrier_->Pass(Thread::Current());
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800875 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100876
877 private:
878 JitCodeCache* const code_cache_;
879 Barrier* const barrier_;
880};
881
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000882void JitCodeCache::NotifyCollectionDone(Thread* self) {
883 collection_in_progress_ = false;
884 lock_cond_.Broadcast(self);
885}
886
887void JitCodeCache::SetFootprintLimit(size_t new_footprint) {
888 size_t per_space_footprint = new_footprint / 2;
889 DCHECK(IsAlignedParam(per_space_footprint, kPageSize));
890 DCHECK_EQ(per_space_footprint * 2, new_footprint);
891 mspace_set_footprint_limit(data_mspace_, per_space_footprint);
892 {
893 ScopedCodeCacheWrite scc(code_map_.get());
894 mspace_set_footprint_limit(code_mspace_, per_space_footprint);
895 }
896}
897
898bool JitCodeCache::IncreaseCodeCacheCapacity() {
899 if (current_capacity_ == max_capacity_) {
900 return false;
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100901 }
902
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000903 // Double the capacity if we're below 1MB, or increase it by 1MB if
904 // we're above.
905 if (current_capacity_ < 1 * MB) {
906 current_capacity_ *= 2;
907 } else {
908 current_capacity_ += 1 * MB;
909 }
910 if (current_capacity_ > max_capacity_) {
911 current_capacity_ = max_capacity_;
912 }
913
914 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
915 LOG(INFO) << "Increasing code cache capacity to " << PrettySize(current_capacity_);
916 }
917
918 SetFootprintLimit(current_capacity_);
919
920 return true;
921}
922
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000923void JitCodeCache::MarkCompiledCodeOnThreadStacks(Thread* self) {
924 Barrier barrier(0);
925 size_t threads_running_checkpoint = 0;
926 MarkCodeClosure closure(this, &barrier);
927 threads_running_checkpoint = Runtime::Current()->GetThreadList()->RunCheckpoint(&closure);
928 // Now that we have run our checkpoint, move to a suspended state and wait
929 // for other threads to run the checkpoint.
930 ScopedThreadSuspension sts(self, kSuspended);
931 if (threads_running_checkpoint != 0) {
932 barrier.Increment(self, threads_running_checkpoint);
933 }
934}
935
Nicolas Geoffray35122442016-03-02 12:05:30 +0000936bool JitCodeCache::ShouldDoFullCollection() {
937 if (current_capacity_ == max_capacity_) {
938 // Always do a full collection when the code cache is full.
939 return true;
940 } else if (current_capacity_ < kReservedCapacity) {
941 // Always do partial collection when the code cache size is below the reserved
942 // capacity.
943 return false;
944 } else if (last_collection_increased_code_cache_) {
945 // This time do a full collection.
946 return true;
947 } else {
948 // This time do a partial collection.
949 return false;
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000950 }
951}
952
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000953void JitCodeCache::GarbageCollectCache(Thread* self) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800954 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000955 if (!garbage_collect_code_) {
956 MutexLock mu(self, lock_);
957 IncreaseCodeCacheCapacity();
958 return;
959 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100960
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000961 // Wait for an existing collection, or let everyone know we are starting one.
962 {
963 ScopedThreadSuspension sts(self, kSuspended);
964 MutexLock mu(self, lock_);
965 if (WaitForPotentialCollectionToComplete(self)) {
966 return;
967 } else {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000968 number_of_collections_++;
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000969 live_bitmap_.reset(CodeCacheBitmap::Create(
970 "code-cache-bitmap",
971 reinterpret_cast<uintptr_t>(code_map_->Begin()),
972 reinterpret_cast<uintptr_t>(code_map_->Begin() + current_capacity_ / 2)));
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000973 collection_in_progress_ = true;
974 }
975 }
976
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000977 TimingLogger logger("JIT code cache timing logger", true, VLOG_IS_ON(jit));
Nicolas Geoffray8d372502016-02-23 13:56:43 +0000978 {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000979 TimingLogger::ScopedTiming st("Code cache collection", &logger);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000980
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000981 bool do_full_collection = false;
982 {
983 MutexLock mu(self, lock_);
984 do_full_collection = ShouldDoFullCollection();
Nicolas Geoffraya96917a2016-03-01 22:18:02 +0000985 }
986
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000987 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
988 LOG(INFO) << "Do "
989 << (do_full_collection ? "full" : "partial")
990 << " code cache collection, code="
991 << PrettySize(CodeCacheSize())
992 << ", data=" << PrettySize(DataCacheSize());
993 }
Nicolas Geoffray35122442016-03-02 12:05:30 +0000994
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +0000995 DoCollection(self, /* collect_profiling_info */ do_full_collection);
996
997 if (!kIsDebugBuild || VLOG_IS_ON(jit)) {
998 LOG(INFO) << "After code cache collection, code="
999 << PrettySize(CodeCacheSize())
1000 << ", data=" << PrettySize(DataCacheSize());
1001 }
1002
1003 {
1004 MutexLock mu(self, lock_);
1005
1006 // Increase the code cache only when we do partial collections.
1007 // TODO: base this strategy on how full the code cache is?
1008 if (do_full_collection) {
1009 last_collection_increased_code_cache_ = false;
1010 } else {
1011 last_collection_increased_code_cache_ = true;
1012 IncreaseCodeCacheCapacity();
Nicolas Geoffray35122442016-03-02 12:05:30 +00001013 }
1014
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001015 bool next_collection_will_be_full = ShouldDoFullCollection();
1016
1017 // Start polling the liveness of compiled code to prepare for the next full collection.
Nicolas Geoffray480d5102016-04-18 12:09:30 +01001018 if (next_collection_will_be_full) {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001019 // Save the entry point of methods we have compiled, and update the entry
1020 // point of those methods to the interpreter. If the method is invoked, the
1021 // interpreter will update its entry point to the compiled code and call it.
1022 for (ProfilingInfo* info : profiling_infos_) {
1023 const void* entry_point = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
1024 if (ContainsPc(entry_point)) {
1025 info->SetSavedEntryPoint(entry_point);
Nicolas Geoffray3b1a7f42017-02-22 10:21:00 +00001026 // Don't call Instrumentation::UpdateMethods, as it can check the declaring
1027 // class of the method. We may be concurrently running a GC which makes accessing
1028 // the class unsafe. We know it is OK to bypass the instrumentation as we've just
1029 // checked that the current entry point is JIT compiled code.
1030 info->GetMethod()->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001031 }
1032 }
1033
1034 DCHECK(CheckLiveCompiledCodeHasProfilingInfo());
1035 }
1036 live_bitmap_.reset(nullptr);
1037 NotifyCollectionDone(self);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001038 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001039 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001040 Runtime::Current()->GetJit()->AddTimingLogger(logger);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001041}
1042
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001043void JitCodeCache::RemoveUnmarkedCode(Thread* self) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001044 ScopedTrace trace(__FUNCTION__);
Mingyao Yang063fc772016-08-02 11:02:54 -07001045 std::unordered_set<OatQuickMethodHeader*> method_headers;
1046 {
1047 MutexLock mu(self, lock_);
1048 ScopedCodeCacheWrite scc(code_map_.get());
1049 // Iterate over all compiled code and remove entries that are not marked.
1050 for (auto it = method_code_map_.begin(); it != method_code_map_.end();) {
1051 const void* code_ptr = it->first;
1052 uintptr_t allocation = FromCodeToAllocation(code_ptr);
1053 if (GetLiveBitmap()->Test(allocation)) {
1054 ++it;
1055 } else {
1056 method_headers.insert(OatQuickMethodHeader::FromCodePointer(it->first));
1057 it = method_code_map_.erase(it);
1058 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001059 }
1060 }
Mingyao Yang063fc772016-08-02 11:02:54 -07001061 FreeAllMethodHeaders(method_headers);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001062}
1063
1064void JitCodeCache::DoCollection(Thread* self, bool collect_profiling_info) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001065 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001066 {
1067 MutexLock mu(self, lock_);
1068 if (collect_profiling_info) {
1069 // Clear the profiling info of methods that do not have compiled code as entrypoint.
1070 // Also remove the saved entry point from the ProfilingInfo objects.
1071 for (ProfilingInfo* info : profiling_infos_) {
1072 const void* ptr = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001073 if (!ContainsPc(ptr) && !info->IsInUseByCompiler()) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001074 info->GetMethod()->SetProfilingInfo(nullptr);
1075 }
Nicolas Geoffrayb9a639d2016-03-22 11:25:20 +00001076
1077 if (info->GetSavedEntryPoint() != nullptr) {
1078 info->SetSavedEntryPoint(nullptr);
1079 // We are going to move this method back to interpreter. Clear the counter now to
Mathieu Chartierf044c222017-05-31 15:27:54 -07001080 // give it a chance to be hot again.
1081 ClearMethodCounter(info->GetMethod(), /*was_warm*/ true);
Nicolas Geoffrayb9a639d2016-03-22 11:25:20 +00001082 }
Nicolas Geoffray35122442016-03-02 12:05:30 +00001083 }
1084 } else if (kIsDebugBuild) {
1085 // Sanity check that the profiling infos do not have a dangling entry point.
1086 for (ProfilingInfo* info : profiling_infos_) {
1087 DCHECK(info->GetSavedEntryPoint() == nullptr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001088 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001089 }
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001090
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001091 // Mark compiled code that are entrypoints of ArtMethods. Compiled code that is not
1092 // an entry point is either:
1093 // - an osr compiled code, that will be removed if not in a thread call stack.
1094 // - discarded compiled code, that will be removed if not in a thread call stack.
1095 for (const auto& it : method_code_map_) {
1096 ArtMethod* method = it.second;
1097 const void* code_ptr = it.first;
1098 const OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1099 if (method_header->GetEntryPoint() == method->GetEntryPointFromQuickCompiledCode()) {
1100 GetLiveBitmap()->AtomicTestAndSet(FromCodeToAllocation(code_ptr));
1101 }
1102 }
1103
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +00001104 // Empty osr method map, as osr compiled code will be deleted (except the ones
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001105 // on thread stacks).
1106 osr_code_map_.clear();
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001107 }
1108
1109 // Run a checkpoint on all threads to mark the JIT compiled code they are running.
Nicolas Geoffray8d372502016-02-23 13:56:43 +00001110 MarkCompiledCodeOnThreadStacks(self);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001111
Nicolas Geoffray9abb2972016-03-04 14:32:59 +00001112 // At this point, mutator threads are still running, and entrypoints of methods can
1113 // change. We do know they cannot change to a code cache entry that is not marked,
1114 // therefore we can safely remove those entries.
1115 RemoveUnmarkedCode(self);
Nicolas Geoffraya96917a2016-03-01 22:18:02 +00001116
Nicolas Geoffray35122442016-03-02 12:05:30 +00001117 if (collect_profiling_info) {
Nicolas Geoffraycf48fa02016-07-30 22:49:11 +01001118 ScopedThreadSuspension sts(self, kSuspended);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001119 MutexLock mu(self, lock_);
1120 // Free all profiling infos of methods not compiled nor being compiled.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001121 auto profiling_kept_end = std::remove_if(profiling_infos_.begin(), profiling_infos_.end(),
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001122 [this] (ProfilingInfo* info) NO_THREAD_SAFETY_ANALYSIS {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001123 const void* ptr = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
Nicolas Geoffray511e41b2016-03-02 17:09:35 +00001124 // We have previously cleared the ProfilingInfo pointer in the ArtMethod in the hope
1125 // that the compiled code would not get revived. As mutator threads run concurrently,
1126 // they may have revived the compiled code, and now we are in the situation where
1127 // a method has compiled code but no ProfilingInfo.
1128 // We make sure compiled methods have a ProfilingInfo object. It is needed for
1129 // code cache collection.
Andreas Gampe542451c2016-07-26 09:02:02 -07001130 if (ContainsPc(ptr) &&
1131 info->GetMethod()->GetProfilingInfo(kRuntimePointerSize) == nullptr) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001132 info->GetMethod()->SetProfilingInfo(info);
Andreas Gampe542451c2016-07-26 09:02:02 -07001133 } else if (info->GetMethod()->GetProfilingInfo(kRuntimePointerSize) != info) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001134 // No need for this ProfilingInfo object anymore.
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001135 FreeData(reinterpret_cast<uint8_t*>(info));
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001136 return true;
1137 }
1138 return false;
1139 });
1140 profiling_infos_.erase(profiling_kept_end, profiling_infos_.end());
Nicolas Geoffray35122442016-03-02 12:05:30 +00001141 DCHECK(CheckLiveCompiledCodeHasProfilingInfo());
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001142 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001143}
1144
Nicolas Geoffray35122442016-03-02 12:05:30 +00001145bool JitCodeCache::CheckLiveCompiledCodeHasProfilingInfo() {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001146 ScopedTrace trace(__FUNCTION__);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001147 // Check that methods we have compiled do have a ProfilingInfo object. We would
1148 // have memory leaks of compiled code otherwise.
1149 for (const auto& it : method_code_map_) {
1150 ArtMethod* method = it.second;
Andreas Gampe542451c2016-07-26 09:02:02 -07001151 if (method->GetProfilingInfo(kRuntimePointerSize) == nullptr) {
Nicolas Geoffray35122442016-03-02 12:05:30 +00001152 const void* code_ptr = it.first;
1153 const OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1154 if (method_header->GetEntryPoint() == method->GetEntryPointFromQuickCompiledCode()) {
1155 // If the code is not dead, then we have a problem. Note that this can even
1156 // happen just after a collection, as mutator threads are running in parallel
1157 // and could deoptimize an existing compiled code.
1158 return false;
1159 }
1160 }
1161 }
1162 return true;
1163}
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001164
1165OatQuickMethodHeader* JitCodeCache::LookupMethodHeader(uintptr_t pc, ArtMethod* method) {
1166 static_assert(kRuntimeISA != kThumb2, "kThumb2 cannot be a runtime ISA");
1167 if (kRuntimeISA == kArm) {
1168 // On Thumb-2, the pc is offset by one.
1169 --pc;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001170 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001171 if (!ContainsPc(reinterpret_cast<const void*>(pc))) {
1172 return nullptr;
1173 }
1174
1175 MutexLock mu(Thread::Current(), lock_);
1176 if (method_code_map_.empty()) {
1177 return nullptr;
1178 }
1179 auto it = method_code_map_.lower_bound(reinterpret_cast<const void*>(pc));
1180 --it;
1181
1182 const void* code_ptr = it->first;
1183 OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromCodePointer(code_ptr);
1184 if (!method_header->Contains(pc)) {
1185 return nullptr;
1186 }
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +00001187 if (kIsDebugBuild && method != nullptr) {
Alex Light1ebe4fe2017-01-30 14:57:11 -08001188 // When we are walking the stack to redefine classes and creating obsolete methods it is
1189 // possible that we might have updated the method_code_map by making this method obsolete in a
1190 // previous frame. Therefore we should just check that the non-obsolete version of this method
1191 // is the one we expect. We change to the non-obsolete versions in the error message since the
1192 // obsolete version of the method might not be fully initialized yet. This situation can only
1193 // occur when we are in the process of allocating and setting up obsolete methods. Otherwise
1194 // method and it->second should be identical. (See runtime/openjdkjvmti/ti_redefine.cc for more
1195 // information.)
1196 DCHECK_EQ(it->second->GetNonObsoleteMethod(), method->GetNonObsoleteMethod())
1197 << ArtMethod::PrettyMethod(method->GetNonObsoleteMethod()) << " "
1198 << ArtMethod::PrettyMethod(it->second->GetNonObsoleteMethod()) << " "
David Sehr709b0702016-10-13 09:12:37 -07001199 << std::hex << pc;
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +00001200 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +01001201 return method_header;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001202}
1203
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001204OatQuickMethodHeader* JitCodeCache::LookupOsrMethodHeader(ArtMethod* method) {
1205 MutexLock mu(Thread::Current(), lock_);
1206 auto it = osr_code_map_.find(method);
1207 if (it == osr_code_map_.end()) {
1208 return nullptr;
1209 }
1210 return OatQuickMethodHeader::FromCodePointer(it->second);
1211}
1212
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001213ProfilingInfo* JitCodeCache::AddProfilingInfo(Thread* self,
1214 ArtMethod* method,
1215 const std::vector<uint32_t>& entries,
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001216 bool retry_allocation)
1217 // No thread safety analysis as we are using TryLock/Unlock explicitly.
1218 NO_THREAD_SAFETY_ANALYSIS {
1219 ProfilingInfo* info = nullptr;
1220 if (!retry_allocation) {
1221 // If we are allocating for the interpreter, just try to lock, to avoid
1222 // lock contention with the JIT.
1223 if (lock_.ExclusiveTryLock(self)) {
1224 info = AddProfilingInfoInternal(self, method, entries);
1225 lock_.ExclusiveUnlock(self);
1226 }
1227 } else {
1228 {
1229 MutexLock mu(self, lock_);
1230 info = AddProfilingInfoInternal(self, method, entries);
1231 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001232
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001233 if (info == nullptr) {
1234 GarbageCollectCache(self);
1235 MutexLock mu(self, lock_);
1236 info = AddProfilingInfoInternal(self, method, entries);
1237 }
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001238 }
1239 return info;
1240}
1241
Nicolas Geoffray1e7da9b2016-03-01 14:11:40 +00001242ProfilingInfo* JitCodeCache::AddProfilingInfoInternal(Thread* self ATTRIBUTE_UNUSED,
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001243 ArtMethod* method,
1244 const std::vector<uint32_t>& entries) {
1245 size_t profile_info_size = RoundUp(
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001246 sizeof(ProfilingInfo) + sizeof(InlineCache) * entries.size(),
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001247 sizeof(void*));
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001248
1249 // Check whether some other thread has concurrently created it.
Andreas Gampe542451c2016-07-26 09:02:02 -07001250 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001251 if (info != nullptr) {
1252 return info;
1253 }
1254
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001255 uint8_t* data = AllocateData(profile_info_size);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001256 if (data == nullptr) {
1257 return nullptr;
1258 }
1259 info = new (data) ProfilingInfo(method, entries);
Nicolas Geoffray07f35642016-01-04 16:06:51 +00001260
1261 // Make sure other threads see the data in the profiling info object before the
1262 // store in the ArtMethod's ProfilingInfo pointer.
1263 QuasiAtomic::ThreadFenceRelease();
1264
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001265 method->SetProfilingInfo(info);
1266 profiling_infos_.push_back(info);
Nicolas Geoffray933330a2016-03-16 14:20:06 +00001267 histogram_profiling_info_memory_use_.AddValue(profile_info_size);
Nicolas Geoffray26705e22015-10-28 12:50:11 +00001268 return info;
1269}
1270
Nicolas Geoffray0a3be162015-11-18 11:15:22 +00001271// NO_THREAD_SAFETY_ANALYSIS as this is called from mspace code, at which point the lock
1272// is already held.
1273void* JitCodeCache::MoreCore(const void* mspace, intptr_t increment) NO_THREAD_SAFETY_ANALYSIS {
1274 if (code_mspace_ == mspace) {
1275 size_t result = code_end_;
1276 code_end_ += increment;
1277 return reinterpret_cast<void*>(result + code_map_->Begin());
1278 } else {
1279 DCHECK_EQ(data_mspace_, mspace);
1280 size_t result = data_end_;
1281 data_end_ += increment;
1282 return reinterpret_cast<void*>(result + data_map_->Begin());
1283 }
1284}
1285
Calin Juravle99629622016-04-19 16:33:46 +01001286void JitCodeCache::GetProfiledMethods(const std::set<std::string>& dex_base_locations,
Calin Juravle940eb0c2017-01-30 19:30:44 -08001287 std::vector<ProfileMethodInfo>& methods) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -08001288 ScopedTrace trace(__FUNCTION__);
Calin Juravle31f2c152015-10-23 17:56:15 +01001289 MutexLock mu(Thread::Current(), lock_);
Calin Juravlea39fd982017-05-18 10:15:52 -07001290 uint16_t jit_compile_threshold = Runtime::Current()->GetJITOptions()->GetCompileThreshold();
Calin Juravle99629622016-04-19 16:33:46 +01001291 for (const ProfilingInfo* info : profiling_infos_) {
1292 ArtMethod* method = info->GetMethod();
1293 const DexFile* dex_file = method->GetDexFile();
Calin Juravle940eb0c2017-01-30 19:30:44 -08001294 if (!ContainsElement(dex_base_locations, dex_file->GetBaseLocation())) {
1295 // Skip dex files which are not profiled.
1296 continue;
Calin Juravle31f2c152015-10-23 17:56:15 +01001297 }
Calin Juravle940eb0c2017-01-30 19:30:44 -08001298 std::vector<ProfileMethodInfo::ProfileInlineCache> inline_caches;
Calin Juravlea39fd982017-05-18 10:15:52 -07001299
1300 // If the method didn't reach the compilation threshold don't save the inline caches.
1301 // They might be incomplete and cause unnecessary deoptimizations.
1302 // If the inline cache is empty the compiler will generate a regular invoke virtual/interface.
1303 if (method->GetCounter() < jit_compile_threshold) {
1304 methods.emplace_back(/*ProfileMethodInfo*/
1305 dex_file, method->GetDexMethodIndex(), inline_caches);
1306 continue;
1307 }
1308
Calin Juravle940eb0c2017-01-30 19:30:44 -08001309 for (size_t i = 0; i < info->number_of_inline_caches_; ++i) {
Mathieu Chartierdbddc222017-05-24 12:04:13 -07001310 std::vector<TypeReference> profile_classes;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001311 const InlineCache& cache = info->cache_[i];
Calin Juravle13439f02017-02-21 01:17:21 -08001312 ArtMethod* caller = info->GetMethod();
Calin Juravle589e71e2017-03-03 16:05:05 -08001313 bool is_missing_types = false;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001314 for (size_t k = 0; k < InlineCache::kIndividualCacheSize; k++) {
1315 mirror::Class* cls = cache.classes_[k].Read();
1316 if (cls == nullptr) {
1317 break;
1318 }
Calin Juravle4ca70a32017-02-21 16:22:24 -08001319
Calin Juravle13439f02017-02-21 01:17:21 -08001320 // Check if the receiver is in the boot class path or if it's in the
1321 // same class loader as the caller. If not, skip it, as there is not
1322 // much we can do during AOT.
1323 if (!cls->IsBootStrapClassLoaded() &&
1324 caller->GetClassLoader() != cls->GetClassLoader()) {
1325 is_missing_types = true;
1326 continue;
1327 }
1328
Calin Juravle4ca70a32017-02-21 16:22:24 -08001329 const DexFile* class_dex_file = nullptr;
1330 dex::TypeIndex type_index;
1331
1332 if (cls->GetDexCache() == nullptr) {
1333 DCHECK(cls->IsArrayClass()) << cls->PrettyClass();
Calin Juravlee21806f2017-02-22 11:49:43 -08001334 // Make a best effort to find the type index in the method's dex file.
1335 // We could search all open dex files but that might turn expensive
1336 // and probably not worth it.
Calin Juravle4ca70a32017-02-21 16:22:24 -08001337 class_dex_file = dex_file;
1338 type_index = cls->FindTypeIndexInOtherDexFile(*dex_file);
1339 } else {
1340 class_dex_file = &(cls->GetDexFile());
1341 type_index = cls->GetDexTypeIndex();
1342 }
1343 if (!type_index.IsValid()) {
1344 // Could be a proxy class or an array for which we couldn't find the type index.
Calin Juravle589e71e2017-03-03 16:05:05 -08001345 is_missing_types = true;
Calin Juravle4ca70a32017-02-21 16:22:24 -08001346 continue;
1347 }
1348 if (ContainsElement(dex_base_locations, class_dex_file->GetBaseLocation())) {
Calin Juravle940eb0c2017-01-30 19:30:44 -08001349 // Only consider classes from the same apk (including multidex).
1350 profile_classes.emplace_back(/*ProfileMethodInfo::ProfileClassReference*/
Calin Juravle4ca70a32017-02-21 16:22:24 -08001351 class_dex_file, type_index);
Calin Juravle589e71e2017-03-03 16:05:05 -08001352 } else {
1353 is_missing_types = true;
Calin Juravle940eb0c2017-01-30 19:30:44 -08001354 }
1355 }
1356 if (!profile_classes.empty()) {
1357 inline_caches.emplace_back(/*ProfileMethodInfo::ProfileInlineCache*/
Calin Juravle589e71e2017-03-03 16:05:05 -08001358 cache.dex_pc_, is_missing_types, profile_classes);
Calin Juravle940eb0c2017-01-30 19:30:44 -08001359 }
1360 }
1361 methods.emplace_back(/*ProfileMethodInfo*/
1362 dex_file, method->GetDexMethodIndex(), inline_caches);
Calin Juravle31f2c152015-10-23 17:56:15 +01001363 }
1364}
1365
Calin Juravle4d77b6a2015-12-01 18:38:09 +00001366uint64_t JitCodeCache::GetLastUpdateTimeNs() const {
1367 return last_update_time_ns_.LoadAcquire();
Calin Juravle31f2c152015-10-23 17:56:15 +01001368}
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001369
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +01001370bool JitCodeCache::IsOsrCompiled(ArtMethod* method) {
1371 MutexLock mu(Thread::Current(), lock_);
1372 return osr_code_map_.find(method) != osr_code_map_.end();
1373}
1374
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001375bool JitCodeCache::NotifyCompilationOf(ArtMethod* method, Thread* self, bool osr) {
1376 if (!osr && ContainsPc(method->GetEntryPointFromQuickCompiledCode())) {
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001377 return false;
1378 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00001379
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00001380 MutexLock mu(self, lock_);
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001381 if (osr && (osr_code_map_.find(method) != osr_code_map_.end())) {
1382 return false;
1383 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001384
Andreas Gampe542451c2016-07-26 09:02:02 -07001385 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001386 if (info == nullptr) {
David Sehr709b0702016-10-13 09:12:37 -07001387 VLOG(jit) << method->PrettyMethod() << " needs a ProfilingInfo to be compiled";
Jeff Hao00286db2017-05-30 16:53:07 -07001388 // Because the counter is not atomic, there are some rare cases where we may not hit the
1389 // threshold for creating the ProfilingInfo. Reset the counter now to "correct" this.
Mathieu Chartierf044c222017-05-31 15:27:54 -07001390 ClearMethodCounter(method, /*was_warm*/ false);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001391 return false;
1392 }
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001393
buzbee454b3b62016-04-07 14:42:47 -07001394 if (info->IsMethodBeingCompiled(osr)) {
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001395 return false;
1396 }
1397
buzbee454b3b62016-04-07 14:42:47 -07001398 info->SetIsMethodBeingCompiled(true, osr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001399 return true;
1400}
1401
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001402ProfilingInfo* JitCodeCache::NotifyCompilerUse(ArtMethod* method, Thread* self) {
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001403 MutexLock mu(self, lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -07001404 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001405 if (info != nullptr) {
Nicolas Geoffrayf6d46682017-02-28 17:41:45 +00001406 if (!info->IncrementInlineUse()) {
1407 // Overflow of inlining uses, just bail.
1408 return nullptr;
1409 }
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001410 }
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001411 return info;
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001412}
1413
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001414void JitCodeCache::DoneCompilerUse(ArtMethod* method, Thread* self) {
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001415 MutexLock mu(self, lock_);
Andreas Gampe542451c2016-07-26 09:02:02 -07001416 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray07e3ca92016-03-11 09:57:57 +00001417 DCHECK(info != nullptr);
1418 info->DecrementInlineUse();
Nicolas Geoffrayb6e20ae2016-03-07 14:29:04 +00001419}
1420
buzbee454b3b62016-04-07 14:42:47 -07001421void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self ATTRIBUTE_UNUSED, bool osr) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001422 ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
buzbee454b3b62016-04-07 14:42:47 -07001423 DCHECK(info->IsMethodBeingCompiled(osr));
1424 info->SetIsMethodBeingCompiled(false, osr);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001425}
1426
Nicolas Geoffraya25dce92016-01-12 16:41:10 +00001427size_t JitCodeCache::GetMemorySizeOfCodePointer(const void* ptr) {
1428 MutexLock mu(Thread::Current(), lock_);
1429 return mspace_usable_size(reinterpret_cast<const void*>(FromCodeToAllocation(ptr)));
1430}
1431
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001432void JitCodeCache::InvalidateCompiledCodeFor(ArtMethod* method,
1433 const OatQuickMethodHeader* header) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001434 ProfilingInfo* profiling_info = method->GetProfilingInfo(kRuntimePointerSize);
Nicolas Geoffray35122442016-03-02 12:05:30 +00001435 if ((profiling_info != nullptr) &&
1436 (profiling_info->GetSavedEntryPoint() == header->GetEntryPoint())) {
1437 // Prevent future uses of the compiled code.
1438 profiling_info->SetSavedEntryPoint(nullptr);
1439 }
1440
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001441 if (method->GetEntryPointFromQuickCompiledCode() == header->GetEntryPoint()) {
Jeff Hao00286db2017-05-30 16:53:07 -07001442 // The entrypoint is the one to invalidate, so we just update it to the interpreter entry point
Mathieu Chartierf044c222017-05-31 15:27:54 -07001443 // and clear the counter to get the method Jitted again.
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001444 Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
1445 method, GetQuickToInterpreterBridge());
Mathieu Chartierf044c222017-05-31 15:27:54 -07001446 ClearMethodCounter(method, /*was_warm*/ profiling_info != nullptr);
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +00001447 } else {
1448 MutexLock mu(Thread::Current(), lock_);
1449 auto it = osr_code_map_.find(method);
1450 if (it != osr_code_map_.end() && OatQuickMethodHeader::FromCodePointer(it->second) == header) {
1451 // Remove the OSR method, to avoid using it again.
1452 osr_code_map_.erase(it);
1453 }
1454 }
1455}
1456
Nicolas Geoffray38ea9bd2016-02-19 16:25:57 +00001457uint8_t* JitCodeCache::AllocateCode(size_t code_size) {
1458 size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
1459 uint8_t* result = reinterpret_cast<uint8_t*>(
1460 mspace_memalign(code_mspace_, alignment, code_size));
1461 size_t header_size = RoundUp(sizeof(OatQuickMethodHeader), alignment);
1462 // Ensure the header ends up at expected instruction alignment.
1463 DCHECK_ALIGNED_PARAM(reinterpret_cast<uintptr_t>(result + header_size), alignment);
1464 used_memory_for_code_ += mspace_usable_size(result);
1465 return result;
1466}
1467
1468void JitCodeCache::FreeCode(uint8_t* code) {
1469 used_memory_for_code_ -= mspace_usable_size(code);
1470 mspace_free(code_mspace_, code);
1471}
1472
1473uint8_t* JitCodeCache::AllocateData(size_t data_size) {
1474 void* result = mspace_malloc(data_mspace_, data_size);
1475 used_memory_for_data_ += mspace_usable_size(result);
1476 return reinterpret_cast<uint8_t*>(result);
1477}
1478
1479void JitCodeCache::FreeData(uint8_t* data) {
1480 used_memory_for_data_ -= mspace_usable_size(data);
1481 mspace_free(data_mspace_, data);
1482}
1483
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001484void JitCodeCache::Dump(std::ostream& os) {
1485 MutexLock mu(Thread::Current(), lock_);
1486 os << "Current JIT code cache size: " << PrettySize(used_memory_for_code_) << "\n"
1487 << "Current JIT data cache size: " << PrettySize(used_memory_for_data_) << "\n"
1488 << "Current JIT capacity: " << PrettySize(current_capacity_) << "\n"
1489 << "Current number of JIT code cache entries: " << method_code_map_.size() << "\n"
1490 << "Total number of JIT compilations: " << number_of_compilations_ << "\n"
1491 << "Total number of JIT compilations for on stack replacement: "
1492 << number_of_osr_compilations_ << "\n"
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001493 << "Total number of JIT code cache collections: " << number_of_collections_ << std::endl;
Nicolas Geoffray933330a2016-03-16 14:20:06 +00001494 histogram_stack_map_memory_use_.PrintMemoryUse(os);
1495 histogram_code_memory_use_.PrintMemoryUse(os);
1496 histogram_profiling_info_memory_use_.PrintMemoryUse(os);
Nicolas Geoffraybcd94c82016-03-03 13:23:33 +00001497}
1498
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001499} // namespace jit
1500} // namespace art