mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 14:45:29 +00:00
Bug 670059 - Add some JS engine telemetry counters to measure occurrences of: E4X, __iterator__, mutable __proto__ (r=taras,waldo)
--HG-- extra : rebase_source : f77f2ad5521bf4543b518f7f6cc40a3778b7a74a
This commit is contained in:
parent
b144912be6
commit
6d4c06f84f
@ -1434,6 +1434,12 @@ JSContext::generatorFor(StackFrame *fp) const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
JSContext::runningWithTrustedPrincipals() const
|
||||
{
|
||||
return !compartment || compartment->principals == runtime->trustedPrincipals();
|
||||
}
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
JSRuntime::onTooMuchMalloc()
|
||||
{
|
||||
|
@ -1296,6 +1296,12 @@ struct JSContext
|
||||
bool stackIterAssertionEnabled;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* See JS_SetTrustedPrincipals in jsapi.h.
|
||||
* Note: !cx->compartment is treated as trusted.
|
||||
*/
|
||||
bool runningWithTrustedPrincipals() const;
|
||||
|
||||
private:
|
||||
/*
|
||||
* The allocation code calls the function to indicate either OOM failure
|
||||
|
@ -80,3 +80,32 @@ JS_GetFrameScopeChainRaw(JSStackFrame *fp)
|
||||
{
|
||||
return &Valueify(fp)->scopeChain();
|
||||
}
|
||||
|
||||
/*
|
||||
* The below code is for temporary telemetry use. It can be removed when
|
||||
* sufficient data has been harvested.
|
||||
*/
|
||||
|
||||
extern size_t sE4XObjectsCreated;
|
||||
|
||||
JS_FRIEND_API(size_t)
|
||||
JS_GetE4XObjectsCreated(JSContext *)
|
||||
{
|
||||
return sE4XObjectsCreated;
|
||||
}
|
||||
|
||||
extern size_t sSetProtoCalled;
|
||||
|
||||
JS_FRIEND_API(size_t)
|
||||
JS_SetProtoCalled(JSContext *)
|
||||
{
|
||||
return sSetProtoCalled;
|
||||
}
|
||||
|
||||
extern size_t sCustomIteratorCount;
|
||||
|
||||
JS_FRIEND_API(size_t)
|
||||
JS_GetCustomIteratorCount(JSContext *cx)
|
||||
{
|
||||
return sCustomIteratorCount;
|
||||
}
|
||||
|
@ -57,6 +57,15 @@ JS_UnwrapObject(JSObject *obj);
|
||||
extern JS_FRIEND_API(JSObject *)
|
||||
JS_GetFrameScopeChainRaw(JSStackFrame *fp);
|
||||
|
||||
extern JS_FRIEND_API(size_t)
|
||||
JS_GetE4XObjectsCreated(JSContext *cx);
|
||||
|
||||
extern JS_FRIEND_API(size_t)
|
||||
JS_SetProtoCalled(JSContext *cx);
|
||||
|
||||
extern JS_FRIEND_API(size_t)
|
||||
JS_GetCustomIteratorCount(JSContext *cx);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsfriendapi_h___ */
|
||||
|
@ -2908,3 +2908,16 @@ RunDebugGC(JSContext *cx)
|
||||
} /* namespace gc */
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
#if JS_HAS_XML_SUPPORT
|
||||
extern size_t sE4XObjectsCreated;
|
||||
|
||||
JSXML *
|
||||
js_NewGCXML(JSContext *cx)
|
||||
{
|
||||
if (!cx->runningWithTrustedPrincipals())
|
||||
++sE4XObjectsCreated;
|
||||
|
||||
return NewGCThing<JSXML>(cx, js::gc::FINALIZE_XML, sizeof(JSXML));
|
||||
}
|
||||
#endif
|
||||
|
@ -256,12 +256,8 @@ js_NewGCShape(JSContext *cx)
|
||||
}
|
||||
|
||||
#if JS_HAS_XML_SUPPORT
|
||||
inline JSXML *
|
||||
js_NewGCXML(JSContext *cx)
|
||||
{
|
||||
return NewGCThing<JSXML>(cx, js::gc::FINALIZE_XML, sizeof(JSXML));
|
||||
}
|
||||
extern JSXML *
|
||||
js_NewGCXML(JSContext *cx);
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* jsgcinlines_h___ */
|
||||
|
@ -339,6 +339,8 @@ GetPropertyNames(JSContext *cx, JSObject *obj, uintN flags, AutoIdVector *props)
|
||||
|
||||
}
|
||||
|
||||
size_t sCustomIteratorCount = 0;
|
||||
|
||||
static inline bool
|
||||
GetCustomIterator(JSContext *cx, JSObject *obj, uintN flags, Value *vp)
|
||||
{
|
||||
@ -353,6 +355,9 @@ GetCustomIterator(JSContext *cx, JSObject *obj, uintN flags, Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!cx->runningWithTrustedPrincipals())
|
||||
++sCustomIteratorCount;
|
||||
|
||||
/* Otherwise call it and return that object. */
|
||||
LeaveTrace(cx);
|
||||
Value arg = BooleanValue((flags & JSITER_FOREACH) == 0);
|
||||
|
@ -165,9 +165,14 @@ obj_getProto(JSContext *cx, JSObject *obj, jsid id, Value *vp)
|
||||
return CheckAccess(cx, obj, id, JSACC_PROTO, vp, &attrs);
|
||||
}
|
||||
|
||||
size_t sSetProtoCalled = 0;
|
||||
|
||||
static JSBool
|
||||
obj_setProto(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
|
||||
{
|
||||
if (!cx->runningWithTrustedPrincipals())
|
||||
++sSetProtoCalled;
|
||||
|
||||
/* ECMAScript 5 8.6.2 forbids changing [[Prototype]] if not [[Extensible]]. */
|
||||
if (!obj->isExtensible()) {
|
||||
obj->reportNotExtensible(cx);
|
||||
|
@ -164,6 +164,8 @@ xml_isXMLName(JSContext *cx, uintN argc, jsval *vp)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
size_t sE4XObjectsCreated = 0;
|
||||
|
||||
/*
|
||||
* This wrapper is needed because NewBuiltinClassInstance doesn't
|
||||
* call the constructor, and we need a place to set the
|
||||
@ -172,6 +174,9 @@ xml_isXMLName(JSContext *cx, uintN argc, jsval *vp)
|
||||
static inline JSObject *
|
||||
NewBuiltinClassInstanceXML(JSContext *cx, Class *clasp)
|
||||
{
|
||||
if (!cx->runningWithTrustedPrincipals())
|
||||
++sE4XObjectsCreated;
|
||||
|
||||
JSObject *obj = NewBuiltinClassInstance(cx, clasp);
|
||||
if (obj)
|
||||
obj->syncSpecialEquality();
|
||||
@ -7186,6 +7191,12 @@ js_InitXMLClass(JSContext *cx, JSObject *obj)
|
||||
xmlProto->setPrivate(xml);
|
||||
xml->object = xmlProto;
|
||||
|
||||
/* Don't count this as a real content-created XML object. */
|
||||
if (!cx->runningWithTrustedPrincipals()) {
|
||||
JS_ASSERT(sE4XObjectsCreated > 0);
|
||||
--sE4XObjectsCreated;
|
||||
}
|
||||
|
||||
const uintN XML_CTOR_LENGTH = 1;
|
||||
JSFunction *ctor = global->createConstructor(cx, XML, &js_XMLClass, CLASS_ATOM(cx, XML),
|
||||
XML_CTOR_LENGTH);
|
||||
|
@ -65,6 +65,7 @@ XPIDLSRCS = \
|
||||
nsIScriptableInterfaces.idl \
|
||||
xpcIJSWeakReference.idl \
|
||||
xpcIJSGetFactory.idl \
|
||||
nsIJSEngineTelemetryStats.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "nsHashKeys.h"
|
||||
#include "jsatom.h"
|
||||
#include "jsobj.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "jsfun.h"
|
||||
#include "jsgc.h"
|
||||
#include "jsscript.h"
|
||||
@ -66,13 +67,14 @@
|
||||
|
||||
#include "xpcquickstubs.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS6(nsXPConnect,
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
|
||||
nsIXPConnect,
|
||||
nsISupportsWeakReference,
|
||||
nsIThreadObserver,
|
||||
nsIJSRuntimeService,
|
||||
nsIJSContextStack,
|
||||
nsIThreadJSContextStack)
|
||||
nsIThreadJSContextStack,
|
||||
nsIJSEngineTelemetryStats)
|
||||
|
||||
nsXPConnect* nsXPConnect::gSelf = nsnull;
|
||||
JSBool nsXPConnect::gOnceAliveNowDead = JS_FALSE;
|
||||
@ -2903,6 +2905,34 @@ nsXPConnect::SetDebugModeWhenPossible(PRBool mode)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPConnect::GetTelemetryValue(JSContext *cx, jsval *rval)
|
||||
{
|
||||
JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
|
||||
if (!obj)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
uintN attrs = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT;
|
||||
|
||||
size_t i = JS_GetE4XObjectsCreated(cx);
|
||||
jsval v = DOUBLE_TO_JSVAL(i);
|
||||
if (!JS_DefineProperty(cx, obj, "e4x", v, NULL, NULL, attrs))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
i = JS_SetProtoCalled(cx);
|
||||
v = DOUBLE_TO_JSVAL(i);
|
||||
if (!JS_DefineProperty(cx, obj, "setProto", v, NULL, NULL, attrs))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
i = JS_GetCustomIteratorCount(cx);
|
||||
v = DOUBLE_TO_JSVAL(i);
|
||||
if (!JS_DefineProperty(cx, obj, "customIter", v, NULL, NULL, attrs))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*rval = OBJECT_TO_JSVAL(obj);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* These are here to be callable from a debugger */
|
||||
JS_BEGIN_EXTERN_C
|
||||
JS_EXPORT_API(void) DumpJSStack()
|
||||
|
@ -103,6 +103,7 @@
|
||||
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsIJSEngineTelemetryStats.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#include "nsIConsoleService.h"
|
||||
@ -461,7 +462,8 @@ class nsXPConnect : public nsIXPConnect,
|
||||
public nsCycleCollectionJSRuntime,
|
||||
public nsCycleCollectionParticipant,
|
||||
public nsIJSRuntimeService,
|
||||
public nsIThreadJSContextStack
|
||||
public nsIThreadJSContextStack,
|
||||
public nsIJSEngineTelemetryStats
|
||||
{
|
||||
public:
|
||||
// all the interface method declarations...
|
||||
@ -471,6 +473,7 @@ public:
|
||||
NS_DECL_NSIJSRUNTIMESERVICE
|
||||
NS_DECL_NSIJSCONTEXTSTACK
|
||||
NS_DECL_NSITHREADJSCONTEXTSTACK
|
||||
NS_DECL_NSIJSENGINETELEMETRYSTATS
|
||||
|
||||
// non-interface implementation
|
||||
public:
|
||||
|
@ -186,6 +186,7 @@ function getSimpleMeasurements() {
|
||||
// uptime in minutes
|
||||
uptime: Math.round((new Date() - si.process) / 60000)
|
||||
}
|
||||
|
||||
if (si.process) {
|
||||
for each (let field in ["main", "firstPaint", "sessionRestored"]) {
|
||||
if (!(field in si))
|
||||
@ -193,6 +194,11 @@ function getSimpleMeasurements() {
|
||||
ret[field] = si[field] - si.process
|
||||
}
|
||||
}
|
||||
|
||||
ret.js = Cc["@mozilla.org/js/xpc/XPConnect;1"]
|
||||
.getService(Ci.nsIJSEngineTelemetryStats)
|
||||
.telemetryValue;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user