Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
open-hippy authored Jan 3, 2025
2 parents 785aa6c + 3b59a7d commit f3f06e5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 13 deletions.
26 changes: 13 additions & 13 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#

# universal files
* @ilikethese @etkmao
* @etkmao

# cmake related
*.cmake @ilikethese @etkmao
CMakeLists.txt @ilikethese @etkmao
*.cmake @etkmao
CMakeLists.txt @etkmao

# driver: js
/driver/js/ @etkmao @ilikethese
/driver/js/ @etkmao
/driver/js/*.js @zealotchen0
/driver/js/.eslintignore @zealotchen0
/driver/js/.eslintrc.js @zealotchen0
Expand All @@ -31,11 +31,11 @@ CMakeLists.txt @ilikethese @etkmao
/driver/js/packages/ @zealotchen0

# driver: vl:
/driver/vl/ @ilikethese @etkmao
/driver/vl/ @etkmao

# framework: android
/framework/android/ @siguangli @iPel
/framework/android/**/src/main/cpp/ @etkmao @ilikethese
/framework/android/**/src/main/cpp/ @etkmao

# framework: ios
/framework/ios/ @wwwcg @ruifanyuan
Expand All @@ -44,7 +44,7 @@ CMakeLists.txt @ilikethese @etkmao
/framework/voltron/ @lvfen @henryjin0511

# dom: others
/dom/ @etkmao @ilikethese
/dom/ @etkmao

# renderer: native
/renderer/native/android/ @siguangli @iPel
Expand All @@ -53,16 +53,16 @@ CMakeLists.txt @ilikethese @etkmao
# renderer: tdf
/renderer/tdf/ @vimerzhao
/renderer/tdf/android/ @siguangli @iPel
/renderer/tdf/android/**/src/main/cpp/ @ilikethese @etkmao
/renderer/tdf/android/**/src/main/cpp/ @etkmao
/renderer/tdf/ios/ @wwwcg @ruifanyuan

# renderer: voltron
/renderer/voltron/ @lvfen @henryjin0511

# module: vfs
/modules/vfs/ @etkmao @ilikethese
/modules/vfs/ @etkmao
/modules/vfs/android/ @siguangli @iPel
/modules/vfs/android/**/src/main/cpp/ @etkmao @ilikethese
/modules/vfs/android/**/src/main/cpp/ @etkmao
/modules/vfs/ios/ @wwwcg @ruifanyuan
/modules/vfs/voltron/ @lvfen @henryjin0511

Expand All @@ -71,13 +71,13 @@ CMakeLists.txt @ilikethese @etkmao

# module: android
/modules/android/ @siguangli @iPel
/modules/android/jni/ @etkmao @ilikethese
/modules/android/jni/ @etkmao

# module: ios
/modules/ios/ @wwwcg @ruifanyuan

# module: footstone
/modules/footstone/ @etkmao @ilikethese
/modules/footstone/ @etkmao

# devtools: backend
/devtools/ @lavnFan
Expand Down Expand Up @@ -110,7 +110,7 @@ CMakeLists.txt @ilikethese @etkmao
/xcodeinitscript.sh @wwwcg @ruifanyuan

# build: config
/buildconfig/ @ilikethese @etkmao
/buildconfig/ @etkmao

# build: ci
/package.json @zealotchen0
Expand Down
50 changes: 50 additions & 0 deletions driver/js/src/js_driver_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ constexpr char kGlobalKey[] = "global";
constexpr char kHippyKey[] = "Hippy";
constexpr char kNativeGlobalKey[] = "__HIPPYNATIVEGLOBAL__";
constexpr char kCallHostKey[] = "hippyCallNatives";
constexpr char kCodeCacheFailCountFilePostfix[] = "_fail_count";
const uint8_t kCodeCacheMaxFailCount = 3;

#if defined(JS_V8) && defined(ENABLE_INSPECTOR) && !defined(V8_WITHOUT_INSPECTOR)
using V8InspectorClientImpl = hippy::inspector::V8InspectorClientImpl;
Expand All @@ -91,6 +93,7 @@ using DevtoolsDataSource = hippy::devtools::DevtoolsDataSource;

static std::unordered_map<int64_t, std::pair<std::shared_ptr<Engine>, uint32_t>> reuse_engine_map;
static std::mutex engine_mutex;
static std::mutex code_cache_file_mutex;

void AsyncInitializeEngine(const std::shared_ptr<Engine>& engine,
const std::shared_ptr<TaskRunner>& task_runner,
Expand Down Expand Up @@ -269,6 +272,39 @@ void JsDriverUtils::InitInstance(
});
}

// Code cache file corruption prevention strategy:
// Record count before RunScript, clean count after RunScript, and if only start recording three times in a row, clean the code cache file.
bool CheckUseCodeCacheBeforeRunScript(const string_view& code_cache_path) {
string_view fail_count_path = code_cache_path + string_view(kCodeCacheFailCountFilePostfix);
u8string content;
HippyFile::ReadFile(fail_count_path, content, false);
if (content.length() == 1) {
uint8_t count = content[0];
if (count >= kCodeCacheMaxFailCount) {
FOOTSTONE_LOG(INFO) << "Check code cache, count >= 3";
// need to remove code cache file
return false;
} else {
FOOTSTONE_LOG(INFO) << "Check code cache, count = " << static_cast<int>(count);
++count;
std::string saveContent;
saveContent.push_back(count);
HippyFile::SaveFile(fail_count_path, saveContent);
}
} else {
FOOTSTONE_LOG(INFO) << "Check code cache, no count";
std::string saveContent;
saveContent.push_back(1);
HippyFile::SaveFile(fail_count_path, saveContent);
}
return true;
}

void CheckUseCodeCacheAfterRunScript(const string_view& code_cache_path) {
string_view fail_count_path = code_cache_path + string_view(kCodeCacheFailCountFilePostfix);
HippyFile::RmFile(fail_count_path);
}

bool JsDriverUtils::RunScript(const std::shared_ptr<Scope>& scope,
const string_view& file_name,
bool is_use_code_cache,
Expand Down Expand Up @@ -298,6 +334,7 @@ bool JsDriverUtils::RunScript(const std::shared_ptr<Scope>& scope,
auto engine = scope->GetEngine().lock();
FOOTSTONE_CHECK(engine);
auto func = hippy::base::MakeCopyable([p = std::move(read_file_promise), code_cache_path, code_cache_dir]() mutable {
std::lock_guard<std::mutex> lock(code_cache_file_mutex);
u8string content;
HippyFile::ReadFile(code_cache_path, content, true);
if (content.empty()) {
Expand All @@ -307,6 +344,12 @@ bool JsDriverUtils::RunScript(const std::shared_ptr<Scope>& scope,
FOOTSTONE_USE(ret);
} else {
FOOTSTONE_DLOG(INFO) << "Read code cache succ";
if (!CheckUseCodeCacheBeforeRunScript(code_cache_path)) {
int ret = HippyFile::RmFullPath(code_cache_dir);
FOOTSTONE_DLOG(INFO) << "RmFullPath on check, ret = " << ret;
FOOTSTONE_USE(ret);
content.clear();
}
}
p.set_value(std::move(content));
});
Expand All @@ -332,6 +375,10 @@ bool JsDriverUtils::RunScript(const std::shared_ptr<Scope>& scope,
if (!read_script_flag || StringViewUtils::IsEmpty(script_content)) {
FOOTSTONE_LOG(WARNING) << "read_script_flag = " << read_script_flag
<< ", script content empty, uri = " << uri;
if (is_use_code_cache) {
std::lock_guard<std::mutex> lock(code_cache_file_mutex);
CheckUseCodeCacheAfterRunScript(code_cache_path);
}
return false;
}

Expand All @@ -345,6 +392,7 @@ bool JsDriverUtils::RunScript(const std::shared_ptr<Scope>& scope,
if (is_use_code_cache) {
if (!StringViewUtils::IsEmpty(code_cache_content)) {
auto func = [code_cache_path, code_cache_dir, code_cache_content] {
std::lock_guard<std::mutex> lock(code_cache_file_mutex);
int check_dir_ret = HippyFile::CheckDir(code_cache_dir, F_OK);
FOOTSTONE_DLOG(INFO) << "check_parent_dir_ret = " << check_dir_ret;
if (check_dir_ret) {
Expand All @@ -364,6 +412,8 @@ bool JsDriverUtils::RunScript(const std::shared_ptr<Scope>& scope,
bool save_file_ret = HippyFile::SaveFile(code_cache_path, u8_code_cache_content);
FOOTSTONE_LOG(INFO) << "code cache save_file_ret = " << save_file_ret;
FOOTSTONE_USE(save_file_ret);

CheckUseCodeCacheAfterRunScript(code_cache_path);
};
auto engine = scope->GetEngine().lock();
FOOTSTONE_CHECK(engine);
Expand Down
5 changes: 5 additions & 0 deletions modules/footstone/src/platform/ios/looper_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ static constexpr CFTimeInterval kInterval = IOS_WORKER_TIME_INTERVAL;
static constexpr CFTimeInterval kInterval = 1.0e10;
#endif

extern "C" void * objc_autoreleasePoolPush(void);
extern "C" void objc_autoreleasePoolPop(void *);

static void OnTimerCb(CFRunLoopTimerRef timer, LooperDriver* driver) {
FOOTSTONE_DCHECK(driver);
driver->OnTimerFire(timer);
Expand Down Expand Up @@ -92,7 +95,9 @@ void LooperDriver::OnTimerFire(CFRunLoopTimerRef timer) {
if (IsExitImmediately()) {
return;
}
auto obj = objc_autoreleasePoolPush();
unit_();
objc_autoreleasePoolPop(obj);
}

}
Expand Down
1 change: 1 addition & 0 deletions modules/vfs/native/include/vfs/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class HippyFile {
std::ios::openmode mode = std::ios::out |
std::ios::binary |
std::ios::trunc);
static int RmFile(const string_view& file_path);
static int RmFullPath(const string_view& dir_full_path);
static int CreateDir(const string_view& dir_path, mode_t mode);
static int CheckDir(const string_view& dir_path, int mode);
Expand Down
9 changes: 9 additions & 0 deletions modules/vfs/native/src/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ bool HippyFile::SaveFile(const string_view& file_path,
}
}

int HippyFile::RmFile(const string_view& file_path) {
FOOTSTONE_DLOG(INFO) << "RmFile file_path = " << file_path;
auto path_str = StringViewUtils::ConvertEncoding(file_path,
string_view::Encoding::Utf8).utf8_value();
auto path = reinterpret_cast<const char*>(path_str.c_str());
unlink(path);
return 0;
}

int HippyFile::RmFullPath(const string_view& dir_full_path) {
FOOTSTONE_DLOG(INFO) << "RmFullPath dir_full_path = " << dir_full_path;
auto path_str = StringViewUtils::ConvertEncoding(dir_full_path,
Expand Down

0 comments on commit f3f06e5

Please sign in to comment.