Skip to content
Open
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
10 changes: 10 additions & 0 deletions NativeScript/ffi/jni/jsi/jni/LRUCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ class LRUCache {
}
}

void clear() {
if (m_evictCallback != nullptr) {
for (auto& entry : m_key_to_value) {
m_evictCallback(entry.second.first, m_state);
}
}
m_key_to_value.clear();
m_key_tracker.clear();
}

void update(const key_type& key, const value_type& value) {
jweak ref = m_loadCallback(key, m_state);
insert(key, ref);
Expand Down
11 changes: 11 additions & 0 deletions NativeScript/ffi/jni/jsi/metadata/MetadataNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,12 @@ std::vector<MetadataNode::MethodCallbackData *> MetadataNode::SetClassMembersFro
callbackData->candidates.push_back(std::move(entry));
callbackData->objectManager = objectManager;
}
for (const auto &extension: collectedExtensionMethods) {
if (std::find(instanceMethodData.begin(), instanceMethodData.end(), extension.second) ==
instanceMethodData.end()) {
cache->methodCallbackData.push_back(extension.second);
}
}
auto instanceFieldCount = *reinterpret_cast<uint16_t *>(curPtr);
curPtr += sizeof(uint16_t);
for (auto i = 0; i < instanceFieldCount; i++) {
Expand Down Expand Up @@ -1392,6 +1398,7 @@ std::vector<MetadataNode::MethodCallbackData *> MetadataNode::SetClassMembersFro
auto &methodName = entry.getName();
if (methodName != lastMethodName) {
callbackData = new MethodCallbackData(this);
cache->methodCallbackData.push_back(callbackData);
auto method = JsFunction::createFromHostFunction(
rt, engine::PropNameID::forAscii(rt, methodName), 0,
[callbackData](JsRuntime &rt, const JsValue &thisVal, const JsValue *args,
Expand Down Expand Up @@ -2556,6 +2563,7 @@ void MetadataNode::SetMissingBaseMethods(

if (callbackData == nullptr) {
callbackData = new MethodCallbackData(this);
GetMetadataNodeCache(rt)->methodCallbackData.push_back(callbackData);
auto proto = constructor.getPropertyAsObject(rt, "prototype");
auto method = JsFunction::createFromHostFunction(
rt, engine::PropNameID::forAscii(rt, methodName), 0,
Expand Down Expand Up @@ -2613,6 +2621,9 @@ void MetadataNode::onDisposeRuntime(JsRuntime &rt) {
for (const auto &entry: it->extendedClassCallbackData) {
delete entry;
}
for (const auto &entry: it->methodCallbackData) {
delete entry;
}
}
s_metadata_node_cache.Remove(key);
delete it;
Expand Down
3 changes: 3 additions & 0 deletions NativeScript/ffi/jni/jsi/metadata/MetadataNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ class MetadataNode {
std::vector<FieldCallbackData *> fieldCallbackData;
std::vector<PropertyCallbackData *> propertyCallbackData;
std::vector<ExtendedClassCallbackData *> extendedClassCallbackData;
// Method callback data no CtorFuncCache entry owns: static methods,
// extension-only methods and methods copied from a skipped base class.
std::vector<MethodCallbackData *> methodCallbackData;
};

static bool s_profilerEnabled;
Expand Down
4 changes: 4 additions & 0 deletions NativeScript/ffi/jni/jsi/objectmanager/ObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ void ObjectManager::OnDisposeRuntime() {
m_idToObject.clear();
m_jsObjectCtor = JsFunction();

// Its destructor leaves the weak global refs alive, and the process-wide
// weak reference table is finite.
m_cache.clear();

// The host-object proxies are owned by the *engine*, and each holds an owned
// handle to the instance it wraps. Nothing above reaches them: they are only
// destroyed when the engine tears its heap down, at which point
Expand Down
10 changes: 10 additions & 0 deletions NativeScript/ffi/jni/napi/jni/LRUCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ class LRUCache {
}
}

void clear() {
if (m_evictCallback != nullptr) {
for (auto& entry : m_key_to_value) {
m_evictCallback(entry.second.first, m_state);
}
}
m_key_to_value.clear();
m_key_tracker.clear();
}

void update(const key_type& key, const value_type& value) {
jweak ref = m_loadCallback(key, m_state);
insert(key, ref);
Expand Down
11 changes: 11 additions & 0 deletions NativeScript/ffi/jni/napi/metadata/MetadataNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,12 @@ std::vector<MetadataNode::MethodCallbackData *> MetadataNode::SetClassMembersFro
callbackData->candidates.push_back(std::move(entry));
callbackData->objectManager = objectManager;
}
for (const auto &extension: collectedExtensionMethods) {
if (std::find(instanceMethodData.begin(), instanceMethodData.end(), extension.second) ==
instanceMethodData.end()) {
GetMetadataNodeCache(env)->methodCallbackData.push_back(extension.second);
}
}
auto instanceFieldCount = *reinterpret_cast<uint16_t *>(curPtr);
curPtr += sizeof(uint16_t);
for (auto i = 0; i < instanceFieldCount; i++) {
Expand Down Expand Up @@ -1657,6 +1663,7 @@ std::vector<MetadataNode::MethodCallbackData *> MetadataNode::SetClassMembersFro
auto &methodName = entry.getName();
if (methodName != lastMethodName) {
callbackData = new MethodCallbackData(this);
GetMetadataNodeCache(env)->methodCallbackData.push_back(callbackData);
napi_value method;
NAPI_GUARD(napi_create_function(env, methodName.c_str(), methodName.size(), MethodCallback,
callbackData, &method)) {}
Expand Down Expand Up @@ -3054,6 +3061,7 @@ void MetadataNode::SetMissingBaseMethods(

if (callbackData == nullptr) {
callbackData = new MethodCallbackData(this);
GetMetadataNodeCache(env)->methodCallbackData.push_back(callbackData);
napi_value proto = napi_util::get_prototype(env, constructor);
napi_value method;
NAPI_GUARD(napi_create_function(env, methodName.c_str(), NAPI_AUTO_LENGTH, MethodCallback,
Expand Down Expand Up @@ -3105,6 +3113,9 @@ void MetadataNode::onDisposeEnv(napi_env env) {
for (const auto &entry: it->fieldCallbackData) {
delete entry;
}
for (const auto &entry: it->methodCallbackData) {
delete entry;
}
}
s_metadata_node_cache.Remove(env);
delete it;
Expand Down
3 changes: 3 additions & 0 deletions NativeScript/ffi/jni/napi/metadata/MetadataNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ class MetadataNode {
robin_hood::unordered_map<MetadataTreeNode *, CtorCacheData> CtorFuncCache;
robin_hood::unordered_map<std::string, MetadataNode::ExtendedClassCacheData> ExtendedCtorFuncCache;
std::vector<FieldCallbackData *> fieldCallbackData;
// Method callback data no CtorFuncCache entry owns: static methods,
// extension-only methods and methods copied from a skipped base class.
std::vector<MethodCallbackData *> methodCallbackData;
};

static bool s_profilerEnabled;
Expand Down
4 changes: 4 additions & 0 deletions NativeScript/ffi/jni/napi/objectmanager/ObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ void ObjectManager::OnDisposeEnv() {
NAPI_GUARD(napi_delete_reference(m_env, entry.second)) {}
}
m_idToObject.clear();

// Its destructor leaves the weak global refs alive, and the process-wide
// weak reference table is finite.
m_cache.clear();
}

napi_value ObjectManager::GetOrCreateProxyWeak(jint javaObjectID, napi_value instance) {
Expand Down
2 changes: 2 additions & 0 deletions NativeScript/runtime/android/jsi/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ Runtime::~Runtime() {
close(m_mainLooper_fd[1]);
}
}

JEnv().DeleteGlobalRef(m_runtime);
}

std::string Runtime::ReadFileText(const std::string &filePath) {
Expand Down
2 changes: 2 additions & 0 deletions NativeScript/runtime/android/napi/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ Runtime::~Runtime() {
close(m_mainLooper_fd[1]);
}
}

JEnv().DeleteGlobalRef(m_runtime);
}

std::string Runtime::ReadFileText(const std::string &filePath) {
Expand Down
Loading