Skip to content

Commit ab3d027

Browse files
Portable EntryPoint feature (#119178)
* Create FEATURE_PORTABLE_ENTRYPOINTS build flag. * WASM uses PortableEntryPoint * Add note to clr-abi about Portable Entry Points. * Create TargetsWasm MSBuild property. * Disable FEATURE_REJIT and FEATURE_TIERED_COMPILATION for wasm.
1 parent 7d4c075 commit ab3d027

31 files changed

+605
-126
lines changed

docs/design/coreclr/botr/clr-abi.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,22 @@ The extra state created by the JIT for synchronized methods (lock taken flag) mu
537537

538538
EnC is supported for adding and editing generic methods and methods on generic types and generic methods on non-generic types.
539539

540+
# Portable entrypoints
541+
542+
On platforms that allow dynamic code generation, the runtime abstracts away execution strategies for dynamically loaded methods by allocating [`Precode`](method-descriptor.md#precode)s. The `Precode` is a small code fragment that is used as a temporary method entrypoint until the actual method code is acquired. `Precode`s are also used as part of the execution for methods that do not have regular JITed or AOT-compiled code, for example stubs or interpreted methods. `Precode`s allow native code to use the same native code calling convention irrespective of the execution strategy used by the target method.
543+
544+
On platforms that do not allow dynamic code generation (Wasm), the runtime abstracts away execution strategies by allocating portable entrypoints for dynamically loaded methods. The `PortableEntryPoint` is a data structure that allows efficient transition to the desired execution strategy for the target method. When the runtime is configured to use portable entrypoints, the managed calling convention is modified as follows:
545+
546+
- The native code to call is obtained by dereferencing the entrypoint
547+
548+
- The entrypoint address is passed in as an extra last hidden argument. The extra hidden argument must be present in signatures of all methods. It is unused by the code of JITed or AOT-compiled methods.
549+
550+
Pseudo code for a call with portable entrypoints:
551+
552+
> `(*(void**)pfn)(arg0, arg1, ..., argN, pfn)`
553+
554+
Portable entrypoints are used for Wasm with interpreter only currently. Note that portable entrypoints are unnecessary for Wasm with native AOT since native AOT does not support dynamic loading.
555+
540556
# System V x86_64 support
541557

542558
This section relates mostly to calling conventions on System V systems (such as Ubuntu Linux and Mac OS X).

eng/OSArch.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<Platform Condition="'$(Platform)' == '' and '$(InferPlatformFromTargetArchitecture)' == 'true'">$(TargetArchitecture)</Platform>
3434
</PropertyGroup>
3535

36+
<PropertyGroup>
37+
<TargetsWasm Condition="'$(TargetArchitecture)' == 'wasm'">true</TargetsWasm>
38+
</PropertyGroup>
39+
3640
<PropertyGroup>
3741
<_ImportedOSArchProps>true</_ImportedOSArchProps>
3842
</PropertyGroup>

src/coreclr/clr.featuredefines.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
<FeatureCoreCLR>true</FeatureCoreCLR>
44
<FeaturePerfTracing>true</FeaturePerfTracing>
55
<FeatureEHFunclets>true</FeatureEHFunclets>
6+
<FeaturePortableEntryPoints>false</FeaturePortableEntryPoints>
67
<ProfilingSupportedBuild>true</ProfilingSupportedBuild>
78
</PropertyGroup>
89

910
<PropertyGroup Condition="'$(TargetsAndroid)' == 'true' OR '$(Configuration)' == 'debug' OR '$(Configuration)' == 'checked'">
1011
<FeatureJavaMarshal>true</FeatureJavaMarshal>
1112
</PropertyGroup>
1213

14+
<PropertyGroup Condition="'$(TargetsWasm)' == 'true'">
15+
<FeaturePortableEntryPoints>true</FeaturePortableEntryPoints>
16+
</PropertyGroup>
17+
1318
<PropertyGroup Condition="'$(TargetsUnix)' == 'true'">
1419
<FeatureXplatEventSource Condition="'$(FeatureXplatEventSource)' == '' AND '$(TargetOS)' == 'linux'">true</FeatureXplatEventSource>
1520
<FeatureComWrappers>true</FeatureComWrappers>
@@ -43,6 +48,7 @@
4348
<DefineConstants Condition="'$(FeatureTypeEquivalence)' == 'true'">$(DefineConstants);FEATURE_TYPEEQUIVALENCE</DefineConstants>
4449
<DefineConstants Condition="'$(FeatureEHFunclets)' == 'true'">$(DefineConstants);FEATURE_EH_FUNCLETS</DefineConstants>
4550
<DefineConstants Condition="'$(FeatureInterpreter)' == 'true'">$(DefineConstants);FEATURE_INTERPRETER</DefineConstants>
51+
<DefineConstants Condition="'$(FeaturePortableEntryPoints)' == 'true'">$(DefineConstants);FEATURE_PORTABLE_ENTRYPOINTS</DefineConstants>
4652

4753
<DefineConstants Condition="'$(ProfilingSupportedBuild)' == 'true'">$(DefineConstants);PROFILING_SUPPORTED</DefineConstants>
4854
</PropertyGroup>

src/coreclr/clrdefinitions.cmake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_
118118
endif (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386 OR CLR_CMAKE_TARGET_ARCH_ARM64))
119119

120120
add_compile_definitions($<${FEATURE_INTERPRETER}:FEATURE_INTERPRETER>)
121+
if (FEATURE_PORTABLE_ENTRYPOINTS)
122+
add_compile_definitions(FEATURE_PORTABLE_ENTRYPOINTS)
123+
endif()
121124

122125
if (CLR_CMAKE_TARGET_WIN32)
123126
add_definitions(-DFEATURE_ISYM_READER)
@@ -160,7 +163,9 @@ add_definitions(-DFEATURE_READYTORUN)
160163

161164
set(FEATURE_READYTORUN 1)
162165

163-
add_compile_definitions(FEATURE_REJIT)
166+
if(FEATURE_REJIT)
167+
add_compile_definitions(FEATURE_REJIT)
168+
endif()
164169

165170
if (CLR_CMAKE_HOST_UNIX AND CLR_CMAKE_TARGET_UNIX)
166171
add_definitions(-DFEATURE_REMOTE_PROC_MEM)
@@ -174,7 +179,11 @@ if (NOT CLR_CMAKE_HOST_ANDROID)
174179
add_definitions(-DFEATURE_SVR_GC)
175180
endif(NOT CLR_CMAKE_HOST_ANDROID)
176181
add_definitions(-DFEATURE_SYMDIFF)
177-
add_compile_definitions(FEATURE_TIERED_COMPILATION)
182+
183+
if (FEATURE_TIERED_COMPILATION)
184+
add_compile_definitions(FEATURE_TIERED_COMPILATION)
185+
endif(FEATURE_TIERED_COMPILATION)
186+
178187
add_compile_definitions(FEATURE_PGO)
179188
if (CLR_CMAKE_TARGET_ARCH_AMD64)
180189
# Enable the AMD64 Unix struct passing JIT-EE interface for all AMD64 platforms, to enable altjit.

src/coreclr/clrfeatures.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
if (NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_MACCATALYST)
22
set(FEATURE_JIT 1)
3+
set(FEATURE_TIERED_COMPILATION 1)
4+
set(FEATURE_REJIT 1)
35
endif()
46

57
if (CLR_CMAKE_TARGET_ARCH_WASM OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_MACCATALYST)
@@ -39,6 +41,7 @@ if(NOT DEFINED FEATURE_INTERPRETER)
3941
set(FEATURE_INTERPRETER 0)
4042
elseif(CLR_CMAKE_TARGET_ARCH_WASM)
4143
set(FEATURE_INTERPRETER 1)
44+
set(FEATURE_PORTABLE_ENTRYPOINTS 1)
4245
else()
4346
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
4447
set(FEATURE_INTERPRETER $<IF:$<CONFIG:Debug,Checked>,1,0>)

src/coreclr/interpreter/compiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ int32_t InterpCompiler::GetDataForHelperFtn(CorInfoHelpFunc ftn)
22332233

22342234
static_assert(sizeof(InterpHelperData) == sizeof(int32_t), "InterpHelperData must be the same size as an int32_t");
22352235

2236-
InterpHelperData result;
2236+
InterpHelperData result{};
22372237
result.accessType = ftnLookup.accessType;
22382238
int32_t dataItemIndex = GetDataItemIndex(ftnLookup.addr);
22392239
result.addressDataItemIndex = dataItemIndex;
@@ -6577,8 +6577,8 @@ void InterpCompiler::PrintPointer(void* pointer)
65776577

65786578
void InterpCompiler::PrintHelperFtn(int32_t _data)
65796579
{
6580-
InterpHelperData data;
6581-
memcpy(&data, &_data, sizeof(int32_t));
6580+
InterpHelperData data{};
6581+
memcpy(&data, &_data, sizeof(_data));
65826582

65836583
void *helperAddr = GetDataItemAtIndex(data.addressDataItemIndex);
65846584
PrintPointer(helperAddr);

src/coreclr/interpreter/interpretershared.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ struct InterpMethod
3030
InterpMethod *self;
3131
#endif
3232
CORINFO_METHOD_HANDLE methodHnd;
33-
int32_t argsSize, allocaSize;
33+
int32_t argsSize;
34+
int32_t allocaSize;
3435
void** pDataItems;
3536
// This stub is used for calling the interpreted method from JITted/AOTed code
3637
CallStubHeader *pCallStub;

src/coreclr/vm/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ set(VM_SOURCES_DAC_AND_WKS_COMMON
112112
peimage.cpp
113113
perfmap.cpp
114114
pgo.cpp
115+
precode_portable.cpp
115116
precode.cpp
116117
prestub.cpp
117118
readytorunstandalonemethodmetadata.cpp
@@ -215,6 +216,7 @@ set(VM_HEADERS_DAC_AND_WKS_COMMON
215216
peimagelayout.inl
216217
perfmap.h
217218
pgo.h
219+
precode_portable.hpp
218220
precode.h
219221
rejit.h
220222
rejit.inl

src/coreclr/vm/appdomain.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,8 +1549,6 @@ class AppDomain final
15491549

15501550
#endif
15511551

1552-
#if defined(FEATURE_TIERED_COMPILATION)
1553-
15541552
public:
15551553
TieredCompilationManager * GetTieredCompilationManager()
15561554
{
@@ -1561,8 +1559,6 @@ class AppDomain final
15611559
private:
15621560
TieredCompilationManager m_tieredCompilationManager;
15631561

1564-
#endif
1565-
15661562
friend struct cdac_data<AppDomain>;
15671563
}; // class AppDomain
15681564

src/coreclr/vm/callhelpers.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ void CopyReturnedFpStructFromRegisters(void* dest, UINT64 returnRegs[2], FpStruc
180180
#endif // TARGET_RISCV64 || TARGET_LOONGARCH64
181181

182182
// Helper for VM->managed calls with simple signatures.
183-
void * DispatchCallSimple(
184-
SIZE_T *pSrc,
185-
DWORD numStackSlotsToCopy,
186-
PCODE pTargetAddress,
187-
DWORD dwDispatchCallSimpleFlags)
183+
void* DispatchCallSimple(
184+
SIZE_T *pSrc,
185+
DWORD numStackSlotsToCopy,
186+
PCODE pTargetAddress,
187+
DWORD dwDispatchCallSimpleFlags)
188188
{
189189
CONTRACTL
190190
{

0 commit comments

Comments
 (0)