summaryrefslogtreecommitdiff
path: root/runtime/mirror/class-inl.h
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2025-02-26 18:19:29 +0000
committer Nicolas Geoffray <ngeoffray@google.com> 2025-02-27 10:51:40 -0800
commit12f7d1eb0ff3fe0126d8dadd6bbfa8b797718e9c (patch)
tree02c4ac57b6a3ab39c2a36ac8f031e1562751859d /runtime/mirror/class-inl.h
parent6d9c6c00c78afb2e5d37f8c1b47b0a4e8772356e (diff)
Fast field lookup in nterp.
Only increase the hotness if we fail the fast lookup. Test: test.py Change-Id: I4526181eda83b3648383788738deaf71418de825
Diffstat (limited to 'runtime/mirror/class-inl.h')
-rw-r--r--runtime/mirror/class-inl.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index 40f119e3c4..373b9b3105 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -1356,6 +1356,38 @@ inline ImTable* Class::FindSuperImt(PointerSize pointer_size) {
return nullptr;
}
+ALWAYS_INLINE FLATTEN inline ArtField* Class::FindDeclaredField(uint32_t dex_field_idx) {
+ size_t num_fields = NumFields();
+ if (num_fields > 0) {
+ // The field array is an ordered list of fields where there may be missing
+ // indices. For example, it could be [40, 42], but in 90% of cases cases we have
+ // [40, 41, 42]. The latter is the case we are optimizing for, where for
+ // example `dex_field_idx` is 41, and we can just substract it with the
+ // first field index (40) and directly access the array with that index (1).
+ uint32_t index = dex_field_idx - GetField(0)->GetDexFieldIndex();
+ if (index < num_fields) {
+ ArtField* field = GetField(index);
+ if (field->GetDexFieldIndex() == dex_field_idx) {
+ return field;
+ }
+ } else {
+ index = num_fields;
+ }
+ // If there is a field, it's down the array. The array is ordered by field
+ // index, so we know we can stop the search if `dex_field_idx` is greater
+ // than the current field's index.
+ for (; index > 0; --index) {
+ ArtField* field = GetField(index - 1);
+ if (field->GetDexFieldIndex() == dex_field_idx) {
+ return field;
+ } else if (field->GetDexFieldIndex() < dex_field_idx) {
+ break;
+ }
+ }
+ }
+ return nullptr;
+}
+
} // namespace mirror
} // namespace art