summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2018-09-07 13:42:22 -0700
committer Alex Light <allight@google.com> 2018-09-10 18:14:06 +0000
commitba9dc922a367bd49dec0b718a9350931a407cd3f (patch)
tree62925044af55c8c8b57d89add93c1a76350903f0
parent4613c8a3a549213240f3ffc46514b600d872938e (diff)
Don't pre-initialize Class.name fields in boot images
The Class.name field is normally allocated and set dynamically when required. We were pre-initializing it for non-app-images in order to reduce dirty pages. It turns out that without this very few classes would ever get this field initialized (~2% according to tests while running a few apps). No longer pre-initializing the field reduces the size of each boot image by ~600kb. This partially reverts commit d418edaf4d. Prior to the change the smaps entry for an art file look like this: 701cd000-70303000 rw-p 00000000 103:1d 5505036 /data/dalvik-cache/arm64/system@framework@boot-core-libart.art Size: 1240 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Rss: 720 kB Pss: 190 kB Shared_Clean: 548 kB Shared_Dirty: 0 kB Private_Clean: 44 kB Private_Dirty: 128 kB Referenced: 720 kB Anonymous: 128 kB With this change running the same program gives us the following smaps entry: 6fc83000-6fdae000 rw-p 00000000 103:1d 6684684 /data/dalvik-cache/arm64/system@framework@boot-core-libart.art Size: 1196 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Rss: 672 kB Pss: 195 kB Shared_Clean: 496 kB Shared_Dirty: 0 kB Private_Clean: 48 kB Private_Dirty: 128 kB Referenced: 672 kB Anonymous: 128 kB All relevant measures of memory use are either improved or remain unchanged. (NB private_clean is the amount of memory that another process could cause to be dirtied by writing to it. It is not relevant to this change.) Bug: 32635074 Test: ./tools/field-null-percent/check-null-fields.py 'Ljava/lang/Class;.name:Ljava/lang/String;' Test: Builds and boots Test: Examine smaps for both old and new version. Change-Id: I96aaeb782715db5c1e035bdf76331b4253c74ce6
-rw-r--r--dex2oat/linker/image_writer.cc19
-rw-r--r--dex2oat/linker/image_writer.h4
2 files changed, 0 insertions, 23 deletions
diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc
index 6a134548a9..685174dedd 100644
--- a/dex2oat/linker/image_writer.cc
+++ b/dex2oat/linker/image_writer.cc
@@ -213,10 +213,6 @@ bool ImageWriter::PrepareImageAddressSpace(TimingLogger* timings) {
// since the cookie field contains long pointers to DexFiles which are not deterministic.
// b/34090128
ClearDexFileCookies();
- } else {
- TimingLogger::ScopedTiming t("ComputeLazyFieldsForImageClasses", timings);
- // Avoid for app image since this may increase RAM and image size.
- ComputeLazyFieldsForImageClasses(); // Add useful information
}
}
{
@@ -753,21 +749,6 @@ bool ImageWriter::AllocMemory() {
return true;
}
-class ImageWriter::ComputeLazyFieldsForClassesVisitor : public ClassVisitor {
- public:
- bool operator()(ObjPtr<Class> c) override REQUIRES_SHARED(Locks::mutator_lock_) {
- StackHandleScope<1> hs(Thread::Current());
- mirror::Class::ComputeName(hs.NewHandle(c));
- return true;
- }
-};
-
-void ImageWriter::ComputeLazyFieldsForImageClasses() {
- ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- ComputeLazyFieldsForClassesVisitor visitor;
- class_linker->VisitClassesWithoutClassesLock(&visitor);
-}
-
static bool IsBootClassLoaderClass(ObjPtr<mirror::Class> klass)
REQUIRES_SHARED(Locks::mutator_lock_) {
return klass->GetClassLoader() == nullptr;
diff --git a/dex2oat/linker/image_writer.h b/dex2oat/linker/image_writer.h
index e45023e6dc..f4557467b6 100644
--- a/dex2oat/linker/image_writer.h
+++ b/dex2oat/linker/image_writer.h
@@ -429,10 +429,6 @@ class ImageWriter final {
// Debug aid that list of requested image classes.
void DumpImageClasses();
- // Preinitializes some otherwise lazy fields (such as Class name) to avoid runtime image dirtying.
- void ComputeLazyFieldsForImageClasses()
- REQUIRES_SHARED(Locks::mutator_lock_);
-
// Visit all class loaders.
void VisitClassLoaders(ClassLoaderVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);