summaryrefslogtreecommitdiff
path: root/runtime/class_linker-inl.h
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2021-02-16 14:06:31 +0000
committer David Srbecky <dsrbecky@google.com> 2021-02-23 15:24:27 +0000
commit1214319d27e7fb4c4ff00b39799df6f15288098a (patch)
tree8708943822a634322bd9790c4d008210e44b3ddb /runtime/class_linker-inl.h
parentb7cb691fb8da124e8a6276a5a7fee47dd0aaa338 (diff)
Lazily allocate DexCache arrays.
We rarely need the DexCache for compiled code. Delay the allocation in hope we never need it. This reduces DexCache memory usage by ~25% at startup. Test: m test-art-host-gtest Test: test.py -r -b --host Change-Id: I680a59c905c2b821ee954e4b32abd5d24876bd11
Diffstat (limited to 'runtime/class_linker-inl.h')
-rw-r--r--runtime/class_linker-inl.h58
1 files changed, 12 insertions, 46 deletions
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h
index 69f5a77a25..f45ccb5929 100644
--- a/runtime/class_linker-inl.h
+++ b/runtime/class_linker-inl.h
@@ -70,10 +70,7 @@ inline ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string
ArtField* referrer) {
Thread::PoisonObjectPointersIfDebug();
DCHECK(!Thread::Current()->IsExceptionPending());
- // We do not need the read barrier for getting the DexCache for the initial resolved type
- // lookup as both from-space and to-space copies point to the same native resolved types array.
- ObjPtr<mirror::String> resolved =
- referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedString(string_idx);
+ ObjPtr<mirror::String> resolved = referrer->GetDexCache()->GetResolvedString(string_idx);
if (resolved == nullptr) {
resolved = DoResolveString(string_idx, referrer->GetDexCache());
}
@@ -84,10 +81,7 @@ inline ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string
ArtMethod* referrer) {
Thread::PoisonObjectPointersIfDebug();
DCHECK(!Thread::Current()->IsExceptionPending());
- // We do not need the read barrier for getting the DexCache for the initial resolved type
- // lookup as both from-space and to-space copies point to the same native resolved types array.
- ObjPtr<mirror::String> resolved =
- referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedString(string_idx);
+ ObjPtr<mirror::String> resolved = referrer->GetDexCache()->GetResolvedString(string_idx);
if (resolved == nullptr) {
resolved = DoResolveString(string_idx, referrer->GetDexCache());
}
@@ -122,10 +116,8 @@ inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
Thread::Current()->PoisonObjectPointers();
}
DCHECK(!Thread::Current()->IsExceptionPending());
- // We do not need the read barrier for getting the DexCache for the initial resolved type
- // lookup as both from-space and to-space copies point to the same native resolved types array.
ObjPtr<mirror::Class> resolved_type =
- referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx);
+ referrer->GetDexCache<kDefaultVerifyFlags>()->GetResolvedType(type_idx);
if (resolved_type == nullptr) {
resolved_type = DoResolveType(type_idx, referrer);
}
@@ -136,10 +128,7 @@ inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
ArtField* referrer) {
Thread::PoisonObjectPointersIfDebug();
DCHECK(!Thread::Current()->IsExceptionPending());
- // We do not need the read barrier for getting the DexCache for the initial resolved type
- // lookup as both from-space and to-space copies point to the same native resolved types array.
- ObjPtr<mirror::Class> resolved_type =
- referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
+ ObjPtr<mirror::Class> resolved_type = referrer->GetDexCache()->GetResolvedType(type_idx);
if (UNLIKELY(resolved_type == nullptr)) {
resolved_type = DoResolveType(type_idx, referrer);
}
@@ -150,10 +139,7 @@ inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
ArtMethod* referrer) {
Thread::PoisonObjectPointersIfDebug();
DCHECK(!Thread::Current()->IsExceptionPending());
- // We do not need the read barrier for getting the DexCache for the initial resolved type
- // lookup as both from-space and to-space copies point to the same native resolved types array.
- ObjPtr<mirror::Class> resolved_type =
- referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
+ ObjPtr<mirror::Class> resolved_type = referrer->GetDexCache()->GetResolvedType(type_idx);
if (UNLIKELY(resolved_type == nullptr)) {
resolved_type = DoResolveType(type_idx, referrer);
}
@@ -174,10 +160,8 @@ inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
ObjPtr<mirror::Class> referrer) {
- // We do not need the read barrier for getting the DexCache for the initial resolved type
- // lookup as both from-space and to-space copies point to the same native resolved types array.
ObjPtr<mirror::Class> type =
- referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx);
+ referrer->GetDexCache<kDefaultVerifyFlags>()->GetResolvedType(type_idx);
if (type == nullptr) {
type = DoLookupResolvedType(type_idx, referrer);
}
@@ -186,10 +170,7 @@ inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type
inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
ArtField* referrer) {
- // We do not need the read barrier for getting the DexCache for the initial resolved type
- // lookup as both from-space and to-space copies point to the same native resolved types array.
- ObjPtr<mirror::Class> type =
- referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
+ ObjPtr<mirror::Class> type = referrer->GetDexCache()->GetResolvedType(type_idx);
if (type == nullptr) {
type = DoLookupResolvedType(type_idx, referrer->GetDeclaringClass());
}
@@ -198,10 +179,7 @@ inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type
inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
ArtMethod* referrer) {
- // We do not need the read barrier for getting the DexCache for the initial resolved type
- // lookup as both from-space and to-space copies point to the same native resolved types array.
- ObjPtr<mirror::Class> type =
- referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
+ ObjPtr<mirror::Class> type = referrer->GetDexCache()->GetResolvedType(type_idx);
if (type == nullptr) {
type = DoLookupResolvedType(type_idx, referrer->GetDeclaringClass());
}
@@ -307,10 +285,7 @@ inline ArtMethod* ClassLinker::GetResolvedMethod(uint32_t method_idx, ArtMethod*
// lookup in the context of the original method from where it steals the code.
// However, we delay the GetInterfaceMethodIfProxy() until needed.
DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor());
- // We do not need the read barrier for getting the DexCache for the initial resolved method
- // lookup as both from-space and to-space copies point to the same native resolved methods array.
- ArtMethod* resolved_method = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedMethod(
- method_idx);
+ ArtMethod* resolved_method = referrer->GetDexCache()->GetResolvedMethod(method_idx);
if (resolved_method == nullptr) {
return nullptr;
}
@@ -350,10 +325,7 @@ inline ArtMethod* ClassLinker::ResolveMethod(Thread* self,
// However, we delay the GetInterfaceMethodIfProxy() until needed.
DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor());
Thread::PoisonObjectPointersIfDebug();
- // We do not need the read barrier for getting the DexCache for the initial resolved method
- // lookup as both from-space and to-space copies point to the same native resolved methods array.
- ArtMethod* resolved_method = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedMethod(
- method_idx);
+ ArtMethod* resolved_method = referrer->GetDexCache()->GetResolvedMethod(method_idx);
DCHECK(resolved_method == nullptr || !resolved_method->IsRuntimeMethod());
if (UNLIKELY(resolved_method == nullptr)) {
referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
@@ -418,10 +390,7 @@ inline ArtMethod* ClassLinker::ResolveMethod(Thread* self,
inline ArtField* ClassLinker::LookupResolvedField(uint32_t field_idx,
ArtMethod* referrer,
bool is_static) {
- // We do not need the read barrier for getting the DexCache for the initial resolved field
- // lookup as both from-space and to-space copies point to the same native resolved fields array.
- ArtField* field = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedField(
- field_idx);
+ ArtField* field = referrer->GetDexCache()->GetResolvedField(field_idx);
if (field == nullptr) {
ObjPtr<mirror::ClassLoader> class_loader = referrer->GetDeclaringClass()->GetClassLoader();
field = LookupResolvedField(field_idx, referrer->GetDexCache(), class_loader, is_static);
@@ -433,10 +402,7 @@ inline ArtField* ClassLinker::ResolveField(uint32_t field_idx,
ArtMethod* referrer,
bool is_static) {
Thread::PoisonObjectPointersIfDebug();
- // We do not need the read barrier for getting the DexCache for the initial resolved field
- // lookup as both from-space and to-space copies point to the same native resolved fields array.
- ArtField* resolved_field = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedField(
- field_idx);
+ ArtField* resolved_field = referrer->GetDexCache()->GetResolvedField(field_idx);
if (UNLIKELY(resolved_field == nullptr)) {
StackHandleScope<2> hs(Thread::Current());
ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass();