glib/gobject
Thomas Haller 482e078083 gobject: avoid GLIB_PRIVATE_CALL() for g_datalist_id_update_atomic()
Cache the function pointer for g_datalist_id_update_atomic() in a static
variable in "gobject.c" to avoid looking it up repeatedly.

g_datalist_id_update_atomic() is anyway internal API. Like GData is not
a useful data structure in general, this function is only useful for
something specific inside GObject.

It can be easily seen that _local_g_datalist_id_update_atomic is never
read without having a GObject at hand (because we call it on
`&object->qdata`). Thus initializing the pointer in
g_object_do_class_init() (under lock) is sufficient to ensure
thread-safe initialization. Note that we still set the pointer via
g_atomic_pointer_set(). This is done in an attempt to pacify thread
sanatizer.

Note that also with LTO enabled, the GLIB_PRIVATE_CALL() call cannot be
inlined. Previously we get:

0000000000011300 <_weak_ref_set>:
   ...
   1131d:       e8 ee 03 ff ff          call   1710 <glib__private__@plt>
   11322:       8b 35 0c b2 05 00       mov    0x5b20c(%rip),%esi        # 6c534 <quark_weak_locations.lto_priv.0>
   11328:       4c 89 e1                mov    %r12,%rcx
   1132b:       49 8d 7c 24 10          lea    0x10(%r12),%rdi
   11330:       48 8d 15 b9 42 ff ff    lea    -0xbd47(%rip),%rdx        # 55f0 <weak_ref_data_get_or_create_cb.lto_priv.0>
   11337:       ff 90 80 00 00 00       call   *0x80(%rax)

afterwards:

0000000000011300 <_weak_ref_set>:
   ...
   1131d:       48 8d 7e 10             lea    0x10(%rsi),%rdi
   11321:       48 89 f1                mov    %rsi,%rcx
   11324:       48 8d 15 c5 42 ff ff    lea    -0xbd3b(%rip),%rdx        # 55f0 <weak_ref_data_get_or_create_cb.lto_priv.0>
   1132b:       8b 35 0b b2 05 00       mov    0x5b20b(%rip),%esi        # 6c53c <quark_weak_locations.lto_priv.0>
   11331:       ff 15 f9 b1 05 00       call   *0x5b1f9(%rip)        # 6c530 <_local_g_datalist_id_update_atomic.lto_priv.0>

Also note, that the point here is not to optimize _weak_ref_set() (which
is not a hot path). There is work in progress that will use
g_datalist_id_update_atomic() for more purposes (and during more
relevant code paths of GObject).
2025-02-24 17:41:18 +01:00
..
2023-10-16 23:34:04 +01:00
2023-12-31 09:09:48 +00:00
2022-10-13 20:53:56 -04:00
2023-10-16 23:35:05 +01:00
2023-12-31 09:09:48 +00:00
2022-10-13 20:53:56 -04:00
2023-10-16 23:34:24 +01:00
2022-10-13 20:53:56 -04:00
2022-10-13 20:53:56 -04:00
2025-02-03 14:38:24 +00:00
2025-02-10 10:26:42 +01:00
2023-10-23 11:26:53 +01:00
2022-10-13 20:53:56 -04:00