Bug 1533070 - Get rid of static initializers in GC.cpp by marking some functions/statics constexpr. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 06 Mar 2019 17:38:11 +0000
changeset 520544 351c542d6e4576a5e9e9b0035dc4780783054e58
parent 520543 608ca009efdfd35fc49127b47bb13a57df6f7273
child 520545 1bc91e8030f2b143fc23431e56b49faed564adcc
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1533070
milestone67.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 1533070 - Get rid of static initializers in GC.cpp by marking some functions/statics constexpr. r=jonco Differential Revision: https://phabricator.services.mozilla.com/D22335
js/src/gc/GC.cpp
js/src/jsutil.h
mfbt/EnumSet.h
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -361,39 +361,39 @@ static const float PretenureGroupThresho
 }  // namespace js
 
 /*
  * We start to incremental collection for a zone when a proportion of its
  * threshold is reached. This is configured by the
  * JSGC_ALLOCATION_THRESHOLD_FACTOR and
  * JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT parameters.
  */
-static const float MinAllocationThresholdFactor = 0.9f;
+static constexpr float MinAllocationThresholdFactor = 0.9f;
 
 /*
  * We may start to collect a zone before its trigger threshold is reached if
  * GCRuntime::maybeGC() is called for that zone or we start collecting other
  * zones. These eager threshold factors are not configurable.
  */
-static const float HighFrequencyEagerAllocTriggerFactor = 0.85f;
-static const float LowFrequencyEagerAllocTriggerFactor = 0.9f;
+static constexpr float HighFrequencyEagerAllocTriggerFactor = 0.85f;
+static constexpr float LowFrequencyEagerAllocTriggerFactor = 0.9f;
 
 /*
  * Don't allow heap growth factors to be set so low that collections could
  * reduce the trigger threshold.
  */
-static const float MinHighFrequencyHeapGrowthFactor =
+static constexpr float MinHighFrequencyHeapGrowthFactor =
     1.0f /
     Min(HighFrequencyEagerAllocTriggerFactor, MinAllocationThresholdFactor);
-static const float MinLowFrequencyHeapGrowthFactor =
+static constexpr float MinLowFrequencyHeapGrowthFactor =
     1.0f /
     Min(LowFrequencyEagerAllocTriggerFactor, MinAllocationThresholdFactor);
 
 /* Increase the IGC marking slice time if we are in highFrequencyGC mode. */
-static const int IGC_MARK_SLICE_MULTIPLIER = 2;
+static constexpr int IGC_MARK_SLICE_MULTIPLIER = 2;
 
 const AllocKind gc::slotsToThingKind[] = {
     // clang-format off
     /*  0 */ AllocKind::OBJECT0,  AllocKind::OBJECT2,  AllocKind::OBJECT2,  AllocKind::OBJECT4,
     /*  4 */ AllocKind::OBJECT4,  AllocKind::OBJECT8,  AllocKind::OBJECT8,  AllocKind::OBJECT8,
     /*  8 */ AllocKind::OBJECT8,  AllocKind::OBJECT12, AllocKind::OBJECT12, AllocKind::OBJECT12,
     /* 12 */ AllocKind::OBJECT12, AllocKind::OBJECT16, AllocKind::OBJECT16, AllocKind::OBJECT16,
     /* 16 */ AllocKind::OBJECT16
@@ -470,31 +470,31 @@ const uint32_t Arena::ThingsPerArena[] =
 struct js::gc::FinalizePhase {
   gcstats::PhaseKind statsPhase;
   AllocKinds kinds;
 };
 
 /*
  * Finalization order for objects swept incrementally on the main thread.
  */
-static const FinalizePhase ForegroundObjectFinalizePhase = {
+static constexpr FinalizePhase ForegroundObjectFinalizePhase = {
     gcstats::PhaseKind::SWEEP_OBJECT,
     {AllocKind::OBJECT0, AllocKind::OBJECT2, AllocKind::OBJECT4,
      AllocKind::OBJECT8, AllocKind::OBJECT12, AllocKind::OBJECT16}};
 
 /*
  * Finalization order for GC things swept incrementally on the main thread.
  */
-static const FinalizePhase ForegroundNonObjectFinalizePhase = {
+static constexpr FinalizePhase ForegroundNonObjectFinalizePhase = {
     gcstats::PhaseKind::SWEEP_SCRIPT, {AllocKind::SCRIPT, AllocKind::JITCODE}};
 
 /*
  * Finalization order for GC things swept on the background thread.
  */
-static const FinalizePhase BackgroundFinalizePhases[] = {
+static constexpr FinalizePhase BackgroundFinalizePhases[] = {
     {gcstats::PhaseKind::SWEEP_SCRIPT, {AllocKind::LAZY_SCRIPT}},
     {gcstats::PhaseKind::SWEEP_OBJECT,
      {AllocKind::FUNCTION, AllocKind::FUNCTION_EXTENDED,
       AllocKind::OBJECT0_BACKGROUND, AllocKind::OBJECT2_BACKGROUND,
       AllocKind::OBJECT4_BACKGROUND, AllocKind::OBJECT8_BACKGROUND,
       AllocKind::OBJECT12_BACKGROUND, AllocKind::OBJECT16_BACKGROUND}},
     {gcstats::PhaseKind::SWEEP_SCOPE,
      {
@@ -2797,24 +2797,24 @@ void GCRuntime::updateCellPointers(Zone*
 // Also, there can be data races calling IsForwarded() on the new location of a
 // cell that is being updated in parallel on another thread. This can be avoided
 // by updating some kinds of cells in different phases. This is done for
 // JSScripts and LazyScripts, and JSScripts and Scopes.
 //
 // Since we want to minimize the number of phases, arrange kinds into three
 // arbitrary phases.
 
-static const AllocKinds UpdatePhaseOne{
+static constexpr AllocKinds UpdatePhaseOne{
     AllocKind::SCRIPT,         AllocKind::BASE_SHAPE,   AllocKind::SHAPE,
     AllocKind::ACCESSOR_SHAPE, AllocKind::OBJECT_GROUP, AllocKind::STRING,
     AllocKind::JITCODE};
 
 // UpdatePhaseTwo is typed object descriptor objects.
 
-static const AllocKinds UpdatePhaseThree{
+static constexpr AllocKinds UpdatePhaseThree{
     AllocKind::LAZY_SCRIPT, AllocKind::SCOPE,
     AllocKind::FUNCTION,    AllocKind::FUNCTION_EXTENDED,
     AllocKind::OBJECT0,     AllocKind::OBJECT0_BACKGROUND,
     AllocKind::OBJECT2,     AllocKind::OBJECT2_BACKGROUND,
     AllocKind::OBJECT4,     AllocKind::OBJECT4_BACKGROUND,
     AllocKind::OBJECT8,     AllocKind::OBJECT8_BACKGROUND,
     AllocKind::OBJECT12,    AllocKind::OBJECT12_BACKGROUND,
     AllocKind::OBJECT16,    AllocKind::OBJECT16_BACKGROUND};
--- a/js/src/jsutil.h
+++ b/js/src/jsutil.h
@@ -138,22 +138,22 @@ static inline HashNumber AddContainerToH
                                             HashNumber hn = 0) {
   for (size_t i = 0; i < c.length(); i++) {
     hn = mozilla::AddToHash(hn, HashNumber(c[i]));
   }
   return hn;
 }
 
 template <class T>
-static inline T Min(T t1, T t2) {
+static constexpr inline T Min(T t1, T t2) {
   return t1 < t2 ? t1 : t2;
 }
 
 template <class T>
-static inline T Max(T t1, T t2) {
+static constexpr inline T Max(T t1, T t2) {
   return t1 > t2 ? t1 : t2;
 }
 
 template <typename T, typename U>
 static constexpr U ComputeByteAlignment(T bytes, U alignment) {
   static_assert(mozilla::IsUnsigned<U>::value,
                 "alignment amount must be unsigned");
 
--- a/mfbt/EnumSet.h
+++ b/mfbt/EnumSet.h
@@ -39,36 +39,36 @@ class EnumSet {
 
   constexpr EnumSet(T aEnum1, T aEnum2, T aEnum3)
       : mBitField(bitFor(aEnum1) | bitFor(aEnum2) | bitFor(aEnum3)) {}
 
   constexpr EnumSet(T aEnum1, T aEnum2, T aEnum3, T aEnum4)
       : mBitField(bitFor(aEnum1) | bitFor(aEnum2) | bitFor(aEnum3) |
                   bitFor(aEnum4)) {}
 
-  MOZ_IMPLICIT EnumSet(std::initializer_list<T> list) : mBitField(0) {
+  constexpr MOZ_IMPLICIT EnumSet(std::initializer_list<T> list) : mBitField(0) {
     for (auto value : list) {
       (*this) += value;
     }
   }
 
   constexpr EnumSet(const EnumSet& aEnumSet) : mBitField(aEnumSet.mBitField) {}
 
   /**
    * Add an element
    */
-  void operator+=(T aEnum) {
+  constexpr void operator+=(T aEnum) {
     incVersion();
     mBitField |= bitFor(aEnum);
   }
 
   /**
    * Add an element
    */
-  EnumSet operator+(T aEnum) const {
+  constexpr EnumSet operator+(T aEnum) const {
     EnumSet result(*this);
     result += aEnum;
     return result;
   }
 
   /**
    * Union
    */
@@ -279,17 +279,17 @@ class EnumSet {
 
  private:
   constexpr static Serialized bitFor(T aEnum) {
     auto bitNumber = static_cast<Serialized>(aEnum);
     MOZ_DIAGNOSTIC_ASSERT(bitNumber < kMaxBits);
     return Serialized(1) << bitNumber;
   }
 
-  void incVersion() {
+  constexpr void incVersion() {
 #ifdef DEBUG
     mVersion++;
 #endif
   }
 
   static const size_t kMaxBits = sizeof(Serialized) * 8;
 
   Serialized mBitField;