Skip to content

Commit

Permalink
Add heap information setter to the CrashManager interface
Browse files Browse the repository at this point in the history
Summary: Add a function to the CrashManager interface so clients can get updated information about the current heap being used by the engine.

Reviewed By: davedets

Differential Revision: D16574877

fbshipit-source-id: 4484946f59c116afa70e6fc7881719149d2e85f1
  • Loading branch information
Alex Cohen authored and facebook-github-bot committed Aug 15, 2019
1 parent 695a898 commit b63b3c1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/hermes/VM/GCBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ class GCBase {
/// Same as \c getHeapInfo, and it adds the amount of malloc memory in use.
virtual void getHeapInfoWithMallocSize(HeapInfo &info) = 0;

/// Populate \p info with crash manager information about the heap
virtual void getCrashManagerHeapInfo(CrashManager::HeapInformation &info) = 0;

#ifndef NDEBUG
/// Populate \p info with more detailed information about the heap that is
/// too expensive to know during production builds.
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/GenGCNC.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ class GenGC final : public GCBase {
void getHeapInfo(HeapInfo &info) override;
void getHeapInfoWithMallocSize(HeapInfo &info) override;

/// Populate \p info with crash manager information about the heap
void getCrashManagerHeapInfo(CrashManager::HeapInformation &info) override;

#ifndef NDEBUG
void getDebugHeapInfo(DebugHeapInfo &info) override;
#endif
Expand Down
1 change: 1 addition & 0 deletions include/hermes/VM/MallocGC.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class MallocGC final : public GCBase {

void getHeapInfo(HeapInfo &info) override;
void getHeapInfoWithMallocSize(HeapInfo &info) override;
void getCrashManagerHeapInfo(CrashManager::HeapInformation &info) override;

/// @name Weak references
/// @{
Expand Down
9 changes: 9 additions & 0 deletions lib/VM/gcs/GenGCNC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,10 @@ void GenGC::updateHeapSize() {
// size().
shrinkTo(usedToDesiredSize(static_cast<gcheapsize_t>(weightedUsed_)));
}

CrashManager::HeapInformation info;
getCrashManagerHeapInfo(info);
crashMgr_->setHeapInfo(info);
}

void GenGC::forAllObjs(const std::function<void(GCCell *)> &callback) {
Expand Down Expand Up @@ -1058,6 +1062,11 @@ void GenGC::getHeapInfo(HeapInfo &info) {
info.youngGenStats = youngGenCollectionCumStats_;
}

void GenGC::getCrashManagerHeapInfo(CrashManager::HeapInformation &info) {
info.size_ = size();
info.used_ = used();
}

void GenGC::getHeapInfoWithMallocSize(HeapInfo &info) {
getHeapInfo(info);
// In case the info is being re-used, ensure the count starts at 0.
Expand Down
6 changes: 6 additions & 0 deletions lib/VM/gcs/MallocGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ void MallocGC::getHeapInfoWithMallocSize(HeapInfo &info) {
}
}

void MallocGC::getCrashManagerHeapInfo(CrashManager::HeapInformation &info) {
info.used_ = allocatedBytes_;
// MallocGC does not have a heap size.
info.size_ = 0;
}

#ifndef NDEBUG
size_t MallocGC::countUsedWeakRefs() const {
size_t count = 0;
Expand Down
4 changes: 4 additions & 0 deletions lib/VM/gcs/YoungGenNC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ void YoungGen::collect() {
/// TODO(T48709128): remove these when the problem is diagnosed.
nextGen_->summarizeCardTableBoundaries();
#endif

CrashManager::HeapInformation crashHeapInfo;
gc_->getCrashManagerHeapInfo(crashHeapInfo);
gc_->crashMgr_->setHeapInfo(crashHeapInfo);
}

void YoungGen::creditExternalMemory(uint32_t size) {
Expand Down
15 changes: 15 additions & 0 deletions public/hermes/Public/CrashManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ class CrashManager {
/// CrashManager during a crash.
virtual void unregisterCallback(CallbackKey key) = 0;

/// the heap information.
struct HeapInformation {
/// The amount of memory that is currently in use
size_t used_{0};
/// The amount of memory that can currently be allocated
/// before a full GC is triggered.
size_t size_{0};
};

/// Record the heap information.
/// \param heapInfo The current heap information
virtual void setHeapInfo(const HeapInformation &heapInfo) = 0;

virtual ~CrashManager() {}
};

Expand All @@ -67,6 +80,8 @@ class NopCrashManager final : public CrashManager {
return 0;
}
void unregisterCallback(CallbackKey /*key*/) override {}
void setHeapInfo(const HeapInformation & /*heapInfo*/) override {}

~NopCrashManager() {}
};

Expand Down

0 comments on commit b63b3c1

Please sign in to comment.