From 7e4b12719c91862a15c8dc39d2d59b009acfabcf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 10 Jul 2013 16:23:28 -0700 Subject: [PATCH] Bug 891215 (part 19) - Slim down Shape-inl.h. r=terrence. --HG-- extra : rebase_source : 77cbecf4148cfcc6df2588001b36c78658eb90ea --- js/src/vm/Shape-inl.h | 107 ------------------------------------------ js/src/vm/Shape.h | 94 ++++++++++++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 119 deletions(-) diff --git a/js/src/vm/Shape-inl.h b/js/src/vm/Shape-inl.h index 40b6ed762677..41b9d6b8423a 100644 --- a/js/src/vm/Shape-inl.h +++ b/js/src/vm/Shape-inl.h @@ -126,12 +126,6 @@ BaseShape::operator=(const BaseShape &other) return *this; } -inline bool -BaseShape::matchesGetterSetter(PropertyOp rawGetter, StrictPropertyOp rawSetter) const -{ - return rawGetter == this->rawGetter && rawSetter == this->rawSetter; -} - inline StackBaseShape::StackBaseShape(ExclusiveContext *cx, Class *clasp, JSObject *parent, JSObject *metadata, uint32_t objectFlags) @@ -155,25 +149,6 @@ StackBaseShape::StackBaseShape(Shape *shape) updateGetterSetter(shape->attrs, shape->getter(), shape->setter()); } -inline void -StackBaseShape::updateGetterSetter(uint8_t attrs, - PropertyOp rawGetter, - StrictPropertyOp rawSetter) -{ - flags &= ~(BaseShape::HAS_GETTER_OBJECT | BaseShape::HAS_SETTER_OBJECT); - if ((attrs & JSPROP_GETTER) && rawGetter) { - JS_ASSERT(!IsPoisonedPtr(rawGetter)); - flags |= BaseShape::HAS_GETTER_OBJECT; - } - if ((attrs & JSPROP_SETTER) && rawSetter) { - JS_ASSERT(!IsPoisonedPtr(rawSetter)); - flags |= BaseShape::HAS_SETTER_OBJECT; - } - - this->rawGetter = rawGetter; - this->rawSetter = rawSetter; -} - inline void BaseShape::adoptUnowned(UnownedBaseShape *other) { @@ -245,28 +220,6 @@ Shape::Shape(UnownedBaseShape *base, uint32_t nfixed) kids.setNull(); } -inline HashNumber -StackShape::hash() const -{ - HashNumber hash = uintptr_t(base); - - /* Accumulate from least to most random so the low bits are most random. */ - hash = JS_ROTATE_LEFT32(hash, 4) ^ (flags & Shape::PUBLIC_FLAGS); - hash = JS_ROTATE_LEFT32(hash, 4) ^ attrs; - hash = JS_ROTATE_LEFT32(hash, 4) ^ shortid; - hash = JS_ROTATE_LEFT32(hash, 4) ^ slot_; - hash = JS_ROTATE_LEFT32(hash, 4) ^ JSID_BITS(propid); - return hash; -} - -inline bool -Shape::matches(const Shape *other) const -{ - return propid_.get() == other->propid_.get() && - matchesParamsAfterId(other->base(), other->maybeSlot(), other->attrs, - other->flags, other->shortid_); -} - inline bool Shape::matches(const StackShape &other) const { @@ -274,17 +227,6 @@ Shape::matches(const StackShape &other) const matchesParamsAfterId(other.base, other.slot_, other.attrs, other.flags, other.shortid); } -inline bool -Shape::matchesParamsAfterId(BaseShape *base, uint32_t aslot, - unsigned aattrs, unsigned aflags, int ashortid) const -{ - return base->unowned() == this->base()->unowned() && - maybeSlot() == aslot && - attrs == aattrs && - ((flags ^ aflags) & PUBLIC_FLAGS) == 0 && - shortid_ == ashortid; -} - inline bool Shape::getUserId(JSContext *cx, MutableHandleId idp) const { @@ -510,39 +452,6 @@ BaseShape::markChildren(JSTracer *trc) MarkObject(trc, &metadata, "metadata"); } -/* - * Property lookup hooks on objects are required to return a non-NULL shape to - * signify that the property has been found. For cases where the property is - * not actually represented by a Shape, use a dummy value. This includes all - * properties of non-native objects, and dense elements for native objects. - * Use separate APIs for these two cases. - */ - -static inline void -MarkNonNativePropertyFound(MutableHandleShape propp) -{ - propp.set(reinterpret_cast(1)); -} - -template -static inline void -MarkDenseElementFound(typename MaybeRooted::MutableHandleType propp) -{ - propp.set(reinterpret_cast(1)); -} - -static inline bool -IsImplicitDenseElement(Shape *prop) -{ - return prop == reinterpret_cast(1); -} - -static inline uint8_t -GetShapeAttributes(HandleShape shape) -{ - return IsImplicitDenseElement(shape) ? JSPROP_ENUMERATE : shape->attributes(); -} - inline AutoRooterGetterSetter::Inner::Inner(ExclusiveContext *cx, uint8_t attrs, PropertyOp *pgetter_, StrictPropertyOp *psetter_) @@ -580,22 +489,6 @@ StackShape::AutoRooter::AutoRooter(ExclusiveContext *cx, const StackShape *shape MOZ_GUARD_OBJECT_NOTIFIER_INIT; } -template -inline -Shape::Range::Range(ExclusiveContext *cx, Shape *shape) - : cursor(cx, shape) -{ - JS_STATIC_ASSERT(allowGC == CanGC); -} - -template -inline -Shape::Range::Range(Shape *shape) - : cursor((ExclusiveContext *) NULL, shape) -{ - JS_STATIC_ASSERT(allowGC == NoGC); -} - } /* namespace js */ #endif /* vm_Shape_inl_h */ diff --git a/js/src/vm/Shape.h b/js/src/vm/Shape.h index 7a326a8e14df..b10a50f50d7a 100644 --- a/js/src/vm/Shape.h +++ b/js/src/vm/Shape.h @@ -312,8 +312,9 @@ class BaseShape : public js::gc::Cell bool isOwned() const { return !!(flags & OWNED_SHAPE); } - inline bool matchesGetterSetter(PropertyOp rawGetter, - StrictPropertyOp rawSetter) const; + bool matchesGetterSetter(PropertyOp rawGetter, StrictPropertyOp rawSetter) const { + return rawGetter == this->rawGetter && rawSetter == this->rawSetter; + } inline void adoptUnowned(UnownedBaseShape *other); inline void setOwned(UnownedBaseShape *unowned); @@ -418,9 +419,20 @@ struct StackBaseShape JSObject *parent, JSObject *metadata, uint32_t objectFlags); inline StackBaseShape(Shape *shape); - inline void updateGetterSetter(uint8_t attrs, - PropertyOp rawGetter, - StrictPropertyOp rawSetter); + void updateGetterSetter(uint8_t attrs, PropertyOp rawGetter, StrictPropertyOp rawSetter) { + flags &= ~(BaseShape::HAS_GETTER_OBJECT | BaseShape::HAS_SETTER_OBJECT); + if ((attrs & JSPROP_GETTER) && rawGetter) { + JS_ASSERT(!IsPoisonedPtr(rawGetter)); + flags |= BaseShape::HAS_GETTER_OBJECT; + } + if ((attrs & JSPROP_SETTER) && rawSetter) { + JS_ASSERT(!IsPoisonedPtr(rawSetter)); + flags |= BaseShape::HAS_SETTER_OBJECT; + } + + this->rawGetter = rawGetter; + this->rawSetter = rawSetter; + } static inline HashNumber hash(const StackBaseShape *lookup); static inline bool match(UnownedBaseShape *key, const StackBaseShape *lookup); @@ -560,8 +572,13 @@ class Shape : public js::gc::Cell typename MaybeRooted::RootType cursor; public: - inline Range(ExclusiveContext *cx, Shape *shape); - inline Range(Shape *shape); + Range(ExclusiveContext *cx, Shape *shape) : cursor(cx, shape) { + JS_STATIC_ASSERT(allowGC == CanGC); + } + + Range(Shape *shape) : cursor((ExclusiveContext *) NULL, shape) { + JS_STATIC_ASSERT(allowGC == NoGC); + } bool empty() const { return !cursor || cursor->isEmptyShape(); @@ -675,11 +692,23 @@ class Shape : public js::gc::Cell void update(PropertyOp getter, StrictPropertyOp setter, uint8_t attrs); - inline bool matches(const Shape *other) const; + bool matches(const Shape *other) const { + return propid_.get() == other->propid_.get() && + matchesParamsAfterId(other->base(), other->maybeSlot(), other->attrs, + other->flags, other->shortid_); + } + inline bool matches(const StackShape &other) const; - inline bool matchesParamsAfterId(BaseShape *base, - uint32_t aslot, unsigned aattrs, unsigned aflags, - int ashortid) const; + + bool matchesParamsAfterId(BaseShape *base, uint32_t aslot, unsigned aattrs, unsigned aflags, + int ashortid) const + { + return base->unowned() == this->base()->unowned() && + maybeSlot() == aslot && + attrs == aattrs && + ((flags ^ aflags) & PUBLIC_FLAGS) == 0 && + shortid_ == ashortid; + } bool get(JSContext* cx, HandleObject receiver, JSObject *obj, JSObject *pobj, MutableHandleValue vp); bool set(JSContext* cx, HandleObject obj, HandleObject receiver, bool strict, MutableHandleValue vp); @@ -990,7 +1019,17 @@ struct StackShape slot_ = slot; } - inline HashNumber hash() const; + HashNumber hash() const { + HashNumber hash = uintptr_t(base); + + /* Accumulate from least to most random so the low bits are most random. */ + hash = JS_ROTATE_LEFT32(hash, 4) ^ (flags & Shape::PUBLIC_FLAGS); + hash = JS_ROTATE_LEFT32(hash, 4) ^ attrs; + hash = JS_ROTATE_LEFT32(hash, 4) ^ shortid; + hash = JS_ROTATE_LEFT32(hash, 4) ^ slot_; + hash = JS_ROTATE_LEFT32(hash, 4) ^ JSID_BITS(propid); + return hash; + } class AutoRooter : private JS::CustomAutoRooter { @@ -1096,6 +1135,37 @@ Shape::searchNoHashify(Shape *start, jsid id) template<> struct RootKind : SpecificRootKind {}; template<> struct RootKind : SpecificRootKind {}; +// Property lookup hooks on objects are required to return a non-NULL shape to +// signify that the property has been found. For cases where the property is +// not actually represented by a Shape, use a dummy value. This includes all +// properties of non-native objects, and dense elements for native objects. +// Use separate APIs for these two cases. + +static inline void +MarkNonNativePropertyFound(MutableHandleShape propp) +{ + propp.set(reinterpret_cast(1)); +} + +template +static inline void +MarkDenseElementFound(typename MaybeRooted::MutableHandleType propp) +{ + propp.set(reinterpret_cast(1)); +} + +static inline bool +IsImplicitDenseElement(Shape *prop) +{ + return prop == reinterpret_cast(1); +} + +static inline uint8_t +GetShapeAttributes(HandleShape shape) +{ + return IsImplicitDenseElement(shape) ? JSPROP_ENUMERATE : shape->attributes(); +} + } // namespace js #ifdef _MSC_VER