diff --git a/src/coreclr/vm/amd64/asmconstants.h b/src/coreclr/vm/amd64/asmconstants.h index 6f8b50e5f87def..5a1dd76dd21240 100644 --- a/src/coreclr/vm/amd64/asmconstants.h +++ b/src/coreclr/vm/amd64/asmconstants.h @@ -570,15 +570,15 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__InterpMethod__pCallStub == offsetof(InterpMethod #ifdef TARGET_UNIX #ifdef _DEBUG -#define OFFSETOF__Thread__m_pInterpThreadContext 0xb00 +#define OFFSETOF__Thread__m_pInterpThreadContext 0xaf8 #else // _DEBUG -#define OFFSETOF__Thread__m_pInterpThreadContext 0x298 +#define OFFSETOF__Thread__m_pInterpThreadContext 0x290 #endif // _DEBUG #else // TARGET_UNIX #ifdef _DEBUG -#define OFFSETOF__Thread__m_pInterpThreadContext 0xb58 +#define OFFSETOF__Thread__m_pInterpThreadContext 0xb50 #else // _DEBUG -#define OFFSETOF__Thread__m_pInterpThreadContext 0x2e0 +#define OFFSETOF__Thread__m_pInterpThreadContext 0x2d8 #endif // _DEBUG #endif // TARGET_UNIX ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_pInterpThreadContext == offsetof(Thread, m_pInterpThreadContext)) diff --git a/src/coreclr/vm/arm/asmconstants.h b/src/coreclr/vm/arm/asmconstants.h index 8a994cd700eab7..fd810c0ec5ec86 100644 --- a/src/coreclr/vm/arm/asmconstants.h +++ b/src/coreclr/vm/arm/asmconstants.h @@ -212,7 +212,7 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__ThreadLocalInfo__m_pThread == offsetof(ThreadLoc ASMCONSTANTS_C_ASSERT(OFFSETOF__InterpMethod__pCallStub == offsetof(InterpMethod, pCallStub)) #ifdef TARGET_UNIX -#define OFFSETOF__Thread__m_pInterpThreadContext 0x634 +#define OFFSETOF__Thread__m_pInterpThreadContext 0x630 #else // TARGET_UNIX #define OFFSETOF__Thread__m_pInterpThreadContext 0x0 #endif // TARGET_UNIX diff --git a/src/coreclr/vm/arm64/asmconstants.h b/src/coreclr/vm/arm64/asmconstants.h index 98ecb5e4885309..9e33e93d31925c 100644 --- a/src/coreclr/vm/arm64/asmconstants.h +++ b/src/coreclr/vm/arm64/asmconstants.h @@ -306,12 +306,12 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__InterpMethod__pCallStub == offsetof(InterpMethod #ifdef TARGET_UNIX #ifdef _DEBUG -#define OFFSETOF__Thread__m_pInterpThreadContext 0xb28 +#define OFFSETOF__Thread__m_pInterpThreadContext 0xb20 #else // _DEBUG -#define OFFSETOF__Thread__m_pInterpThreadContext 0x2c0 +#define OFFSETOF__Thread__m_pInterpThreadContext 0x2b8 #endif // _DEBUG #else // TARGET_UNIX -#define OFFSETOF__Thread__m_pInterpThreadContext 0xb50 +#define OFFSETOF__Thread__m_pInterpThreadContext 0xb48 #endif // TARGET_UNIX ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_pInterpThreadContext == offsetof(Thread, m_pInterpThreadContext)) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.cpp b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.cpp index 8b486c67b678d5..eb5fabdc6c7b54 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.cpp +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.cpp @@ -127,10 +127,9 @@ walk_managed_stack_for_threads ( // Walk the stack and write it out as an event. if (ep_rt_coreclr_walk_managed_stack_for_thread (target_thread, current_stack_contents) && !ep_stack_contents_is_empty (current_stack_contents)) { - // Set the payload. If the GC mode on suspension > 0, then the thread was in cooperative mode. - // Even though there are some cases where this is not managed code, we assume it is managed code here. - // If the GC mode on suspension == 0 then the thread was in preemptive mode, which we qualify as external here. - uint32_t payload_data = target_thread->GetGCModeOnSuspension () ? EP_SAMPLE_PROFILER_SAMPLE_TYPE_MANAGED : EP_SAMPLE_PROFILER_SAMPLE_TYPE_EXTERNAL; + // Set the payload. If the thread is trapped for suspension, it was in cooperative mode (managed code). + // Otherwise, it was in preemptive mode (external code). + uint32_t payload_data = target_thread->HasThreadState (Thread::TS_SuspensionTrapped) ? EP_SAMPLE_PROFILER_SAMPLE_TYPE_MANAGED : EP_SAMPLE_PROFILER_SAMPLE_TYPE_EXTERNAL; // Write the sample. ep_write_sample_profile_event ( @@ -141,9 +140,6 @@ walk_managed_stack_for_threads ( (uint8_t *)&payload_data, sizeof (payload_data)); } - - // Reset the GC mode. - target_thread->ClearGCModeOnSuspension (); } ep_stack_contents_fini (current_stack_contents); diff --git a/src/coreclr/vm/riscv64/asmconstants.h b/src/coreclr/vm/riscv64/asmconstants.h index 12efe007f07c4f..7a892c5a918e7a 100644 --- a/src/coreclr/vm/riscv64/asmconstants.h +++ b/src/coreclr/vm/riscv64/asmconstants.h @@ -242,7 +242,7 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__ThreadLocalInfo__m_pThread == offsetof(ThreadLoc #endif ASMCONSTANTS_C_ASSERT(OFFSETOF__InterpMethod__pCallStub == offsetof(InterpMethod, pCallStub)) -#define OFFSETOF__Thread__m_pInterpThreadContext 0xB28 +#define OFFSETOF__Thread__m_pInterpThreadContext 0xB20 ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_pInterpThreadContext == offsetof(Thread, m_pInterpThreadContext)) #define OFFSETOF__InterpThreadContext__pStackPointer 0x10 diff --git a/src/coreclr/vm/threads.h b/src/coreclr/vm/threads.h index f54ee613485dc6..7250e49721cf4f 100644 --- a/src/coreclr/vm/threads.h +++ b/src/coreclr/vm/threads.h @@ -506,7 +506,7 @@ class Thread TS_AbortRequested = 0x00000001, // Abort the thread - // unused = 0x00000002, + TS_SuspensionTrapped = 0x00000002, // Thread is trapped waiting for suspension to complete (was in managed code) TS_GCSuspendRedirected = 0x00000004, // ThreadSuspend::SuspendRuntime has redirected the thread to suspention routine. TS_DebugSuspendPending = 0x00000008, // Is the debugger suspending threads? @@ -3584,32 +3584,11 @@ class Thread #ifdef FEATURE_PERFTRACING private: - // SampleProfiler thread state. This is set on suspension and cleared before restart. - // True if the thread was in cooperative mode. False if it was in preemptive when the suspension started. - Volatile m_gcModeOnSuspension; - // The activity ID for the current thread. // An activity ID of zero means the thread is not executing in the context of an activity. GUID m_activityId; public: - bool GetGCModeOnSuspension() - { - LIMITED_METHOD_CONTRACT; - return m_gcModeOnSuspension != 0U; - } - - void SaveGCModeOnSuspension() - { - LIMITED_METHOD_CONTRACT; - m_gcModeOnSuspension = m_fPreemptiveGCDisabled; - } - - void ClearGCModeOnSuspension() - { - m_gcModeOnSuspension = 0; - } - LPCGUID GetActivityId() const { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/threadsuspend.cpp b/src/coreclr/vm/threadsuspend.cpp index 0dc93643a5985d..dafb078348c34a 100644 --- a/src/coreclr/vm/threadsuspend.cpp +++ b/src/coreclr/vm/threadsuspend.cpp @@ -2138,6 +2138,10 @@ void Thread::RareDisablePreemptiveGC() if (ThreadStore::IsTrappingThreadsForSuspension()) { + // Mark that this thread is trapped for suspension. + // Used by the sample profiler to determine this thread was in managed code. + SetThreadState(TS_SuspensionTrapped); + EnablePreemptiveGC(); #ifdef PROFILING_SUPPORTED @@ -2177,6 +2181,9 @@ void Thread::RareDisablePreemptiveGC() // disable preemptive gc. m_fPreemptiveGCDisabled.StoreWithoutBarrier(1); + // Clear the suspension trapped flag now that we're resuming. + ResetThreadState(TS_SuspensionTrapped); + // check again if we have something to do continue; }