Bug 728411 - Begin to move simple functions from JSObject to ObjectImpl. r=bhackett

--HG--
extra : rebase_source : 1a82d604cb32e941a296a63b3047a6c76426d57e
This commit is contained in:
Jeff Walden 2012-02-16 15:02:15 -08:00
parent 66bba64a57
commit ae0ff8a417
5 changed files with 157 additions and 110 deletions

View File

@ -420,11 +420,6 @@ struct JSObject : public js::ObjectImpl
void makeLazyType(JSContext *cx);
public:
inline js::Shape *lastProperty() const {
JS_ASSERT(shape_);
return shape_;
}
/*
* Update the last property, keeping the number of allocated slots in sync
* with the object's new slot span.
@ -462,9 +457,6 @@ struct JSObject : public js::ObjectImpl
*/
bool setSlotSpan(JSContext *cx, uint32_t span);
static inline size_t offsetOfShape() { return offsetof(JSObject, shape_); }
inline js::HeapPtrShape *addressOfShape() { return &shape_; }
const js::Shape *nativeLookup(JSContext *cx, jsid id);
inline bool nativeContains(JSContext *cx, jsid id);
@ -474,23 +466,6 @@ struct JSObject : public js::ObjectImpl
static const uint32_t NELEMENTS_LIMIT = JS_BIT(28);
public:
inline bool isNative() const;
inline js::Class *getClass() const;
inline JSClass *getJSClass() const;
inline bool hasClass(const js::Class *c) const;
inline const js::ObjectOps *getOps() const;
/*
* An object is a delegate if it is on another object's prototype or scope
* chain, and therefore the delegate might be asked implicitly to get or
* set a property on behalf of another object. Delegates may be accessed
* directly too, as may any object, but only those objects linked after the
* head of any prototype or scope chain are flagged as delegates. This
* definition helps to optimize shape-based property cache invalidation
* (see Purge{Scope,Proto}Chain in jsobj.cpp).
*/
inline bool isDelegate() const;
inline bool setDelegate(JSContext *cx);
inline bool isBoundFunction() const;
@ -556,13 +531,6 @@ struct JSObject : public js::ObjectImpl
/* Whether there may be indexed properties on this object. */
inline bool isIndexed() const;
/*
* Return true if this object is a native one that has been converted from
* shared-immutable prototype-rooted shape storage to dictionary-shapes in
* a doubly-linked list.
*/
inline bool inDictionaryMode() const;
inline uint32_t propertyCount() const;
inline bool hasPropertyTable() const;
@ -736,18 +704,6 @@ struct JSObject : public js::ObjectImpl
inline void setFixedSlot(uintN slot, const js::Value &value);
inline void initFixedSlot(uintN slot, const js::Value &value);
/*
* Whether this is the only object which has its specified type. This
* object will have its type constructed lazily as needed by analysis.
*/
bool hasSingletonType() const { return !!type_->singleton; }
/*
* Whether the object's type has not been constructed yet. If an object
* might have a lazy type, use getType() below, otherwise type().
*/
bool hasLazyType() const { return type_->lazy(); }
/*
* Marks this object as having a singleton type, and leave the type lazy.
* Constructs a new, unique shape for the object.
@ -756,19 +712,11 @@ struct JSObject : public js::ObjectImpl
inline js::types::TypeObject *getType(JSContext *cx);
js::types::TypeObject *type() const {
JS_ASSERT(!hasLazyType());
return type_;
}
js::HeapPtr<js::types::TypeObject> &typeFromGC() {
/* Direct field access for use by GC. */
return type_;
}
static inline size_t offsetOfType() { return offsetof(JSObject, type_); }
inline js::HeapPtrTypeObject *addressOfType() { return &type_; }
inline void setType(js::types::TypeObject *newType);
js::types::TypeObject *getNewType(JSContext *cx, JSFunction *fun = NULL);
@ -799,10 +747,6 @@ struct JSObject : public js::ObjectImpl
*/
bool shouldSplicePrototype(JSContext *cx);
JSObject * getProto() const {
return type_->proto;
}
/*
* Parents and scope chains.
*
@ -1357,13 +1301,12 @@ struct JSObject : public js::ObjectImpl
private:
static void staticAsserts() {
/* Check alignment for any fixed slots allocated after the object. */
JS_STATIC_ASSERT(sizeof(JSObject) % sizeof(js::Value) == 0);
JS_STATIC_ASSERT(offsetof(JSObject, shape_) == offsetof(js::shadow::Object, shape));
JS_STATIC_ASSERT(offsetof(JSObject, slots) == offsetof(js::shadow::Object, slots));
JS_STATIC_ASSERT(offsetof(JSObject, type_) == offsetof(js::shadow::Object, type));
JS_STATIC_ASSERT(sizeof(JSObject) == sizeof(js::shadow::Object));
MOZ_STATIC_ASSERT(sizeof(JSObject) == sizeof(js::shadow::Object),
"shadow interface must match actual interface");
MOZ_STATIC_ASSERT(sizeof(JSObject) == sizeof(js::ObjectImpl),
"JSObject itself must not have any fields");
MOZ_STATIC_ASSERT(sizeof(JSObject) % sizeof(js::Value) == 0,
"fixed slots after an object must be aligned");
}
};

View File

@ -80,8 +80,10 @@
#include "jsscriptinlines.h"
#include "gc/Barrier-inl.h"
#include "vm/String-inl.h"
#include "vm/ObjectImpl-inl.h"
#include "vm/RegExpStatics-inl.h"
#include "vm/String-inl.h"
inline bool
JSObject::hasPrivate() const
@ -866,11 +868,6 @@ inline bool JSObject::setSystem(JSContext *cx)
return setFlag(cx, js::BaseShape::SYSTEM);
}
inline bool JSObject::isDelegate() const
{
return lastProperty()->hasObjectFlag(js::BaseShape::DELEGATE);
}
inline bool JSObject::setDelegate(JSContext *cx)
{
return setFlag(cx, js::BaseShape::DELEGATE, GENERATE_SHAPE);
@ -1171,12 +1168,6 @@ JSObject::nativeSetSlotWithType(JSContext *cx, const js::Shape *shape, const js:
js::types::AddTypePropertyId(cx, this, shape->propid(), value);
}
inline bool
JSObject::isNative() const
{
return lastProperty()->isNative();
}
inline bool
JSObject::nativeContains(JSContext *cx, jsid id)
{
@ -1195,12 +1186,6 @@ JSObject::nativeEmpty() const
return lastProperty()->isEmptyShape();
}
inline bool
JSObject::inDictionaryMode() const
{
return lastProperty()->inDictionary();
}
inline uint32_t
JSObject::propertyCount() const
{

View File

@ -1113,30 +1113,6 @@ Shape::search(JSContext *cx, Shape *start, jsid id, Shape ***pspp, bool adding)
#pragma warning(pop)
#endif
inline js::Class *
JSObject::getClass() const
{
return lastProperty()->getObjectClass();
}
inline JSClass *
JSObject::getJSClass() const
{
return Jsvalify(getClass());
}
inline bool
JSObject::hasClass(const js::Class *c) const
{
return getClass() == c;
}
inline const js::ObjectOps *
JSObject::getOps() const
{
return &getClass()->ops;
}
namespace JS {
template<> class AnchorPermitted<js::Shape *> { };
template<> class AnchorPermitted<const js::Shape *> { };

View File

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=78:
*
* 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 ObjectImpl_inl_h___
#define ObjectImpl_inl_h___
#include "ObjectImpl.h"
inline bool
js::ObjectImpl::isNative() const
{
return lastProperty()->isNative();
}
inline js::Class *
js::ObjectImpl::getClass() const
{
return lastProperty()->getObjectClass();
}
inline JSClass *
js::ObjectImpl::getJSClass() const
{
return Jsvalify(getClass());
}
inline bool
js::ObjectImpl::hasClass(const Class *c) const
{
return getClass() == c;
}
inline const js::ObjectOps *
js::ObjectImpl::getOps() const
{
return &getClass()->ops;
}
inline bool
js::ObjectImpl::isDelegate() const
{
return lastProperty()->hasObjectFlag(BaseShape::DELEGATE);
}
inline bool
js::ObjectImpl::inDictionaryMode() const
{
return lastProperty()->inDictionary();
}
#endif /* ObjectImpl_inl_h__ */

View File

@ -11,6 +11,9 @@
#include "mozilla/Assertions.h"
#include "mozilla/StdInt.h"
#include "jsinfer.h"
#include "jsval.h"
#include "gc/Barrier.h"
namespace js {
@ -74,8 +77,11 @@ class ObjectElements
/* Shared singleton for objects with no elements. */
extern HeapValue *emptyObjectElements;
struct Shape;
struct Class;
struct GCMarker;
struct ObjectOps;
struct Shape;
class NewObjectCache;
/*
@ -145,11 +151,93 @@ class ObjectImpl : public gc::Cell
HeapValue *slots; /* Slots for object properties. */
HeapValue *elements; /* Slots for object elements. */
protected:
friend struct Shape;
friend struct GCMarker;
friend class NewObjectCache;
private:
static void staticAsserts() {
MOZ_STATIC_ASSERT(sizeof(ObjectImpl) == sizeof(shadow::Object),
"shadow interface must match actual implementation");
MOZ_STATIC_ASSERT(sizeof(ObjectImpl) % sizeof(Value) == 0,
"fixed slots after an object must be aligned");
MOZ_STATIC_ASSERT(offsetof(ObjectImpl, shape_) == offsetof(shadow::Object, shape),
"shadow shape must match actual shape");
MOZ_STATIC_ASSERT(offsetof(ObjectImpl, type_) == offsetof(shadow::Object, type),
"shadow type must match actual type");
MOZ_STATIC_ASSERT(offsetof(ObjectImpl, slots) == offsetof(shadow::Object, slots),
"shadow slots must match actual slots");
MOZ_STATIC_ASSERT(offsetof(ObjectImpl, elements) == offsetof(shadow::Object, _1),
"shadow placeholder must match actual elements");
}
protected:
friend struct GCMarker;
friend struct Shape;
friend class NewObjectCache;
/*
* These functions are currently public for simplicity; in the long run
* it may make sense to make at least some of them private.
*/
public:
Shape * lastProperty() const {
MOZ_ASSERT(shape_);
return shape_;
}
types::TypeObject *type() const {
MOZ_ASSERT(!hasLazyType());
return type_;
}
/*
* Whether this is the only object which has its specified type. This
* object will have its type constructed lazily as needed by analysis.
*/
bool hasSingletonType() const { return !!type_->singleton; }
/*
* Whether the object's type has not been constructed yet. If an object
* might have a lazy type, use getType() below, otherwise type().
*/
bool hasLazyType() const { return type_->lazy(); }
inline bool isNative() const;
inline Class *getClass() const;
inline JSClass *getJSClass() const;
inline bool hasClass(const Class *c) const;
inline const ObjectOps *getOps() const;
/*
* An object is a delegate if it is on another object's prototype or scope
* chain, and therefore the delegate might be asked implicitly to get or
* set a property on behalf of another object. Delegates may be accessed
* directly too, as may any object, but only those objects linked after the
* head of any prototype or scope chain are flagged as delegates. This
* definition helps to optimize shape-based property cache invalidation
* (see Purge{Scope,Proto}Chain in jsobj.cpp).
*/
inline bool isDelegate() const;
/*
* Return true if this object is a native one that has been converted from
* shared-immutable prototype-rooted shape storage to dictionary-shapes in
* a doubly-linked list.
*/
inline bool inDictionaryMode() 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_); }
HeapPtrTypeObject *addressOfType() { return &type_; }
/* These functions are public, and they should remain public. */
public:
JSObject * getProto() const {
return type_->proto;
}
};
} /* namespace js */