From 3ef5fb9669e0a4d7afb9425fe703bdb7667f2f06 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Mon, 12 Aug 2024 00:32:50 +0100 Subject: [PATCH] Improve inlining of array access Move the error handling behind a method boundary and make the rest inlinable. Signed-off-by: Stefan Marr --- src/vmobjects/VMArray.cpp | 26 ++++++-------------------- src/vmobjects/VMArray.h | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/vmobjects/VMArray.cpp b/src/vmobjects/VMArray.cpp index 78e268db..210eede8 100644 --- a/src/vmobjects/VMArray.cpp +++ b/src/vmobjects/VMArray.cpp @@ -48,26 +48,6 @@ VMArray::VMArray(size_t arraySize, size_t additionalBytes) nilInitializeFields(); } -vm_oop_t VMArray::GetIndexableField(size_t idx) const { - if (unlikely(idx > GetNumberOfIndexableFields())) { - ErrorExit(("Array index out of bounds: Accessing " + to_string(idx) + - ", but array size is only " + - to_string(GetNumberOfIndexableFields()) + "\n") - .c_str()); - } - return GetField(idx); -} - -void VMArray::SetIndexableField(size_t idx, vm_oop_t value) { - if (unlikely(idx > GetNumberOfIndexableFields())) { - ErrorExit(("Array index out of bounds: Accessing " + to_string(idx) + - ", but array size is only " + - to_string(GetNumberOfIndexableFields()) + "\n") - .c_str()); - } - SetField(idx, value); -} - VMArray* VMArray::Copy() const { VMArray* copy = Universe::NewArray(GetNumberOfIndexableFields()); @@ -97,6 +77,12 @@ VMArray* VMArray::CloneForMovingGC() const { return clone; } +void VMArray::IndexOutOfBounds(size_t idx) const { + ErrorExit(("Array index out of bounds: Accessing " + to_string(idx) + + ", but array size is only " + to_string(numberOfFields) + "\n") + .c_str()); +} + void VMArray::CopyIndexableFieldsTo(VMArray* to) const { const size_t numIndexableFields = GetNumberOfIndexableFields(); for (size_t i = 0; i < numIndexableFields; ++i) { diff --git a/src/vmobjects/VMArray.h b/src/vmobjects/VMArray.h index 8bcc4801..1467e95f 100644 --- a/src/vmobjects/VMArray.h +++ b/src/vmobjects/VMArray.h @@ -50,8 +50,24 @@ class VMArray : public VMObject { VMArray* Copy() const; VMArray* CopyAndExtendWith(vm_oop_t) const; - vm_oop_t GetIndexableField(size_t idx) const; - void SetIndexableField(size_t idx, vm_oop_t value); + + inline vm_oop_t GetIndexableField(size_t idx) const { + if (unlikely(idx > numberOfFields)) { + IndexOutOfBounds(idx); + } + return GetField(idx); + } + + inline void SetIndexableField(size_t idx, vm_oop_t value) { + if (unlikely(idx > GetNumberOfIndexableFields())) { + IndexOutOfBounds(idx); + } + SetField(idx, value); + } + + __attribute__((noreturn)) __attribute__((noinline)) void IndexOutOfBounds( + size_t idx) const; + void CopyIndexableFieldsTo(VMArray*) const; VMArray* CloneForMovingGC() const override;