From 07db5166811b62d11fb6cdeefe44530ac77285e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=98=95=EC=A3=BC/Common=20Platform=20Lab=28SR=29?= =?utf8?q?/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 5 Dec 2022 12:40:54 +0900 Subject: [PATCH] Refactoring preloading (#452) * Separate thread-safe preload from others * Add UIFW to dotnet/dotnet-nui launchers --- Managed/Tizen.Runtime/Preloader.cs | 15 ++++++++----- NativeLauncher/dotnet-nui.launcher | 2 ++ NativeLauncher/dotnet.launcher | 2 ++ NativeLauncher/launcher/exec/launcher.cc | 17 +++++++++++++-- NativeLauncher/launcher/lib/core_runtime.cc | 33 ++++++++++++++++++++++------- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/Managed/Tizen.Runtime/Preloader.cs b/Managed/Tizen.Runtime/Preloader.cs index 6424e14..aa8de31 100644 --- a/Managed/Tizen.Runtime/Preloader.cs +++ b/Managed/Tizen.Runtime/Preloader.cs @@ -38,6 +38,11 @@ namespace Tizen.Runtime _ = "abc".ToUpper().ToLower(); } + public static void CoreclrPreload() + { + CheckAsciiCasing(); + } + public static void Preload() { CheckAsciiCasing(); @@ -45,6 +50,7 @@ namespace Tizen.Runtime if (!Directory.Exists(preloadPath)) return; + string uifw = System.Environment.GetEnvironmentVariable("TIZEN_UIFW"); string[] paths = Directory.GetFiles(preloadPath, "*.preload"); Array.Sort(paths); foreach (string path in paths) @@ -63,18 +69,17 @@ namespace Tizen.Runtime if (fileName.IndexOf('.') != 2) continue; - string value = System.Environment.GetEnvironmentVariable("TIZEN_UIFW"); // if TIZEN_UIFW is not set, do not preload UI related dll - if (value == null && (fileName.Contains("NUI") || fileName.Contains("ElmSharp") || fileName.Contains("XSF") )) + if (uifw == null && (fileName.Contains("NUI") || fileName.Contains("ElmSharp") || fileName.Contains("XSF"))) continue; - else if (value == "ElmSharp" && fileName.Contains("NUI")) + else if (uifw == "ElmSharp" && (fileName.Contains("NUI") || fileName.Contains("XSF"))) continue; - else if (value == "NUI" && (fileName.Contains("ElmSharp") || fileName.Contains("XSF"))) + else if (uifw == "NUI" && (fileName.Contains("ElmSharp") || fileName.Contains("XSF"))) continue; try { - Console.WriteLine("Start preload : " + fileName); + Console.WriteLine("UIFW: " + uifw + " Start preload : " + fileName); BindingFlags bindingFlag = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; foreach (string line in File.ReadLines(path)) { diff --git a/NativeLauncher/dotnet-nui.launcher b/NativeLauncher/dotnet-nui.launcher index aab6a19..5543c2c 100644 --- a/NativeLauncher/dotnet-nui.launcher +++ b/NativeLauncher/dotnet-nui.launcher @@ -6,5 +6,7 @@ EXTRA_ARG --PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CH EXTRA_ARG --profile EXTRA_ARG --appType EXTRA_ARG dotnet-nui +EXTRA_ARG TIZEN_UIFW +EXTRA_ARG NUI EXTRA_ARG --standalone diff --git a/NativeLauncher/dotnet.launcher b/NativeLauncher/dotnet.launcher index 5548409..4e77926 100644 --- a/NativeLauncher/dotnet.launcher +++ b/NativeLauncher/dotnet.launcher @@ -6,5 +6,7 @@ EXTRA_ARG --PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CH EXTRA_ARG --profile EXTRA_ARG --appType EXTRA_ARG dotnet +EXTRA_ARG TIZEN_UIFW +EXTRA_ARG ElmSharp EXTRA_ARG --standalone diff --git a/NativeLauncher/launcher/exec/launcher.cc b/NativeLauncher/launcher/exec/launcher.cc index dcb8e89..d26d7f9 100644 --- a/NativeLauncher/launcher/exec/launcher.cc +++ b/NativeLauncher/launcher/exec/launcher.cc @@ -36,9 +36,11 @@ using tizen::runtime::dotnetcore::CoreRuntime; #define APPID_MAX_LENGTH (25 + 105) #define PRC_NAME_LENGTH 16 +static const char* KEY_TIZEN_UIFW = "TIZEN_UIFW"; static std::string StandaloneOption("--standalone"); static std::string PaddingOption("--PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE"); static std::string AppTypeOption("--appType"); +static std::string UIFWOption(KEY_TIZEN_UIFW); static std::string ProfileOption("--profile"); static std::string GlobalizationInvariantOption("--invariant"); @@ -51,6 +53,7 @@ int main(int argc, char *argv[]) bool paddingExist = false; bool profile = false; const char* appType = "dotnet"; + const char* UIFWType = "ElmSharp"; const char* appRootPath = NULL; char appId[APPID_MAX_LENGTH] = {0,}; @@ -64,7 +67,7 @@ int main(int argc, char *argv[]) setenv("DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", "false", 1); } else if (StandaloneOption.compare(argv[i]) == 0) { if (i > argc - 1) { - _ERR("Assembly path must be after \"--standalone\" option"); + _ERR("Assembly path must be after %s option", StandaloneOption.c_str()); return -1; } i++; @@ -75,11 +78,18 @@ int main(int argc, char *argv[]) profile = true; } else if (AppTypeOption.compare(argv[i]) == 0) { if (i > argc - 1) { - _ERR("app type for launchpad must be after \"--appType\" option"); + _ERR("app type for launchpad must be after %s option", AppTypeOption.c_str()); return -1; } i++; appType = argv[i]; + } else if (UIFWOption.compare(argv[i]) == 0) { + if (i > argc - 1) { + _ERR("UIFW type for launchpad must be after %s option", UIFWOption.c_str()); + return -1; + } + i++; + UIFWType = argv[i]; } else { vargs.push_back(argv[i]); } @@ -107,6 +117,9 @@ int main(int argc, char *argv[]) memset(argv[0], '\0', cmdlineSize); snprintf(argv[0], cmdlineSize - 1, "%s", standalonePath); + setenv(KEY_TIZEN_UIFW, UIFWType, 1); + _INFO("TIZEN_UIFW is set to %s", UIFWType); + // initialize CoreRuntime int err = CoreRuntime::initialize(appType, LaunchMode::launcher); if (err) { diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index 25b59a0..3c7a42d 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -268,12 +268,26 @@ void preload() pluginPreload(); } -static pthread_t preloadThreadId = 0; -static void* preloadThread(void* arg) +static pthread_t coreclrPreloadThreadId = 0; +static void* coreclrPreloadThread(void* arg) { - _INFO("PreloadThread START\n"); - preload(); - _INFO("PreloadThread END\n"); + _INFO("CoreclrPreloadThread START\n"); + typedef void (*CoreclrPreloadDelegate)(); + CoreclrPreloadDelegate coreclrPreloadDelegate; + + int ret = createDelegate(__hostHandle, + __domainId, + "Tizen.Runtime", + "Tizen.Runtime.Preloader", + "CoreclrPreload", + (void**)&coreclrPreloadDelegate); + + if (ret < 0) { + _ERR("Failed to create delegate for Tizen.Runtime CoreclrPreload (0x%08x)", ret); + } else { + coreclrPreloadDelegate(); + } + _INFO("CoreclrPreloadThread END\n"); pthread_exit(NULL); } @@ -476,13 +490,16 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) return -1; } - // preload libraries and manage dlls for optimizing startup time - int err = pthread_create(&preloadThreadId, NULL, preloadThread, NULL); + //Preload and execute long-duration jobs + int err = pthread_create(&coreclrPreloadThreadId, NULL, coreclrPreloadThread, NULL); if (err) { - _ERR("PreloadThread Creation Failed: %s", strerror(err)); + _ERR("CoreclrPreloadThread Creation Failed: %s", strerror(err)); } if (launchMode == LaunchMode::loader) { + // preload libraries and manage dlls for optimizing startup time + preload(); + // The debug pipe created in the candidate process has a "User" label. // As a result, smack deny occurs when app process try to access the debug pipe. // Also, since debugging is performed only in standalone mode, -- 2.7.4