Hi,

I'm doing some profiling of pdf.js, and I would like to get the
allocation point for every object, either when it's allocated, and/or
when the JS memory reporter runs. This is for some ad hoc profiling --
I just want to dump the info to stderr so I can post-process it -- so
it doesn't need to be neat and tidy.

I have a patch that attempts the former (see below). It gives
semi-reasonable results, but I'm suspicious that they might just be
lies. In particular, the ExclusiveContext-to-JSContexts are highly
dubious. I also wonder if this misses objects created from jitted
code.

Suggestions on how to do this properly would be appreciated. The
object metadata stuff is probably a better way to proceed here...

Nick


diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -3136,16 +3136,24 @@ template<bool allocateCapacity>
 static MOZ_ALWAYS_INLINE ArrayObject *
 NewArray(ExclusiveContext *cxArg, uint32_t length,
          JSObject *protoArg, NewObjectKind newKind = GenericObject)
 {
     gc::AllocKind allocKind = GuessArrayGCKind(length);
     JS_ASSERT(CanBeFinalizedInBackground(allocKind, &ArrayObject::class_));
     allocKind = GetBackgroundAllocKind(allocKind);

+    // njn: temp
+    JS::Rooted<JSScript*> script(cxArg);
+    unsigned lineno;
+    if (JS_DescribeScriptedCaller((JSContext*)cxArg, &script, &lineno)) {
+        fprintf(stderr, "a: %s, %d, %u\n",
JS_GetScriptFilename((JSContext*)cxArg, script), lineno, length);
+    }
+
+
     NewObjectCache::EntryIndex entry = -1;
     if (JSContext *cx = cxArg->maybeJSContext()) {
         NewObjectCache &cache = cx->runtime()->newObjectCache;
         if (newKind == GenericObject &&
             !cx->compartment()->hasObjectMetadataCallback() &&
             cache.lookupGlobal(&ArrayObject::class_, cx->global(),
allocKind, &entry))
         {
             RootedObject obj(cx, cache.newObjectFromHit(cx, entry,
diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -1245,16 +1245,23 @@ NewObject(ExclusiveContext *cx, types::T
 {
     const Class *clasp = type_->clasp();

     JS_ASSERT(clasp != &ArrayObject::class_);
     JS_ASSERT_IF(clasp == &JSFunction::class_,
                  kind == JSFunction::FinalizeKind || kind ==
JSFunction::ExtendedFinalizeKind);
     JS_ASSERT_IF(parent, &parent->global() == cx->global());

+    // njn: temp
+    JS::Rooted<JSScript*> script(cx);
+    unsigned lineno;
+    if (JS_DescribeScriptedCaller((JSContext*)cx, &script, &lineno)) {
+        fprintf(stderr, "o: %s, %d\n",
JS_GetScriptFilename((JSContext*)cx, script), lineno);
+    }
+
     RootedTypeObject type(cx, type_);

     JSObject *metadata = nullptr;
     if (!NewObjectMetadata(cx, &metadata))
         return nullptr;

     RootedShape shape(cx, EmptyShape::getInitialShape(cx, clasp,
type->proto(),
parent, metadata, kind));
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals

Reply via email to