Bug 1352317 - Output the kind of string in gc edges log. r=jandem
authorTooru Fujisawa <arai_a@mac.com>
Sun, 09 Apr 2017 17:52:45 +0900
changeset 559360 02b94db5f51caba6d30b1378feef50958a8b3d2d
parent 559359 bf3ed77b00c1d78b23f014776fd76cb3fc11756b
child 559361 03913270e54c0bfcdd6a04e9a94ecd687687ab77
push id53058
push userarchaeopteryx@coole-files.de
push dateSun, 09 Apr 2017 21:36:26 +0000
reviewersjandem
bugs1352317
milestone55.0a1
Bug 1352317 - Output the kind of string in gc edges log. r=jandem
js/src/gc/Tracer.cpp
--- a/js/src/gc/Tracer.cpp
+++ b/js/src/gc/Tracer.cpp
@@ -284,16 +284,47 @@ CountDecimalDigits(size_t num)
     do {
         num /= 10;
         numDigits++;
     } while (num > 0);
 
     return numDigits;
 }
 
+static const char*
+StringKindHeader(JSString* str)
+{
+    MOZ_ASSERT(str->isLinear());
+
+    if (str->isAtom()) {
+        if (str->isPermanentAtom())
+            return "permanent atom: ";
+        return "atom: ";
+    }
+
+    if (str->isFlat()) {
+        if (str->isExtensible())
+            return "extensible: ";
+        if (str->isUndepended())
+            return "undepended: ";
+        if (str->isInline()) {
+            if (str->isFatInline())
+                return "fat inline: ";
+            return "inline: ";
+        }
+        return "flat: ";
+    }
+
+    if (str->isDependent())
+        return "dependent: ";
+    if (str->isExternal())
+        return "external: ";
+    return "linear: ";
+}
+
 JS_PUBLIC_API(void)
 JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing,
                      JS::TraceKind kind, bool details)
 {
     const char* name = nullptr; /* silence uninitialized warning */
     size_t n;
 
     if (bufsize == 0)
@@ -382,22 +413,23 @@ JS_GetTraceThingInfo(char* buf, size_t b
 
           case JS::TraceKind::String:
           {
             *buf++ = ' ';
             bufsize--;
             JSString* str = (JSString*)thing;
 
             if (str->isLinear()) {
-                bool willFit = str->length() + strlen("<length > ") +
+                const char* header = StringKindHeader(str);
+                bool willFit = str->length() + strlen("<length > ") + strlen(header) +
                                CountDecimalDigits(str->length()) < bufsize;
 
-                n = snprintf(buf, bufsize, "<length %" PRIuSIZE "%s> ",
-                                str->length(),
-                                willFit ? "" : " (truncated)");
+                n = snprintf(buf, bufsize, "<%slength %" PRIuSIZE "%s> ",
+                             header, str->length(),
+                             willFit ? "" : " (truncated)");
                 buf += n;
                 bufsize -= n;
 
                 PutEscapedString(buf, bufsize, &str->asLinear(), 0);
             } else {
                 snprintf(buf, bufsize, "<rope: length %" PRIuSIZE ">", str->length());
             }
             break;