Bug 1606851 - Refactor arena layout lookup table calcuations r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 03 Jan 2020 17:31:45 +0000
changeset 509050 c61a30feaaa2639f86b97c9a11250998a2c36a48
parent 509049 96d386ccccb607dc1ac14ecc919bc63a715e6e93
child 509051 bee0ee9d17a2aac2ae6f8609bd2ba77d57e257d5
push id36990
push usernbeleuzu@mozilla.com
push dateTue, 07 Jan 2020 16:19:47 +0000
treeherdermozilla-central@9f55d547e196 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1606851
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1606851 - Refactor arena layout lookup table calcuations r=sfink This moves the calcuation of the table data to constexpr methods which is easier to read and understand. Depends on D58625 Differential Revision: https://phabricator.services.mozilla.com/D58626
js/src/gc/GC.cpp
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -309,54 +309,50 @@ static_assert(mozilla::ArrayLength(slots
                 #sizedType " is smaller than FreeSpan");                       \
   static_assert(sizeof(sizedType) % CellAlignBytes == 0,                       \
                 "Size of " #sizedType " is not a multiple of CellAlignBytes"); \
   static_assert(sizeof(sizedType) >= MinCellSize,                              \
                 "Size of " #sizedType " is smaller than the minimum size");
 FOR_EACH_ALLOCKIND(CHECK_THING_SIZE);
 #undef CHECK_THING_SIZE
 
+template <typename T>
+struct ArenaLayout {
+  static constexpr size_t thingSize() { return sizeof(T); }
+  static constexpr size_t thingsPerArena() {
+    return (ArenaSize - ArenaHeaderSize) / thingSize();
+  }
+  static constexpr size_t firstThingOffset() {
+    return ArenaSize - thingSize() * thingsPerArena();
+  }
+};
+
 const uint8_t Arena::ThingSizes[] = {
-#define EXPAND_THING_SIZE(allocKind, traceKind, type, sizedType, bgFinal, \
-                          nursery, compact)                               \
-  sizeof(sizedType),
+#define EXPAND_THING_SIZE(_1, _2, _3, sizedType, _4, _5, _6) \
+  ArenaLayout<sizedType>::thingSize(),
     FOR_EACH_ALLOCKIND(EXPAND_THING_SIZE)
 #undef EXPAND_THING_SIZE
 };
 
+const uint8_t Arena::FirstThingOffsets[] = {
+#define EXPAND_FIRST_THING_OFFSET(_1, _2, _3, sizedType, _4, _5, _6) \
+  ArenaLayout<sizedType>::firstThingOffset(),
+    FOR_EACH_ALLOCKIND(EXPAND_FIRST_THING_OFFSET)
+#undef EXPAND_FIRST_THING_OFFSET
+};
+
+const uint8_t Arena::ThingsPerArena[] = {
+#define EXPAND_THINGS_PER_ARENA(_1, _2, _3, sizedType, _4, _5, _6) \
+  ArenaLayout<sizedType>::thingsPerArena(),
+    FOR_EACH_ALLOCKIND(EXPAND_THINGS_PER_ARENA)
+#undef EXPAND_THINGS_PER_ARENA
+};
+
 FreeSpan FreeLists::emptySentinel;
 
-#undef CHECK_THING_SIZE_INNER
-#undef CHECK_THING_SIZE
-
-#define OFFSET(type) \
-  uint32_t(ArenaHeaderSize + (ArenaSize - ArenaHeaderSize) % sizeof(type))
-
-const uint8_t Arena::FirstThingOffsets[] = {
-#define EXPAND_FIRST_THING_OFFSET(allocKind, traceKind, type, sizedType, \
-                                  bgFinal, nursery, compact)             \
-  OFFSET(sizedType),
-    FOR_EACH_ALLOCKIND(EXPAND_FIRST_THING_OFFSET)
-#undef EXPAND_FIRST_THING_OFFSET
-};
-
-#undef OFFSET
-
-#define COUNT(type) uint32_t((ArenaSize - ArenaHeaderSize) / sizeof(type))
-
-const uint8_t Arena::ThingsPerArena[] = {
-#define EXPAND_THINGS_PER_ARENA(allocKind, traceKind, type, sizedType, \
-                                bgFinal, nursery, compact)             \
-  COUNT(sizedType),
-    FOR_EACH_ALLOCKIND(EXPAND_THINGS_PER_ARENA)
-#undef EXPAND_THINGS_PER_ARENA
-};
-
-#undef COUNT
-
 struct js::gc::FinalizePhase {
   gcstats::PhaseKind statsPhase;
   AllocKinds kinds;
 };
 
 /*
  * Finalization order for objects swept incrementally on the main thread.
  */