@@ -895,9 +895,12 @@ void FixedSizeCachedAllocator::setLimit(
895895
896896AllocatorLimitter* FixedSizeCachedAllocator::setLimit (
897897 AllocatorStats::Type type, AllocatorLimitter *limitter, bool force) {
898- static_cast <void >(type);
899- static_cast <void >(limitter);
900- static_cast <void >(force);
898+ if (localAlloc_.get () != NULL ) {
899+ localAlloc_->setLimit (type, limitter, force);
900+ }
901+ if (localLockedAlloc_.get () != NULL ) {
902+ localLockedAlloc_->setLimit (type, limitter, force);
903+ }
901904 return NULL ;
902905}
903906
@@ -1419,8 +1422,6 @@ void* StackAllocator::allocateOverBlock(size_t size) {
14191422 hugeCount_++;
14201423 hugeSize_ += blockSize;
14211424
1422- stats_.values_ [AllocatorStats::STAT_TOTAL_SIZE] =
1423- AllocatorStats::asStatValue (getTotalSizeForStats ());
14241425 stats_.values_ [AllocatorStats::STAT_PEAK_TOTAL_SIZE] = std::max (
14251426 stats_.values_ [AllocatorStats::STAT_PEAK_TOTAL_SIZE],
14261427 stats_.values_ [AllocatorStats::STAT_TOTAL_SIZE]);
@@ -1441,6 +1442,8 @@ void* StackAllocator::allocateOverBlock(size_t size) {
14411442 restSize_ = newBlock->bodySize () - size;
14421443
14431444 totalSize_ += newBlock->blockSize_ ;
1445+ stats_.values_ [AllocatorStats::STAT_TOTAL_SIZE] =
1446+ AllocatorStats::asStatValue (getTotalSizeForStats ());
14441447
14451448 return newBlock->body ();
14461449#endif
@@ -1805,7 +1808,9 @@ void AllocatorManager::setSharingLimitterGroup(GroupId id, GroupId sharingId) {
18051808 assert (sharingEntry.totalLimitter_ != NULL );
18061809
18071810 entry.sharingLimitterId_ = sharingId;
1808- entry.totalLimitter_ = sharingEntry.totalLimitter_ ;
1811+ setLimit (id, LIMIT_GROUP_TOTAL_SIZE, std::numeric_limits<size_t >::max ());
1812+
1813+ assert (entry.totalLimitter_ != NULL );
18091814}
18101815
18111816int64_t AllocatorManager::estimateHeapUsage (
@@ -1869,7 +1874,7 @@ void AllocatorManager::applyAllocatorLimit(
18691874 switch (limitType) {
18701875 case LIMIT_GROUP_TOTAL_SIZE:
18711876 command = COMMAND_SET_TOTAL_LIMITTER;
1872- type = AllocatorStats::STAT_TYPE_END ;
1877+ type = AllocatorStats::STAT_GROUP_TOTAL_LIMIT ;
18731878 if (groupEntry.totalLimitter_ == NULL ) {
18741879 return ;
18751880 }
@@ -2119,6 +2124,7 @@ AllocatorLimitter& AllocatorManager::prepareTotalLimitter(
21192124 else {
21202125 entry.totalLimitter_ =
21212126 &prepareTotalLimitter (entry.sharingLimitterId_ , found);
2127+ found = false ;
21222128 }
21232129 }
21242130 else {
@@ -2243,6 +2249,7 @@ AllocatorLimitter::AllocatorLimitter(
22432249 limit_ (std::numeric_limits<size_t >::max()),
22442250 acquired_ (0 ),
22452251 reserved_ (0 ),
2252+ peakUsage_ (0 ),
22462253 failOnExcess_ (false ),
22472254 errorHandler_ (NULL ) {
22482255}
@@ -2251,6 +2258,18 @@ AllocatorLimitter::~AllocatorLimitter() {
22512258 assert (acquired_ == 0 );
22522259}
22532260
2261+ AllocatorLimitter::Stats AllocatorLimitter::getStats () {
2262+ util::LockGuard<util::Mutex> guard (mutex_);
2263+
2264+ Stats stats;
2265+ stats.usage_ = getLocalUsageSize ();
2266+ stats.peakUsage_ = peakUsage_;
2267+ stats.limit_ = limit_;
2268+ stats.failOnExcess_ = failOnExcess_;
2269+
2270+ return stats;
2271+ }
2272+
22542273void AllocatorLimitter::setFailOnExcess (bool enabled) {
22552274 util::LockGuard<util::Mutex> guard (mutex_);
22562275 failOnExcess_ = enabled;
@@ -2278,6 +2297,7 @@ size_t AllocatorLimitter::acquire(
22782297 const size_t size =
22792298 acquireLocal (requestingMin, requestingDesired, force, requester);
22802299 reserved_ -= std::min (reserved_, size);
2300+ updatePeakUsageSize ();
22812301 return size;
22822302}
22832303
@@ -2296,6 +2316,7 @@ void AllocatorLimitter::shrinkReservation(size_t size) {
22962316 const size_t actualSize = std::min (reserved_, size);
22972317 releaseLocal (actualSize);
22982318 reserved_ -= actualSize;
2319+ updatePeakUsageSize ();
22992320}
23002321
23012322size_t AllocatorLimitter::getAvailableSize () {
@@ -2388,6 +2409,17 @@ size_t AllocatorLimitter::getLocalAvailableSize() {
23882409 return limit_ - acquired_;
23892410}
23902411
2412+ size_t AllocatorLimitter::getLocalUsageSize () {
2413+ return acquired_ - reserved_;
2414+ }
2415+
2416+ void AllocatorLimitter::updatePeakUsageSize () {
2417+ const size_t current = getLocalUsageSize ();
2418+ if (current > peakUsage_) {
2419+ peakUsage_ = current;
2420+ }
2421+ }
2422+
23912423const AllocatorLimitter& AllocatorLimitter::resolveRequester (
23922424 const AllocatorLimitter *base) {
23932425 if (base == NULL ) {
@@ -2447,4 +2479,11 @@ AllocatorLimitter::Scope::~Scope() {
24472479 unbinder_ (allocator_, orgLimitter_);
24482480}
24492481
2482+ AllocatorLimitter::Stats::Stats () :
2483+ usage_ (0 ),
2484+ peakUsage_ (0 ),
2485+ limit_ (0 ),
2486+ failOnExcess_ (false ) {
2487+ }
2488+
24502489}
0 commit comments