Skip to content

Commit 2287456

Browse files
neildharfacebook-github-bot
authored andcommitted
Make minAllocationSize constexpr
Summary: Make HadesGC::minAllocationSize and GCBase::minAllocationSize constexpr, this allows us to use them in compile time checks. Reviewed By: dulinriley Differential Revision: D26478072 fbshipit-source-id: 9c75be352ef49f085518dd959354167139e0eb5a
1 parent 42dc07a commit 2287456

5 files changed

Lines changed: 22 additions & 26 deletions

File tree

include/hermes/VM/GCBase-inline.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ constexpr uint32_t GCBase::maxAllocationSize() {
8080
// Return the lesser of the two GC options' max allowed sizes.
8181
return min(HadesGC::maxAllocationSize(), GenGC::maxAllocationSize());
8282
}
83+
84+
constexpr uint32_t GCBase::minAllocationSize() {
85+
// Return the greater of the two GC options' min allowed sizes.
86+
return max(HadesGC::minAllocationSize(), GenGC::minAllocationSize());
87+
}
8388
#endif
8489

8590
template <typename Acceptor>

include/hermes/VM/GCBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,9 @@ class GCBase {
10101010
#endif
10111011

10121012
#ifdef HERMESVM_GC_RUNTIME
1013-
static uint32_t minAllocationSize();
1013+
inline static constexpr uint32_t minAllocationSize();
10141014

1015-
static constexpr uint32_t maxAllocationSize();
1015+
inline static constexpr uint32_t maxAllocationSize();
10161016
#endif
10171017

10181018
/// Dump detailed heap contents to the given output stream, \p os.

include/hermes/VM/HadesGC.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "hermes/ADT/BitArray.h"
1212
#include "hermes/ADT/ExponentialMovingAverage.h"
13+
#include "hermes/Support/Algorithms.h"
1314
#include "hermes/Support/SlowAssert.h"
1415
#include "hermes/VM/AlignedHeapSegment.h"
1516
#include "hermes/VM/GCBase.h"
@@ -76,14 +77,17 @@ class HadesGC final : public GCBase {
7677
return gc->getKind() == HeapKind::HADES;
7778
}
7879

79-
static uint32_t minAllocationSize();
80-
8180
static constexpr uint32_t maxAllocationSize() {
8281
// The largest allocation allowable in Hades is the max size a single
8382
// segment supports.
8483
return HeapSegment::maxSize();
8584
}
8685

86+
static constexpr uint32_t minAllocationSize() {
87+
return heapAlignSize(
88+
max(sizeof(OldGen::FreelistCell), sizeof(CopyListCell)));
89+
}
90+
8791
/// \name GCBase overrides
8892
/// \{
8993

@@ -234,14 +238,22 @@ class HadesGC final : public GCBase {
234238

235239
class CollectionStats;
236240
class HeapMarkingAcceptor;
237-
struct CopyListCell;
238241
template <bool CompactionEnabled>
239242
class EvacAcceptor;
240243
class MarkAcceptor;
241244
class MarkWeakRootsAcceptor;
242245
class OldGen;
243246
class Executor;
244247

248+
struct CopyListCell final : public GCCell {
249+
// Linked list of cells pointing to the next cell that was copied.
250+
CopyListCell *next_;
251+
// If the cell was trimmed, this field will have the original size of the
252+
// object stored. If the cell wasn't trimmed it'll have the same size as the
253+
// forwarded pointer.
254+
uint32_t originalSize_;
255+
};
256+
245257
/// Similar to AlignedHeapSegment except it uses a free list.
246258
class HeapSegment final : public AlignedHeapSegment {
247259
public:

lib/VM/GCBase.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@ GCBase::GCBase(
9494
#endif
9595
}
9696

97-
#ifdef HERMESVM_GC_RUNTIME
98-
/* static */
99-
uint32_t GCBase::minAllocationSize() {
100-
return std::max({GenGC::minAllocationSize(), HadesGC::minAllocationSize()});
101-
}
102-
#endif
103-
10497
GCBase::GCCycle::GCCycle(
10598
GCBase *gc,
10699
OptValue<GCCallbacks *> gcCallbacksOpt,

lib/VM/gcs/HadesGC.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ HadesGC::HeapSegment::HeapSegment(AlignedStorage storage)
3939
growToLimit();
4040
}
4141

42-
struct HadesGC::CopyListCell final : public GCCell {
43-
// Linked list of cells pointing to the next cell that was copied.
44-
CopyListCell *next_;
45-
// If the cell was trimmed, this field will have the original size of the
46-
// object stored. If the cell wasn't trimmed it'll have the same size as the
47-
// forwarded pointer.
48-
uint32_t originalSize_;
49-
};
50-
5142
GCCell *
5243
HadesGC::OldGen::finishAlloc(GCCell *cell, uint32_t sz, uint16_t segmentIdx) {
5344
// Track the number of allocated bytes in a segment.
@@ -1301,11 +1292,6 @@ HadesGC::~HadesGC() {
13011292
"Must call finalizeAll before destructor.");
13021293
}
13031294

1304-
uint32_t HadesGC::minAllocationSize() {
1305-
return heapAlignSize(
1306-
std::max(sizeof(OldGen::FreelistCell), sizeof(CopyListCell)));
1307-
}
1308-
13091295
void HadesGC::getHeapInfo(HeapInfo &info) {
13101296
std::lock_guard<Mutex> lk{gcMutex_};
13111297
GCBase::getHeapInfo(info);

0 commit comments

Comments
 (0)