Bug 1154997 - Deal with self-hosted builtins when stringifying tracked optimization type info. (r=djvj)
authorShu-yu Guo <shu@rfrn.org>
Thu, 16 Apr 2015 20:32:49 -0700
changeset 239697 66eee8b402fd5dbc78479a55c32bb2aad131c847
parent 239696 fd1a9a382e7bba119a07869ea392a816f574cae8
child 239698 ad181e1e0b53db82ac440739fe71e295fb4635e6
push id12444
push userryanvm@gmail.com
push dateFri, 17 Apr 2015 20:04:42 +0000
treeherderfx-team@560a202db924 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdjvj
bugs1154997
milestone40.0a1
Bug 1154997 - Deal with self-hosted builtins when stringifying tracked optimization type info. (r=djvj)
js/public/TrackedOptimizationInfo.h
js/src/jit/OptimizationTracking.cpp
js/src/shell/js.cpp
tools/profiler/ProfileEntry.cpp
--- a/js/public/TrackedOptimizationInfo.h
+++ b/js/public/TrackedOptimizationInfo.h
@@ -210,22 +210,22 @@ struct ForEachTrackedOptimizationTypeInf
     // The location parameter is the filename if the type is keyed by
     // "constructor", "alloc site", or if the type itself refers to a scripted
     // function. If the type is keyed by "native", it is the offset of the
     // native function, suitable for use with addr2line on Linux or atos on OS
     // X. Otherwise it is nullptr.
     //
     // The lineno parameter is the line number if the type is keyed by
     // "constructor", "alloc site", or if the type itself refers to a scripted
-    // function. Otherwise it is UINT32_MAX.
+    // function. Otherwise it is Nothing().
     //
     // The location parameter is the only one that may need escaping if being
     // quoted.
     virtual void readType(const char* keyedBy, const char* name,
-                          const char* location, unsigned lineno) = 0;
+                          const char* location, mozilla::Maybe<unsigned> lineno) = 0;
 
     // Called once per entry.
     virtual void operator()(TrackedTypeSite site, const char* mirType) = 0;
 };
 
 JS_PUBLIC_API(void)
 ForEachTrackedOptimizationTypeInfo(JSRuntime* rt, void* addr, uint8_t index,
                                    ForEachTrackedOptimizationTypeInfoOp& op);
--- a/js/src/jit/OptimizationTracking.cpp
+++ b/js/src/jit/OptimizationTracking.cpp
@@ -1140,27 +1140,29 @@ JS::ForEachTrackedOptimizationAttempt(JS
     JitcodeGlobalTable* table = rt->jitRuntime()->getJitcodeGlobalTable();
     JitcodeGlobalEntry entry;
     table->lookupInfallible(addr, &entry, rt);
     entry.youngestFrameLocationAtAddr(rt, addr, scriptOut, pcOut);
     entry.trackedOptimizationAttempts(index).forEach(op);
 }
 
 static void
-InterpretedFunctionFilenameAndLineNumber(JSFunction* fun, const char** filename, unsigned* lineno)
+InterpretedFunctionFilenameAndLineNumber(JSFunction* fun, const char** filename,
+                                         Maybe<unsigned>* lineno)
 {
-    ScriptSource* source;
     if (fun->hasScript()) {
-        source = fun->nonLazyScript()->maybeForwardedScriptSource();
-        *lineno = fun->nonLazyScript()->lineno();
+        *filename = fun->nonLazyScript()->maybeForwardedScriptSource()->filename();
+        *lineno = Some((unsigned) fun->nonLazyScript()->lineno());
+    } else if (fun->lazyScriptOrNull()) {
+        *filename = fun->lazyScript()->maybeForwardedScriptSource()->filename();
+        *lineno = Some((unsigned) fun->lazyScript()->lineno());
     } else {
-        source = fun->lazyScript()->maybeForwardedScriptSource();
-        *lineno = fun->lazyScript()->lineno();
+        *filename = "(self-hosted builtin)";
+        *lineno = Nothing();
     }
-    *filename = source->filename();
 }
 
 static JSFunction*
 FunctionFromTrackedType(const IonTrackedTypeWithAddendum& tracked)
 {
     if (tracked.hasConstructor())
         return tracked.constructor;
 
@@ -1175,17 +1177,17 @@ FunctionFromTrackedType(const IonTracked
 }
 
 void
 IonTrackedOptimizationsTypeInfo::ForEachOpAdapter::readType(const IonTrackedTypeWithAddendum& tracked)
 {
     TypeSet::Type ty = tracked.type;
 
     if (ty.isPrimitive() || ty.isUnknown() || ty.isAnyObject()) {
-        op_.readType("primitive", TypeSet::NonObjectTypeString(ty), nullptr, 0);
+        op_.readType("primitive", TypeSet::NonObjectTypeString(ty), nullptr, Nothing());
         return;
     }
 
     char buf[512];
     const uint32_t bufsize = mozilla::ArrayLength(buf);
 
     if (JSFunction* fun = FunctionFromTrackedType(tracked)) {
         // The displayAtom is useful for identifying both native and
@@ -1216,45 +1218,45 @@ IonTrackedOptimizationsTypeInfo::ForEach
             //   if (dladdr(addr, &info) != 0)
             //       offset = uintptr_t(addr) - uintptr_t(info.dli_fbase);
             //
             char locationBuf[20];
             if (!name) {
                 uintptr_t addr = JS_FUNC_TO_DATA_PTR(uintptr_t, fun->native());
                 JS_snprintf(locationBuf, mozilla::ArrayLength(locationBuf), "%llx", addr);
             }
-            op_.readType("native", name, name ? nullptr : locationBuf, UINT32_MAX);
+            op_.readType("native", name, name ? nullptr : locationBuf, Nothing());
             return;
         }
 
         const char* filename;
-        unsigned lineno;
+        Maybe<unsigned> lineno;
         InterpretedFunctionFilenameAndLineNumber(fun, &filename, &lineno);
         op_.readType(tracked.constructor ? "constructor" : "function",
                      name, filename, lineno);
         return;
     }
 
     const char* className = ty.objectKey()->clasp()->name;
     JS_snprintf(buf, bufsize, "[object %s]", className);
 
     if (tracked.hasAllocationSite()) {
         JSScript* script = tracked.script;
         op_.readType("alloc site", buf,
                      script->maybeForwardedScriptSource()->filename(),
-                     PCToLineNumber(script, script->offsetToPC(tracked.offset)));
+                     Some(PCToLineNumber(script, script->offsetToPC(tracked.offset))));
         return;
     }
 
     if (ty.isGroup()) {
-        op_.readType("prototype", buf, nullptr, UINT32_MAX);
+        op_.readType("prototype", buf, nullptr, Nothing());
         return;
     }
 
-    op_.readType("singleton", buf, nullptr, UINT32_MAX);
+    op_.readType("singleton", buf, nullptr, Nothing());
 }
 
 void
 IonTrackedOptimizationsTypeInfo::ForEachOpAdapter::operator()(JS::TrackedTypeSite site,
                                                               MIRType mirType)
 {
     op_(site, StringFromMIRType(mirType));
 }
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -4348,32 +4348,32 @@ class SprintOptimizationTypeInfoOp : pub
 
   public:
     explicit SprintOptimizationTypeInfoOp(Sprinter* sp)
       : sp(sp),
         startedTypes_(false)
     { }
 
     void readType(const char* keyedBy, const char* name,
-                  const char* location, unsigned lineno) override
+                  const char* location, Maybe<unsigned> lineno) override
     {
         if (!startedTypes_) {
             startedTypes_ = true;
             Sprint(sp, "{\"typeset\": [");
         }
         Sprint(sp, "{\"keyedBy\":\"%s\"", keyedBy);
         if (name)
             Sprint(sp, ",\"name\":\"%s\"", name);
         if (location) {
             char buf[512];
             PutEscapedString(buf, mozilla::ArrayLength(buf), location, strlen(location), '"');
             Sprint(sp, ",\"location\":%s", buf);
         }
-        if (lineno != UINT32_MAX)
-            Sprint(sp, ",\"line\":%u", lineno);
+        if (lineno.isSome())
+            Sprint(sp, ",\"line\":%u", *lineno);
         Sprint(sp, "},");
     }
 
     void operator()(JS::TrackedTypeSite site, const char* mirType) override {
         if (startedTypes_) {
             // Clear trailing ,
             if ((*sp)[sp->getOffset() - 1] == ',')
                 (*sp)[sp->getOffset() - 1] = ' ';
--- a/tools/profiler/ProfileEntry.cpp
+++ b/tools/profiler/ProfileEntry.cpp
@@ -230,34 +230,34 @@ class StreamOptimizationTypeInfoOp : pub
 
 public:
   explicit StreamOptimizationTypeInfoOp(JSStreamWriter& b)
     : mWriter(b)
     , mStartedTypeList(false)
   { }
 
   void readType(const char* keyedBy, const char* name,
-                const char* location, unsigned lineno) override {
+                const char* location, Maybe<unsigned> lineno) override {
     if (!mStartedTypeList) {
       mStartedTypeList = true;
       mWriter.BeginObject();
         mWriter.Name("types");
         mWriter.BeginArray();
     }
 
     mWriter.BeginObject();
       mWriter.NameValue("keyedBy", keyedBy);
       if (name) {
         mWriter.NameValue("name", name);
       }
       if (location) {
         mWriter.NameValue("location", location);
       }
-      if (lineno != UINT32_MAX) {
-        mWriter.NameValue("line", lineno);
+      if (lineno.isSome()) {
+        mWriter.NameValue("line", *lineno);
       }
     mWriter.EndObject();
   }
 
   void operator()(JS::TrackedTypeSite site, const char* mirType) override {
     if (mStartedTypeList) {
       mWriter.EndArray();
       mStartedTypeList = false;