summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-06-22 12:52:03 +0000
committerMoonchild <moonchild@palemoon.org>2020-06-22 12:52:03 +0000
commitb791b67121821257b8a4dc63ac96d83e5c7240b2 (patch)
tree26adf26104d67b7c4a457ac54cfb94f85c55a0dc
parentc15bc7d3dd4dcbfdd3ed699e8ecfe29bc8e86b6f (diff)
downloaduxp-b791b67121821257b8a4dc63ac96d83e5c7240b2.tar.gz
Issue #1459 - Inline a number of helper functions.
-rw-r--r--js/src/jit/BaselineIC.cpp20
-rw-r--r--js/src/jit/MCallOptimize.cpp11
-rw-r--r--js/src/jit/VMFunctions.cpp2
-rw-r--r--js/src/jsarray.cpp30
-rw-r--r--js/src/jsobj.cpp8
-rw-r--r--js/src/vm/UnboxedObject-inl.h38
6 files changed, 49 insertions, 60 deletions
diff --git a/js/src/jit/BaselineIC.cpp b/js/src/jit/BaselineIC.cpp
index eb17184664..7933160747 100644
--- a/js/src/jit/BaselineIC.cpp
+++ b/js/src/jit/BaselineIC.cpp
@@ -2388,8 +2388,12 @@ CanOptimizeDenseOrUnboxedArraySetElem(JSObject* obj, uint32_t index,
Shape* oldShape, uint32_t oldCapacity, uint32_t oldInitLength,
bool* isAddingCaseOut, size_t* protoDepthOut)
{
- uint32_t initLength = GetAnyBoxedOrUnboxedInitializedLength(obj);
- uint32_t capacity = GetAnyBoxedOrUnboxedCapacity(obj);
+ uint32_t initLength = obj->isNative() ?
+ obj->as<NativeObject>().getDenseInitializedLength() :
+ 0;
+ uint32_t capacity = obj->isNative() ?
+ obj->as<NativeObject>().getDenseCapacity() :
+ 0;
*isAddingCaseOut = false;
*protoDepthOut = 0;
@@ -2478,9 +2482,9 @@ DoSetElemFallback(JSContext* cx, BaselineFrame* frame, ICSetElem_Fallback* stub_
// Check the old capacity
uint32_t oldCapacity = 0;
uint32_t oldInitLength = 0;
- if (index.isInt32() && index.toInt32() >= 0) {
- oldCapacity = GetAnyBoxedOrUnboxedCapacity(obj);
- oldInitLength = GetAnyBoxedOrUnboxedInitializedLength(obj);
+ if (index.isInt32() && index.toInt32() >= 0 && obj->isNative()) {
+ oldCapacity = obj->as<NativeObject>().getDenseCapacity();
+ oldInitLength = obj->as<NativeObject>().getDenseInitializedLength();
}
if (op == JSOP_INITELEM || op == JSOP_INITHIDDENELEM) {
@@ -5778,7 +5782,7 @@ TryAttachCallStub(JSContext* cx, ICCall_Fallback* stub, HandleScript script, jsb
static bool
CopyArray(JSContext* cx, HandleObject obj, MutableHandleValue result)
{
- uint32_t length = GetAnyBoxedOrUnboxedArrayLength(obj);
+ uint32_t length = obj->as<ArrayObject>().length();
JSObject* nobj = NewFullyAllocatedArrayTryReuseGroup(cx, obj, length, TenuredObject);
if (!nobj)
return false;
@@ -5820,9 +5824,9 @@ TryAttachStringSplit(JSContext* cx, ICCall_Fallback* stub, HandleScript script,
// Atomize all elements of the array.
RootedObject arrObj(cx, &arr.toObject());
- uint32_t initLength = GetAnyBoxedOrUnboxedArrayLength(arrObj);
+ uint32_t initLength = arrObj->as<ArrayObject>().length();
for (uint32_t i = 0; i < initLength; i++) {
- JSAtom* str = js::AtomizeString(cx, GetAnyBoxedOrUnboxedDenseElement(arrObj, i).toString());
+ JSAtom* str = js::AtomizeString(cx, arrObj->as<NativeObject>().getDenseElement(i).toString());
if (!str)
return false;
diff --git a/js/src/jit/MCallOptimize.cpp b/js/src/jit/MCallOptimize.cpp
index cd8ea1c66a..f6066d8df5 100644
--- a/js/src/jit/MCallOptimize.cpp
+++ b/js/src/jit/MCallOptimize.cpp
@@ -518,7 +518,7 @@ IonBuilder::inlineArray(CallInfo& callInfo)
// Make sure initLength matches the template object's length. This is
// not guaranteed to be the case, for instance if we're inlining the
// MConstant may come from an outer script.
- if (initLength != GetAnyBoxedOrUnboxedArrayLength(templateObject))
+ if (initLength != templateObject->as<ArrayObject>().length())
return InliningStatus_NotInlined;
// Don't inline large allocations.
@@ -1385,13 +1385,16 @@ IonBuilder::inlineConstantStringSplitString(CallInfo& callInfo)
if (!key.maybeTypes()->hasType(TypeSet::StringType()))
return InliningStatus_NotInlined;
- uint32_t initLength = GetAnyBoxedOrUnboxedArrayLength(templateObject);
- if (GetAnyBoxedOrUnboxedInitializedLength(templateObject) != initLength)
+ uint32_t arrayLength = templateObject->as<ArrayObject>().length();
+ uint32_t initLength = templateObject->isNative() ?
+ templateObject->as<NativeObject>().getDenseInitializedLength() :
+ 0;
+ if (arrayLength != initLength)
return InliningStatus_NotInlined;
Vector<MConstant*, 0, SystemAllocPolicy> arrayValues;
for (uint32_t i = 0; i < initLength; i++) {
- Value str = GetAnyBoxedOrUnboxedDenseElement(templateObject, i);
+ Value str = templateObject->as<NativeObject>().getDenseElement(i);
MOZ_ASSERT(str.toString()->isAtom());
MConstant* value = MConstant::New(alloc().fallible(), str, constraints());
if (!value)
diff --git a/js/src/jit/VMFunctions.cpp b/js/src/jit/VMFunctions.cpp
index 037d66a696..ac594e8474 100644
--- a/js/src/jit/VMFunctions.cpp
+++ b/js/src/jit/VMFunctions.cpp
@@ -327,7 +327,7 @@ ArrayPopDense(JSContext* cx, HandleObject obj, MutableHandleValue rval)
bool
ArrayPushDense(JSContext* cx, HandleObject obj, HandleValue v, uint32_t* length)
{
- *length = GetAnyBoxedOrUnboxedArrayLength(obj);
+ *length = obj->as<ArrayObject>().length();
DenseElementResult result =
SetOrExtendAnyBoxedOrUnboxedDenseElements(cx, obj, *length, v.address(), 1,
ShouldUpdateTypes::DontUpdate);
diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp
index 29d40390bc..05f7d371b1 100644
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -249,8 +249,11 @@ GetElement(JSContext* cx, HandleObject obj, HandleObject receiver,
uint32_t index, bool* hole, MutableHandleValue vp)
{
AssertGreaterThanZero(index);
- if (index < GetAnyBoxedOrUnboxedInitializedLength(obj)) {
- vp.set(GetAnyBoxedOrUnboxedDenseElement(obj, uint32_t(index)));
+ uint32_t initLength = obj->isNative() ?
+ obj->as<NativeObject>().getDenseInitializedLength() :
+ 0;
+ if (index < initLength) {
+ vp.set(obj->as<NativeObject>().getDenseElement(index));
if (!vp.isMagic(JS_ELEMENTS_HOLE)) {
*hole = false;
return true;
@@ -849,7 +852,10 @@ js::ObjectMayHaveExtraIndexedProperties(JSObject* obj)
if (ObjectMayHaveExtraIndexedOwnProperties(obj))
return true;
- if (GetAnyBoxedOrUnboxedInitializedLength(obj) != 0)
+ uint32_t initLength = obj->isNative() ?
+ obj->as<NativeObject>().getDenseInitializedLength() :
+ 0;
+ if (initLength != 0)
return true;
} while (true);
}
@@ -1208,8 +1214,11 @@ js::array_join(JSContext* cx, unsigned argc, Value* vp)
// An optimized version of a special case of steps 7-11: when length==1 and
// the 0th element is a string, ToString() of that element is a no-op and
// so it can be immediately returned as the result.
- if (length == 1 && GetAnyBoxedOrUnboxedInitializedLength(obj) == 1) {
- Value elem0 = GetAnyBoxedOrUnboxedDenseElement(obj, 0);
+ uint32_t initLength = obj->isNative() ?
+ obj->as<NativeObject>().getDenseInitializedLength() :
+ 0;
+ if (length == 1 && initLength == 1) {
+ Value elem0 = obj->as<NativeObject>().getDenseElement(0);
if (elem0.isString()) {
args.rval().set(elem0);
return true;
@@ -2404,8 +2413,11 @@ CanOptimizeForDenseStorage(HandleObject arr, uint32_t startingIndex, uint32_t co
* other indexed properties on the object. (Note that non-writable length
* is subsumed by the initializedLength comparison.)
*/
+ uint32_t initLength = arr->isNative() ?
+ arr->as<NativeObject>().getDenseInitializedLength() :
+ 0;
return !ObjectMayHaveExtraIndexedProperties(arr) &&
- startingIndex + count <= GetAnyBoxedOrUnboxedInitializedLength(arr);
+ startingIndex + count <= initLength;
}
static inline bool
@@ -2866,7 +2878,9 @@ ArraySliceOrdinary(JSContext* cx, HandleObject obj, uint32_t length, uint32_t be
begin = end;
if (!ObjectMayHaveExtraIndexedProperties(obj)) {
- size_t initlen = GetAnyBoxedOrUnboxedInitializedLength(obj);
+ size_t initlen = obj->isNative() ?
+ obj->as<NativeObject>().getDenseInitializedLength() :
+ 0;
size_t count = 0;
if (initlen > begin)
count = Min<size_t>(initlen - begin, end - begin);
@@ -3006,7 +3020,7 @@ template <JSValueType Type>
DenseElementResult
ArraySliceDenseKernel(JSContext* cx, JSObject* obj, int32_t beginArg, int32_t endArg, JSObject* result)
{
- int32_t length = GetAnyBoxedOrUnboxedArrayLength(obj);
+ int32_t length = obj->as<ArrayObject>().length();
uint32_t begin = NormalizeSliceTerm(beginArg, length);
uint32_t end = NormalizeSliceTerm(endArg, length);
diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp
index 5593efb5ef..58e1adfc12 100644
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -1144,13 +1144,15 @@ GetScriptArrayObjectElements(JSContext* cx, HandleObject obj, MutableHandle<GCVe
MOZ_ASSERT(obj->is<ArrayObject>());
MOZ_ASSERT(!obj->isIndexed());
- size_t length = GetAnyBoxedOrUnboxedArrayLength(obj);
+ size_t length = obj->as<ArrayObject>().length();
if (!values.appendN(MagicValue(JS_ELEMENTS_HOLE), length))
return false;
- size_t initlen = GetAnyBoxedOrUnboxedInitializedLength(obj);
+ size_t initlen = obj->isNative() ?
+ obj->as<NativeObject>().getDenseInitializedLength() :
+ 0;
for (size_t i = 0; i < initlen; i++)
- values[i].set(GetAnyBoxedOrUnboxedDenseElement(obj, i));
+ values[i].set(obj->as<NativeObject>().getDenseElement(i));
return true;
}
diff --git a/js/src/vm/UnboxedObject-inl.h b/js/src/vm/UnboxedObject-inl.h
index f60b5ffb80..606e457280 100644
--- a/js/src/vm/UnboxedObject-inl.h
+++ b/js/src/vm/UnboxedObject-inl.h
@@ -176,40 +176,6 @@ UnboxedPlainObject::layout() const
// Combined methods for NativeObject and UnboxedArrayObject accesses.
/////////////////////////////////////////////////////////////////////
-static inline bool
-HasAnyBoxedOrUnboxedDenseElements(JSObject* obj)
-{
- return obj->isNative();
-}
-
-static inline size_t
-GetAnyBoxedOrUnboxedInitializedLength(JSObject* obj)
-{
- if (obj->isNative())
- return obj->as<NativeObject>().getDenseInitializedLength();
- return 0;
-}
-
-static inline size_t
-GetAnyBoxedOrUnboxedCapacity(JSObject* obj)
-{
- if (obj->isNative())
- return obj->as<NativeObject>().getDenseCapacity();
- return 0;
-}
-
-static inline Value
-GetAnyBoxedOrUnboxedDenseElement(JSObject* obj, size_t index)
-{
- return obj->as<NativeObject>().getDenseElement(index);
-}
-
-static inline size_t
-GetAnyBoxedOrUnboxedArrayLength(JSObject* obj)
-{
- return obj->as<ArrayObject>().length();
-}
-
static inline void
SetAnyBoxedOrUnboxedArrayLength(JSContext* cx, JSObject* obj, size_t length)
{
@@ -436,7 +402,7 @@ template <typename F>
DenseElementResult
CallBoxedOrUnboxedSpecialization(F f, JSObject* obj)
{
- if (!HasAnyBoxedOrUnboxedDenseElements(obj))
+ if (!obj->isNative())
return DenseElementResult::Incomplete;
switch (GetBoxedOrUnboxedType(obj)) {
case JSVAL_TYPE_MAGIC:
@@ -461,7 +427,7 @@ template <typename F>
DenseElementResult
CallBoxedOrUnboxedSpecialization(F f, JSObject* obj1, JSObject* obj2)
{
- if (!HasAnyBoxedOrUnboxedDenseElements(obj1) || !HasAnyBoxedOrUnboxedDenseElements(obj2))
+ if (!obj1->isNative() || !obj2->isNative())
return DenseElementResult::Incomplete;
#define SPECIALIZE_OBJ2(TYPE) \