Bug 1391633: Integrate use counters in the JavaScript engine; r=jonco, r=froydnj, data-review=francois

MozReview-Commit-ID: 1KOo0Zz0ccG

--HG--
extra : rebase_source : 1bdd89205a3d96f6d8314fc0cf08423b5c141cb6
extra : histedit_source : a000151b02c6423c967a72054b22679b08e25df9
This commit is contained in:
Benjamin Bouvier 2017-08-18 15:48:49 +02:00
Родитель 2cc6df95c3
Коммит e8f41447d2
7 изменённых файлов: 71 добавлений и 0 удалений

Просмотреть файл

@ -90,3 +90,7 @@ method DataTransfer.mozSetDataAt
method DataTransfer.mozGetDataAt
attribute DataTransfer.mozUserCancelled
attribute DataTransfer.mozSourceNode
// JavaScript feature usage
custom JS_asmjs uses asm.js
custom JS_wasm uses WebAssembly

Просмотреть файл

@ -657,6 +657,12 @@ JS_SetAccumulateTelemetryCallback(JSContext* cx, JSAccumulateTelemetryDataCallba
cx->runtime()->setTelemetryCallback(cx->runtime(), callback);
}
JS_FRIEND_API(void)
JS_SetSetUseCounterCallback(JSContext* cx, JSSetUseCounterCallback callback)
{
cx->runtime()->setUseCounterCallback(cx->runtime(), callback);
}
JS_FRIEND_API(JSObject*)
JS_CloneObject(JSContext* cx, HandleObject obj, HandleObject protoArg)
{

Просмотреть файл

@ -172,6 +172,24 @@ typedef void
extern JS_FRIEND_API(void)
JS_SetAccumulateTelemetryCallback(JSContext* cx, JSAccumulateTelemetryDataCallback callback);
/*
* Use counter names passed to the accumulate use counter callback.
*
* It's OK to for these enum values to change as they will be mapped to a
* fixed member of the mozilla::UseCounter enum by the callback.
*/
enum class JSUseCounter {
ASMJS,
WASM
};
typedef void
(*JSSetUseCounterCallback)(JSObject* obj, JSUseCounter counter);
extern JS_FRIEND_API(void)
JS_SetSetUseCounterCallback(JSContext* cx, JSSetUseCounterCallback callback);
extern JS_FRIEND_API(bool)
JS_GetIsSecureContext(JSCompartment* compartment);

Просмотреть файл

@ -444,6 +444,19 @@ JSRuntime::setTelemetryCallback(JSRuntime* rt, JSAccumulateTelemetryDataCallback
rt->telemetryCallback = callback;
}
void
JSRuntime::setUseCounter(JSObject* obj, JSUseCounter counter)
{
if (useCounterCallback)
(*useCounterCallback)(obj, counter);
}
void
JSRuntime::setUseCounterCallback(JSRuntime* rt, JSSetUseCounterCallback callback)
{
rt->useCounterCallback = callback;
}
void
JSRuntime::addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf, JS::RuntimeSizes* rtSizes)
{

Просмотреть файл

@ -455,6 +455,10 @@ struct JSRuntime : public js::MallocProvider<JSRuntime>
/* Call this to accumulate telemetry data. */
js::ActiveThreadData<JSAccumulateTelemetryDataCallback> telemetryCallback;
/* Call this to accumulate use counter data. */
js::ActiveThreadData<JSSetUseCounterCallback> useCounterCallback;
public:
// Accumulates data for Firefox telemetry. |id| is the ID of a JS_TELEMETRY_*
// histogram. |key| provides an additional key to identify the histogram.
@ -463,6 +467,13 @@ struct JSRuntime : public js::MallocProvider<JSRuntime>
void setTelemetryCallback(JSRuntime* rt, JSAccumulateTelemetryDataCallback callback);
// Sets the use counter for a specific feature, measuring the presence or
// absence of usage of a feature on a specific web page and document which
// the passed JSObject belongs to.
void setUseCounter(JSObject* obj, JSUseCounter counter);
void setUseCounterCallback(JSRuntime* rt, JSSetUseCounterCallback callback);
public:
js::UnprotectedData<js::OffThreadPromiseRuntimeState> offThreadPromiseState;

Просмотреть файл

@ -1206,5 +1206,8 @@ Module::instantiate(JSContext* cx,
uint32_t mode = uint32_t(metadata().isAsmJS() ? Telemetry::ASMJS : Telemetry::WASM);
cx->runtime()->addTelemetry(JS_TELEMETRY_AOT_USAGE, mode);
JSUseCounter useCounter = metadata().isAsmJS() ? JSUseCounter::ASMJS : JSUseCounter::WASM;
cx->runtime()->setUseCounter(instance, useCounter);
return true;
}

Просмотреть файл

@ -2663,6 +2663,21 @@ AccumulateTelemetryCallback(int id, uint32_t sample, const char* key)
}
}
static void
SetUseCounterCallback(JSObject* obj, JSUseCounter counter)
{
switch (counter) {
case JSUseCounter::ASMJS:
SetDocumentAndPageUseCounter(nullptr, obj, eUseCounter_custom_JS_asmjs);
break;
case JSUseCounter::WASM:
SetDocumentAndPageUseCounter(nullptr, obj, eUseCounter_custom_JS_wasm);
break;
default:
MOZ_ASSERT_UNREACHABLE("Unexpected JSUseCounter id");
}
}
static void
CompartmentNameCallback(JSContext* cx, JSCompartment* comp,
char* buf, size_t bufsize)
@ -2865,6 +2880,7 @@ XPCJSRuntime::Initialize(JSContext* cx)
JS_SetWrapObjectCallbacks(cx, &WrapObjectCallbacks);
js::SetPreserveWrapperCallback(cx, PreserveWrapper);
JS_SetAccumulateTelemetryCallback(cx, AccumulateTelemetryCallback);
JS_SetSetUseCounterCallback(cx, SetUseCounterCallback);
js::SetWindowProxyClass(cx, &OuterWindowProxyClass);
js::SetXrayJitInfo(&gXrayJitInfo);
JS::SetProcessLargeAllocationFailureCallback(OnLargeAllocationFailureCallback);