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
4 changes: 2 additions & 2 deletions src/coreclr/vm/amd64/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,9 @@ 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 0xb50
#define OFFSETOF__Thread__m_pInterpThreadContext 0xb48
#else // TARGET_UNIX
#define OFFSETOF__Thread__m_pInterpThreadContext 0xba8
#define OFFSETOF__Thread__m_pInterpThreadContext 0xba0
#endif // TARGET_UNIX
ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_pInterpThreadContext == offsetof(Thread, m_pInterpThreadContext))

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/arm64/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ 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 0xb78
#define OFFSETOF__Thread__m_pInterpThreadContext 0xb70
#else // TARGET_UNIX
#define OFFSETOF__Thread__m_pInterpThreadContext 0xba0
#define OFFSETOF__Thread__m_pInterpThreadContext 0xb98
#endif // TARGET_UNIX
ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_pInterpThreadContext == offsetof(Thread, m_pInterpThreadContext))

Expand Down
10 changes: 3 additions & 7 deletions src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,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 (
Expand All @@ -128,9 +127,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);
Expand Down
23 changes: 1 addition & 22 deletions src/coreclr/vm/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,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?
Expand Down Expand Up @@ -3748,32 +3748,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<ULONG> 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;
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/vm/threadsuspend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,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
Expand Down Expand Up @@ -2233,6 +2237,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;
}
Expand Down
Loading