Merge pull request #5299 from cherusker/cherusker-2017-08-01-next-generic-inst-id
authormonojenkins <jo.shields+jenkins@xamarin.com>
Wed, 2 Aug 2017 23:10:32 +0000 (01:10 +0200)
committerGitHub <noreply@github.com>
Wed, 2 Aug 2017 23:10:32 +0000 (01:10 +0200)
[metadata] Fix racy next_generic_inst_id

Like suggested by @luhenry, I would like to propose this fix which was discussed in https://bugzilla.xamarin.com/show_bug.cgi?id=58423. As `next_generic_inst_id` is `int`, `InterlockedIncrement64 ()` seems to be the right choice.

Also, I cannot add any reviewers or assignees, which is why I would kindly ask @lambdageek to review this as well :)

mono/metadata/class-internals.h
mono/metadata/metadata.c

index 39061bd142a1ec1e5411aaee98f7848babe99d1b..ef8127e14a4ab94e43f545d5eea84ef80f660039 100644 (file)
@@ -492,7 +492,7 @@ struct MonoVTable {
  */
 struct _MonoGenericInst {
 #ifndef MONO_SMALL_CONFIG
-       guint id;                       /* unique ID for debugging */
+       gint32 id;                      /* unique ID for debugging */
 #endif
        guint type_argc    : 22;        /* number of type arguments */
        guint is_open      :  1;        /* if this is an open type */
index 651538c3c5cb3378ccdd2bef5423c4a81d73b49d..aea1343df99c5dac29b3945222b080ea19b6b481 100644 (file)
@@ -1522,7 +1522,7 @@ builtin_types[] = {
 #define NBUILTIN_TYPES() (sizeof (builtin_types) / sizeof (builtin_types [0]))
 
 static GHashTable *type_cache = NULL;
-static int next_generic_inst_id = 0;
+static gint32 next_generic_inst_id = 0;
 
 /* Protected by image_sets_mutex */
 static MonoImageSet *mscorlib_image_set;
@@ -3160,7 +3160,7 @@ mono_metadata_get_canonical_generic_inst (MonoGenericInst *candidate)
                int size = MONO_SIZEOF_GENERIC_INST + type_argc * sizeof (MonoType *);
                ginst = (MonoGenericInst *)mono_image_set_alloc0 (set, size);
 #ifndef MONO_SMALL_CONFIG
-               ginst->id = ++next_generic_inst_id;
+               ginst->id = InterlockedIncrement (&next_generic_inst_id);
 #endif
                ginst->is_open = is_open;
                ginst->type_argc = type_argc;