Commit ba7fb121 authored by Philip Chimento's avatar Philip Chimento

jsapi-util-root: Add debug_addr() method for pointer types

For GjsMaybeOwned<T> where T is a pointer type, we add a debug_addr()
method which returns the pointer address without triggering a read
barrier. This is needed for debug methods because we want to be able to
debug-log things even after they are marked for sweeping. (The read
barrier will assert in debug mode if the object is already marked for
sweeping.)
parent 132e55c9
......@@ -105,7 +105,7 @@ static void global_context_finalized(JS::HandleFunction func, void* data) {
gjs_debug_closure(
"Context global object destroy notifier on closure %p which calls "
"object %p",
c, c->func.get());
c, c->func.debug_addr());
if (c->func) {
g_assert(c->func == func.get());
......@@ -135,7 +135,7 @@ closure_invalidated(gpointer data,
GJS_DEC_COUNTER(closure);
gjs_debug_closure("Invalidating closure %p which calls function %p",
closure, c->func.get());
closure, c->func.debug_addr());
if (!c->func) {
gjs_debug_closure(" (closure %p already dead, nothing to do)",
......@@ -165,7 +165,7 @@ closure_set_invalid(gpointer data,
Closure *self = &((GjsClosure*) closure)->priv;
gjs_debug_closure("Invalidating signal closure %p which calls function %p",
closure, self->func.get());
closure, self->func.debug_addr());
self->func.prevent_collection();
self->func.reset();
......@@ -217,7 +217,7 @@ gjs_closure_invoke(GClosure *closure,
gjs_debug_closure(
"Closure invocation failed (exception should have been thrown) "
"closure %p function %p",
closure, c->func.get());
closure, c->func.debug_addr());
/* If an exception has been thrown, log it, unless the caller
* explicitly wants to handle it manually (for example to turn it
* into a GError), in which case it replaces the return value
......@@ -320,7 +320,7 @@ GClosure* gjs_closure_new(JSContext* context, JSFunction* callable,
g_closure_add_finalize_notifier(&gc->base, NULL, closure_finalize);
gjs_debug_closure("Create closure %p which calls function %p '%s'", gc,
c->func.get(), description);
c->func.debug_addr(), description);
JS_EndRequest(context);
......
......@@ -215,6 +215,13 @@ public:
}
operator const T(void) const { return get(); }
/* Use debug_addr() only for debug logging, because it is unbarriered. */
template <typename U = T>
GJS_USE const T
debug_addr(std::enable_if_t<std::is_pointer<U>::value>* = nullptr) const {
return m_rooted ? m_thing.root->get() : m_thing.heap.unbarrieredGet();
}
bool
operator==(const T& other) const
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment