Skip to content

Commit 8bfefa0

Browse files
committed
Bug 1830851 - Optimize post barrier code for JSAtom. r=jonco
Atoms are always tenured so treat them similar to `TenuredCell` types. This should get rid of some post barrier code when atomizing strings. Differential Revision: https://phabricator.services.mozilla.com/D176898
1 parent 464ae78 commit 8bfefa0

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

js/src/gc/Cell.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,14 @@ class alignas(gc::CellAlignBytes) CellWithTenuredGCPointer : public BaseCell {
856856

857857
void CellHeaderPostWriteBarrier(JSObject** ptr, JSObject* prev, JSObject* next);
858858

859+
template <typename T>
860+
constexpr inline bool GCTypeIsTenured() {
861+
static_assert(std::is_base_of_v<Cell, T>);
862+
static_assert(!std::is_same_v<Cell, T> && !std::is_same_v<TenuredCell, T>);
863+
864+
return std::is_base_of_v<TenuredCell, T> || std::is_base_of_v<JSAtom, T>;
865+
}
866+
859867
template <class PtrT>
860868
class alignas(gc::CellAlignBytes) TenuredCellWithGCPointer
861869
: public TenuredCell {
@@ -869,7 +877,7 @@ class alignas(gc::CellAlignBytes) TenuredCellWithGCPointer
869877
std::is_base_of_v<Cell, PtrT>,
870878
"Only use TenuredCellWithGCPointer for pointers to GC things");
871879
static_assert(
872-
!std::is_base_of_v<TenuredCell, PtrT>,
880+
!GCTypeIsTenured<PtrT>,
873881
"Don't use TenuredCellWithGCPointer for always-tenured GC things");
874882
}
875883

js/src/gc/StoreBuffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "ds/BitArray.h"
1717
#include "ds/LifoAlloc.h"
18+
#include "gc/Cell.h"
1819
#include "gc/Nursery.h"
1920
#include "gc/TraceKind.h"
2021
#include "js/AllocPolicy.h"
@@ -641,7 +642,7 @@ MOZ_ALWAYS_INLINE void PostWriteBarrier(T** vp, T* prev, T* next) {
641642
static_assert(std::is_base_of_v<Cell, T>);
642643
static_assert(!std::is_same_v<Cell, T> && !std::is_same_v<TenuredCell, T>);
643644

644-
if constexpr (!std::is_base_of_v<TenuredCell, T>) {
645+
if constexpr (!GCTypeIsTenured<T>()) {
645646
using BaseT = typename BaseGCType<T>::type;
646647
PostWriteBarrierImpl<BaseT>(vp, prev, next);
647648
return;

js/src/gc/Tenuring.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ void js::gc::StoreBuffer::WholeCellBuffer::trace(TenuringTracer& mover) {
385385
template <typename T>
386386
void js::gc::StoreBuffer::CellPtrEdge<T>::trace(TenuringTracer& mover) const {
387387
static_assert(std::is_base_of_v<Cell, T>, "T must be a Cell type");
388-
static_assert(!std::is_base_of_v<TenuredCell, T>,
389-
"T must not be a tenured Cell type");
388+
static_assert(!GCTypeIsTenured<T>(), "T must not be a tenured Cell type");
390389

391390
T* thing = *edge;
392391
if (!thing) {

0 commit comments

Comments
 (0)