summaryrefslogtreecommitdiff
path: root/runtime/class_linker-inl.h
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2021-10-18 15:10:41 +0100
committer Treehugger Robot <treehugger-gerrit@google.com> 2021-11-09 11:18:38 +0000
commitcc76459f5d32d9002d8d0a432ccd6a3ca1f25bd0 (patch)
treea8122328ac86f383f15d4f3b89d78503b283785e /runtime/class_linker-inl.h
parent01f0b8417d75428ed12e4adf19afcbf557651aaa (diff)
Modified revert of "Add couple DexCache read-barriers."
Remove the DexCache read-barriers again (the revert) since there is measurable performance difference in app startup (~1%). It turns out they are on very hot path in the interpreter. The lazy array initialization made the DexCache fields mutable. However, instead of the read-barriers, we can just ensure we get the right to-space object on the array-initialization slow path. Test: test.py -b -r --host Change-Id: I3f0123141e9a7875a26f088bff68d50641b66883
Diffstat (limited to 'runtime/class_linker-inl.h')
-rw-r--r--runtime/class_linker-inl.h58
1 files changed, 46 insertions, 12 deletions
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h
index 26c422b9eb..e51d5a744d 100644
--- a/runtime/class_linker-inl.h
+++ b/runtime/class_linker-inl.h
@@ -70,7 +70,10 @@ inline ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string
ArtField* referrer) {
Thread::PoisonObjectPointersIfDebug();
DCHECK(!Thread::Current()->IsExceptionPending());
- ObjPtr<mirror::String> resolved = referrer->GetDexCache()->GetResolvedString(string_idx);
+ // 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);
if (resolved == nullptr) {
resolved = DoResolveString(string_idx, referrer->GetDexCache());
}
@@ -81,7 +84,10 @@ inline ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string
ArtMethod* referrer) {
Thread::PoisonObjectPointersIfDebug();
DCHECK(!Thread::Current()->IsExceptionPending());
- ObjPtr<mirror::String> resolved = referrer->GetDexCache()->GetResolvedString(string_idx);
+ // 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);
if (resolved == nullptr) {
resolved = DoResolveString(string_idx, referrer->GetDexCache());
}
@@ -116,8 +122,10 @@ 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>()->GetResolvedType(type_idx);
+ referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx);
if (resolved_type == nullptr) {
resolved_type = DoResolveType(type_idx, referrer);
}
@@ -128,7 +136,10 @@ inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
ArtField* referrer) {
Thread::PoisonObjectPointersIfDebug();
DCHECK(!Thread::Current()->IsExceptionPending());
- ObjPtr<mirror::Class> resolved_type = referrer->GetDexCache()->GetResolvedType(type_idx);
+ // 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);
if (UNLIKELY(resolved_type == nullptr)) {
resolved_type = DoResolveType(type_idx, referrer);
}
@@ -139,7 +150,10 @@ inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
ArtMethod* referrer) {
Thread::PoisonObjectPointersIfDebug();
DCHECK(!Thread::Current()->IsExceptionPending());
- ObjPtr<mirror::Class> resolved_type = referrer->GetDexCache()->GetResolvedType(type_idx);
+ // 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);
if (UNLIKELY(resolved_type == nullptr)) {
resolved_type = DoResolveType(type_idx, referrer);
}
@@ -161,8 +175,10 @@ 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>()->GetResolvedType(type_idx);
+ referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx);
if (type == nullptr) {
type = DoLookupResolvedType(type_idx, referrer);
}
@@ -171,7 +187,10 @@ inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type
inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
ArtField* referrer) {
- ObjPtr<mirror::Class> type = referrer->GetDexCache()->GetResolvedType(type_idx);
+ // 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);
if (type == nullptr) {
type = DoLookupResolvedType(type_idx, referrer->GetDeclaringClass());
}
@@ -180,7 +199,10 @@ inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type
inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
ArtMethod* referrer) {
- ObjPtr<mirror::Class> type = referrer->GetDexCache()->GetResolvedType(type_idx);
+ // 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);
if (type == nullptr) {
type = DoLookupResolvedType(type_idx, referrer->GetDeclaringClass());
}
@@ -289,7 +311,10 @@ 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());
- ArtMethod* resolved_method = referrer->GetDexCache()->GetResolvedMethod(method_idx);
+ // 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);
if (resolved_method == nullptr) {
return nullptr;
}
@@ -339,7 +364,10 @@ inline ArtMethod* ClassLinker::ResolveMethod(Thread* self,
// However, we delay the GetInterfaceMethodIfProxy() until needed.
DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor());
Thread::PoisonObjectPointersIfDebug();
- ArtMethod* resolved_method = referrer->GetDexCache()->GetResolvedMethod(method_idx);
+ // 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);
DCHECK(resolved_method == nullptr || !resolved_method->IsRuntimeMethod());
if (UNLIKELY(resolved_method == nullptr)) {
referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
@@ -502,7 +530,10 @@ inline ArtMethod* ClassLinker::ResolveMethod(uint32_t method_idx,
inline ArtField* ClassLinker::LookupResolvedField(uint32_t field_idx,
ArtMethod* referrer,
bool is_static) {
- ArtField* field = referrer->GetDexCache()->GetResolvedField(field_idx);
+ // 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);
if (field == nullptr) {
referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
ObjPtr<mirror::ClassLoader> class_loader = referrer->GetDeclaringClass()->GetClassLoader();
@@ -515,7 +546,10 @@ inline ArtField* ClassLinker::ResolveField(uint32_t field_idx,
ArtMethod* referrer,
bool is_static) {
Thread::PoisonObjectPointersIfDebug();
- ArtField* resolved_field = referrer->GetDexCache()->GetResolvedField(field_idx);
+ // 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);
if (UNLIKELY(resolved_field == nullptr)) {
StackHandleScope<2> hs(Thread::Current());
referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);