Fix race condition and use less memory in mono_lookup_icall_symbol. (#14532)
commitc37fc12ca5edd9cbf169ac7e4ab5b2e6ef202f79
authorJay Krell <jaykrell@microsoft.com>
Wed, 31 Jul 2019 12:13:21 +0000 (31 05:13 -0700)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 31 Jul 2019 12:13:21 +0000 (31 14:13 +0200)
treea8957a208a7e10fa8aeda18760a8c4c8c28d445a
parent471421023c27752f02ce4728778d6ff814ce362f
Fix race condition and use less memory in mono_lookup_icall_symbol. (#14532)

It is racy because it is doing on-demand initialization, which is often racy.

The rewrite changes the result to be one pointer, atomically swapped, which implies a full barrier and data dependency, so no race.

It could also be fixed by copying and sorting an array of pairs, and one pointer to that.

However in order to save memory I instead use indirect data that is an array of uint16 pointing into the original data. That is a slight memory vs. time tradeoff.

Yes there is debugging code left, under #if, that I prefer to leave, both as evidence that I tested it, and to make it somewhat but ideally testable in future.

The code also was using an unnecessary somewhat risky but probably ok here way to compare pointers, that I fixed.

As well the result is marginally smaller and faster because it was inlining something like bubblesort, now reuses qsort.
mono/metadata/icall-table.c
mono/mini/main.c