summaryrefslogtreecommitdiff
path: root/dex2oat
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2024-11-28 16:28:04 +0000
committer Nicolas Geoffray <ngeoffray@google.com> 2025-01-16 11:36:58 +0000
commit990cf07523a5c6ae437a0bd0cc80fb63320def5e (patch)
tree7d7160e014b14368c6cd8dcfcbfe9e2996f19e51 /dex2oat
parentae13bd8a14183069642a5eed4793cf34f5a2eadc (diff)
Merge sFields and iFields.
Test: test.py Change-Id: Ib97fca637a8866a41a4389b150c6000d9fb6d99b
Diffstat (limited to 'dex2oat')
-rw-r--r--dex2oat/driver/compiler_driver.cc8
-rw-r--r--dex2oat/linker/image_writer.cc62
2 files changed, 27 insertions, 43 deletions
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index bbb70e4ef1..fc2d94a342 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -1404,10 +1404,9 @@ class ClinitImageUpdate {
} else if (can_include_in_image) {
// Check whether the class is initialized and has a clinit or static fields.
// Such classes must be kept too.
- if (klass->IsInitialized()) {
+ if (klass->IsInitialized() && !klass->IsArrayClass()) {
PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
- if (klass->FindClassInitializer(pointer_size) != nullptr ||
- klass->NumStaticFields() != 0) {
+ if (klass->FindClassInitializer(pointer_size) != nullptr || klass->HasStaticFields()) {
DCHECK(!Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(klass->GetDexCache()))
<< klass->PrettyDescriptor();
data_->image_classes_.push_back(data_->hs_.NewHandle(klass));
@@ -2275,8 +2274,9 @@ class InitializeClassVisitor : public CompilationVisitor {
// cannot be initialized, no need to proceed.
old_status = klass->GetStatus();
+ ClassAccessor accessor(klass->GetDexFile(), klass->GetDexClassDefIndex());
bool too_many_encoded_fields = (!is_boot_image && !is_boot_image_extension) &&
- klass->NumStaticFields() > kMaxEncodedFields;
+ accessor.NumStaticFields() > kMaxEncodedFields;
bool have_profile = (compiler_options.GetProfileCompilationInfo() != nullptr) &&
!compiler_options.GetProfileCompilationInfo()->IsEmpty();
diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc
index 179a0bb4f7..04bf4833cd 100644
--- a/dex2oat/linker/image_writer.cc
+++ b/dex2oat/linker/image_writer.cc
@@ -761,23 +761,12 @@ ImageWriter::Bin ImageWriter::GetImageBin(mirror::Object* object) {
// If the class's static fields are all final, put it into a separate bin
// since it's very likely it will stay clean.
- uint32_t num_static_fields = as_klass->NumStaticFields();
- if (num_static_fields == 0) {
+ auto fields = as_klass->GetFields();
+ bool all_final = std::all_of(fields.begin(),
+ fields.end(),
+ [](ArtField& f) { return !f.IsStatic() || f.IsFinal(); });
+ if (all_final) {
bin = Bin::kClassInitializedFinalStatics;
- } else {
- // Maybe all the statics are final?
- bool all_final = true;
- for (uint32_t i = 0; i < num_static_fields; ++i) {
- ArtField* field = as_klass->GetStaticField(i);
- if (!field->IsFinal()) {
- all_final = false;
- break;
- }
- }
-
- if (all_final) {
- bin = Bin::kClassInitializedFinalStatics;
- }
}
}
} else if (!klass->HasSuperClass()) {
@@ -1415,28 +1404,24 @@ void ImageWriter::RecordNativeRelocations(ObjPtr<mirror::Class> klass, size_t oa
// Extra consistency check: no boot loader classes should be left!
CHECK(!klass->IsBootStrapClassLoaded()) << klass->PrettyClass();
}
- LengthPrefixedArray<ArtField>* fields[] = {
- klass->GetSFieldsPtr(), klass->GetIFieldsPtr(),
- };
ImageInfo& image_info = GetImageInfo(oat_index);
- for (LengthPrefixedArray<ArtField>* cur_fields : fields) {
- // Total array length including header.
- if (cur_fields != nullptr) {
- // Forward the entire array at once.
- size_t offset = image_info.GetBinSlotSize(Bin::kArtField);
- DCHECK(!IsInBootImage(cur_fields));
- bool inserted =
- native_object_relocations_.insert(std::make_pair(
- cur_fields,
- NativeObjectRelocation{
- oat_index, offset, NativeObjectRelocationType::kArtFieldArray
- })).second;
- CHECK(inserted) << "Field array " << cur_fields << " already forwarded";
- const size_t size = LengthPrefixedArray<ArtField>::ComputeSize(cur_fields->size());
- offset += size;
- image_info.IncrementBinSlotSize(Bin::kArtField, size);
- DCHECK_EQ(offset, image_info.GetBinSlotSize(Bin::kArtField));
- }
+ LengthPrefixedArray<ArtField>* fields = klass->GetFieldsPtr();
+ // Total array length including header.
+ if (fields != nullptr) {
+ // Forward the entire array at once.
+ size_t offset = image_info.GetBinSlotSize(Bin::kArtField);
+ DCHECK(!IsInBootImage(fields));
+ bool inserted =
+ native_object_relocations_.insert(std::make_pair(
+ fields,
+ NativeObjectRelocation{
+ oat_index, offset, NativeObjectRelocationType::kArtFieldArray
+ })).second;
+ CHECK(inserted) << "Field array " << fields << " already forwarded";
+ const size_t size = LengthPrefixedArray<ArtField>::ComputeSize(fields->size());
+ offset += size;
+ image_info.IncrementBinSlotSize(Bin::kArtField, size);
+ DCHECK_EQ(offset, image_info.GetBinSlotSize(Bin::kArtField));
}
// Visit and assign offsets for methods.
size_t num_methods = klass->NumMethods();
@@ -3334,8 +3319,7 @@ T* ImageWriter::NativeLocationInImage(T* obj) {
ArtField* ImageWriter::NativeLocationInImage(ArtField* src_field) {
// Fields are not individually stored in the native relocation map. Use the field array.
ObjPtr<mirror::Class> declaring_class = src_field->GetDeclaringClass<kWithoutReadBarrier>();
- LengthPrefixedArray<ArtField>* src_fields =
- src_field->IsStatic() ? declaring_class->GetSFieldsPtr() : declaring_class->GetIFieldsPtr();
+ LengthPrefixedArray<ArtField>* src_fields = declaring_class->GetFieldsPtr();
DCHECK(src_fields != nullptr);
LengthPrefixedArray<ArtField>* dst_fields = NativeLocationInImage(src_fields);
DCHECK(dst_fields != nullptr);