Bug 989414 - Convert FixedHeapPtr to take a T* as template parameter instead of T; r=jonco

--HG--
extra : rebase_source : 1b71b0bdf3437e9f02dbb89b5db1186040d94872
This commit is contained in:
Terrence Cole 2014-04-25 14:22:27 -07:00
parent c3b59a5d99
commit 2bdc771587
4 changed files with 20 additions and 17 deletions

View File

@ -545,9 +545,9 @@ class HeapPtr : public BarrieredPtr<T>
}; };
/* /*
* FixedHeapPtr is designed for one very narrow case: replacing immutable raw * ImmutableTenuredPtr is designed for one very narrow case: replacing
* pointers to GC-managed things, implicitly converting to a handle type for * immutable raw pointers to GC-managed things, implicitly converting to a
* ease of use. Pointers encapsulated by this type must: * handle type for ease of use. Pointers encapsulated by this type must:
* *
* be immutable (no incremental write barriers), * be immutable (no incremental write barriers),
* never point into the nursery (no generational write barriers), and * never point into the nursery (no generational write barriers), and
@ -556,20 +556,21 @@ class HeapPtr : public BarrieredPtr<T>
* In short: you *really* need to know what you're doing before you use this * In short: you *really* need to know what you're doing before you use this
* class! * class!
*/ */
template <class T> template <typename T>
class FixedHeapPtr class ImmutableTenuredPtr
{ {
T *value; T value;
public: public:
operator T*() const { return value; } operator T() const { return value; }
T * operator->() const { return value; } T operator->() const { return value; }
operator Handle<T*>() const { operator Handle<T>() const {
return Handle<T*>::fromMarkedLocation(&value); return Handle<T>::fromMarkedLocation(&value);
} }
void init(T *ptr) { void init(T ptr) {
JS_ASSERT(ptr->isTenured());
value = ptr; value = ptr;
} }
}; };
@ -728,6 +729,8 @@ typedef EncapsulatedPtr<jsid> EncapsulatedId;
typedef RelocatablePtr<jsid> RelocatableId; typedef RelocatablePtr<jsid> RelocatableId;
typedef HeapPtr<jsid> HeapId; typedef HeapPtr<jsid> HeapId;
typedef ImmutableTenuredPtr<PropertyName*> ImmutablePropertyNamePtr;
/* Useful for hashtables with a HeapPtr as key. */ /* Useful for hashtables with a HeapPtr as key. */
template <class T> template <class T>
struct HeapPtrHasher struct HeapPtrHasher

View File

@ -149,7 +149,7 @@ JSRuntime::initializeAtoms(JSContext *cx)
if (!commonNames) if (!commonNames)
return false; return false;
FixedHeapPtr<PropertyName> *names = reinterpret_cast<FixedHeapPtr<PropertyName> *>(commonNames); ImmutablePropertyNamePtr *names = reinterpret_cast<ImmutablePropertyNamePtr *>(commonNames);
for (size_t i = 0; i < ArrayLength(cachedNames); i++, names++) { for (size_t i = 0; i < ArrayLength(cachedNames); i++, names++) {
JSAtom *atom = Atomize(cx, cachedNames[i].str, cachedNames[i].length, InternAtom); JSAtom *atom = Atomize(cx, cachedNames[i].str, cachedNames[i].length, InternAtom);
if (!atom) if (!atom)

View File

@ -158,7 +158,7 @@ TypeName(JSType type, const JSAtomState &names)
{ {
JS_ASSERT(type < JSTYPE_LIMIT); JS_ASSERT(type < JSTYPE_LIMIT);
JS_STATIC_ASSERT(offsetof(JSAtomState, undefined) + JS_STATIC_ASSERT(offsetof(JSAtomState, undefined) +
JSTYPE_LIMIT * sizeof(FixedHeapPtr<PropertyName>) <= JSTYPE_LIMIT * sizeof(ImmutablePropertyNamePtr) <=
sizeof(JSAtomState)); sizeof(JSAtomState));
JS_STATIC_ASSERT(JSTYPE_VOID == 0); JS_STATIC_ASSERT(JSTYPE_VOID == 0);
return (&names.undefined)[type]; return (&names.undefined)[type];
@ -169,7 +169,7 @@ ClassName(JSProtoKey key, JSAtomState &atomState)
{ {
JS_ASSERT(key < JSProto_LIMIT); JS_ASSERT(key < JSProto_LIMIT);
JS_STATIC_ASSERT(offsetof(JSAtomState, Null) + JS_STATIC_ASSERT(offsetof(JSAtomState, Null) +
JSProto_LIMIT * sizeof(FixedHeapPtr<PropertyName>) <= JSProto_LIMIT * sizeof(ImmutablePropertyNamePtr) <=
sizeof(JSAtomState)); sizeof(JSAtomState));
JS_STATIC_ASSERT(JSProto_Null == 0); JS_STATIC_ASSERT(JSProto_Null == 0);
return (&atomState.Null)[key]; return (&atomState.Null)[key];

View File

@ -452,10 +452,10 @@ struct RuntimeSizes;
/* Various built-in or commonly-used names pinned on first context. */ /* Various built-in or commonly-used names pinned on first context. */
struct JSAtomState struct JSAtomState
{ {
#define PROPERTYNAME_FIELD(idpart, id, text) js::FixedHeapPtr<js::PropertyName> id; #define PROPERTYNAME_FIELD(idpart, id, text) js::ImmutablePropertyNamePtr id;
FOR_EACH_COMMON_PROPERTYNAME(PROPERTYNAME_FIELD) FOR_EACH_COMMON_PROPERTYNAME(PROPERTYNAME_FIELD)
#undef PROPERTYNAME_FIELD #undef PROPERTYNAME_FIELD
#define PROPERTYNAME_FIELD(name, code, init, clasp) js::FixedHeapPtr<js::PropertyName> name; #define PROPERTYNAME_FIELD(name, code, init, clasp) js::ImmutablePropertyNamePtr name;
JS_FOR_EACH_PROTOTYPE(PROPERTYNAME_FIELD) JS_FOR_EACH_PROTOTYPE(PROPERTYNAME_FIELD)
#undef PROPERTYNAME_FIELD #undef PROPERTYNAME_FIELD
}; };
@ -467,7 +467,7 @@ namespace js {
inline HandlePropertyName inline HandlePropertyName
AtomStateOffsetToName(const JSAtomState &atomState, size_t offset) AtomStateOffsetToName(const JSAtomState &atomState, size_t offset)
{ {
return *(js::FixedHeapPtr<js::PropertyName>*)((char*)&atomState + offset); return *reinterpret_cast<js::ImmutablePropertyNamePtr *>((char*)&atomState + offset);
} }
// There are several coarse locks in the enum below. These may be either // There are several coarse locks in the enum below. These may be either