diff --git a/src/coreclr/clrdefinitions.cmake b/src/coreclr/clrdefinitions.cmake index ee5fba323c9c6d..8d3ea3d89cf1ca 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/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/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 a5bc3ce4c60010..0df03a93cb9aba 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1721,8 +1721,18 @@ struct JIT_LOAD_DATA // Otherwise, this will be S_OK (which is zero). }; -// Here's the global data for JIT load and initialization state. +#ifdef FEATURE_STATICALLY_LINKED + +EXTERN_C void jitStartup(ICorJitHost* host); +EXTERN_C ICorJitCompiler* getJit(); + +#endif // FEATURE_STATICALLY_LINKED + +#if !defined(FEATURE_STATICALLY_LINKED) || defined(FEATURE_JIT) + +#ifdef FEATURE_JIT JIT_LOAD_DATA g_JitLoadData; +#endif // FEATURE_JIT #ifdef FEATURE_INTERPRETER JIT_LOAD_DATA g_interpreterLoadData; @@ -1897,12 +1907,30 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath) LogJITInitializationError("LoadAndInitializeJIT: failed to load %s, hr=0x%08X", utf8JitName, hr); } } +#endif // !FEATURE_STATICALLY_LINKED || FEATURE_JIT -#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; @@ -1922,22 +1950,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) @@ -1950,7 +1965,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 @@ -2048,6 +2063,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 //************************************************************************** @@ -3740,12 +3756,19 @@ BOOL InterpreterJitManager::LoadInterpreter() ICorJitCompiler* newInterpreter = NULL; m_interpreter = NULL; +// 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(); +#else // FEATURE_STATICALLY_LINKED && !FEATURE_JIT 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 && !FEATURE_JIT // Publish the interpreter. m_interpreter = newInterpreter; @@ -5149,7 +5172,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 // @@ -5170,7 +5193,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 8055e53c1a4f76..2f6aebc962914c 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -13363,7 +13363,12 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, { LPWSTR interpreterConfig; IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Interpreter, &interpreterConfig)); - if ((interpreterConfig != NULL) && !interpreterMgr->LoadInterpreter()) + if ( +#ifdef FEATURE_JIT + // 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()) { EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_EXECUTIONENGINE, W("Failed to load interpreter")); } @@ -13384,6 +13389,12 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, } #endif // FEATURE_INTERPRETER +#ifndef FEATURE_JIT + if (!ret) + { + _ASSERTE(!"this platform does not support JIT compilation"); + } +#else // !FEATURE_JIT if (!ret) { EEJitManager *jitMgr = ExecutionManager::GetEEJitManager(); @@ -13442,6 +13453,7 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, break; } } +#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)