Skip to content

Commit 0c7defc

Browse files
Riley Dulinfacebook-github-bot
Riley Dulin
authored andcommitted
Remove jsi::Value return from jsi::Instrumentation::getHeapInfo
Summary: `getHeapInfo` was creating and return a `jsi::Object`. This object was not being traced when API tracing was turned on. This resulted in a bug in synth traces, an object was being acted upon without its creation source being logged. In order to prevent this, change the API of `getHeapInfo` to no longer return any objects, or modify other heap contents. This is preferable to having `TracingRuntime` attempt to mimic the operations of two different implementations. ## Changelog: [Internal] [Changed] - Changed `jsi::Instrumentation::getHeapInfo` to use a `std::unordered_map` Reviewed By: mhorowitz Differential Revision: D17273235 fbshipit-source-id: f69860dcc524c2cf501746a41dbac20b4db8c456
1 parent bd8e6cd commit 0c7defc

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

ReactCommon/jsi/jsi/decorator.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
325325
return plain().instrumentation().getRecordedGCStats();
326326
}
327327

328-
Value getHeapInfo(bool includeExpensive) override {
328+
std::unordered_map<std::string, int64_t> getHeapInfo(
329+
bool includeExpensive) override {
329330
return plain().instrumentation().getHeapInfo(includeExpensive);
330331
}
331332

ReactCommon/jsi/jsi/instrumentation.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <iosfwd>
1010
#include <string>
11+
#include <unordered_map>
1112

1213
#include <jsi/jsi.h>
1314

@@ -17,6 +18,8 @@ namespace jsi {
1718
/// Methods for starting and collecting instrumentation, an \c Instrumentation
1819
/// instance is associated with a particular \c Runtime instance, which it
1920
/// controls the instrumentation of.
21+
/// None of these functions should return newly created jsi values, nor should
22+
/// it modify the values of any jsi values in the heap (although GCs are fine).
2023
class Instrumentation {
2124
public:
2225
virtual ~Instrumentation() = default;
@@ -40,9 +43,10 @@ class Instrumentation {
4043
/// function can be called at any time, and should produce information that is
4144
/// correct at the instant it is called (i.e, not stale).
4245
///
43-
/// \return a jsi Value containing whichever statistics the runtime supports
44-
/// for its heap.
45-
virtual Value getHeapInfo(bool includeExpensive) = 0;
46+
/// \return a map from a string key to a number associated with that
47+
/// statistic.
48+
virtual std::unordered_map<std::string, int64_t> getHeapInfo(
49+
bool includeExpensive) = 0;
4650

4751
/// perform a full garbage collection
4852
virtual void collectGarbage() = 0;

ReactCommon/jsi/jsi/jsi.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ Instrumentation& Runtime::instrumentation() {
7171
return "";
7272
}
7373

74-
Value getHeapInfo(bool) override {
75-
return Value::undefined();
74+
std::unordered_map<std::string, int64_t> getHeapInfo(bool) override {
75+
return std::unordered_map<std::string, int64_t>{};
7676
}
7777

7878
void collectGarbage() override {}

0 commit comments

Comments
 (0)