Fix ABA bug with PreObjectAlloc event being missed
We prevent the PreObjectAlloc event from ever being disabled after
being activated for allocation pausing the first time. This is to
prevent an instance of the ABA problem where a thread can miss the
fact that the size of the object it's allocating has changed if it was
suspended within the allocation path during the redefinition.
We need to make sure that every thread gets a chance to see the
PreObjectAlloc event at least once or else it could miss the fact that
the object its allocating had its size changed.
Consider the following 2 threads. T1 is allocating an object of class
K. It is suspended (by user code) somewhere in the
AllocObjectWithAllocator function, perhaps while doing a GC to attempt
to clear space. With that thread suspended on thread T2 we decide to
structurally redefine 'K', changing its size. To do this we insert
this PreObjectAlloc event to check and update the size of the class
being allocated. This is done successfully. Now imagine if T2 removed
the listener event then T1 subsequently resumes. T1 would see there is
no PreObjectAlloc event and so allocate using the old object size.
This leads to it not allocating enough. To prevent this we simply
force every allocation after our first pause to go through the
PreObjectAlloc event.
Test: setup runit.sh to run test 2005.
./art/tools/parallel_run.py -j80 --out art/out.txt ./art/runit.sh
Test: ./test.py --host
Bug: 146436130
Change-Id: I7cdc1d133a7cbba7784b906b587e565072a453b2
2 files changed