|
26 | 26 |
|
27 | 27 | class CTimer : public Engine { |
28 | 28 | private: |
29 | | - // Count of signal handlers currently executing past the _enabled check. |
30 | | - // drainInflight() waits for this to reach zero before JFR teardown, closing |
31 | | - // the TOCTOU window between the _enabled check and JFR buffer access. |
32 | | - // Placed on its own cache line to avoid false sharing with _enabled: |
33 | | - // _enabled is read-only on the hot path; _inflight is read-write. |
34 | | - alignas(64) static int _inflight; |
35 | | - |
36 | 29 | // cppcheck-suppress unusedPrivateFunction |
37 | 30 | static void signalHandler(int signo, siginfo_t *siginfo, void *ucontext); |
38 | 31 |
|
@@ -66,50 +59,10 @@ class CTimer : public Engine { |
66 | 59 | __atomic_store_n(&_enabled, enabled, __ATOMIC_RELEASE); |
67 | 60 | } |
68 | 61 |
|
69 | | - // In-flight handler tracking accessors (used by InflightGuard). |
70 | | - // ACQUIRE on increment / RELEASE on decrement so drainInflight() observes |
71 | | - // all handler-side writes before observing the counter at zero. |
72 | | - static void enterHandler() { |
73 | | - __atomic_fetch_add(&_inflight, 1, __ATOMIC_ACQUIRE); |
74 | | - } |
75 | | - static void exitHandler() { |
76 | | - __atomic_fetch_sub(&_inflight, 1, __ATOMIC_RELEASE); |
77 | | - } |
78 | | - static bool hasInflightHandlers() { |
79 | | - return __atomic_load_n(&_inflight, __ATOMIC_ACQUIRE) > 0; |
80 | | - } |
81 | | - |
82 | | - // Spin until all signal handlers that passed the _enabled=true check have |
83 | | - // returned. Must be called with _enabled already false (after disableEngines()), |
84 | | - // before any JFR teardown that handlers could race against. |
85 | | - // Returns true if all handlers drained successfully, false if timeout fired. |
86 | | - // Caller must NOT proceed with JFR teardown if this returns false. |
87 | | - static bool drainInflight(); |
88 | | - |
89 | 62 | // Get the signal number used by CTimer (0 if not initialized) |
90 | 63 | static int getSignal() { return _signal; } |
91 | 64 | }; |
92 | 65 |
|
93 | | -// RAII guard for CTimer signal handler in-flight tracking. |
94 | | -// Increments the in-flight counter on construction and decrements on destruction, |
95 | | -// ensuring the counter is always balanced regardless of which exit path the |
96 | | -// handler takes. The counter (CTimer::_inflight) is cache-line-aligned to avoid |
97 | | -// false sharing with _enabled, minimizing cache line bouncing. |
98 | | -// |
99 | | -// Usage (at the start of CTimer signal handlers): |
100 | | -// InflightGuard inflight; |
101 | | -class InflightGuard { |
102 | | -public: |
103 | | - InflightGuard() { CTimer::enterHandler(); } |
104 | | - ~InflightGuard() { CTimer::exitHandler(); } |
105 | | - |
106 | | - // Non-copyable, non-movable |
107 | | - InflightGuard(const InflightGuard&) = delete; |
108 | | - InflightGuard& operator=(const InflightGuard&) = delete; |
109 | | - InflightGuard(InflightGuard&&) = delete; |
110 | | - InflightGuard& operator=(InflightGuard&&) = delete; |
111 | | -}; |
112 | | - |
113 | 66 | // A CPU-time engine that reuses CTimer's per-thread timer_create / SIGPROF |
114 | 67 | // dispatch, but instead of walking the stack in the signal handler delegates |
115 | 68 | // the walk to HotSpot's JFR RequestStackTrace JVMTI extension. The sampled |
@@ -141,19 +94,6 @@ class CTimer : public Engine { |
141 | 94 | } |
142 | 95 |
|
143 | 96 | static bool supported() { return false; } |
144 | | - |
145 | | - // No-op on non-Linux platforms |
146 | | - static bool drainInflight() { return true; } |
147 | | - static bool hasInflightHandlers() { return false; } |
148 | | -}; |
149 | | - |
150 | | -// No-op InflightGuard on non-Linux platforms where CTimer is unavailable. |
151 | | -class InflightGuard { |
152 | | -public: |
153 | | - InflightGuard() {} |
154 | | - ~InflightGuard() {} |
155 | | - InflightGuard(const InflightGuard&) = delete; |
156 | | - InflightGuard& operator=(const InflightGuard&) = delete; |
157 | 97 | }; |
158 | 98 |
|
159 | 99 | class CTimerJvmti : public Engine { |
|
0 commit comments