[perfcounters] fix alignment issue on 32bit
commita36d08a55ac1fee1cfdc58e279afe7f414ba39bd
authorBernhard Urban <lewurm@gmail.com>
Thu, 29 Mar 2018 15:49:59 +0000 (29 17:49 +0200)
committerBernhard Urban <bernhard.urban@xamarin.com>
Thu, 29 Mar 2018 23:03:06 +0000 (30 01:03 +0200)
tree85e99fc355e39bae2b2de3baf0920dff6b815ce7
parent60707875d590056cd4faf5b03e04a6533c58c322
[perfcounters] fix alignment issue on 32bit

clang fails to properly align 64bit members of the `MonoPerfCounters` struct on
32bit builds:

```
* thread #1, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_ARM_DA_ALIGN, address=0x16933124)
    frame #0: 0x0066f4b2 mini`mono_atomic_cas_i64(dest=0x16933124, exch=<unavailable>, comp=<unavailable>) at atomic.c:519 [opt]
   516  gint64
   517  mono_atomic_cas_i64(volatile gint64 *dest, gint64 exch, gint64 comp)
   518  {
-> 519  return  __sync_val_compare_and_swap (dest, comp, exch);
   520  }
   521
   522  #elif defined (TARGET_ANDROID)
(lldb) up
frame #1: 0x006292ea mini`ves_icall_System_Threading_ThreadPool_NotifyWorkItemQueued [inlined] mono_atomic_inc_i64 at atomic.h:397 [opt]
   394  do {
   395  get = *val;
   396  set = get + 1;
-> 397  } while (mono_atomic_cas_i64 (val, set, get) != get);
   398  return set;
   399  }
   400
(lldb) up
frame #2: 0x006292d6 mini`ves_icall_System_Threading_ThreadPool_NotifyWorkItemQueued at threadpool.c:743 [opt]
   740  ves_icall_System_Threading_ThreadPool_NotifyWorkItemQueued (void)
   741  {
   742  #ifndef DISABLE_PERFCOUNTERS
-> 743  mono_atomic_inc_i64 (&mono_perfcounters->threadpool_workitems);
   744  #endif
   745  }
   746
```

Note that the member `threadpool_workitems` is on an unnatural alignment
(`0x16933124`) regarding to its type `gint64`.

related https://github.com/xamarin/xamarin-macios/issues/3826
mono/metadata/class-internals.h