Skip to content
Merged
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
1 change: 1 addition & 0 deletions test-app/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ add_library(
src/main/cpp/DirectBuffer.cpp
src/main/cpp/FieldAccessor.cpp
src/main/cpp/File.cpp
src/main/cpp/IsolateDisposer.cpp
src/main/cpp/JEnv.cpp
src/main/cpp/DesugaredInterfaceCompanionClassNameResolver.cpp
src/main/cpp/JType.cpp
Expand Down
8 changes: 8 additions & 0 deletions test-app/runtime/src/main/cpp/ArgConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,12 @@ Local<String> ArgConverter::ConvertToV8UTF16String(Isolate* isolate, const u16st
return String::NewFromTwoByte(isolate, ((const uint16_t*) utf16string.data())).ToLocalChecked();
}

void ArgConverter::onDisposeIsolate(Isolate* isolate) {
auto itFound = s_type_long_operations_cache.find(isolate);
if (itFound != s_type_long_operations_cache.end()) {
delete itFound->second;
s_type_long_operations_cache.erase(itFound);
}
}

std::map<Isolate*, ArgConverter::TypeLongOperationsCache*> ArgConverter::s_type_long_operations_cache;
2 changes: 2 additions & 0 deletions test-app/runtime/src/main/cpp/ArgConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ArgConverter {

static v8::Local<v8::String> ConvertToV8UTF16String(v8::Isolate* isolate, const std::u16string& utf16string);

static void onDisposeIsolate(v8::Isolate* isolate);

private:

// TODO: plamen5kov: rewrite logic for java long number operations in javascript (java long -> javascript number operations check)
Expand Down
19 changes: 19 additions & 0 deletions test-app/runtime/src/main/cpp/IsolateDisposer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Created by Eduardo Speroni on 3/4/22.
//

#include "IsolateDisposer.h"
#include "ArgConverter.h"
#include "MetadataNode.h"
#include "V8GlobalHelpers.h"
#include <console/Console.h>


namespace tns {
void disposeIsolate(v8::Isolate *isolate) {
tns::ArgConverter::onDisposeIsolate(isolate);
tns::MetadataNode::onDisposeIsolate(isolate);
tns::V8GlobalHelpers::onDisposeIsolate(isolate);
tns::Console::onDisposeIsolate(isolate);
}
}
13 changes: 13 additions & 0 deletions test-app/runtime/src/main/cpp/IsolateDisposer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Created by Eduardo Speroni on 3/4/22.
//

#ifndef TEST_APP_ISOLATEDISPOSER_H
#define TEST_APP_ISOLATEDISPOSER_H
#include "v8.h"

namespace tns {
void disposeIsolate(v8::Isolate* isolate);
}

#endif //TEST_APP_ISOLATEDISPOSER_H
26 changes: 26 additions & 0 deletions test-app/runtime/src/main/cpp/MetadataNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,32 @@ std::string MetadataNode::GetJniClassName(MetadataEntry entry) {
return fullClassName;
}

void MetadataNode::onDisposeIsolate(Isolate* isolate) {
{
auto it = s_metadata_node_cache.find(isolate);
if (it != s_metadata_node_cache.end()) {
delete it->second;
s_metadata_node_cache.erase(it);
}
}
{
auto it = s_arrayObjectTemplates.find(isolate);
if (it != s_arrayObjectTemplates.end()) {
delete it->second;
s_arrayObjectTemplates.erase(it);
}
}
{
for (auto it = s_treeNode2NodeCache.begin(); it != s_treeNode2NodeCache.end(); it++) {
auto it2 = it->second->m_poCtorCachePerIsolate.find(isolate);
if(it2 != it->second->m_poCtorCachePerIsolate.end()) {
delete it2->second;
it->second->m_poCtorCachePerIsolate.erase(it2);
}
}
}
}

string MetadataNode::TNS_PREFIX = "com/tns/gen/";
MetadataReader MetadataNode::s_metadataReader;
std::map<std::string, MetadataNode*> MetadataNode::s_name2NodeCache;
Expand Down
2 changes: 2 additions & 0 deletions test-app/runtime/src/main/cpp/MetadataNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class MetadataNode {
static MetadataNode* GetOrCreate(const std::string& className);

static std::string GetTypeMetadataName(v8::Isolate* isolate, v8::Local<v8::Value>& value);

static void onDisposeIsolate(v8::Isolate* isolate);
private:
struct MethodCallbackData;

Expand Down
2 changes: 2 additions & 0 deletions test-app/runtime/src/main/cpp/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "sys/system_properties.h"
#include "ManualInstrumentation.h"
#include <snapshot_blob.h>
#include "IsolateDisposer.h"

#ifdef APPLICATION_IN_DEBUG
#include "JsV8InspectorClient.h"
Expand Down Expand Up @@ -809,6 +810,7 @@ bool Runtime::RunExtraCode(Isolate* isolate, Local<Context> context, const char*
void Runtime::DestroyRuntime() {
s_id2RuntimeCache.erase(m_id);
s_isolate2RuntimesCache.erase(m_isolate);
tns::disposeIsolate(m_isolate);
}

Local<Context> Runtime::GetContext() {
Expand Down
4 changes: 4 additions & 0 deletions test-app/runtime/src/main/cpp/V8GlobalHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ bool tns::V8SetPrivateValue(Isolate* isolate, const Local<Object>& obj, const Lo

return res.FromMaybe(false);
}

void tns::V8GlobalHelpers::onDisposeIsolate(Isolate* isolate) {
isolateToPersistentSmartJSONStringify.erase(isolate);
}
4 changes: 4 additions & 0 deletions test-app/runtime/src/main/cpp/V8GlobalHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ v8::Local<v8::String> JsonStringifyObject(v8::Isolate* isolate, v8::Handle<v8::V
bool V8GetPrivateValue(v8::Isolate* isolate, const v8::Local<v8::Object>& obj, const v8::Local<v8::String>& propName, v8::Local<v8::Value>& out);

bool V8SetPrivateValue(v8::Isolate* isolate, const v8::Local<v8::Object>& obj, const v8::Local<v8::String>& propName, const v8::Local<v8::Value>& value);

namespace V8GlobalHelpers {
void onDisposeIsolate(v8::Isolate* isolate);
}
}

#endif /* V8GLOBALHELPERS_H_ */
4 changes: 4 additions & 0 deletions test-app/runtime/src/main/cpp/console/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}
}

void Console::onDisposeIsolate(v8::Isolate* isolate) {
s_isolateToConsoleTimersMap.erase(isolate);
}

const char* Console::LOG_TAG = "JS";
std::map<v8::Isolate*, std::map<std::string, double>> Console::s_isolateToConsoleTimersMap;
ConsoleCallback Console::m_callback = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions test-app/runtime/src/main/cpp/console/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <include/v8.h>
#include <string>
#include <ArgConverter.h>
#include <android/log.h>

namespace tns {

Expand All @@ -27,6 +28,8 @@ class Console {
static void timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info);
static void timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info);

static void onDisposeIsolate(v8::Isolate* isolate);

private:
static int m_maxLogcatObjectSize;
static bool m_forceLog;
Expand Down