Skip to content

[wasm][coreclr] Interpret everything on wasm #115788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 26, 2025
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
10 changes: 7 additions & 3 deletions src/coreclr/clrdefinitions.cmake
Original file line number Diff line number Diff line change
@@ -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($<$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>:DACCESS_COMPILE>)

if (CLR_CMAKE_TARGET_ARCH_ARM64)
Expand Down Expand Up @@ -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($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_FEATURE_MERGE_JIT_AND_ENGINE>>>:FEATURE_MERGE_JIT_AND_ENGINE>)
endif(FEATURE_MERGE_JIT_AND_ENGINE)
if(FEATURE_STATICALLY_LINKED)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_FEATURE_STATICALLY_LINKED>>>:FEATURE_STATICALLY_LINKED>)
endif(FEATURE_STATICALLY_LINKED)
add_compile_definitions(FEATURE_MULTICOREJIT)
if(CLR_CMAKE_TARGET_UNIX)
add_definitions(-DFEATURE_PAL_ANSI)
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/clrfeatures.cmake
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions src/coreclr/interpreter/eeinterp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
#include <string.h>
#include <stdio.h>

#ifdef _MSC_VER
#define INTERP_API
#else
#define INTERP_API __attribute__ ((visibility ("default")))
#endif // _MSC_VER

/*****************************************************************************/
ICorJitHost* g_interpHost = nullptr;
bool g_interpInitialized = false;
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/interpreter/interpretershared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 47 additions & 24 deletions src/coreclr/vm/codeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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

//**************************************************************************

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
//
Expand All @@ -5170,7 +5193,7 @@ LPCWSTR ExecutionManager::GetJitName()
return pwzJitName;
}

#endif // !FEATURE_MERGE_JIT_AND_ENGINE
#endif // !FEATURE_STATICALLY_LINKED

#ifdef FEATURE_INTERPRETER

Expand Down
14 changes: 13 additions & 1 deletion src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand All @@ -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();
Expand Down Expand Up @@ -13442,6 +13453,7 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config,
break;
}
}
#endif // !FEATURE_JIT

#ifdef _DEBUG
static BOOL fHeartbeat = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/wks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading