Re: [JS-internals] Getting the allocation point of every object

2014-02-26 Thread Nicholas Nethercote
On Wed, Feb 26, 2014 at 2:29 PM, Nicholas Nethercote n.netherc...@gmail.com

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

billm pointed me to
http://mxr.mozilla.org/mozilla-central/source/js/src/builtin/TestingFunctions.cpp#1066
and
http://mxr.mozilla.org/mozilla-central/source/js/src/builtin/TestingFunctions.cpp#1024,
which is probably the right way to proceed here...

Nick
___
dev-tech-js-engine-internals mailing list
dev-tech-js-engine-internals@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals


Re: [JS-internals] Getting the allocation point of every object

2014-02-26 Thread Nicholas Nethercote
On Wed, Feb 26, 2014 at 2:46 PM, Nicholas Nethercote
n.netherc...@gmail.com wrote:
 On Wed, Feb 26, 2014 at 2:29 PM, Nicholas Nethercote n.netherc...@gmail.com

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

 billm pointed me to
 http://mxr.mozilla.org/mozilla-central/source/js/src/builtin/TestingFunctions.cpp#1066
 and
 http://mxr.mozilla.org/mozilla-central/source/js/src/builtin/TestingFunctions.cpp#1024,
 which is probably the right way to proceed here...

I have this working now. In the output I see quite a few lines of the
??? (1) form, i.e. the NonBuiltinScriptFrameIter has zero elements.
I'm not sure what this means... allocations triggered from within C++
code rather than JS code?

Nick


diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -5094,16 +5094,40 @@ AutoFinishGC::AutoFinishGC(JSRuntime *rt
 AutoPrepareForTracing::AutoPrepareForTracing(JSRuntime *rt,
ZoneSelector selector)
   : finish(rt),
 session(rt),
 copy(rt, selector)
 {
 RecordNativeStackTopForGC(rt);
 }

+static bool
+MyObjectMetadataCallback(JSContext *cx, JSObject **pmetadata)
+{
+*pmetadata = nullptr;
+
+NonBuiltinScriptFrameIter i(cx);
+if (i.done()) {
+fprintf(stderr, o: ??? (1)\n);
+return true;
+}
+
+// If the caller is hidden, the embedding wants us to return null here so
+// that it can check its own stack.
+if (i.activation()-scriptedCallerIsHidden()) {
+fprintf(stderr, o: ??? (2)\n);
+return true;
+}
+
+fprintf(stderr, o: %s, %d\n,
+JS_GetScriptFilename(cx, i.script()),
+js::PCToLineNumber(i.script(), i.pc()));
+return true;
+}
+
 JSCompartment *
 js::NewCompartment(JSContext *cx, Zone *zone, JSPrincipals *principals,
const JS::CompartmentOptions options)
 {
 JSRuntime *rt = cx-runtime();
 JS_AbortIfWrongThread(rt);

 ScopedJSDeletePtrZone zoneHolder;
@@ -5138,16 +5162,19 @@ js::NewCompartment(JSContext *cx, Zone *
 }

 if (zoneHolder  !rt-zones.append(zone)) {
 js_ReportOutOfMemory(cx);
 return nullptr;
 }

 zoneHolder.forget();
+
+compartment-setObjectMetadataCallback(MyObjectMetadataCallback);
+
 return compartment.forget();
 }

 void
 gc::MergeCompartments(JSCompartment *source, JSCompartment *target)
 {
 // The source compartment must be specifically flagged as mergable.  This
 // also implies that the compartment is not visible to the debugger.
___
dev-tech-js-engine-internals mailing list
dev-tech-js-engine-internals@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals


Re: [JS-internals] Getting the allocation point of every object

2014-02-26 Thread Nicholas Nethercote
 I have this working now. In the output I see quite a few lines of the
 ??? (1) form, i.e. the NonBuiltinScriptFrameIter has zero elements.
 I'm not sure what this means... allocations triggered from within C++
 code rather than JS code?
 Or in self hosted code, right? Maybe the iterator { value, done } objects?

I looked at a few stack traces. The ones I looked at were all C++
allocations, but some of them might be self-hosted code.

Nick
___
dev-tech-js-engine-internals mailing list
dev-tech-js-engine-internals@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals


Re: [JS-internals] Getting the allocation point of every object

2014-02-26 Thread Till Schneidereit
On Thu, Feb 27, 2014 at 4:09 PM, Nicholas Nethercote n.netherc...@gmail.com
 wrote:

  I have this working now. In the output I see quite a few lines of the
  ??? (1) form, i.e. the NonBuiltinScriptFrameIter has zero elements.
  I'm not sure what this means... allocations triggered from within C++
  code rather than JS code?
  Or in self hosted code, right? Maybe the iterator { value, done }
 objects?

 I looked at a few stack traces. The ones I looked at were all C++
 allocations, but some of them might be self-hosted code.


Except for a very few cases - mostly Intl-related, I think - he self-hosted
code should be called by content code, so I think these should be pretty
rare. You could use the ScriptFrameIterator, which doesn't censor
self-hosted scripts' frames.
___
dev-tech-js-engine-internals mailing list
dev-tech-js-engine-internals@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals