From e2976163c2333b67afaa1e5485834b153292e14c Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Wed, 14 Jun 2017 15:17:35 +0200 Subject: [PATCH] Bug 1372182 part 1 - Inline NativeObject::dynamicSlotsCount and related methods. r=anba --- js/src/vm/NativeObject-inl.h | 30 ++++++++++++++++++++++++++++++ js/src/vm/NativeObject.cpp | 18 ------------------ js/src/vm/NativeObject.h | 11 ++++------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/js/src/vm/NativeObject-inl.h b/js/src/vm/NativeObject-inl.h index c7dcd755e77f..453fb66440b4 100644 --- a/js/src/vm/NativeObject-inl.h +++ b/js/src/vm/NativeObject-inl.h @@ -500,6 +500,36 @@ NativeObject::create(JSContext* cx, js::gc::AllocKind kind, js::gc::InitialHeap return nobj; } +MOZ_ALWAYS_INLINE uint32_t +NativeObject::numDynamicSlots() const +{ + return dynamicSlotsCount(numFixedSlots(), slotSpan(), getClass()); +} + +/* static */ MOZ_ALWAYS_INLINE uint32_t +NativeObject::dynamicSlotsCount(uint32_t nfixed, uint32_t span, const Class* clasp) +{ + if (span <= nfixed) + return 0; + span -= nfixed; + + // Increase the slots to SLOT_CAPACITY_MIN to decrease the likelihood + // the dynamic slots need to get increased again. ArrayObjects ignore + // this because slots are uncommon in that case. + if (clasp != &ArrayObject::class_ && span <= SLOT_CAPACITY_MIN) + return SLOT_CAPACITY_MIN; + + uint32_t slots = mozilla::RoundUpPow2(span); + MOZ_ASSERT(slots >= span); + return slots; +} + +/* static */ MOZ_ALWAYS_INLINE uint32_t +NativeObject::dynamicSlotsCount(Shape* shape) +{ + return dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan(), shape->getObjectClass()); +} + MOZ_ALWAYS_INLINE bool NativeObject::updateSlotsForSpan(JSContext* cx, size_t oldSpan, size_t newSpan) { diff --git a/js/src/vm/NativeObject.cpp b/js/src/vm/NativeObject.cpp index 176a2e864685..78ec97c25ffc 100644 --- a/js/src/vm/NativeObject.cpp +++ b/js/src/vm/NativeObject.cpp @@ -286,24 +286,6 @@ js::NativeObject::numFixedSlotsForCompilation() const return gc::GetGCKindSlots(kind, getClass()); } -uint32_t -js::NativeObject::dynamicSlotsCount(uint32_t nfixed, uint32_t span, const Class* clasp) -{ - if (span <= nfixed) - return 0; - span -= nfixed; - - // Increase the slots to SLOT_CAPACITY_MIN to decrease the likelihood - // the dynamic slots need to get increased again. ArrayObjects ignore - // this because slots are uncommon in that case. - if (clasp != &ArrayObject::class_ && span <= SLOT_CAPACITY_MIN) - return SLOT_CAPACITY_MIN; - - uint32_t slots = mozilla::RoundUpPow2(span); - MOZ_ASSERT(slots >= span); - return slots; -} - void NativeObject::setLastPropertyShrinkFixedSlots(Shape* shape) { diff --git a/js/src/vm/NativeObject.h b/js/src/vm/NativeObject.h index cb9a147a2344..864617732b1e 100644 --- a/js/src/vm/NativeObject.h +++ b/js/src/vm/NativeObject.h @@ -741,9 +741,7 @@ class NativeObject : public ShapedObject bool hasDynamicSlots() const { return !!slots_; } /* Compute dynamicSlotsCount() for this object. */ - uint32_t numDynamicSlots() const { - return dynamicSlotsCount(numFixedSlots(), slotSpan(), getClass()); - } + MOZ_ALWAYS_INLINE uint32_t numDynamicSlots() const; bool empty() const { return lastProperty()->isEmptyShape(); @@ -1024,10 +1022,9 @@ class NativeObject : public ShapedObject * capacity is not stored explicitly, and the allocated size of the slot * array is kept in sync with this count. */ - static uint32_t dynamicSlotsCount(uint32_t nfixed, uint32_t span, const Class* clasp); - static uint32_t dynamicSlotsCount(Shape* shape) { - return dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan(), shape->getObjectClass()); - } + static MOZ_ALWAYS_INLINE uint32_t dynamicSlotsCount(uint32_t nfixed, uint32_t span, + const Class* clasp); + static MOZ_ALWAYS_INLINE uint32_t dynamicSlotsCount(Shape* shape); /* Elements accessors. */