From fa40e6e318b21d4a1885a6ffea6efc3c0b5cc1cd Mon Sep 17 00:00:00 2001
From: David Srbecky <dsrbecky@google.com>
Date: Wed, 1 Dec 2021 17:09:08 +0000
Subject: Add thread-shared interpreter cache

The thread-local interpreter cache handles around 75% of method/field
lookups from the interpreter.

Add thread-shared interpreter cache which can be much bigger (since
we pay the memory just once rather then per thread).  This increases
the cache hit rate to 90%.

This effectively halves the amount of time we spend in
'NterpGetMethod' (including DexCache lookups), which is the single
most expensive method during startup.

Furthermore, it also reduces the amount of time we spend resolving
methods by around 25% since DexCache entries get evicted less often.

The shared cache increases memory use by 256k per process, so also
reduce the fixed-size DexCache fields array, which balances it back.

Test: test.py --host
Change-Id: I3cd369613d47de117ab69d5bee00d4cf89b87913
---
 tools/cpp-define-generator/thread.def | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

(limited to 'tools/cpp-define-generator/thread.def')

diff --git a/tools/cpp-define-generator/thread.def b/tools/cpp-define-generator/thread.def
index ec8e28b977..07ca8841f8 100644
--- a/tools/cpp-define-generator/thread.def
+++ b/tools/cpp-define-generator/thread.def
@@ -30,11 +30,12 @@ ASM_DEFINE(THREAD_ID_OFFSET,
 ASM_DEFINE(THREAD_INTERPRETER_CACHE_OFFSET,
            art::Thread::InterpreterCacheOffset<art::kRuntimePointerSize>().Int32Value())
 ASM_DEFINE(THREAD_INTERPRETER_CACHE_SIZE_LOG2,
-           art::Thread::InterpreterCacheSizeLog2())
+           art::WhichPowerOf2(art::InterpreterCache::kThreadLocalSize))
 ASM_DEFINE(THREAD_INTERPRETER_CACHE_SIZE_MASK,
-           (sizeof(art::InterpreterCache::Entry) * (art::InterpreterCache::kSize - 1)))
+           (sizeof(art::InterpreterCache::Entry) * (art::InterpreterCache::kThreadLocalSize - 1)))
 ASM_DEFINE(THREAD_INTERPRETER_CACHE_SIZE_SHIFT,
-           2)
+           (art::WhichPowerOf2(sizeof(art::InterpreterCache::Entry)) -
+            art::InterpreterCache::kHashShift))
 ASM_DEFINE(THREAD_IS_GC_MARKING_OFFSET,
            art::Thread::IsGcMarkingOffset<art::kRuntimePointerSize>().Int32Value())
 ASM_DEFINE(THREAD_LOCAL_ALLOC_STACK_END_OFFSET,
-- 
cgit v1.2.3-59-g8ed1b

