Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace System
{
public static partial class Environment
{
public static extern int CurrentManagedThreadId
public static int CurrentManagedThreadId
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Threading.ManagedThreadId.Current;
}

// Terminates this process with the given exit code.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
JITHELPER(CORINFO_HELP_TAILCALL, NULL, METHOD__NIL)
#endif

JITHELPER(CORINFO_HELP_GETCURRENTMANAGEDTHREADID, JIT_GetCurrentManagedThreadId, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_GETCURRENTMANAGEDTHREADID, NULL, METHOD__ENVIRONMENT__CURRENT_MANAGED_THREAD_ID)

JITHELPER(CORINFO_HELP_INIT_PINVOKE_FRAME, JIT_InitPInvokeFrame, METHOD__NIL)

Expand Down
16 changes: 15 additions & 1 deletion src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4314,7 +4314,21 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
// drop get_CurrentThread() call
impPopStack();
call->ReplaceWith(gtNewNothingNode(), this);
retNode = gtNewHelperCallNode(CORINFO_HELP_GETCURRENTMANAGEDTHREADID, TYP_INT);
GenTreeCall* tidCall = gtNewHelperCallNode(CORINFO_HELP_GETCURRENTMANAGEDTHREADID, TYP_INT);
impConvertToUserCallAndMarkForInlining(tidCall);
if (tidCall->IsInlineCandidate())
{
// The helper was converted into an inlinable user call; spill it to its own
// statement and hand back a GT_RET_EXPR so the inliner can fold the property.
impAppendTree(tidCall, CHECK_SPILL_ALL, impCurStmtDI, false);
GenTreeRetExpr* retExpr = gtNewInlineCandidateReturnExpr(tidCall, TYP_INT);
tidCall->GetSingleInlineCandidateInfo()->retExpr = retExpr;
retNode = retExpr;
}
else
{
retNode = tidCall;
}
Comment thread
VSadov marked this conversation as resolved.
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ DEFINE_CLASS(RUNE, Text, Rune)
DEFINE_CLASS(ENUM, System, Enum)

DEFINE_CLASS(ENVIRONMENT, System, Environment)
DEFINE_METHOD(ENVIRONMENT, CURRENT_MANAGED_THREAD_ID, get_CurrentManagedThreadId, NoSig)
DEFINE_METHOD(ENVIRONMENT, GET_RESOURCE_STRING, GetResourceString, SM_PtrChar_PtrStr_PtrException_RetVoid)
DEFINE_METHOD(ENVIRONMENT, INITIALIZE_COMMAND_LINE_ARGS, InitializeCommandLineArgs, SM_PtrChar_Int_PtrPtrChar_PtrArrStr_PtrException_RetVoid)
DEFINE_METHOD(ENVIRONMENT, CALL_ENTRY_POINT, CallEntryPoint, SM_IntPtr_PtrArrStr_PtrInt_Bool_PtrException_RetVoid)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ FCFuncStart(gStringFuncs)
FCFuncEnd()

FCFuncStart(gEnvironmentFuncs)
FCFuncElement("get_CurrentManagedThreadId", JIT_GetCurrentManagedThreadId)
FCFuncElement("set_ExitCode", EnvironmentNative::SetExitCode)
FCFuncElement("get_ExitCode", EnvironmentNative::GetExitCode)
FCFuncEnd()
Expand Down
9 changes: 0 additions & 9 deletions src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,15 +1202,6 @@ void JIT_RareDisableHelper()
}
}

FCIMPL0(INT32, JIT_GetCurrentManagedThreadId)
{
FCALL_CONTRACT;

Thread * pThread = GetThread();
return pThread->GetThreadId();
}
FCIMPLEND

/*********************************************************************/
/* we don't use HCIMPL macros because we don't want the overhead even in debug mode */

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ EXTERN_C FCDECL1(void*, JIT_GetGCStaticBase_Helper, MethodTable *pMT);
EXTERN_C void DoJITFailFast();
EXTERN_C FCDECL0(void, JIT_FailFast);

FCDECL0(int, JIT_GetCurrentManagedThreadId);

EXTERN_C void ReversePInvokeBadTransition();

#if !defined(FEATURE_USE_ASM_GC_WRITE_BARRIERS) && defined(FEATURE_COUNT_GC_WRITE_BARRIERS)
Expand Down
Loading