Skip to content

Commit

Permalink
Bug 1507377 - Add tunables for pretenure thresholds r=jonco
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBone committed Dec 14, 2018
1 parent 4cc6373 commit 8d89f09
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
18 changes: 18 additions & 0 deletions js/public/GCAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,24 @@ typedef enum JSGCParamKey {
* Pref: None
*/
JSGC_NURSERY_FREE_THRESHOLD_FOR_IDLE_COLLECTION = 27,

/**
* If this percentage of the nursery is tenured, then proceed to examine which
* groups we should pretenure.
*
* Default: PretenureThreshold
* Pref: None
*/
JSGC_PRETENURE_THRESHOLD = 28,

/**
* If the above condition is met, then any object group that tenures more than
* this number of objects will be pretenured (if it can be).
*
* Default: PretenureGroupThreshold
* Pref: None
*/
JSGC_PRETENURE_GROUP_THRESHOLD = 29,
} JSGCParamKey;

/*
Expand Down
34 changes: 33 additions & 1 deletion js/src/gc/GC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ static const bool CompactingEnabled = true;
static const uint32_t NurseryFreeThresholdForIdleCollection =
Nursery::NurseryChunkUsableSize / 4;

/* JSGC_PRETENURE_THRESHOLD */
static const float PretenureThreashold = 0.6f;

/* JSGC_PRETENURE_GROUP_THRESHOLD */
static const float PretenureGroupThreshold = 3000;

} // namespace TuningDefaults
} // namespace gc
} // namespace js
Expand Down Expand Up @@ -1464,6 +1470,20 @@ bool GCSchedulingTunables::setParameter(JSGCParamKey key, uint32_t value,
}
nurseryFreeThresholdForIdleCollection_ = value;
break;
case JSGC_PRETENURE_THRESHOLD: {
// 100 disables pretenuring
if (value == 0 || value > 100) {
return false;
}
pretenureThreshold_ = value / 100.0f;
break;
}
case JSGC_PRETENURE_GROUP_THRESHOLD:
if (value <= 0) {
return false;
}
pretenureGroupThreshold_ = value;
break;
default:
MOZ_CRASH("Unknown GC parameter.");
}
Expand Down Expand Up @@ -1551,7 +1571,9 @@ GCSchedulingTunables::GCSchedulingTunables()
minEmptyChunkCount_(TuningDefaults::MinEmptyChunkCount),
maxEmptyChunkCount_(TuningDefaults::MaxEmptyChunkCount),
nurseryFreeThresholdForIdleCollection_(
TuningDefaults::NurseryFreeThresholdForIdleCollection) {}
TuningDefaults::NurseryFreeThresholdForIdleCollection),
pretenureThreshold_(TuningDefaults::PretenureThreashold),
pretenureGroupThreshold_(TuningDefaults::PretenureGroupThreshold) {}

void GCRuntime::resetParameter(JSGCParamKey key, AutoLockGC& lock) {
switch (key) {
Expand Down Expand Up @@ -1633,6 +1655,12 @@ void GCSchedulingTunables::resetParameter(JSGCParamKey key,
nurseryFreeThresholdForIdleCollection_ =
TuningDefaults::NurseryFreeThresholdForIdleCollection;
break;
case JSGC_PRETENURE_THRESHOLD:
pretenureThreshold_ = TuningDefaults::PretenureThreashold;
break;
case JSGC_PRETENURE_GROUP_THRESHOLD:
pretenureGroupThreshold_ = TuningDefaults::PretenureGroupThreshold;
break;
default:
MOZ_CRASH("Unknown GC parameter.");
}
Expand Down Expand Up @@ -1691,6 +1719,10 @@ uint32_t GCRuntime::getParameter(JSGCParamKey key, const AutoLockGC& lock) {
return tunables.maxEmptyChunkCount();
case JSGC_COMPACTING_ENABLED:
return compactingEnabled;
case JSGC_PRETENURE_THRESHOLD:
return uint32_t(tunables.pretenureThreshold() * 100);
case JSGC_PRETENURE_GROUP_THRESHOLD:
return tunables.pretenureGroupThreshold();
default:
MOZ_ASSERT(key == JSGC_NUMBER);
return uint32_t(number);
Expand Down
2 changes: 1 addition & 1 deletion js/src/gc/GCInternals.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct MovingTracer : JS::CallbackTracer {
// been tenured during a minor collection.
struct TenureCount {
ObjectGroup* group;
int count;
unsigned count;

// ObjectGroups are never nursery-allocated, and TenureCounts are only used
// in minor GC (not compacting GC), so prevent the analysis from
Expand Down
8 changes: 5 additions & 3 deletions js/src/gc/Nursery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,15 @@ void js::Nursery::collect(JS::gcreason::Reason reason) {
bool validPromotionRate;
const float promotionRate = calcPromotionRate(&validPromotionRate);
uint32_t pretenureCount = 0;
bool shouldPretenure = (validPromotionRate && promotionRate > 0.6) ||
IsFullStoreBufferReason(reason);
bool shouldPretenure = tunables().attemptPretenuring() &&
((validPromotionRate &&
promotionRate > tunables().pretenureThreshold()) ||
IsFullStoreBufferReason(reason));

if (shouldPretenure) {
JSContext* cx = rt->mainContextFromOwnThread();
for (auto& entry : tenureCounts.entries) {
if (entry.count >= 3000) {
if (entry.count >= tunables().pretenureGroupThreshold()) {
ObjectGroup* group = entry.group;
AutoRealm ar(cx, group);
AutoSweepObjectGroup sweep(group);
Expand Down
22 changes: 22 additions & 0 deletions js/src/gc/Scheduling.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,24 @@ class GCSchedulingTunables {
*/
UnprotectedData<uint32_t> nurseryFreeThresholdForIdleCollection_;

/*
* JSGC_PRETENURE_THRESHOLD
*
* Fraction of objects tenured to trigger pretenuring (between 0 and 1). If
* this fraction is met, the GC proceeds to calculate which objects will be
* tenured. If this is 1.0f (actually if it is not < 1.0f) then pretenuring
* is disabled.
*/
UnprotectedData<float> pretenureThreshold_;

/*
* JSGC_PRETENURE_GROUP_THRESHOLD
*
* During a single nursery collection, if this many objects from the same
* object group are tenured, then that group will be pretenured.
*/
UnprotectedData<uint32_t> pretenureGroupThreshold_;

public:
GCSchedulingTunables();

Expand Down Expand Up @@ -471,6 +489,10 @@ class GCSchedulingTunables {
return nurseryFreeThresholdForIdleCollection_;
}

bool attemptPretenuring() const { return pretenureThreshold_ < 1.0f; }
float pretenureThreshold() const { return pretenureThreshold_; }
uint32_t pretenureGroupThreshold() const { return pretenureGroupThreshold_; }

MOZ_MUST_USE bool setParameter(JSGCParamKey key, uint32_t value,
const AutoLockGC& lock);
void resetParameter(JSGCParamKey key, const AutoLockGC& lock);
Expand Down

0 comments on commit 8d89f09

Please sign in to comment.