diff --git a/include/ircd/js/context.h b/include/ircd/js/context.h index 0d22f6b1a..af9ceae0d 100644 --- a/include/ircd/js/context.h +++ b/include/ircd/js/context.h @@ -117,6 +117,8 @@ JSCompartment *current_compartment(context &); JSCompartment *current_compartment(); JSObject *current_global(context &c); JSObject *current_global(); // thread_local +JS::Zone *current_zone(context &); +JS::Zone *current_zone(); // Memory void set(context &c, const JSGCParamKey &, const uint32_t &val); @@ -183,6 +185,18 @@ pending_exception(const context &c) return JS_IsExceptionPending(c); } +inline JS::Zone * +current_zone() +{ + return current_zone(*cx); +} + +inline JS::Zone * +current_zone(context &c) +{ + return ::js::GetContextZone(c); +} + inline JSObject * current_global() { @@ -195,6 +209,18 @@ current_global(context &c) return JS::CurrentGlobalOrNull(c); } +inline JSCompartment * +current_compartment() +{ + return current_compartment(*cx); +} + +inline JSCompartment * +current_compartment(context &c) +{ + return ::js::GetContextCompartment(c); +} + inline void priv(context &c, privdata *const &ptr) diff --git a/include/ircd/js/runtime.h b/include/ircd/js/runtime.h index 799185612..9b97502d0 100644 --- a/include/ircd/js/runtime.h +++ b/include/ircd/js/runtime.h @@ -34,6 +34,8 @@ class runtime static void handle_gc(JSRuntime *, JSGCStatus, void *) noexcept; static void handle_finalize(JSFreeOp *, JSFinalizeStatus, bool is_compartment, void *) noexcept; static void handle_telemetry(int id, uint32_t sample, const char *key) noexcept; + static void handle_zone_sweep(JS::Zone *) noexcept; + static void handle_zone_destroy(JS::Zone *) noexcept; static void handle_compartment_name(JSRuntime *, JSCompartment *, char *buf, size_t) noexcept; static void handle_compartment_destroy(JSFreeOp *, JSCompartment *) noexcept; static bool handle_context(JSContext *, uint op, void *) noexcept; diff --git a/ircd/js.cc b/ircd/js.cc index 497fd089e..f5ba4202d 100644 --- a/ircd/js.cc +++ b/ircd/js.cc @@ -2216,18 +2216,6 @@ ircd::js::set(context &c, JS_SetGCParameter(c.runtime(), key, val); } -JSCompartment * -ircd::js::current_compartment() -{ - return current_compartment(*cx); -} - -JSCompartment * -ircd::js::current_compartment(context &c) -{ - return ::js::GetContextCompartment(c); -} - /////////////////////////////////////////////////////////////////////////////// // // ircd/js/timer.h @@ -2410,6 +2398,8 @@ ircd::js::runtime::runtime(const struct opts &opts, JS_SetGCCallback(get(), handle_gc, nullptr); JS_AddFinalizeCallback(get(), handle_finalize, nullptr); JS_SetAccumulateTelemetryCallback(get(), handle_telemetry); + JS_SetSweepZoneCallback(get(), handle_zone_sweep); + JS_SetDestroyZoneCallback(get(), handle_zone_destroy); JS_SetCompartmentNameCallback(get(), handle_compartment_name); JS_SetDestroyCompartmentCallback(get(), handle_compartment_destroy); JS_SetContextCallback(get(), handle_context, nullptr); @@ -2504,9 +2494,11 @@ ircd::js::runtime::handle_compartment_destroy(JSFreeOp *const fop, JSCompartment *const compartment) noexcept { - log.debug("runtime(%p): compartment(%p) destroy: fop(%p)", + log.debug("runtime(%p): compartment: %p %s%sdestroy: fop(%p)", (const void *)(our_runtime(*fop).ptr()), (const void *)compartment, + ::js::IsSystemCompartment(compartment)? "[system] " : "", + ::js::IsAtomsCompartment(compartment)? "[atoms] " : "", (const void *)fop); } @@ -2524,6 +2516,28 @@ noexcept max); } +void +ircd::js::runtime::handle_zone_destroy(JS::Zone *const zone) +noexcept +{ + log.debug("runtime(%p): zone: %p %s%sdestroy", + (const void *)rt, + (const void *)zone, + ::js::IsSystemZone(zone)? "[system] " : "", + ::js::IsAtomsZone(zone)? "[atoms] " : ""); +} + +void +ircd::js::runtime::handle_zone_sweep(JS::Zone *const zone) +noexcept +{ + log.debug("runtime(%p): zone: %p %s%ssweep", + (const void *)rt, + (const void *)zone, + ::js::IsSystemZone(zone)? "[system] " : "", + ::js::IsAtomsZone(zone)? "[atoms] " : ""); +} + void ircd::js::runtime::handle_telemetry(const int id, const uint32_t sample,