Bug 1896505 - Track Type III subclassing in TypedArrays r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D210540
This commit is contained in:
Matthew Gaudet 2024-05-29 19:14:13 +00:00
parent a18aa75499
commit 647a5c80d4
8 changed files with 82 additions and 13 deletions

View File

@ -75,6 +75,7 @@ custom JS_subclassing_array_type_3 Array is Type III subclassed
custom JS_subclassing_promise_type_2 Promise is Type II subclassed
custom JS_subclassing_promise_type_3 Promise is Type III subclassed
custom JS_subclassing_typedarray_type_2 TypedArray is Type II subclassed
custom JS_subclassing_typedarray_type_3 TypedArray is Type III subclassed
// Console API
method console.assert

View File

@ -107,8 +107,8 @@ use.counter:
send_in_pings:
- use-counters
# Total of 2319 use counter metrics (excludes denominators).
# Total of 359 'page' use counters.
# Total of 2321 use counter metrics (excludes denominators).
# Total of 360 'page' use counters.
use.counter.page:
svgsvgelement_getelementbyid:
type: counter
@ -620,6 +620,23 @@ use.counter.page:
send_in_pings:
- use-counters
js_subclassing_typedarray_type_3:
type: counter
description: >
Whether a page TypedArray is Type III subclassed.
Compare against `use.counter.top_level_content_documents_destroyed`
to calculate the rate.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
notification_emails:
- dom-core@mozilla.com
- emilio@mozilla.com
expires: never
send_in_pings:
- use-counters
console_assert:
type: counter
description: >
@ -6213,7 +6230,7 @@ use.counter.page:
send_in_pings:
- use-counters
# Total of 359 'document' use counters.
# Total of 360 'document' use counters.
use.counter.doc:
svgsvgelement_getelementbyid:
type: counter
@ -6725,6 +6742,23 @@ use.counter.doc:
send_in_pings:
- use-counters
js_subclassing_typedarray_type_3:
type: counter
description: >
Whether a document TypedArray is Type III subclassed.
Compare against `use.counter.content_documents_destroyed`
to calculate the rate.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
notification_emails:
- dom-core@mozilla.com
- emilio@mozilla.com
expires: never
send_in_pings:
- use-counters
console_assert:
type: counter
description: >

View File

@ -84,15 +84,16 @@ using JSAccumulateTelemetryDataCallback = void (*)(JSMetric, uint32_t);
extern JS_PUBLIC_API void JS_SetAccumulateTelemetryCallback(
JSContext* cx, JSAccumulateTelemetryDataCallback callback);
#define FOR_EACH_JS_USE_COUNTER(_) \
_(ASMJS, AsmJS) \
_(WASM, Wasm) \
_(WASM_LEGACY_EXCEPTIONS, WasmLegacyExceptions) \
_(SUBCLASSING_ARRAY_TYPE_II, SubclassingArrayTypeII) \
_(SUBCLASSING_ARRAY_TYPE_III, SubclassingArrayTypeIII) \
_(SUBCLASSING_PROMISE_TYPE_II, SubclassingPromiseTypeII) \
_(SUBCLASSING_PROMISE_TYPE_III, SubclassingPromiseTypeIII) \
_(SUBCLASSING_TYPEDARRAY_TYPE_II, SubclassingTypedArrayTypeII)
#define FOR_EACH_JS_USE_COUNTER(_) \
_(ASMJS, AsmJS) \
_(WASM, Wasm) \
_(WASM_LEGACY_EXCEPTIONS, WasmLegacyExceptions) \
_(SUBCLASSING_ARRAY_TYPE_II, SubclassingArrayTypeII) \
_(SUBCLASSING_ARRAY_TYPE_III, SubclassingArrayTypeIII) \
_(SUBCLASSING_PROMISE_TYPE_II, SubclassingPromiseTypeII) \
_(SUBCLASSING_PROMISE_TYPE_III, SubclassingPromiseTypeIII) \
_(SUBCLASSING_TYPEDARRAY_TYPE_II, SubclassingTypedArrayTypeII) \
_(SUBCLASSING_TYPEDARRAY_TYPE_III, SubclassingTypedArrayTypeIII)
/*
* Use counter names passed to the accumulate use counter callback.

View File

@ -151,5 +151,7 @@
#define SUBCLASS_ARRAY_TYPE_III \
((SUBCLASSING_ARRAY << SUBCLASSING_BUILTIN_SHIFT) | SUBCLASSING_TYPE_III)
#define SUBCLASS_TYPEDARRAY_TYPE_III \
((SUBCLASSING_TYPEDARRAY << SUBCLASSING_BUILTIN_SHIFT) | SUBCLASSING_TYPE_III)
#endif

View File

@ -103,6 +103,7 @@ function TypedArraySpeciesConstructor(obj) {
// Step 7.
if (IsConstructor(s)) {
ReportUsageCounter(s, SUBCLASS_TYPEDARRAY_TYPE_III)
return s;
}

View File

@ -52,3 +52,26 @@ TYPED_ARRAY_FROM_NON_ITERATOR.forEach((x) => {
SUBCLASS_FROM_NON_ITERATOR.forEach((x) => {
test_function_for_use_counter_integration(x, "SubclassingTypedArrayTypeII", /* expected_growth = */ true)
})
// Type III Subclassing
class Sentinel extends Int8Array { }
class MyInt8Array extends Int8Array {
static get [Symbol.species]() {
return Sentinel;
}
}
function int8_test() {
let a = Int8Array.of(0, 1, 2, 3);
let r = a.filter(() => true);
assertEq(r instanceof Int8Array, true);
}
function myint8_test() {
let a = MyInt8Array.of(0, 1, 2, 3);
let r = a.filter(() => true);
assertEq(r instanceof Sentinel, true);
}
test_function_for_use_counter_integration(int8_test, "SubclassingTypedArrayTypeIII", /*expected_growth=*/ false);
test_function_for_use_counter_integration(myint8_test, "SubclassingTypedArrayTypeIII", /*expected_growth=*/ true);

View File

@ -3034,7 +3034,6 @@ bool js::ReportUsageCounter(JSContext* cx, HandleObject constructorArg,
// I'm inclined to say not at the moment -- but it would
// be a behaviour change if we removed subclassing.
if (constructor && IsTypedArrayConstructor(constructor)) {
fprintf(stderr, "Skipping known typed array constructor\n");
return true;
}
switch (type) {
@ -3042,6 +3041,10 @@ bool js::ReportUsageCounter(JSContext* cx, HandleObject constructorArg,
cx->runtime()->setUseCounter(
cx->global(), JSUseCounter::SUBCLASSING_TYPEDARRAY_TYPE_II);
return true;
case SUBCLASSING_TYPE_III:
cx->runtime()->setUseCounter(
cx->global(), JSUseCounter::SUBCLASSING_TYPEDARRAY_TYPE_III);
return true;
default:
MOZ_CRASH("Unhandled subclassing type");
}

View File

@ -2655,6 +2655,10 @@ static void SetUseCounterCallback(JSObject* obj, JSUseCounter counter) {
SetUseCounter(
obj, mozilla::eUseCounter_custom_JS_subclassing_typedarray_type_2);
return;
case JSUseCounter::SUBCLASSING_TYPEDARRAY_TYPE_III:
SetUseCounter(
obj, mozilla::eUseCounter_custom_JS_subclassing_typedarray_type_3);
return;
case JSUseCounter::COUNT:
break;
}