Bug 790349 - Make JSAtomState store FixedHeapPtr<PropertyName> so that cached-name uses don't have to be rooted. r=jorendorff

--HG--
extra : rebase_source : f9113497185b3404415603da4fc8c43125d9052c
This commit is contained in:
Jeff Walden 2012-09-10 20:42:08 -07:00
parent 9641f5c879
commit d6e3e21556
4 changed files with 25 additions and 16 deletions

View File

@ -988,7 +988,7 @@ JSRuntime::~JSRuntime()
#endif
FinishRuntimeNumberState(this);
FinishAtoms(this);
FinishCommonNames(this);
if (dtoaState)
js_DestroyDtoaState(dtoaState);

View File

@ -159,16 +159,16 @@ js::InitCommonNames(JSContext *cx)
#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;
}

View File

@ -7,12 +7,14 @@
#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 *
@ -150,28 +152,29 @@ AtomHasher::match(const AtomStateEntry &entry, const Lookup &lookup)
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];

View File

@ -383,19 +383,25 @@ struct RuntimeSizes;
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
{
@ -785,7 +791,7 @@ struct JSRuntime : js::RuntimeFriendFields
js::Value negativeInfinityValue;
js::Value positiveInfinityValue;
JSAtom *emptyString;
js::PropertyName *emptyString;
/* List of active contexts sharing this runtime. */
JSCList contextList;
@ -913,7 +919,7 @@ struct JSRuntime : js::RuntimeFriendFields
*/
JSAtomState atomState;
js::PropertyName *firstCachedName;
js::FixedHeapPtr<js::PropertyName> firstCachedName;
};
/* Tables of strings that are pre-allocated in the atomsCompartment. */