Skip to content

Commit

Permalink
Add getCellKind for cell classes
Browse files Browse the repository at this point in the history
Summary:
Add the ability to get the `CellKind` for a given cell class. This
already exists for a small number of cells (the ones that are
templates), this diff expands it to everything else.

This is used in a subsequent diff to retrieve the `CellKind` for
classes in the `GC::makeA` template.

Reviewed By: kodafb

Differential Revision: D33251143

fbshipit-source-id: 7236eac5e23832c59faf2052913cf7d49e26eda4
  • Loading branch information
neildhar authored and facebook-github-bot committed Feb 12, 2022
1 parent eb2be51 commit a79bfd8
Show file tree
Hide file tree
Showing 31 changed files with 150 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/hermes/VM/BoxedDouble.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class BoxedDouble final : public GCCell {
double value_;

public:
static constexpr CellKind getCellKind() {
return CellKind::BoxedDoubleKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::BoxedDoubleKind;
}
Expand Down
24 changes: 24 additions & 0 deletions include/hermes/VM/Callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Environment final
public:
static const VTable vt;

static constexpr CellKind getCellKind() {
return CellKind::EnvironmentKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::EnvironmentKind;
}
Expand Down Expand Up @@ -345,6 +348,9 @@ class BoundFunction final : public Callable {
using Super = Callable;
static const CallableVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::BoundFunctionKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::BoundFunctionKind;
}
Expand Down Expand Up @@ -440,6 +446,9 @@ class NativeFunction : public Callable {
using Super = Callable;
static const CallableVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::NativeFunctionKind;
}
static bool classof(const GCCell *cell) {
return kindInRange(
cell->getKind(),
Expand Down Expand Up @@ -693,6 +702,9 @@ class NativeConstructor final : public NativeFunction {

static const CallableVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::NativeConstructorKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::NativeConstructorKind;
}
Expand Down Expand Up @@ -878,6 +890,9 @@ class JSFunction : public Callable {
public:
static const CallableVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSFunctionKind;
}
static bool classof(const GCCell *cell) {
return kindInRange(
cell->getKind(),
Expand Down Expand Up @@ -975,6 +990,9 @@ class JSAsyncFunction final : public JSFunction {
runtime->getEmptyCodeBlock());
}

static constexpr CellKind getCellKind() {
return CellKind::JSAsyncFunctionKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSAsyncFunctionKind;
}
Expand Down Expand Up @@ -1043,6 +1061,9 @@ class JSGeneratorFunction final : public JSFunction {
runtime->getEmptyCodeBlock());
}

static constexpr CellKind getCellKind() {
return CellKind::JSGeneratorFunctionKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSGeneratorFunctionKind;
}
Expand Down Expand Up @@ -1108,6 +1129,9 @@ class GeneratorInnerFunction final : public JSFunction {
public:
static const CallableVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::GeneratorInnerFunctionKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::GeneratorInnerFunctionKind;
}
Expand Down
4 changes: 4 additions & 0 deletions include/hermes/VM/DecoratedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class DecoratedObject : public JSObject {

using Super = JSObject;
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::DecoratedObjectKind;
}
static bool classof(const GCCell *cell) {
return kindInRange(
cell->getKind(),
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/DictPropertyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class DictPropertyMap final

static const VTable vt;

static constexpr CellKind getCellKind() {
return CellKind::DictPropertyMapKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::DictPropertyMapKind;
}
Expand Down
6 changes: 6 additions & 0 deletions include/hermes/VM/Domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class Domain final : public GCCell {
OptValue<uint32_t> cjsEntryModuleID_;

public:
static constexpr CellKind getCellKind() {
return CellKind::DomainKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::DomainKind;
}
Expand Down Expand Up @@ -253,6 +256,9 @@ class RequireContext final : public JSObject {
friend void RequireContextSerialize(Serializer &, const GCCell *);

public:
static constexpr CellKind getCellKind() {
return CellKind::RequireContextKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::RequireContextKind;
}
Expand Down
1 change: 1 addition & 0 deletions include/hermes/VM/DummyObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct DummyObject final : public GCCell {

static DummyObject *create(GC *gc);
static DummyObject *createLongLived(GC *gc);
static constexpr CellKind getCellKind();
static bool classof(const GCCell *cell);
static void _finalizeImpl(GCCell *cell, GC *);
static size_t _mallocSizeImpl(GCCell *cell);
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/FillerCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class FillerCell : public VariableSizeRuntimeCell {
return &vt;
};

static constexpr CellKind getCellKind() {
return CellKind::FillerCellKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::FillerCellKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/HadesGC.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ class HadesGC final : public GCBase {
/// \pre getAllocatedSize() >= sz + minAllocationSize()
GCCell *carve(uint32_t sz);

static constexpr CellKind getCellKind() {
return CellKind::FreelistKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::FreelistKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/HiddenClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ class HiddenClass final : public GCCell {

static const VTable vt;

static constexpr CellKind getCellKind() {
return CellKind::HiddenClassKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::HiddenClassKind;
}
Expand Down
6 changes: 6 additions & 0 deletions include/hermes/VM/HostModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class FinalizableNativeFunction final : public NativeFunction {
public:
static const CallableVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::FinalizableNativeFunctionKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::FinalizableNativeFunctionKind;
}
Expand Down Expand Up @@ -99,6 +102,9 @@ class HostObject final : public DecoratedObject {
public:
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::HostObjectKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::HostObjectKind;
}
Expand Down
9 changes: 9 additions & 0 deletions include/hermes/VM/JSArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ class Arguments final : public ArrayImpl {
static const PropStorage::size_type NAMED_PROPERTY_SLOTS =
Super::NAMED_PROPERTY_SLOTS + 1;

static constexpr CellKind getCellKind() {
return CellKind::ArgumentsKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::ArgumentsKind;
}
Expand Down Expand Up @@ -283,6 +286,9 @@ class JSArray final : public ArrayImpl {
Runtime *runtime,
Handle<JSObject> prototypeHandle);

static constexpr CellKind getCellKind() {
return CellKind::JSArrayKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSArrayKind;
}
Expand Down Expand Up @@ -390,6 +396,9 @@ class JSArrayIterator : public JSObject {
public:
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSArrayIteratorKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSArrayIteratorKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSArrayBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class JSArrayBuffer final : public JSObject {

static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSArrayBufferKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSArrayBufferKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSCallableProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class JSCallableProxy : public NativeFunction {
friend detail::ProxySlots &detail::slots(JSObject *selfHandle);

static const CallableVTable vt;
static constexpr CellKind getCellKind() {
return CellKind::JSCallableProxyKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSCallableProxyKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSDataView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class JSDataView final : public JSObject {

static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSDataViewKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSDataViewKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class JSDate final : public JSObject {
public:
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSDateKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSDateKind;
}
Expand Down
4 changes: 4 additions & 0 deletions include/hermes/VM/JSError.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class JSError final : public JSObject {
public:
using Super = JSObject;
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSErrorKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSErrorKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class JSGenerator final : public JSObject {
const static ObjectVTable vt;

public:
static constexpr CellKind getCellKind() {
return CellKind::JSGeneratorKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSGeneratorKind;
}
Expand Down
6 changes: 6 additions & 0 deletions include/hermes/VM/JSMapImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class JSMapImpl final : public JSObject {
public:
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return C;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == C;
}
Expand Down Expand Up @@ -178,6 +181,9 @@ class JSMapIteratorImpl final : public JSObject {
public:
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return C;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == C;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ class JSObject : public GCCell {
/// Number of property slots allocated directly inside the object.
static const PropStorage::size_type DIRECT_PROPERTY_SLOTS = 5;

static constexpr CellKind getCellKind() {
return CellKind::JSObjectKind;
}
static bool classof(const GCCell *cell) {
return kindInRange(
cell->getKind(), CellKind::ObjectKind_first, CellKind::ObjectKind_last);
Expand Down
4 changes: 4 additions & 0 deletions include/hermes/VM/JSProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class JSProxy : public JSObject {
friend detail::ProxySlots &detail::slots(JSObject *selfHandle);

static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSProxyKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSProxyKind;
}
Expand Down
4 changes: 4 additions & 0 deletions include/hermes/VM/JSRegExp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class JSRegExp final : public JSObject {
public:
using Super = JSObject;
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSRegExpKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSRegExpKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSRegExpStringIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class JSRegExpStringIterator : public JSObject {
public:
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return CellKind::JSRegExpStringIteratorKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::JSRegExpStringIteratorKind;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSTypedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class JSTypedArray final : public JSTypedArrayBase {

static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return C;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == C;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/JSWeakMapImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ class JSWeakMapImpl final : public JSWeakMapImplBase {
public:
static const ObjectVTable vt;

static constexpr CellKind getCellKind() {
return C;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == C;
}
Expand Down
6 changes: 6 additions & 0 deletions include/hermes/VM/OrderedHashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class HashMapEntry final : public GCCell {
/// Next entry in the hash table bucket.
GCPointer<HashMapEntry> nextEntryInBucket{nullptr};

static constexpr CellKind getCellKind() {
return CellKind::HashMapEntryKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::HashMapEntryKind;
}
Expand Down Expand Up @@ -85,6 +88,9 @@ class OrderedHashMap final : public GCCell {
public:
static const VTable vt;

static constexpr CellKind getCellKind() {
return CellKind::OrderedHashMapKind;
}
static bool classof(const GCCell *cell) {
return cell->getKind() == CellKind::OrderedHashMapKind;
}
Expand Down
Loading

0 comments on commit a79bfd8

Please sign in to comment.