mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 670059 - Add some JS engine telemetry counters to measure occurrences of: E4X, __iterator__, mutable __proto__ (r=taras,waldo)
This commit is contained in:
parent
6d1540eb97
commit
b747d1721b
@ -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___ */
|
||||
|
@ -338,6 +338,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)
|
||||
{
|
||||
@ -352,6 +354,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
|
||||
|
53
js/src/xpconnect/idl/nsIJSEngineTelemetryStats.idl
Normal file
53
js/src/xpconnect/idl/nsIJSEngineTelemetryStats.idl
Normal file
@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Firefox.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Foundation <http://www.mozilla.org>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* Telemetry uses this interface on the @mozilla.org/js/xpc/XPConnect;1 service
|
||||
* to extract JS engine stats.
|
||||
*/
|
||||
[scriptable, uuid(5a6ea52b-4e23-402f-93e3-59f29b2f1a88)]
|
||||
interface nsIJSEngineTelemetryStats : nsISupports
|
||||
{
|
||||
/**
|
||||
* The value returned by this attribute is included as the 'js' property of
|
||||
* the telemetry ping JSON blob.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval telemetryValue;
|
||||
};
|
@ -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