Skip to content

Commit 12eba0a

Browse files
radekdoulikjkotas
andauthored
[wasm][coreclr] Interpret everything on wasm (#115788)
* Interpret everything on wasm Do not try to setup the jit and use it, instead use the interpreter * Fix build * Fix build * Feedback * Enable interpreter everywhere, where JIT is not available, not just WASM Co-authored-by: Jan Kotas <[email protected]> * Link interpreter statically only when JIT is missing Co-authored-by: Jan Kotas <[email protected]> * Fix build * Apply suggestions from code review * Apply suggestions from code review * Update src/coreclr/vm/codeman.cpp * Update src/coreclr/vm/codeman.cpp --------- Co-authored-by: Jan Kotas <[email protected]>
1 parent b61c3e8 commit 12eba0a

File tree

10 files changed

+91
-39
lines changed

10 files changed

+91
-39
lines changed

src/coreclr/clrdefinitions.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
include(${CMAKE_CURRENT_LIST_DIR}/clrfeatures.cmake)
22

3+
if(FEATURE_JIT)
4+
add_compile_definitions(FEATURE_JIT)
5+
endif(FEATURE_JIT)
6+
37
add_compile_definitions($<$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>:DACCESS_COMPILE>)
48

59
if (CLR_CMAKE_TARGET_ARCH_ARM64)
@@ -132,9 +136,9 @@ if (CLR_CMAKE_TARGET_WIN32)
132136
add_definitions(-DFEATURE_ISYM_READER)
133137
endif(CLR_CMAKE_TARGET_WIN32)
134138

135-
if(FEATURE_MERGE_JIT_AND_ENGINE)
136-
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_FEATURE_MERGE_JIT_AND_ENGINE>>>:FEATURE_MERGE_JIT_AND_ENGINE>)
137-
endif(FEATURE_MERGE_JIT_AND_ENGINE)
139+
if(FEATURE_STATICALLY_LINKED)
140+
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_FEATURE_STATICALLY_LINKED>>>:FEATURE_STATICALLY_LINKED>)
141+
endif(FEATURE_STATICALLY_LINKED)
138142
add_compile_definitions(FEATURE_MULTICOREJIT)
139143
if(CLR_CMAKE_TARGET_UNIX)
140144
add_definitions(-DFEATURE_PAL_ANSI)

src/coreclr/clrfeatures.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
2+
set(FEATURE_JIT 1)
3+
endif()
4+
15
if(CLR_CMAKE_TARGET_TIZEN_LINUX)
26
set(FEATURE_GDBJIT_LANGID_CS 1)
37
endif()

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ if(FEATURE_PERFTRACING)
168168
endif(CLR_CMAKE_TARGET_LINUX)
169169
endif(FEATURE_PERFTRACING)
170170

171-
if(FEATURE_MERGE_JIT_AND_ENGINE)
171+
if(FEATURE_STATICALLY_LINKED)
172172
set(CLRJIT_STATIC clrjit_static)
173-
endif(FEATURE_MERGE_JIT_AND_ENGINE)
173+
endif(FEATURE_STATICALLY_LINKED)
174174

175175
if (CLR_CMAKE_TARGET_OSX)
176176
find_library(FOUNDATION Foundation REQUIRED)

src/coreclr/interpreter/eeinterp.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
#include <string.h>
1010
#include <stdio.h>
1111

12-
#ifdef _MSC_VER
13-
#define INTERP_API
14-
#else
15-
#define INTERP_API __attribute__ ((visibility ("default")))
16-
#endif // _MSC_VER
17-
1812
/*****************************************************************************/
1913
ICorJitHost* g_interpHost = nullptr;
2014
bool g_interpInitialized = false;
@@ -66,10 +60,15 @@ CorJitResult CILInterp::compileMethod(ICorJitInfo* compHnd,
6660
else
6761
{
6862
const char *methodName = compHnd->getMethodNameFromMetadata(methodInfo->ftn, nullptr, nullptr, nullptr, 0);
69-
63+
#ifdef TARGET_WASM
64+
// interpret everything on wasm
65+
doInterpret = true;
66+
#else
7067
// TODO: replace this by something like the JIT does to support multiple methods being specified
7168
const char *methodToInterpret = InterpConfig.Interpreter();
7269
doInterpret = (methodName != NULL && strcmp(methodName, methodToInterpret) == 0);
70+
#endif
71+
7372
if (doInterpret)
7473
g_interpModule = methodInfo->scope;
7574
}

src/coreclr/interpreter/interpretershared.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
#include "intopsshared.h"
1010

11+
#ifdef _MSC_VER
12+
#define INTERP_API
13+
#else
14+
#define INTERP_API __attribute__ ((visibility ("default")))
15+
#endif // _MSC_VER
16+
1117
#define INTERP_STACK_SLOT_SIZE 8 // Alignment of each var offset on the interpreter stack
1218
#define INTERP_STACK_ALIGNMENT 16 // Alignment of interpreter stack at the start of a frame
1319

src/coreclr/jit/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function(create_standalone_jit)
6060
add_jit(${TARGETDETAILS_TARGET})
6161

6262
set_target_definitions_to_custom_os_and_arch(${ARGN})
63-
set_target_properties(${TARGETDETAILS_TARGET} PROPERTIES IGNORE_FEATURE_MERGE_JIT_AND_ENGINE TRUE)
63+
set_target_properties(${TARGETDETAILS_TARGET} PROPERTIES IGNORE_FEATURE_STATICALLY_LINKED TRUE)
6464

6565
target_compile_definitions(${TARGETDETAILS_TARGET} PRIVATE FEATURE_NO_HOST)
6666
target_compile_definitions(${TARGETDETAILS_TARGET} PRIVATE SELF_NO_HOST)

src/coreclr/vm/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ endif(FEATURE_PERFTRACING)
4747
add_compile_definitions($<${FEATURE_CORECLR_CACHED_INTERFACE_DISPATCH}:FEATURE_CACHED_INTERFACE_DISPATCH>)
4848
add_compile_definitions($<${FEATURE_CORECLR_VIRTUAL_STUB_DISPATCH}:FEATURE_VIRTUAL_STUB_DISPATCH>)
4949

50+
if(CLR_CMAKE_TARGET_ARCH_WASM)
51+
add_compile_definitions(FEATURE_STATICALLY_LINKED)
52+
endif()
53+
5054
set(VM_SOURCES_DAC_AND_WKS_COMMON
5155
appdomain.cpp
5256
array.cpp

src/coreclr/vm/codeman.cpp

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,8 +1721,18 @@ struct JIT_LOAD_DATA
17211721
// Otherwise, this will be S_OK (which is zero).
17221722
};
17231723

1724-
// Here's the global data for JIT load and initialization state.
1724+
#ifdef FEATURE_STATICALLY_LINKED
1725+
1726+
EXTERN_C void jitStartup(ICorJitHost* host);
1727+
EXTERN_C ICorJitCompiler* getJit();
1728+
1729+
#endif // FEATURE_STATICALLY_LINKED
1730+
1731+
#if !defined(FEATURE_STATICALLY_LINKED) || defined(FEATURE_JIT)
1732+
1733+
#ifdef FEATURE_JIT
17251734
JIT_LOAD_DATA g_JitLoadData;
1735+
#endif // FEATURE_JIT
17261736

17271737
#ifdef FEATURE_INTERPRETER
17281738
JIT_LOAD_DATA g_interpreterLoadData;
@@ -1897,12 +1907,30 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName DEBUGARG(LPCWSTR pwzJitPath)
18971907
LogJITInitializationError("LoadAndInitializeJIT: failed to load %s, hr=0x%08X", utf8JitName, hr);
18981908
}
18991909
}
1910+
#endif // !FEATURE_STATICALLY_LINKED || FEATURE_JIT
19001911

1901-
#ifdef FEATURE_MERGE_JIT_AND_ENGINE
1902-
EXTERN_C void jitStartup(ICorJitHost* host);
1903-
EXTERN_C ICorJitCompiler* getJit();
1904-
#endif // FEATURE_MERGE_JIT_AND_ENGINE
1912+
#ifdef FEATURE_STATICALLY_LINKED
1913+
static ICorJitCompiler* InitializeStaticJIT()
1914+
{
1915+
ICorJitCompiler* newJitCompiler = NULL;
1916+
EX_TRY
1917+
{
1918+
jitStartup(JitHost::getJitHost());
1919+
1920+
newJitCompiler = getJit();
19051921

1922+
// We don't need to call getVersionIdentifier(), since the JIT is linked together with the VM.
1923+
}
1924+
EX_CATCH
1925+
{
1926+
}
1927+
EX_END_CATCH(SwallowAllExceptions)
1928+
1929+
return newJitCompiler;
1930+
}
1931+
#endif // FEATURE_STATICALLY_LINKED
1932+
1933+
#ifdef FEATURE_JIT
19061934
BOOL EEJitManager::LoadJIT()
19071935
{
19081936
STANDARD_VM_CONTRACT;
@@ -1922,22 +1950,9 @@ BOOL EEJitManager::LoadJIT()
19221950

19231951
ICorJitCompiler* newJitCompiler = NULL;
19241952

1925-
#ifdef FEATURE_MERGE_JIT_AND_ENGINE
1926-
1927-
EX_TRY
1928-
{
1929-
jitStartup(JitHost::getJitHost());
1930-
1931-
newJitCompiler = getJit();
1932-
1933-
// We don't need to call getVersionIdentifier(), since the JIT is linked together with the VM.
1934-
}
1935-
EX_CATCH
1936-
{
1937-
}
1938-
EX_END_CATCH(SwallowAllExceptions)
1939-
1940-
#else // !FEATURE_MERGE_JIT_AND_ENGINE
1953+
#ifdef FEATURE_STATICALLY_LINKED
1954+
newJitCompiler = InitializeStaticJIT();
1955+
#else // !FEATURE_STATICALLY_LINKED
19411956

19421957
m_JITCompiler = NULL;
19431958
#if defined(TARGET_X86) || defined(TARGET_AMD64)
@@ -1950,7 +1965,7 @@ BOOL EEJitManager::LoadJIT()
19501965
IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_JitPath, &mainJitPath));
19511966
#endif
19521967
LoadAndInitializeJIT(ExecutionManager::GetJitName() DEBUGARG(mainJitPath), &m_JITCompiler, &newJitCompiler, &g_JitLoadData, getClrVmOs());
1953-
#endif // !FEATURE_MERGE_JIT_AND_ENGINE
1968+
#endif // !FEATURE_STATICALLY_LINKED
19541969

19551970
#ifdef ALLOW_SXS_JIT
19561971

@@ -2048,6 +2063,7 @@ BOOL EEJitManager::LoadJIT()
20482063
// In either failure case, we'll rip down the VM (so no need to clean up (unload) either JIT that did load successfully.
20492064
return IsJitLoaded();
20502065
}
2066+
#endif // FEATURE_JIT
20512067

20522068
//**************************************************************************
20532069

@@ -3740,12 +3756,19 @@ BOOL InterpreterJitManager::LoadInterpreter()
37403756
ICorJitCompiler* newInterpreter = NULL;
37413757
m_interpreter = NULL;
37423758

3759+
// If both JIT and interpret are available, statically link the JIT. Interpreter can be loaded dynamically
3760+
// via config switch for testing purposes.
3761+
#if defined(FEATURE_STATICALLY_LINKED) && !defined(FEATURE_JIT)
3762+
newInterpreter = InitializeStaticJIT();
3763+
#else // FEATURE_STATICALLY_LINKED && !FEATURE_JIT
37433764
g_interpreterLoadData.jld_id = JIT_LOAD_INTERPRETER;
3765+
37443766
LPWSTR interpreterPath = NULL;
37453767
#ifdef _DEBUG
37463768
IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_InterpreterPath, &interpreterPath));
37473769
#endif
37483770
LoadAndInitializeJIT(ExecutionManager::GetInterpreterName() DEBUGARG(interpreterPath), &m_interpreterHandle, &newInterpreter, &g_interpreterLoadData, getClrVmOs());
3771+
#endif // FEATURE_STATICALLY_LINKED && !FEATURE_JIT
37493772

37503773
// Publish the interpreter.
37513774
m_interpreter = newInterpreter;
@@ -5149,7 +5172,7 @@ BOOL ExecutionManager::IsReadyToRunCode(PCODE currentPC)
51495172
return FALSE;
51505173
}
51515174

5152-
#ifndef FEATURE_MERGE_JIT_AND_ENGINE
5175+
#ifndef FEATURE_STATICALLY_LINKED
51535176
/*********************************************************************/
51545177
// This static method returns the name of the jit dll
51555178
//
@@ -5170,7 +5193,7 @@ LPCWSTR ExecutionManager::GetJitName()
51705193
return pwzJitName;
51715194
}
51725195

5173-
#endif // !FEATURE_MERGE_JIT_AND_ENGINE
5196+
#endif // !FEATURE_STATICALLY_LINKED
51745197

51755198
#ifdef FEATURE_INTERPRETER
51765199

src/coreclr/vm/jitinterface.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13346,7 +13346,12 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config,
1334613346
{
1334713347
LPWSTR interpreterConfig;
1334813348
IfFailThrow(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Interpreter, &interpreterConfig));
13349-
if ((interpreterConfig != NULL) && !interpreterMgr->LoadInterpreter())
13349+
if (
13350+
#ifdef FEATURE_JIT
13351+
// If both JIT and interpret are available, load the interpreter for testing purposes only if the config switch is set
13352+
(interpreterConfig != NULL) &&
13353+
#endif
13354+
!interpreterMgr->LoadInterpreter())
1335013355
{
1335113356
EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_EXECUTIONENGINE, W("Failed to load interpreter"));
1335213357
}
@@ -13367,6 +13372,12 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config,
1336713372
}
1336813373
#endif // FEATURE_INTERPRETER
1336913374

13375+
#ifndef FEATURE_JIT
13376+
if (!ret)
13377+
{
13378+
_ASSERTE(!"this platform does not support JIT compilation");
13379+
}
13380+
#else // !FEATURE_JIT
1337013381
if (!ret)
1337113382
{
1337213383
EEJitManager *jitMgr = ExecutionManager::GetEEJitManager();
@@ -13425,6 +13436,7 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config,
1342513436
break;
1342613437
}
1342713438
}
13439+
#endif // !FEATURE_JIT
1342813440

1342913441
#ifdef _DEBUG
1343013442
static BOOL fHeartbeat = -1;

src/coreclr/vm/wks/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ add_dependencies(cee_wks_core precompiled_asm)
4949
add_dependencies(cee_wks precompiled_asm)
5050
add_dependencies(cee_wks_mergeable precompiled_asm)
5151

52-
target_compile_definitions(cee_wks_mergeable PUBLIC FEATURE_MERGE_JIT_AND_ENGINE)
52+
target_compile_definitions(cee_wks_mergeable PUBLIC FEATURE_STATICALLY_LINKED)
5353
target_compile_definitions(cee_wks_mergeable PUBLIC CORECLR_EMBEDDED)
5454

5555
if (CLR_CMAKE_HOST_WIN32)

0 commit comments

Comments
 (0)