Diff
Modified: trunk/JSTests/ChangeLog (263069 => 263070)
--- trunk/JSTests/ChangeLog 2020-06-16 00:20:44 UTC (rev 263069)
+++ trunk/JSTests/ChangeLog 2020-06-16 01:23:44 UTC (rev 263070)
@@ -1,3 +1,14 @@
+2020-06-15 Alexey Shvayka <[email protected]>
+
+ Expand JSObject::defineOwnIndexedProperty() fast path for existing properties
+ https://bugs.webkit.org/show_bug.cgi?id=213133
+
+ Reviewed by Yusuke Suzuki.
+
+ * microbenchmarks/array-redefine-index-and-reverse.js: Added.
+ * microbenchmarks/array-redefine-index.js: Added.
+ * stress/define-own-indexed-property-fast-path.js: Added.
+
2020-06-15 Caio Lima <[email protected]>
[ARMv7][MIPS][JSC] Skip check-is-constant-non-cell-should-not-array-profile-during-osr-exit.js
Added: trunk/JSTests/microbenchmarks/array-redefine-index-and-reverse.js (0 => 263070)
--- trunk/JSTests/microbenchmarks/array-redefine-index-and-reverse.js (rev 0)
+++ trunk/JSTests/microbenchmarks/array-redefine-index-and-reverse.js 2020-06-16 01:23:44 UTC (rev 263070)
@@ -0,0 +1,21 @@
+var arr = [0, 0, 0, 0];
+Object.defineProperty(arr, 0, {value: 0});
+Object.defineProperty(arr, 1, {value: 1, writable: true});
+Object.defineProperty(arr, 2, {value: 2, enumerable: true});
+Object.defineProperty(arr, 3, {value: 3, configurable: true});
+
+var lastIndex = arr.length - 1;
+function reverseTwice() {
+ for (var i = 0; i <= lastIndex; i++) {
+ var el = arr[lastIndex - i];
+ arr[lastIndex - i] = arr[i];
+ arr[i] = el;
+ }
+}
+noInline(reverseTwice);
+
+for (var i = 0; i < 1e5; i++)
+ reverseTwice();
+
+if (arr.some((el, i) => el !== i))
+ throw `Bad array: ${arr}`;
Added: trunk/JSTests/microbenchmarks/array-redefine-index.js (0 => 263070)
--- trunk/JSTests/microbenchmarks/array-redefine-index.js (rev 0)
+++ trunk/JSTests/microbenchmarks/array-redefine-index.js 2020-06-16 01:23:44 UTC (rev 263070)
@@ -0,0 +1,16 @@
+var arr = [0, 1, 2, 3];
+
+function redefineIndices(i) {
+ Object.defineProperty(arr, 0, {value: i});
+ Object.defineProperty(arr, 1, {value: i, writable: true});
+ Object.defineProperty(arr, 2, {value: i, enumerable: true});
+ Object.defineProperty(arr, 3, {value: i, configurable: true});
+}
+noInline(redefineIndices);
+
+var max = 1e5;
+for (var i = 0; i <= max; i++)
+ redefineIndices(i);
+
+if (arr.some(el => el !== max))
+ throw `Bad array: ${arr}`;
Added: trunk/JSTests/stress/define-own-indexed-property-fast-path.js (0 => 263070)
--- trunk/JSTests/stress/define-own-indexed-property-fast-path.js (rev 0)
+++ trunk/JSTests/stress/define-own-indexed-property-fast-path.js 2020-06-16 01:23:44 UTC (rev 263070)
@@ -0,0 +1,90 @@
+function assertSameDescriptor(a, b) {
+ const aString = stringifyDescriptor(a);
+ const bString = stringifyDescriptor(b);
+
+ if (aString !== bString)
+ throw new Error(`Bad descriptor!\nActual: ${aString}\nExpected: ${bString}`);
+}
+
+function stringifyDescriptor(descriptor) {
+ const sortedDescriptor = {};
+ for (const key of Object.keys(descriptor).sort())
+ sortedDescriptor[key] = descriptor[key];
+
+ return JSON.stringify(sortedDescriptor, null, 2);
+}
+
+function getCombinations(options) {
+ const optionKeys = Object.keys(options);
+ const results = [];
+
+ function getNextCombination(optionIndex, current) {
+ const optionKey = optionKeys[optionIndex];
+
+ for (const value of options[optionKey]) {
+ current[optionKey] = value;
+
+ const nextIndex = optionIndex + 1;
+ if (nextIndex < optionKeys.length) {
+ getNextCombination(nextIndex, current);
+ break;
+ }
+
+ // deep clone `current` and remove `undefined` values
+ const result = JSON.parse(JSON.stringify(current));
+ results.push(result);
+ }
+ }
+
+ getNextCombination(0, {});
+ return results;
+}
+
+function testCreateProperty(object, key, descriptor) {
+ if (object.hasOwnProperty(key))
+ throw new Error(`Property ${key} should not exist.`);
+
+ Object.defineProperty(object, key, descriptor);
+
+ assertSameDescriptor(
+ Object.getOwnPropertyDescriptor(object, key),
+ {value: undefined, writable: false, enumerable: false, configurable: false, ...descriptor},
+ );
+}
+
+function testRedefineProperty(object, key, descriptor) {
+ if (!object.hasOwnProperty(key))
+ throw new Error(`Property ${key} should exist.`);
+
+ const value = object[key];
+ Object.defineProperty(object, key, descriptor);
+
+ assertSameDescriptor(
+ Object.getOwnPropertyDescriptor(object, key),
+ {value, writable: true, enumerable: true, configurable: true, ...descriptor},
+ );
+}
+
+const dataDescriptor = {
+ value: [1, 2, undefined],
+ writable: [true, false, undefined],
+ enumerable: [true, false, undefined],
+ configurable: [true, false, undefined],
+};
+
+const accessorDescriptor = {
+ get: [function() {}, undefined],
+ set: [function(value) {}, undefined],
+ enumerable: [true, false, undefined],
+ configurable: [true, false, undefined],
+};
+
+for (const descriptor of getCombinations(dataDescriptor)) {
+ testCreateProperty([], "0", descriptor);
+ testRedefineProperty([1], "0", descriptor);
+}
+
+for (const descriptor of getCombinations(accessorDescriptor)) {
+ testCreateProperty([1, 2], "2", descriptor);
+ testRedefineProperty([1, 2, 3], "2", descriptor);
+}
Modified: trunk/Source/_javascript_Core/ChangeLog (263069 => 263070)
--- trunk/Source/_javascript_Core/ChangeLog 2020-06-16 00:20:44 UTC (rev 263069)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-06-16 01:23:44 UTC (rev 263070)
@@ -1,3 +1,24 @@
+2020-06-15 Alexey Shvayka <[email protected]>
+
+ Expand JSObject::defineOwnIndexedProperty() fast path for existing properties
+ https://bugs.webkit.org/show_bug.cgi?id=213133
+
+ Reviewed by Yusuke Suzuki.
+
+ This patch expands fast path of JSObject::defineOwnIndexedProperty() to cover existing properties
+ if given data descriptor has no falsy attributes, preventing the object from entering SparseMode.
+ The optimization is possible due to this invariant: indexed properties of non-SparseMode objects
+ have attributes of PropertyAttribute::None (except for typed arrays; added assert covers it).
+
+ PropertyDescriptor::attributesOverridingCurrent() with PropertyAttribute::None descriptor
+ is used to support partial descriptors like {value: 1, writable: true}.
+
+ This change advances Object.defineProperty microbenchmark by 35%; array read/write benchmark
+ following property redefinition is progressed by a factor of 16 due to avoiding SparseMode.
+
+ * runtime/JSObject.cpp:
+ (JSC::JSObject::defineOwnIndexedProperty):
+
2020-06-15 Robin Morisset <[email protected]>
testB3::testReportUsedRegistersLateUseFollowedByEarlyDefDoesNotMarkUseAsDead() has a validation failure in debug mode
Modified: trunk/Source/_javascript_Core/runtime/JSObject.cpp (263069 => 263070)
--- trunk/Source/_javascript_Core/runtime/JSObject.cpp 2020-06-16 00:20:44 UTC (rev 263069)
+++ trunk/Source/_javascript_Core/runtime/JSObject.cpp 2020-06-16 01:23:44 UTC (rev 263070)
@@ -2611,7 +2611,7 @@
|| jsDynamicCast<JSFinalObject*>(vm, object);
}
-// Defined in ES5.1 8.12.9
+// https://tc39.es/ecma262/#sec-ordinarydefineownproperty
bool JSObject::defineOwnIndexedProperty(JSGlobalObject* globalObject, unsigned index, const PropertyDescriptor& descriptor, bool throwException)
{
VM& vm = globalObject->vm();
@@ -2622,11 +2622,21 @@
ensureWritable(vm);
if (!inSparseIndexingMode()) {
+ const PropertyDescriptor emptyAttributesDescriptor(jsUndefined(), static_cast<unsigned>(PropertyAttribute::None));
+ ASSERT(emptyAttributesDescriptor.attributes() == static_cast<unsigned>(PropertyAttribute::None));
+
+#if ASSERT_ENABLED
+ if (canGetIndexQuickly(index) && canDoFastPutDirectIndex(vm, this)) {
+ PropertyDescriptor currentDescriptor;
+ ASSERT(getOwnPropertyDescriptor(globalObject, Identifier::from(vm, index), currentDescriptor));
+ scope.assertNoException();
+ ASSERT(currentDescriptor.attributes() == emptyAttributesDescriptor.attributes());
+ }
+#endif
// Fast case: we're putting a regular property to a regular array
- // FIXME: this will pessimistically assume that if attributes are missing then they'll default to false
- // however if the property currently exists missing attributes will override from their current 'true'
- // state (i.e. defineOwnProperty could be used to set a value without needing to entering 'SparseMode').
- if (!descriptor.attributes() && descriptor.value() && canDoFastPutDirectIndex(vm, this)) {
+ if (descriptor.value()
+ && (!descriptor.attributes() || (canGetIndexQuickly(index) && !descriptor.attributesOverridingCurrent(emptyAttributesDescriptor)))
+ && canDoFastPutDirectIndex(vm, this)) {
ASSERT(!descriptor.isAccessorDescriptor());
RELEASE_AND_RETURN(scope, putDirectIndex(globalObject, index, descriptor.value(), 0, throwException ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow));
}