Skip to content

Commit

Permalink
Merge branch 'master' into export-D28763472
Browse files Browse the repository at this point in the history
  • Loading branch information
neildhar authored May 28, 2021
2 parents 8340357 + 4a43886 commit ff53fe9
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 102 deletions.
25 changes: 7 additions & 18 deletions include/hermes/VM/Domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,9 @@ class RequireContext final : public JSObject {
friend void RequireContextBuildMeta(
const GCCell *cell,
Metadata::Builder &mb);
friend void RequireContextSerialize(Serializer &, const GCCell *);

public:
// We need two anonymous slots for the domain and dirname.
static const PropStorage::size_type ANONYMOUS_PROPERTY_SLOTS =
Super::ANONYMOUS_PROPERTY_SLOTS + 2;

static constexpr SlotIndex domainPropIndex() {
return numOverlapSlots<RequireContext>() + ANONYMOUS_PROPERTY_SLOTS - 2;
}

static constexpr SlotIndex dirnamePropIndex() {
return numOverlapSlots<RequireContext>() + ANONYMOUS_PROPERTY_SLOTS - 1;
}

static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::RequireContextKind;
}
Expand All @@ -292,16 +281,12 @@ class RequireContext final : public JSObject {

/// \return the domain for this require context.
static Domain *getDomain(Runtime *runtime, RequireContext *self) {
return vmcast<Domain>(
JSObject::getDirectSlotValue<domainPropIndex()>(self).getObject(
runtime));
return self->domain_.get(runtime);
}

/// \return the current dirname for this require context.
static StringPrimitive *getDirname(Runtime *runtime, RequireContext *self) {
return vmcast<StringPrimitive>(
JSObject::getDirectSlotValue<dirnamePropIndex()>(self).getString(
runtime));
return self->dirname_.get(runtime);
}

#ifdef HERMESVM_SERIALIZE
Expand All @@ -315,6 +300,10 @@ class RequireContext final : public JSObject {
Handle<JSObject> parent,
Handle<HiddenClass> clazz)
: JSObject(runtime, &vt.base, *parent, *clazz) {}

private:
GCPointer<Domain> domain_;
GCPointer<StringPrimitive> dirname_;
};

} // namespace vm
Expand Down
17 changes: 4 additions & 13 deletions include/hermes/VM/JSArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class ArrayImpl : public JSObject {
using Super = JSObject;
friend void ArrayImplBuildMeta(const GCCell *cell, Metadata::Builder &mb);

static constexpr size_t indexedStoragePropIndex() {
return numOverlapSlots<ArrayImpl>() + ANONYMOUS_PROPERTY_SLOTS - 1;
}

public:
#ifdef HERMESVM_SERIALIZE
ArrayImpl(Deserializer &d, const VTable *vt);
Expand All @@ -32,10 +28,6 @@ class ArrayImpl : public JSObject {
serializeArrayImpl(Serializer &s, const GCCell *cell, unsigned overlapSlots);
#endif

/// Add an anonymous property slot to hold the indexedStorage pointer.
static const PropStorage::size_type ANONYMOUS_PROPERTY_SLOTS =
Super::ANONYMOUS_PROPERTY_SLOTS + 1;

static bool classof(const GCCell *cell) {
return kindInRange(
cell->getKind(),
Expand Down Expand Up @@ -130,16 +122,13 @@ class ArrayImpl : public JSObject {
/// Get a pointer to the indexed storage for this array. The returned value
/// may be null if there is no indexed storage.
StorageType *getIndexedStorage(PointerBase *base) const {
return vmcast_or_null<StorageType>(
JSObject::getDirectSlotValue<indexedStoragePropIndex()>(this).getObject(
base));
return indexedStorage_.get(base);
}

/// Set the indexed storage of this array to be \p p. The pointer is allowed
/// to be null.
void setIndexedStorage(PointerBase *base, StorageType *p, GC *gc) {
JSObject::setDirectSlotValue<indexedStoragePropIndex()>(
this, SmallHermesValue::encodeObjectValue(p, base), gc);
indexedStorage_.set(base, p, gc);
}

/// @}
Expand Down Expand Up @@ -241,6 +230,8 @@ class ArrayImpl : public JSObject {
uint32_t beginIndex_{0};
/// One past the last index contained in the storage.
uint32_t endIndex_{0};
/// The indexed storage for this array.
GCPointer<StorageType> indexedStorage_;
};

class Arguments final : public ArrayImpl {
Expand Down
33 changes: 15 additions & 18 deletions include/hermes/VM/JSDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@ namespace vm {
/// Date object.
class JSDate final : public JSObject {
using Super = JSObject;

protected:
static constexpr SlotIndex primitiveValuePropIndex() {
return numOverlapSlots<JSDate>() + ANONYMOUS_PROPERTY_SLOTS - 1;
}
friend void DateBuildMeta(const GCCell *, Metadata::Builder &);

public:
static const ObjectVTable vt;

/// Need one anonymous slot for the [[PrimitiveValue]] internal property.
static const PropStorage::size_type ANONYMOUS_PROPERTY_SLOTS =
Super::ANONYMOUS_PROPERTY_SLOTS + 1;

static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::DateKind;
}
Expand All @@ -43,26 +35,31 @@ class JSDate final : public JSObject {
}

/// \return the [[PrimitiveValue]] internal property.
static SmallHermesValue getPrimitiveValue(JSObject *self) {
return JSObject::getDirectSlotValue<JSDate::primitiveValuePropIndex()>(
self);
double getPrimitiveValue() {
return primitiveValue_;
}

/// Set the [[PrimitiveValue]] internal property.
static void
setPrimitiveValue(JSObject *self, Runtime *runtime, SmallHermesValue value) {
return JSObject::setDirectSlotValue<JSDate::primitiveValuePropIndex()>(
self, value, &runtime->getHeap());
void setPrimitiveValue(double value) {
primitiveValue_ = value;
}

#ifdef HERMESVM_SERIALIZE
explicit JSDate(Deserializer &d);

friend void DateSerialize(Serializer &s, const GCCell *cell);
friend void DateDeserialize(Deserializer &d, CellKind kind);
#endif

JSDate(Runtime *runtime, Handle<JSObject> parent, Handle<HiddenClass> clazz)
: JSObject(runtime, &vt.base, *parent, *clazz) {}
JSDate(
Runtime *runtime,
double value,
Handle<JSObject> parent,
Handle<HiddenClass> clazz)
: JSObject(runtime, &vt.base, *parent, *clazz), primitiveValue_{value} {}

private:
double primitiveValue_;
};

} // namespace vm
Expand Down
22 changes: 12 additions & 10 deletions lib/VM/Domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,24 @@ const ObjectVTable RequireContext::vt{
void RequireContextBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
mb.addJSObjectOverlapSlots(JSObject::numOverlapSlots<RequireContext>());
ObjectBuildMeta(cell, mb);
const auto *self = static_cast<const RequireContext *>(cell);
mb.setVTable(&RequireContext::vt.base);
mb.addField(&self->domain_);
mb.addField(&self->dirname_);
}

#ifdef HERMESVM_SERIALIZE
RequireContext::RequireContext(Deserializer &d) : JSObject(d, &vt.base) {}
RequireContext::RequireContext(Deserializer &d) : JSObject(d, &vt.base) {
d.readRelocation(&domain_, RelocationKind::GCPointer);
d.readRelocation(&dirname_, RelocationKind::GCPointer);
}

void RequireContextSerialize(Serializer &s, const GCCell *cell) {
JSObject::serializeObjectImpl(
s, cell, JSObject::numOverlapSlots<RequireContext>());
const auto *self = static_cast<const RequireContext *>(cell);
s.writeRelocation(self->domain_.get(s.getRuntime()));
s.writeRelocation(self->dirname_.get(s.getRuntime()));
s.endObject(cell);
}

Expand All @@ -464,15 +473,8 @@ Handle<RequireContext> RequireContext::create(
objProto,
runtime->getHiddenClassForPrototype(*objProto, ANONYMOUS_PROPERTY_SLOTS));
auto self = JSObjectInit::initToHandle(runtime, cell);

JSObject::setDirectSlotValue<domainPropIndex()>(
*self,
SmallHermesValue::encodeObjectValue(domain.get(), runtime),
&runtime->getHeap());
JSObject::setDirectSlotValue<dirnamePropIndex()>(
*self,
SmallHermesValue::encodeStringValue(dirname.get(), runtime),
&runtime->getHeap());
self->domain_.set(runtime, *domain, &runtime->getHeap());
self->dirname_.set(runtime, *dirname, &runtime->getHeap());
return self;
}

Expand Down
6 changes: 6 additions & 0 deletions lib/VM/JSArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ namespace vm {
void ArrayImplBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
mb.addJSObjectOverlapSlots(JSObject::numOverlapSlots<ArrayImpl>());
ObjectBuildMeta(cell, mb);
const auto *self = static_cast<const ArrayImpl *>(cell);
// This edge has to be called "elements" in order for Chrome to attribute
// the size of the indexed storage as part of total usage of "JS Arrays".
mb.addField("elements", &self->indexedStorage_);
}

void ArrayImpl::_snapshotAddEdgesImpl(
Expand Down Expand Up @@ -61,6 +65,7 @@ void ArrayImpl::_snapshotAddEdgesImpl(
ArrayImpl::ArrayImpl(Deserializer &d, const VTable *vt) : JSObject(d, vt) {
beginIndex_ = d.readInt<uint32_t>();
endIndex_ = d.readInt<uint32_t>();
d.readRelocation(&indexedStorage_, RelocationKind::GCPointer);
}

void serializeArrayImpl(
Expand All @@ -71,6 +76,7 @@ void serializeArrayImpl(
JSObject::serializeObjectImpl(s, cell, overlapSlots);
s.writeInt<uint32_t>(self->beginIndex_);
s.writeInt<uint32_t>(self->endIndex_);
s.writeRelocation(self->indexedStorage_.get(s.getRuntime()));
}
#endif

Expand Down
9 changes: 8 additions & 1 deletion lib/VM/JSDate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ void DateBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
}

#ifdef HERMESVM_SERIALIZE
JSDate::JSDate(Deserializer &d) : JSObject(d, &vt.base) {}
JSDate::JSDate(Deserializer &d) : JSObject(d, &vt.base) {
HermesValue hv;
d.readHermesValue(&hv);
primitiveValue_ = hv.getNumber();
}

void DateSerialize(Serializer &s, const GCCell *cell) {
JSObject::serializeObjectImpl(s, cell, JSObject::numOverlapSlots<JSDate>());
const auto *self = static_cast<const JSDate *>(cell);
s.writeHermesValue(HermesValue::encodeNumberValue(self->primitiveValue_));
s.endObject(cell);
}

Expand All @@ -55,6 +61,7 @@ PseudoHandle<JSDate>
JSDate::create(Runtime *runtime, double value, Handle<JSObject> parentHandle) {
auto *cell = runtime->makeAFixed<JSDate>(
runtime,
value,
parentHandle,
runtime->getHiddenClassForPrototype(
*parentHandle, numOverlapSlots<JSDate>() + ANONYMOUS_PROPERTY_SLOTS));
Expand Down
Loading

0 comments on commit ff53fe9

Please sign in to comment.