src: fix DTrace GC callbacks DCHECKs and add cleanup · nodejs/node@f47adfb (original) (raw)
`@@ -248,15 +248,19 @@ void DTRACE_HTTP_CLIENT_RESPONSE(const FunctionCallbackInfo& args) {
`
248
248
`NODE_HTTP_CLIENT_RESPONSE(&conn, conn.remote, conn.port, conn.fd);
`
249
249
`}
`
250
250
``
251
``
-
252
``
`-
void dtrace_gc_start(Isolate* isolate, GCType type, GCCallbackFlags flags) {
`
``
251
`+
void dtrace_gc_start(Isolate* isolate,
`
``
252
`+
GCType type,
`
``
253
`+
GCCallbackFlags flags,
`
``
254
`+
void* data) {
`
253
255
`// Previous versions of this probe point only logged type and flags.
`
254
256
`// That's why for reasons of backwards compatibility the isolate goes last.
`
255
257
`NODE_GC_START(type, flags, isolate);
`
256
258
`}
`
257
259
``
258
``
-
259
``
`-
void dtrace_gc_done(Isolate* isolate, GCType type, GCCallbackFlags flags) {
`
``
260
`+
void dtrace_gc_done(Isolate* isolate,
`
``
261
`+
GCType type,
`
``
262
`+
GCCallbackFlags flags,
`
``
263
`+
void* data) {
`
260
264
`// Previous versions of this probe point only logged type and flags.
`
261
265
`// That's why for reasons of backwards compatibility the isolate goes last.
`
262
266
`NODE_GC_DONE(type, flags, isolate);
`
`@@ -272,8 +276,16 @@ void InitDTrace(Environment* env) {
`
272
276
` }
`
273
277
`#endif
`
274
278
``
275
``
`-
env->isolate()->AddGCPrologueCallback(dtrace_gc_start);
`
276
``
`-
env->isolate()->AddGCEpilogueCallback(dtrace_gc_done);
`
``
279
`+
// We need to use the variant of GC callbacks that takes data to
`
``
280
`+
// avoid running into DCHECKs when multiple Environments try to add
`
``
281
`+
// the same callback to the same isolate multiple times.
`
``
282
`+
env->isolate()->AddGCPrologueCallback(dtrace_gc_start, env);
`
``
283
`+
env->isolate()->AddGCEpilogueCallback(dtrace_gc_done, env);
`
``
284
`+
env->AddCleanupHook([](void* data) {
`
``
285
`+
Environment* env = static_cast<Environment*>(data);
`
``
286
`+
env->isolate()->RemoveGCPrologueCallback(dtrace_gc_start, env);
`
``
287
`+
env->isolate()->RemoveGCEpilogueCallback(dtrace_gc_done, env);
`
``
288
`+
}, env);
`
277
289
`}
`
278
290
``
279
291
`void InitializeDTrace(Local target,
`