From cc516944f84dc5a239bf7b6af2546dfc07f3664c Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 20 May 2025 15:28:41 +0200 Subject: [PATCH 01/11] Interpret everything on wasm Do not try to setup the jit and use it, instead use the interpreter --- src/coreclr/interpreter/eeinterp.cpp | 13 ++++++------- src/coreclr/interpreter/interpretershared.h | 6 ++++++ src/coreclr/vm/codeman.cpp | 20 ++++++++++++++++++++ src/coreclr/vm/jitinterface.cpp | 13 ++++++++++++- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/coreclr/interpreter/eeinterp.cpp b/src/coreclr/interpreter/eeinterp.cpp index 338b429e78ee65..e503fa72786b40 100644 --- a/src/coreclr/interpreter/eeinterp.cpp +++ b/src/coreclr/interpreter/eeinterp.cpp @@ -9,12 +9,6 @@ #include #include -#ifdef _MSC_VER -#define INTERP_API -#else -#define INTERP_API __attribute__ ((visibility ("default"))) -#endif // _MSC_VER - /*****************************************************************************/ ICorJitHost* g_interpHost = nullptr; bool g_interpInitialized = false; @@ -66,10 +60,15 @@ CorJitResult CILInterp::compileMethod(ICorJitInfo* compHnd, else { const char *methodName = compHnd->getMethodNameFromMetadata(methodInfo->ftn, nullptr, nullptr, nullptr, 0); - +#ifdef TARGET_WASM + // interpret everything on wasm + doInterpret = true; +#else // TODO: replace this by something like the JIT does to support multiple methods being specified const char *methodToInterpret = InterpConfig.Interpreter(); doInterpret = (methodName != NULL && strcmp(methodName, methodToInterpret) == 0); +#endif + if (doInterpret) g_interpModule = methodInfo->scope; } diff --git a/src/coreclr/interpreter/interpretershared.h b/src/coreclr/interpreter/interpretershared.h index 14b25f71c2c82f..e73f8fbba8aa37 100644 --- a/src/coreclr/interpreter/interpretershared.h +++ b/src/coreclr/interpreter/interpretershared.h @@ -8,6 +8,12 @@ #include "intopsshared.h" +#ifdef _MSC_VER +#define INTERP_API +#else +#define INTERP_API __attribute__ ((visibility ("default"))) +#endif // _MSC_VER + #define INTERP_STACK_SLOT_SIZE 8 // Alignment of each var offset on the interpreter stack #define INTERP_STACK_ALIGNMENT 16 // Alignment of interpreter stack at the start of a frame diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index a5bc3ce4c60010..287dc3873c1762 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1734,6 +1734,13 @@ CORINFO_OS getClrVmOs(); LOG((LF_JIT, LL_FATALERROR, __VA_ARGS__)); \ LogErrorToHost(__VA_ARGS__); +#ifdef TARGET_WASM +#include "../interpreter/interpretershared.h" + +extern "C" INTERP_API void jitStartup(ICorJitHost* jitHost); +extern "C" INTERP_API ICorJitCompiler* getJit(); +#endif + // LoadAndInitializeJIT: load the JIT dll into the process, and initialize it (call the UtilCode initialization function, // check the JIT-EE interface GUID, etc.) // @@ -1768,7 +1775,12 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) *phJit = NULL; *ppICorJitCompiler = NULL; +#ifdef TARGET_WASM +// we are statically linking the interpreter into the host + HRESULT hr = S_OK; +#elif HRESULT hr = E_FAIL; +#endif #ifdef _DEBUG if (pwzJitPath != NULL) @@ -1827,7 +1839,11 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) EX_TRY { typedef void (* pjitStartup)(ICorJitHost*); +#ifdef TARGET_WASM + pjitStartup jitStartupFn = jitStartup; +#else pjitStartup jitStartupFn = (pjitStartup) GetProcAddress(*phJit, "jitStartup"); +#endif if (jitStartupFn) { @@ -1839,7 +1855,11 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) } typedef ICorJitCompiler* (__stdcall* pGetJitFn)(); +#ifdef TARGET_WASM + pGetJitFn getJitFn = getJit; +#else pGetJitFn getJitFn = (pGetJitFn) GetProcAddress(*phJit, "getJit"); +#endif if (getJitFn) { diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 8055e53c1a4f76..94a9fb5ffdd5e1 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -13363,7 +13363,11 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, { LPWSTR interpreterConfig; IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Interpreter, &interpreterConfig)); - if ((interpreterConfig != NULL) && !interpreterMgr->LoadInterpreter()) + if ( +#ifndef TARGET_WASM + (interpreterConfig != NULL) && +#endif + !interpreterMgr->LoadInterpreter()) { EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_EXECUTIONENGINE, W("Failed to load interpreter")); } @@ -13384,6 +13388,12 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, } #endif // FEATURE_INTERPRETER +#ifdef TARGET_WASM + if (!ret) + { + _ASSERTE(!"WASM cannot jit yet"); + } +#elif // !TARGET_WASM if (!ret) { EEJitManager *jitMgr = ExecutionManager::GetEEJitManager(); @@ -13442,6 +13452,7 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, break; } } +#endif // !TARGET_WASM #ifdef _DEBUG static BOOL fHeartbeat = -1; From 0861646a6862b368f0067b5caea426d76d4af8e2 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 20 May 2025 18:17:31 +0200 Subject: [PATCH 02/11] Fix build --- src/coreclr/vm/jitinterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 94a9fb5ffdd5e1..692736942cd6c4 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -13393,7 +13393,7 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, { _ASSERTE(!"WASM cannot jit yet"); } -#elif // !TARGET_WASM +#else // !TARGET_WASM if (!ret) { EEJitManager *jitMgr = ExecutionManager::GetEEJitManager(); From c0ad6b5569d3ad2552e37016e1fd36abbcde353e Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 20 May 2025 19:05:51 +0200 Subject: [PATCH 03/11] Fix build --- src/coreclr/vm/codeman.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 287dc3873c1762..37750e34a1f7ff 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1778,7 +1778,7 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) #ifdef TARGET_WASM // we are statically linking the interpreter into the host HRESULT hr = S_OK; -#elif +#else HRESULT hr = E_FAIL; #endif From 121abf13bda049bb56f1d74f4d2154c98a7bd2a9 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 22 May 2025 20:20:01 +0200 Subject: [PATCH 04/11] Feedback --- src/coreclr/clrdefinitions.cmake | 10 ++- src/coreclr/clrfeatures.cmake | 4 + .../dlls/mscoree/coreclr/CMakeLists.txt | 4 +- src/coreclr/jit/CMakeLists.txt | 2 +- src/coreclr/vm/CMakeLists.txt | 4 + src/coreclr/vm/codeman.cpp | 84 +++++++++---------- src/coreclr/vm/jitinterface.cpp | 8 +- src/coreclr/vm/wks/CMakeLists.txt | 2 +- 8 files changed, 64 insertions(+), 54 deletions(-) diff --git a/src/coreclr/clrdefinitions.cmake b/src/coreclr/clrdefinitions.cmake index c7f6ae41d4d8aa..34fca26ac1e287 100644 --- a/src/coreclr/clrdefinitions.cmake +++ b/src/coreclr/clrdefinitions.cmake @@ -1,5 +1,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/clrfeatures.cmake) +if(FEATURE_JIT) + add_compile_definitions(FEATURE_JIT) +endif(FEATURE_JIT) + add_compile_definitions($<$>:DACCESS_COMPILE>) if (CLR_CMAKE_TARGET_ARCH_ARM64) @@ -132,9 +136,9 @@ if (CLR_CMAKE_TARGET_WIN32) add_definitions(-DFEATURE_ISYM_READER) endif(CLR_CMAKE_TARGET_WIN32) -if(FEATURE_MERGE_JIT_AND_ENGINE) - add_compile_definitions($<$>>:FEATURE_MERGE_JIT_AND_ENGINE>) -endif(FEATURE_MERGE_JIT_AND_ENGINE) +if(FEATURE_STATICALLY_LINKED) + add_compile_definitions($<$>>:FEATURE_STATICALLY_LINKED>) +endif(FEATURE_STATICALLY_LINKED) add_compile_definitions(FEATURE_MULTICOREJIT) if(CLR_CMAKE_TARGET_UNIX) add_definitions(-DFEATURE_PAL_ANSI) diff --git a/src/coreclr/clrfeatures.cmake b/src/coreclr/clrfeatures.cmake index 19b53e6ed268af..93a32c3df576f5 100644 --- a/src/coreclr/clrfeatures.cmake +++ b/src/coreclr/clrfeatures.cmake @@ -1,3 +1,7 @@ +if (NOT CLR_CMAKE_TARGET_ARCH_WASM) + set(FEATURE_JIT 1) +endif() + if(CLR_CMAKE_TARGET_TIZEN_LINUX) set(FEATURE_GDBJIT_LANGID_CS 1) endif() diff --git a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt index cada329416163e..60f6a310451d90 100644 --- a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt @@ -168,9 +168,9 @@ if(FEATURE_PERFTRACING) endif(CLR_CMAKE_TARGET_LINUX) endif(FEATURE_PERFTRACING) -if(FEATURE_MERGE_JIT_AND_ENGINE) +if(FEATURE_STATICALLY_LINKED) set(CLRJIT_STATIC clrjit_static) -endif(FEATURE_MERGE_JIT_AND_ENGINE) +endif(FEATURE_STATICALLY_LINKED) if (CLR_CMAKE_TARGET_OSX) find_library(FOUNDATION Foundation REQUIRED) diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index 1cfe40b6853a25..a26bc8a5b64a95 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -60,7 +60,7 @@ function(create_standalone_jit) add_jit(${TARGETDETAILS_TARGET}) set_target_definitions_to_custom_os_and_arch(${ARGN}) - set_target_properties(${TARGETDETAILS_TARGET} PROPERTIES IGNORE_FEATURE_MERGE_JIT_AND_ENGINE TRUE) + set_target_properties(${TARGETDETAILS_TARGET} PROPERTIES IGNORE_FEATURE_STATICALLY_LINKED TRUE) target_compile_definitions(${TARGETDETAILS_TARGET} PRIVATE FEATURE_NO_HOST) target_compile_definitions(${TARGETDETAILS_TARGET} PRIVATE SELF_NO_HOST) diff --git a/src/coreclr/vm/CMakeLists.txt b/src/coreclr/vm/CMakeLists.txt index 07545fdfca53ae..c0805d6fbc55a0 100644 --- a/src/coreclr/vm/CMakeLists.txt +++ b/src/coreclr/vm/CMakeLists.txt @@ -47,6 +47,10 @@ endif(FEATURE_PERFTRACING) add_compile_definitions($<${FEATURE_CORECLR_CACHED_INTERFACE_DISPATCH}:FEATURE_CACHED_INTERFACE_DISPATCH>) add_compile_definitions($<${FEATURE_CORECLR_VIRTUAL_STUB_DISPATCH}:FEATURE_VIRTUAL_STUB_DISPATCH>) +if(CLR_CMAKE_TARGET_ARCH_WASM) + add_compile_definitions(FEATURE_STATICALLY_LINKED) +endif() + set(VM_SOURCES_DAC_AND_WKS_COMMON appdomain.cpp array.cpp diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 37750e34a1f7ff..559744e37b69fb 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1721,6 +1721,13 @@ struct JIT_LOAD_DATA // Otherwise, this will be S_OK (which is zero). }; +#ifdef FEATURE_STATICALLY_LINKED + +EXTERN_C void jitStartup(ICorJitHost* host); +EXTERN_C ICorJitCompiler* getJit(); + +#else // !FEATURE_STATICALLY_LINKED + // Here's the global data for JIT load and initialization state. JIT_LOAD_DATA g_JitLoadData; @@ -1734,13 +1741,6 @@ CORINFO_OS getClrVmOs(); LOG((LF_JIT, LL_FATALERROR, __VA_ARGS__)); \ LogErrorToHost(__VA_ARGS__); -#ifdef TARGET_WASM -#include "../interpreter/interpretershared.h" - -extern "C" INTERP_API void jitStartup(ICorJitHost* jitHost); -extern "C" INTERP_API ICorJitCompiler* getJit(); -#endif - // LoadAndInitializeJIT: load the JIT dll into the process, and initialize it (call the UtilCode initialization function, // check the JIT-EE interface GUID, etc.) // @@ -1775,12 +1775,7 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) *phJit = NULL; *ppICorJitCompiler = NULL; -#ifdef TARGET_WASM -// we are statically linking the interpreter into the host - HRESULT hr = S_OK; -#else HRESULT hr = E_FAIL; -#endif #ifdef _DEBUG if (pwzJitPath != NULL) @@ -1839,11 +1834,7 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) EX_TRY { typedef void (* pjitStartup)(ICorJitHost*); -#ifdef TARGET_WASM - pjitStartup jitStartupFn = jitStartup; -#else pjitStartup jitStartupFn = (pjitStartup) GetProcAddress(*phJit, "jitStartup"); -#endif if (jitStartupFn) { @@ -1855,11 +1846,7 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) } typedef ICorJitCompiler* (__stdcall* pGetJitFn)(); -#ifdef TARGET_WASM - pGetJitFn getJitFn = getJit; -#else pGetJitFn getJitFn = (pGetJitFn) GetProcAddress(*phJit, "getJit"); -#endif if (getJitFn) { @@ -1917,12 +1904,30 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) LogJITInitializationError("LoadAndInitializeJIT: failed to load %s, hr=0x%08X", utf8JitName, hr); } } +#endif -#ifdef FEATURE_MERGE_JIT_AND_ENGINE -EXTERN_C void jitStartup(ICorJitHost* host); -EXTERN_C ICorJitCompiler* getJit(); -#endif // FEATURE_MERGE_JIT_AND_ENGINE +#ifdef FEATURE_STATICALLY_LINKED +static ICorJitCompiler* InitializeStaticJIT() +{ + ICorJitCompiler* newJitCompiler = NULL; + EX_TRY + { + jitStartup(JitHost::getJitHost()); + + newJitCompiler = getJit(); + // We don't need to call getVersionIdentifier(), since the JIT is linked together with the VM. + } + EX_CATCH + { + } + EX_END_CATCH(SwallowAllExceptions) + + return newJitCompiler; +} +#endif // FEATURE_STATICALLY_LINKED + +#ifdef FEATURE_JIT BOOL EEJitManager::LoadJIT() { STANDARD_VM_CONTRACT; @@ -1942,22 +1947,9 @@ BOOL EEJitManager::LoadJIT() ICorJitCompiler* newJitCompiler = NULL; -#ifdef FEATURE_MERGE_JIT_AND_ENGINE - - EX_TRY - { - jitStartup(JitHost::getJitHost()); - - newJitCompiler = getJit(); - - // We don't need to call getVersionIdentifier(), since the JIT is linked together with the VM. - } - EX_CATCH - { - } - EX_END_CATCH(SwallowAllExceptions) - -#else // !FEATURE_MERGE_JIT_AND_ENGINE +#ifdef FEATURE_STATICALLY_LINKED + newJitCompiler = InitializeStaticJIT(); +#else // !FEATURE_STATICALLY_LINKED m_JITCompiler = NULL; #if defined(TARGET_X86) || defined(TARGET_AMD64) @@ -1970,7 +1962,7 @@ BOOL EEJitManager::LoadJIT() IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_JitPath, &mainJitPath)); #endif LoadAndInitializeJIT(ExecutionManager::GetJitName() DEBUGARG(mainJitPath), &m_JITCompiler, &newJitCompiler, &g_JitLoadData, getClrVmOs()); -#endif // !FEATURE_MERGE_JIT_AND_ENGINE +#endif // !FEATURE_STATICALLY_LINKED #ifdef ALLOW_SXS_JIT @@ -2068,6 +2060,7 @@ BOOL EEJitManager::LoadJIT() // In either failure case, we'll rip down the VM (so no need to clean up (unload) either JIT that did load successfully. return IsJitLoaded(); } +#endif // FEATURE_JIT //************************************************************************** @@ -3760,12 +3753,17 @@ BOOL InterpreterJitManager::LoadInterpreter() ICorJitCompiler* newInterpreter = NULL; m_interpreter = NULL; +#ifdef FEATURE_STATICALLY_LINKED + newInterpreter = InitializeStaticJIT(); +#else // !FEATURE_STATICALLY_LINKED g_interpreterLoadData.jld_id = JIT_LOAD_INTERPRETER; + LPWSTR interpreterPath = NULL; #ifdef _DEBUG IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_InterpreterPath, &interpreterPath)); #endif LoadAndInitializeJIT(ExecutionManager::GetInterpreterName() DEBUGARG(interpreterPath), &m_interpreterHandle, &newInterpreter, &g_interpreterLoadData, getClrVmOs()); +#endif // !FEATURE_STATICALLY_LINKED // Publish the interpreter. m_interpreter = newInterpreter; @@ -5169,7 +5167,7 @@ BOOL ExecutionManager::IsReadyToRunCode(PCODE currentPC) return FALSE; } -#ifndef FEATURE_MERGE_JIT_AND_ENGINE +#ifndef FEATURE_STATICALLY_LINKED /*********************************************************************/ // This static method returns the name of the jit dll // @@ -5190,7 +5188,7 @@ LPCWSTR ExecutionManager::GetJitName() return pwzJitName; } -#endif // !FEATURE_MERGE_JIT_AND_ENGINE +#endif // !FEATURE_STATICALLY_LINKED #ifdef FEATURE_INTERPRETER diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 692736942cd6c4..ceb978e965d126 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -13388,12 +13388,12 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, } #endif // FEATURE_INTERPRETER -#ifdef TARGET_WASM +#ifndef FEATURE_JIT if (!ret) { - _ASSERTE(!"WASM cannot jit yet"); + _ASSERTE(!"this platform does not support JIT compilation"); } -#else // !TARGET_WASM +#else // !FEATURE_JIT if (!ret) { EEJitManager *jitMgr = ExecutionManager::GetEEJitManager(); @@ -13452,7 +13452,7 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, break; } } -#endif // !TARGET_WASM +#endif // !FEATURE_JIT #ifdef _DEBUG static BOOL fHeartbeat = -1; diff --git a/src/coreclr/vm/wks/CMakeLists.txt b/src/coreclr/vm/wks/CMakeLists.txt index e519458d736e2e..280665e8b47d17 100644 --- a/src/coreclr/vm/wks/CMakeLists.txt +++ b/src/coreclr/vm/wks/CMakeLists.txt @@ -49,7 +49,7 @@ add_dependencies(cee_wks_core precompiled_asm) add_dependencies(cee_wks precompiled_asm) add_dependencies(cee_wks_mergeable precompiled_asm) -target_compile_definitions(cee_wks_mergeable PUBLIC FEATURE_MERGE_JIT_AND_ENGINE) +target_compile_definitions(cee_wks_mergeable PUBLIC FEATURE_STATICALLY_LINKED) target_compile_definitions(cee_wks_mergeable PUBLIC CORECLR_EMBEDDED) if (CLR_CMAKE_HOST_WIN32) From 239d861f58f65070606834917377dcc463f88b54 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 23 May 2025 13:29:28 +0200 Subject: [PATCH 05/11] Enable interpreter everywhere, where JIT is not available, not just WASM Co-authored-by: Jan Kotas --- src/coreclr/vm/jitinterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index ceb978e965d126..fcb0d14690a69d 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -13364,7 +13364,8 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, LPWSTR interpreterConfig; IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Interpreter, &interpreterConfig)); if ( -#ifndef TARGET_WASM +#ifdef FEATURE_JIT + // If both JIT and interpret are available, load the interpreter only for testing purposes only if the config switch is set (interpreterConfig != NULL) && #endif !interpreterMgr->LoadInterpreter()) From fc1f6b2525d7e4dea7feedcf501019618e0d9119 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 23 May 2025 13:31:29 +0200 Subject: [PATCH 06/11] Link interpreter statically only when JIT is missing Co-authored-by: Jan Kotas --- src/coreclr/vm/codeman.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 559744e37b69fb..6541a9ebd39713 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -3753,7 +3753,9 @@ BOOL InterpreterJitManager::LoadInterpreter() ICorJitCompiler* newInterpreter = NULL; m_interpreter = NULL; -#ifdef FEATURE_STATICALLY_LINKED +// If both JIT and interpret are available, statically link the JIT. Interpret can be loaded dynamically +// via config switch for testing purposes. +#if defined(FEATURE_STATICALLY_LINKED) && !defined(FEATURE_JIT) newInterpreter = InitializeStaticJIT(); #else // !FEATURE_STATICALLY_LINKED g_interpreterLoadData.jld_id = JIT_LOAD_INTERPRETER; From 08df7e59ad657e1a458c707ecdf13e06cf0fa7e5 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 23 May 2025 15:38:01 +0200 Subject: [PATCH 07/11] Fix build --- src/coreclr/vm/codeman.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 6541a9ebd39713..f25b64e43fa0a5 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1726,7 +1726,9 @@ struct JIT_LOAD_DATA EXTERN_C void jitStartup(ICorJitHost* host); EXTERN_C ICorJitCompiler* getJit(); -#else // !FEATURE_STATICALLY_LINKED +#endif // FEATURE_STATICALLY_LINKED + +#if !defined(FEATURE_STATICALLY_LINKED) || defined(FEATURE_JIT) // Here's the global data for JIT load and initialization state. JIT_LOAD_DATA g_JitLoadData; @@ -1904,7 +1906,7 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) LogJITInitializationError("LoadAndInitializeJIT: failed to load %s, hr=0x%08X", utf8JitName, hr); } } -#endif +#endif // !FEATURE_STATICALLY_LINKED || defined(FEATURE_JIT) #ifdef FEATURE_STATICALLY_LINKED static ICorJitCompiler* InitializeStaticJIT() From a880bdf79625ce5b9196bb03f8faa9fdb1026714 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 23 May 2025 08:48:12 -0700 Subject: [PATCH 08/11] Apply suggestions from code review --- src/coreclr/vm/codeman.cpp | 2 +- src/coreclr/vm/jitinterface.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index f25b64e43fa0a5..6bf149cb58639e 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -3755,7 +3755,7 @@ BOOL InterpreterJitManager::LoadInterpreter() ICorJitCompiler* newInterpreter = NULL; m_interpreter = NULL; -// If both JIT and interpret are available, statically link the JIT. Interpret can be loaded dynamically +// If both JIT and interpret are available, statically link the JIT. Interpreter can be loaded dynamically // via config switch for testing purposes. #if defined(FEATURE_STATICALLY_LINKED) && !defined(FEATURE_JIT) newInterpreter = InitializeStaticJIT(); diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index fcb0d14690a69d..2f6aebc962914c 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -13365,7 +13365,7 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Interpreter, &interpreterConfig)); if ( #ifdef FEATURE_JIT - // If both JIT and interpret are available, load the interpreter only for testing purposes only if the config switch is set + // If both JIT and interpret are available, load the interpreter for testing purposes only if the config switch is set (interpreterConfig != NULL) && #endif !interpreterMgr->LoadInterpreter()) From ef92810dce6b735b65b416a89caf9abd61001e19 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 23 May 2025 08:49:34 -0700 Subject: [PATCH 09/11] Apply suggestions from code review --- src/coreclr/vm/codeman.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 6bf149cb58639e..86870f5a8282c6 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -3759,7 +3759,7 @@ BOOL InterpreterJitManager::LoadInterpreter() // via config switch for testing purposes. #if defined(FEATURE_STATICALLY_LINKED) && !defined(FEATURE_JIT) newInterpreter = InitializeStaticJIT(); -#else // !FEATURE_STATICALLY_LINKED +#else // FEATURE_STATICALLY_LINKED && !FEATURE_JIT g_interpreterLoadData.jld_id = JIT_LOAD_INTERPRETER; LPWSTR interpreterPath = NULL; @@ -3767,7 +3767,7 @@ BOOL InterpreterJitManager::LoadInterpreter() IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_InterpreterPath, &interpreterPath)); #endif LoadAndInitializeJIT(ExecutionManager::GetInterpreterName() DEBUGARG(interpreterPath), &m_interpreterHandle, &newInterpreter, &g_interpreterLoadData, getClrVmOs()); -#endif // !FEATURE_STATICALLY_LINKED +#endif // FEATURE_STATICALLY_LINKED && !FEATURE_JIT // Publish the interpreter. m_interpreter = newInterpreter; From 38fa841261d584f3e9ccbd2b4346ffd25706dace Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 23 May 2025 08:51:27 -0700 Subject: [PATCH 10/11] Update src/coreclr/vm/codeman.cpp --- src/coreclr/vm/codeman.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 86870f5a8282c6..0e7b4a3b2a2043 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1906,7 +1906,7 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) LogJITInitializationError("LoadAndInitializeJIT: failed to load %s, hr=0x%08X", utf8JitName, hr); } } -#endif // !FEATURE_STATICALLY_LINKED || defined(FEATURE_JIT) +#endif // !FEATURE_STATICALLY_LINKED || FEATURE_JIT #ifdef FEATURE_STATICALLY_LINKED static ICorJitCompiler* InitializeStaticJIT() From 03af71bb54b65ac25e120fbb32c531bace50389b Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 23 May 2025 08:58:53 -0700 Subject: [PATCH 11/11] Update src/coreclr/vm/codeman.cpp --- src/coreclr/vm/codeman.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 0e7b4a3b2a2043..0df03a93cb9aba 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1730,8 +1730,9 @@ EXTERN_C ICorJitCompiler* getJit(); #if !defined(FEATURE_STATICALLY_LINKED) || defined(FEATURE_JIT) -// Here's the global data for JIT load and initialization state. +#ifdef FEATURE_JIT JIT_LOAD_DATA g_JitLoadData; +#endif // FEATURE_JIT #ifdef FEATURE_INTERPRETER JIT_LOAD_DATA g_interpreterLoadData;