Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSI method for adjusting external memory size #41436

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/react-native/ReactCommon/jsc/JSCRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class JSCRuntime : public jsi::Runtime {
bool strictEquals(const jsi::String& a, const jsi::String& b) const override;
bool strictEquals(const jsi::Object& a, const jsi::Object& b) const override;
bool instanceOf(const jsi::Object& o, const jsi::Function& f) override;
void setExternalMemoryPressure(const jsi::Object&, size_t) override;

private:
// Basically convenience casts
Expand Down Expand Up @@ -1392,6 +1393,8 @@ bool JSCRuntime::instanceOf(const jsi::Object& o, const jsi::Function& f) {
return res;
}

void JSCRuntime::setExternalMemoryPressure(const jsi::Object&, size_t) {}

jsi::Runtime::PointerValue* JSCRuntime::makeSymbolValue(
JSValueRef symbolRef) const {
#ifndef NDEBUG
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/ReactCommon/jsi/jsi/decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
plain_.setNativeState(o, state);
}

void setExternalMemoryPressure(const Object& obj, size_t amt) override {
plain_.setExternalMemoryPressure(obj, amt);
}

Value getProperty(const Object& o, const PropNameID& name) override {
return plain_.getProperty(o, name);
};
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native/ReactCommon/jsi/jsi/jsi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ inline void Object::setNativeState(
runtime.setNativeState(*this, state);
}

inline void Object::setExternalMemoryPressure(Runtime& runtime, size_t amt)
const {
runtime.setExternalMemoryPressure(*this, amt);
}

inline Array Object::getPropertyNames(Runtime& runtime) const {
return runtime.getPropertyNames(*this);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/react-native/ReactCommon/jsi/jsi/jsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ class JSI_EXPORT Runtime {

virtual bool instanceOf(const Object& o, const Function& f) = 0;

/// See Object::setExternalMemoryPressure.
virtual void setExternalMemoryPressure(
const jsi::Object& obj,
size_t amount) = 0;

// These exist so derived classes can access the private parts of
// Value, Symbol, String, and Object, which are all friends of Runtime.
template <typename T>
Expand Down Expand Up @@ -834,6 +839,16 @@ class JSI_EXPORT Object : public Pointer {
/// works. I only need it in one place.)
Array getPropertyNames(Runtime& runtime) const;

/// Inform the runtime that there is additional memory associated with a given
/// JavaScript object that is not visible to the GC. This can be used if an
/// object is known to retain some native memory, and may be used to guide
/// decisions about when to run garbage collection.
/// This method may be invoked multiple times on an object, and subsequent
/// calls will overwrite any previously set value. Once the object is garbage
/// collected, the associated external memory will be considered freed and may
/// no longer factor into GC decisions.
void setExternalMemoryPressure(Runtime& runtime, size_t amt) const;

protected:
void setPropertyValue(
Runtime& runtime,
Expand Down