After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 693676 - test GObject Class failure
test GObject Class failure
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
1.35.x
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
: 693695 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-02-12 20:08 UTC by darkxst
Modified: 2017-04-01 20:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
closure: Fix reference counting of closures, unbreak tests (2.72 KB, patch)
2013-02-13 14:53 UTC, Stef Walter
reviewed Details | Review
object: Register auto generated GType classes as static types (7.21 KB, patch)
2013-02-13 14:53 UTC, Stef Walter
committed Details | Review
closure: Fix reference counting of closures, unbreak tests (2.22 KB, patch)
2013-02-13 15:02 UTC, Stef Walter
committed Details | Review

Description darkxst 2013-02-12 20:08:29 UTC
gjs make test is leaking 2 closures in 'testDerived' of testGObjectclass.

JS LOG: running test testDerived
      JS CTX: Script evaluation succeeded
      JS CTX: Script returned integer code 0
   JS MEMORY: Memory report: before destroying context
   JS MEMORY:   116 objects currently alive
   JS MEMORY:            boxed = 4
   JS MEMORY:           gerror = 0
   JS MEMORY:          closure = 9
   JS MEMORY:         database = 0
   JS MEMORY:         function = 71
   JS MEMORY:         importer = 2
   JS MEMORY:               ns = 4
   JS MEMORY:           object = 19
   JS MEMORY:            param = 5
   JS MEMORY:             repo = 1
   JS MEMORY:        resultset = 0
   JS MEMORY:         weakhash = 0
   JS MEMORY:        interface = 1
      JS CTX: Destroying JS context
   JS MEMORY: Memory report: after destroying context
   JS MEMORY:   2 objects currently alive
   JS MEMORY:            boxed = 0
   JS MEMORY:           gerror = 0
   JS MEMORY:          closure = 2
   JS MEMORY:         database = 0
   JS MEMORY:         function = 0
   JS MEMORY:         importer = 0
   JS MEMORY:               ns = 0
   JS MEMORY:           object = 0
   JS MEMORY:            param = 0
   JS MEMORY:             repo = 0
   JS MEMORY:        resultset = 0
   JS MEMORY:         weakhash = 0
   JS MEMORY:        interface = 0
Comment 1 Giovanni Campagna 2013-02-13 13:55:08 UTC
*** Bug 693695 has been marked as a duplicate of this bug. ***
Comment 2 Giovanni Campagna 2013-02-13 13:56:51 UTC
This used to work fine, because the closures are destroyed in the class_finalize function.

My bet is some change in glib that broke dynamic types, following the trend of keeping all GTypeModules resident.
Comment 3 Stef Walter 2013-02-13 14:53:50 UTC
Created attachment 235884 [details] [review]
closure: Fix reference counting of closures, unbreak tests

Glib no longer finalizes type classes, plugin or not. So essentially gjs
will 'leak' the classes that it registers in gjs_register_type().

GClosures that have been associated with such leaked classes (eg: through
g_signal_override_class_closure()) will leak too. However the javascript
context, object and runtime associated with the Closure do not leak.

Make our memory reference tracking for closures to track the javascript
related contents of the Closure and not the GClosure itself.

https://bugzilla.gnome.org/show_bug.cgi?id=693695
Comment 4 Stef Walter 2013-02-13 14:53:54 UTC
Created attachment 235885 [details] [review]
object: Register auto generated GType classes as static types

Glib no longer allows unloading/finalizing of type classes regardless
of whether they're static or plugin. So just use static classes here,
as they'll 'leak' anyway.
Comment 5 Stef Walter 2013-02-13 15:02:12 UTC
Created attachment 235887 [details] [review]
closure: Fix reference counting of closures, unbreak tests

Glib no longer finalizes type classes, plugin or not. So essentially gjs
will 'leak' the classes that it registers in gjs_register_type().

GClosures that have been associated with such leaked classes (eg: through
g_signal_override_class_closure()) will leak too. However the javascript
context, object and runtime associated with the Closure do not leak.

Make our memory reference tracking for closures to track the javascript
related contents of the Closure and not the GClosure itself.
Comment 6 Giovanni Campagna 2013-02-13 15:17:39 UTC
Review of attachment 235884 [details] [review]:

::: gi/closure.c
@@ +245,1 @@
     GJS_DEC_COUNTER(closure);

Aren't we decrementing the counter twice here?
Comment 7 Stef Walter 2013-02-13 15:21:04 UTC
(In reply to comment #6)
> Review of attachment 235884 [details] [review]:
> 
> ::: gi/closure.c
> @@ +245,1 @@
>      GJS_DEC_COUNTER(closure);
> 
> Aren't we decrementing the counter twice here?

No, there are two invalidation paths. See g_closure_add_invalidate_notifier() calls in gjs_closure_new(). This is probably ripe for some cleanup.
Comment 8 Giovanni Campagna 2013-02-13 15:21:50 UTC
Review of attachment 235885 [details] [review]:

Ok
Comment 9 Giovanni Campagna 2013-02-13 15:23:31 UTC
Review of attachment 235887 [details] [review]:

Oh ugh...
Comment 10 Stef Walter 2013-02-13 15:25:07 UTC
FWIW, on IRC Ryan was suggesting holding off applying the static types patch, since he's not sure if this change in glib is going to 'stick'.
Comment 11 Giovanni Campagna 2013-02-13 15:28:10 UTC
(In reply to comment #10)
> FWIW, on IRC Ryan was suggesting holding off applying the static types patch,
> since he's not sure if this change in glib is going to 'stick'.

Even then, the dynamic type was just a hack, because types were not registered inside the load() virtual, so you could not really unregister a type and register a new one with the same name.
So, once the closure count is fixed, we can go back to static types.

Or even better, we can stop using GClosures inside our tests, and override the virtual function instead...
Comment 12 Stef Walter 2013-02-13 15:52:32 UTC
(In reply to comment #11)
> (In reply to comment #10)
> > FWIW, on IRC Ryan was suggesting holding off applying the static types patch,
> > since he's not sure if this change in glib is going to 'stick'.
> 
> Even then, the dynamic type was just a hack, because types were not registered
> inside the load() virtual, so you could not really unregister a type and
> register a new one with the same name.
> So, once the closure count is fixed, we can go back to static types.

So should I merge both patches?

> Or even better, we can stop using GClosures inside our tests, and override the
> virtual function instead...

The actual cause was providing default implementations of these signals in the testGObjectClass.js file:

    on_run_last: function() {
        this._run_last_callback();
    },

    on_empty: function() {
        this.empty_called = true;
    }
Comment 13 Stef Walter 2013-02-13 15:54:38 UTC
Comment on attachment 235887 [details] [review]
closure: Fix reference counting of closures, unbreak tests

Attachment 235887 [details] pushed as 03ac265 - closure: Fix reference counting of closures, unbreak tests
Comment 14 Giovanni Campagna 2013-02-13 16:18:43 UTC
(In reply to comment #12)
> [...]
> 
> The actual cause was providing default implementations of these signals in the
> testGObjectClass.js file:
> 
>     on_run_last: function() {
>         this._run_last_callback();
>     },
> 
>     on_empty: function() {
>         this.empty_called = true;
>     }

Oh right, and these signals are created by gjs so they don't have matching vfuncs.
Ok, ignore my comment then.
Comment 15 Philip Chimento 2017-04-01 20:13:56 UTC
Cosimo and I discussed this and we think the patch is an improvement,
regardless of whether the change in GLib went through or not. The type module
code could never be unloaded anyway, since it called g_assert_not_reached() in
its unload function.

This doesn't seem to break anything. It's early in the cycle so if it turns out
otherwise, there is plenty of time to revert it.

Attachment 235885 [details] pushed as 0fe780c - object: Register auto generated GType classes as static types