Bug 790349 - Make JSAtomState store FixedHeapPtr<PropertyName> so that cached-name uses don't have to be rooted. r=jorendorff
authorJeff Walden <jwalden@mit.edu>
Mon, 10 Sep 2012 20:42:08 -0700
changeset 107338 353ca9d39c444bc26bd657c4aa21f8e29d645c55
parent 107337 e8b22eab71ecbcd8b3192f1dc318818e21c7d905
child 107339 f27c74c5ac8044453ad4ed38f9cc362daa444874
push id23480
push usergraememcc_firefox@graeme-online.co.uk
push dateTue, 18 Sep 2012 11:48:11 +0000
treeherdermozilla-central@e4757379b99a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs790349
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 790349 - Make JSAtomState store FixedHeapPtr<PropertyName> so that cached-name uses don't have to be rooted. r=jorendorff
js/src/jsatom.cpp
js/src/jsatominlines.h
js/src/jscntxt.h
--- a/js/src/jsatom.cpp
+++ b/js/src/jsatom.cpp
@@ -154,26 +154,26 @@ js::InitCommonNames(JSContext *cx)
 #define COMMON_NAME_INFO(idpart, id, text) { js_##idpart##_str, sizeof(text) - 1 },
         FOR_EACH_COMMON_PROPERTYNAME(COMMON_NAME_INFO)
 #undef COMMON_NAME_INFO
 #define COMMON_NAME_INFO(name, code, init) { js_##name##_str, sizeof(#name) - 1 },
         JS_FOR_EACH_PROTOTYPE(COMMON_NAME_INFO)
 #undef COMMON_NAME_INFO
     };
 
-    PropertyName **names = &cx->runtime->firstCachedName;
+    FixedHeapPtr<PropertyName> *names = &cx->runtime->firstCachedName;
     for (size_t i = 0; i < ArrayLength(cachedNames); i++, names++) {
         JSAtom *atom = Atomize(cx, cachedNames[i].str, cachedNames[i].length, InternAtom);
         if (!atom)
             return false;
-        *names = atom->asPropertyName();
+        names->init(atom->asPropertyName());
     }
     JS_ASSERT(uintptr_t(names) == uintptr_t(&cx->runtime->atomState + 1));
 
-    cx->runtime->emptyString = cx->runtime->atomState.emptyAtom;
+    cx->runtime->emptyString = cx->names().empty;
     return true;
 }
 
 void
 js::FinishCommonNames(JSRuntime *rt)
 {
     rt->emptyString = NULL;
 #ifdef DEBUG
--- a/js/src/jsatominlines.h
+++ b/js/src/jsatominlines.h
@@ -2,22 +2,24 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef jsatominlines_h___
 #define jsatominlines_h___
 
+#include "mozilla/RangedPtr.h"
+
 #include "jsatom.h"
 #include "jsnum.h"
 #include "jsobj.h"
 #include "jsstr.h"
 
-#include "mozilla/RangedPtr.h"
+#include "gc/Barrier.h"
 #include "vm/String.h"
 
 inline JSAtom *
 js::AtomStateEntry::asPtr() const
 {
     JS_ASSERT(bits != 0);
     JSAtom *atom = reinterpret_cast<JSAtom *>(bits & NO_TAG_MASK);
     JSString::readBarrier(atom);
@@ -145,38 +147,39 @@ AtomHasher::match(const AtomStateEntry &
     JSAtom *key = entry.asPtr();
     if (lookup.atom)
         return lookup.atom == key;
     if (key->length() != lookup.length)
         return false;
     return PodEqual(key->chars(), lookup.chars, lookup.length);
 }
 
-inline PropertyName *
+inline Handle<PropertyName*>
 TypeName(JSType type, JSRuntime *rt)
 {
     JS_ASSERT(type < JSTYPE_LIMIT);
     JS_STATIC_ASSERT(offsetof(JSAtomState, undefinedAtom) +
-                     JSTYPE_LIMIT * sizeof(PropertyName *) <=
+                     JSTYPE_LIMIT * sizeof(FixedHeapPtr<PropertyName>) <=
                      sizeof(JSAtomState));
     JS_STATIC_ASSERT(JSTYPE_VOID == 0);
     return (&rt->atomState.undefinedAtom)[type];
 }
 
-inline PropertyName *
+inline Handle<PropertyName*>
 TypeName(JSType type, JSContext *cx)
 {
     return TypeName(type, cx->runtime);
 }
 
-inline PropertyName *
+inline Handle<PropertyName*>
 ClassName(JSProtoKey key, JSContext *cx)
 {
     JS_ASSERT(key < JSProto_LIMIT);
-    JS_STATIC_ASSERT(offsetof(JSAtomState, NullAtom) + JSProto_LIMIT * sizeof(PropertyName *) <=
+    JS_STATIC_ASSERT(offsetof(JSAtomState, NullAtom) +
+                     JSProto_LIMIT * sizeof(FixedHeapPtr<PropertyName>) <=
                      sizeof(JSAtomState));
     JS_STATIC_ASSERT(JSProto_Null == 0);
     return (&cx->runtime->atomState.NullAtom)[key];
 }
 
 } // namespace js
 
 #endif /* jsatominlines_h___ */
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -378,29 +378,35 @@ class FreeOp : public JSFreeOp {
 namespace JS {
 struct RuntimeSizes;
 }
 
 /* Various built-in or commonly-used names pinned on first context. */
 struct JSAtomState
 {
 #define PROPERTYNAME_FIELD(idpart, id, text) \
-    union { js::PropertyName *idpart##Atom; js::PropertyName *id; };
+    union { \
+        js::FixedHeapPtr<js::PropertyName> idpart##Atom; \
+        js::FixedHeapPtr<js::PropertyName> id; \
+    };
     FOR_EACH_COMMON_PROPERTYNAME(PROPERTYNAME_FIELD)
 #undef PROPERTYNAME_FIELD
 #define PROPERTYNAME_FIELD(name, code, init) \
-    union { js::PropertyName *name##Atom; js::PropertyName *name; };
+    union { \
+        js::FixedHeapPtr<js::PropertyName> name##Atom; \
+        js::FixedHeapPtr<js::PropertyName> name; \
+    };
     JS_FOR_EACH_PROTOTYPE(PROPERTYNAME_FIELD)
 #undef PROPERTYNAME_FIELD
 };
 
-#define ATOM(name) js::HandlePropertyName::fromMarkedLocation(&cx->names().name)
+#define ATOM(name) (cx->names().name)
 
 #define NAME_OFFSET(name)       offsetof(JSAtomState, name##Atom)
-#define OFFSET_TO_NAME(rt,off)  (*(js::PropertyName **)((char*)&(rt)->atomState + (off)))
+#define OFFSET_TO_NAME(rt,off)  (*(js::FixedHeapPtr<js::PropertyName>*)((char*)&(rt)->atomState + (off)))
 
 struct JSRuntime : js::RuntimeFriendFields
 {
     /* Default compartment. */
     JSCompartment       *atomsCompartment;
 
     /* List of compartments (protected by the GC lock). */
     js::CompartmentVector compartments;
@@ -780,17 +786,17 @@ struct JSRuntime : js::RuntimeFriendFiel
     /* Strong references on scripts held for PCCount profiling API. */
     js::ScriptAndCountsVector *scriptAndCountsVector;
 
     /* Well-known numbers held for use by this runtime's contexts. */
     js::Value           NaNValue;
     js::Value           negativeInfinityValue;
     js::Value           positiveInfinityValue;
 
-    JSAtom              *emptyString;
+    js::PropertyName    *emptyString;
 
     /* List of active contexts sharing this runtime. */
     JSCList             contextList;
 
     bool hasContexts() const {
         return !JS_CLIST_IS_EMPTY(&contextList);
     }
 
@@ -908,17 +914,17 @@ struct JSRuntime : js::RuntimeFriendFiel
 
     union {
         /*
          * Cached pointers to various interned property names, initialized in
          * order from first to last via the other union arm.
          */
         JSAtomState atomState;
 
-        js::PropertyName *firstCachedName;
+        js::FixedHeapPtr<js::PropertyName> firstCachedName;
     };
 
     /* Tables of strings that are pre-allocated in the atomsCompartment. */
     js::StaticStrings   staticStrings;
 
     JSWrapObjectCallback                   wrapObjectCallback;
     JSSameCompartmentWrapObjectCallback    sameCompartmentWrapObjectCallback;
     JSPreWrapCallback                      preWrapObjectCallback;