Bug 728411 - Move some elements bits into ObjectImpl. r=bhackett

--HG--
extra : rebase_source : 4d8644e37674795c4b3803d5e4b4ded828df7e63
This commit is contained in:
Jeff Walden 2012-02-16 15:08:50 -08:00
parent 5aaebbd7d0
commit 6b37ab9657
7 changed files with 68 additions and 69 deletions

View File

@ -3959,20 +3959,6 @@ JSObject::setSlotSpan(JSContext *cx, uint32_t span)
return true;
}
#if defined(_MSC_VER) && _MSC_VER >= 1500
/* Work around a compiler bug in MSVC9 and above, where inlining this function
causes stack pointer offsets to go awry and spp to refer to something higher
up the stack. */
MOZ_NEVER_INLINE
#endif
const js::Shape *
JSObject::nativeLookup(JSContext *cx, jsid id)
{
JS_ASSERT(isNative());
js::Shape **spp;
return js::Shape::search(cx, lastProperty(), id, &spp);
}
bool
JSObject::growSlots(JSContext *cx, uint32_t oldCount, uint32_t newCount)
{

View File

@ -457,8 +457,6 @@ struct JSObject : public js::ObjectImpl
*/
bool setSlotSpan(JSContext *cx, uint32_t span);
const js::Shape *nativeLookup(JSContext *cx, jsid id);
inline bool nativeContains(JSContext *cx, jsid id);
inline bool nativeContains(JSContext *cx, const js::Shape &shape);
@ -541,13 +539,9 @@ struct JSObject : public js::ObjectImpl
size_t *slotsSize, size_t *elementsSize,
size_t *miscSize) const;
inline size_t numFixedSlots() const;
static const uint32_t MAX_FIXED_SLOTS = 16;
private:
inline js::HeapValue* fixedSlots() const;
/*
* Get internal pointers to the range of values starting at start and
* running for length.
@ -568,11 +562,6 @@ struct JSObject : public js::ObjectImpl
/* Get a raw pointer to the object's properties. */
inline const js::HeapValue *getRawSlots();
/* JIT Accessors */
static inline size_t getFixedSlotOffset(size_t slot);
static inline size_t getPrivateDataOffset(size_t nfixed);
static inline size_t offsetOfSlots() { return offsetof(JSObject, slots); }
/*
* Grow or shrink slots immediately before changing the slot span.
* The number of allocated slots is not stored explicitly, and changes to
@ -813,7 +802,6 @@ struct JSObject : public js::ObjectImpl
inline void *&privateRef(uint32_t nfixed) const;
public:
inline bool isExtensible() const;
bool preventExtensions(JSContext *cx, js::AutoIdVector *props);
/* ES5 15.2.3.8: non-extensible, all props non-configurable */
@ -826,10 +814,6 @@ struct JSObject : public js::ObjectImpl
/* Accessors for elements. */
js::ObjectElements *getElementsHeader() const {
return js::ObjectElements::fromElements(elements);
}
inline bool ensureElements(JSContext *cx, uintN cap);
bool growElements(JSContext *cx, uintN cap);
void shrinkElements(JSContext *cx, uintN cap);
@ -852,12 +836,6 @@ struct JSObject : public js::ObjectImpl
return elements != js::emptyObjectElements && elements != fixedElements();
}
/* JIT Accessors */
static inline size_t offsetOfElements() { return offsetof(JSObject, elements); }
static inline size_t offsetOfFixedElements() {
return sizeof(JSObject) + sizeof(js::ObjectElements);
}
inline js::ElementIteratorObject *asElementIterator();
/*
@ -1314,28 +1292,6 @@ operator!=(const JSObject &lhs, const JSObject &rhs)
return &lhs != &rhs;
}
inline js::HeapValue*
JSObject::fixedSlots() const
{
return (js::HeapValue *) (uintptr_t(this) + sizeof(JSObject));
}
inline size_t
JSObject::numFixedSlots() const
{
return reinterpret_cast<const js::shadow::Object *>(this)->numFixedSlots();
}
/* static */ inline size_t
JSObject::getFixedSlotOffset(size_t slot) {
return sizeof(JSObject) + (slot * sizeof(js::Value));
}
/* static */ inline size_t
JSObject::getPrivateDataOffset(size_t nfixed) {
return getFixedSlotOffset(nfixed);
}
struct JSObject_Slots2 : JSObject { js::Value fslots[2]; };
struct JSObject_Slots4 : JSObject { js::Value fslots[4]; };
struct JSObject_Slots8 : JSObject { js::Value fslots[8]; };

View File

@ -884,11 +884,6 @@ inline bool JSObject::setUncacheableProto(JSContext *cx)
return setFlag(cx, js::BaseShape::UNCACHEABLE_PROTO, GENERATE_SHAPE);
}
inline bool JSObject::isExtensible() const
{
return !lastProperty()->hasObjectFlag(js::BaseShape::NOT_EXTENSIBLE);
}
inline bool JSObject::isBoundFunction() const
{
return lastProperty()->hasObjectFlag(js::BaseShape::BOUND_FUNCTION);

View File

@ -461,9 +461,10 @@ struct Shape : public js::gc::Cell
{
friend struct ::JSObject;
friend struct ::JSFunction;
friend class js::StaticBlockObject;
friend class js::PropertyTree;
friend class js::Bindings;
friend class js::ObjectImpl;
friend class js::PropertyTree;
friend class js::StaticBlockObject;
friend struct js::StackShape;
friend struct js::StackBaseShape;

View File

@ -11,6 +11,7 @@
#include "mozilla/Assertions.h"
#include "jscell.h"
#include "jsgc.h"
#include "js/TemplateLib.h"
@ -78,4 +79,10 @@ js::ObjectImpl::sizeOfThis() const
return arenaHeader()->getThingSize();
}
inline bool
js::ObjectImpl::isExtensible() const
{
return !lastProperty()->hasObjectFlag(BaseShape::NOT_EXTENSIBLE);
}
#endif /* ObjectImpl_inl_h__ */

View File

@ -5,8 +5,15 @@
* 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/. */
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "jsscope.h"
#include "ObjectImpl.h"
#include "ObjectImpl-inl.h"
using namespace js;
static ObjectElements emptyElementsHeader(0, 0);
@ -14,3 +21,19 @@ static ObjectElements emptyElementsHeader(0, 0);
/* Objects with no elements share one empty set of elements. */
HeapValue *js::emptyObjectElements =
reinterpret_cast<HeapValue *>(uintptr_t(&emptyElementsHeader) + sizeof(ObjectElements));
#if defined(_MSC_VER) && _MSC_VER >= 1500
/*
* Work around a compiler bug in MSVC9 and above, where inlining this function
* causes stack pointer offsets to go awry and spp to refer to something higher
* up the stack.
*/
MOZ_NEVER_INLINE
#endif
const Shape *
js::ObjectImpl::nativeLookup(JSContext *cx, jsid id)
{
MOZ_ASSERT(isNative());
Shape **spp;
return Shape::search(cx, lastProperty(), id, &spp);
}

View File

@ -11,6 +11,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/StdInt.h"
#include "jsfriendapi.h"
#include "jsinfer.h"
#include "jsval.h"
@ -176,6 +177,10 @@ class ObjectImpl : public gc::Cell
/* Minimum size for dynamically allocated slots. */
static const uint32_t SLOT_CAPACITY_MIN = 8;
HeapValue * fixedSlots() const {
return reinterpret_cast<HeapValue *>(uintptr_t(this) + sizeof(ObjectImpl));
}
/*
* These functions are currently public for simplicity; in the long run
* it may make sense to make at least some of them private.
@ -192,6 +197,10 @@ class ObjectImpl : public gc::Cell
return type_;
}
size_t numFixedSlots() const {
return reinterpret_cast<const shadow::Object *>(this)->numFixedSlots();
}
/*
* Whether this is the only object which has its specified type. This
* object will have its type constructed lazily as needed by analysis.
@ -206,6 +215,8 @@ class ObjectImpl : public gc::Cell
inline bool isNative() const;
const Shape * nativeLookup(JSContext *cx, jsid id);
inline Class *getClass() const;
inline JSClass *getJSClass() const;
inline bool hasClass(const Class *c) const;
@ -240,18 +251,38 @@ class ObjectImpl : public gc::Cell
/* Memory usage functions. */
inline size_t sizeOfThis() const;
/* JIT helpers. */
static inline size_t offsetOfShape() { return offsetof(ObjectImpl, shape_); }
inline HeapPtrShape *addressOfShape() { return &shape_; }
static inline size_t offsetOfType() { return offsetof(ObjectImpl, type_); }
/* Elements accessors. */
ObjectElements * getElementsHeader() const {
return ObjectElements::fromElements(elements);
}
/* JIT Accessors */
static size_t offsetOfShape() { return offsetof(ObjectImpl, shape_); }
HeapPtrShape *addressOfShape() { return &shape_; }
static size_t offsetOfType() { return offsetof(ObjectImpl, type_); }
HeapPtrTypeObject *addressOfType() { return &type_; }
static size_t offsetOfElements() { return offsetof(ObjectImpl, elements); }
static size_t offsetOfFixedElements() {
return sizeof(ObjectImpl) + sizeof(ObjectElements);
}
static size_t getFixedSlotOffset(size_t slot) {
return sizeof(ObjectImpl) + slot * sizeof(Value);
}
static size_t getPrivateDataOffset(size_t nfixed) { return getFixedSlotOffset(nfixed); }
static size_t offsetOfSlots() { return offsetof(ObjectImpl, slots); }
/* These functions are public, and they should remain public. */
public:
JSObject * getProto() const {
return type_->proto;
}
inline bool isExtensible() const;
};
} /* namespace js */