Changeset 233071 in webkit


Ignore:
Timestamp:
Jun 21, 2018 11:41:10 PM (6 years ago)
Author:
Carlos Garcia Campos
Message:

[GLIB] improve get_type() fast path in WEBKIT_DEFINE_TYPE
https://bugs.webkit.org/show_bug.cgi?id=186885

Reviewed by Anders Carlsson.

This is a backport of glib commit
https://gitlab.gnome.org/GNOME/glib/commit/e924f777369710221c3e0a9d7bf40392a27d1fa4

"The -fstack-protector-strong used in many distributions by default has a
rather drastic slowdown of the fast path in generated _get_type()
functions using G_DEFINE_* macros. The amount can vary by architecture,
GCC version, and compiler flags.

To work around this, and ensure a higher probability that our fast-path
will match what we had previously, we need to break out the slow-path
(registering the type) into a secondary function that is not a candidate
for inlining.

This ensures that the common case (type registered, return the GType id)
is the hot path and handled in the prologue of the generated assembly even
when -fstack-protector-strong is enabled."

  • wtf/glib/WTFGType.h:
Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r233006 r233071  
     12018-06-21  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GLIB] improve get_type() fast path in WEBKIT_DEFINE_TYPE
     4        https://bugs.webkit.org/show_bug.cgi?id=186885
     5
     6        Reviewed by Anders Carlsson.
     7
     8        This is a backport of glib commit
     9        https://gitlab.gnome.org/GNOME/glib/commit/e924f777369710221c3e0a9d7bf40392a27d1fa4
     10
     11        "The -fstack-protector-strong used in many distributions by default has a
     12        rather drastic slowdown of the fast path in generated _get_type()
     13        functions using G_DEFINE_* macros. The amount can vary by architecture,
     14        GCC version, and compiler flags.
     15
     16        To work around this, and ensure a higher probability that our fast-path
     17        will match what we had previously, we need to break out the slow-path
     18        (registering the type) into a secondary function that is not a candidate
     19        for inlining.
     20
     21        This ensures that the common case (type registered, return the GType id)
     22        is the hot path and handled in the prologue of the generated assembly even
     23        when -fstack-protector-strong is enabled."
     24
     25        * wtf/glib/WTFGType.h:
     26
    1272018-06-20  Yusuke Suzuki  <utatane.tea@gmail.com>
    228
  • trunk/Source/WTF/wtf/glib/WTFGType.h

    r231565 r233071  
    2121
    2222#include <glib.h>
     23#include <wtf/Compiler.h>
    2324
    2425#define WEBKIT_PARAM_READABLE (static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB))
     
    4748\
    4849static void type_name##_class_init(TypeName##Class* klass); \
     50static GType type_name##_get_type_once(void); \
    4951static gpointer type_name##_parent_class = 0; \
    5052static void type_name##_finalize(GObject* object) \
     
    6971    self->priv = priv; \
    7072    new (priv) TypeName##Private(); \
    71 }\
     73} \
     74\
    7275GType type_name##_get_type(void) \
    7376{ \
    7477    static volatile gsize g_define_type_id__volatile = 0; \
    7578    if (g_once_init_enter(&g_define_type_id__volatile)) { \
    76         GType g_define_type_id = \
    77             g_type_register_static_simple( \
    78                 TYPE_PARENT, \
    79                 g_intern_static_string(#TypeName), \
    80                 sizeof(TypeName##Class), \
    81                 (GClassInitFunc)type_name##_class_intern_init, \
    82                 sizeof(TypeName), \
    83                 (GInstanceInitFunc)type_name##_init, \
    84                 (GTypeFlags)flags); \
    85         // Custom code follows.
    86 #define _WEBKIT_DEFINE_TYPE_EXTENDED_END() \
     79        GType g_define_type_id = type_name##_get_type_once(); \
    8780        g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); \
    8881    } \
    8982    return g_define_type_id__volatile; \
    90 } // Closes type_name##_get_type().
     83} /* Closes type_name##_get_type(). */ \
     84\
     85NEVER_INLINE static GType type_name##_get_type_once(void) \
     86{ \
     87    GType g_define_type_id =  \
     88        g_type_register_static_simple( \
     89            TYPE_PARENT, \
     90            g_intern_static_string(#TypeName), \
     91            sizeof(TypeName##Class), \
     92            (GClassInitFunc)(void (*)(void))type_name##_class_intern_init, \
     93            sizeof(TypeName), \
     94            (GInstanceInitFunc)(void (*)(void))type_name##_init, \
     95            (GTypeFlags)flags); \
     96    /* Custom code follows. */
     97#define _WEBKIT_DEFINE_TYPE_EXTENDED_END() \
     98    return g_define_type_id; \
     99} /* Closes type_name##_get_type_once() */
Note: See TracChangeset for help on using the changeset viewer.