RegisterNativeAllocation: Avoid case of double blocking gc.
If multiple threads call RegisterNativeAllocation causing the blocking watermark to be exceeded while a background GC is in progress, then two back-to-back blocking GCs would be performed when a single blocking GC is sufficient. For example: 1. Thread A RegisterNativeAllocation triggers background GC1 2. Thread A RegisterNativeAllocation triggers blocking GC2 3. Thread A's GC2 waits for GC1 to complete. 4. Thread B RegisterNativeAllocation sees GC2 in progress and waits for it to complete before triggering a second blocking GC3. 5. GC1 completes. Because thread B's RegisterNativeAllocation was called before GC1 completed and GC2 had not begun for real, thread B can simply wait for GC2 to start and finish before returning, rather than waiting for GC2 to start and finish and then doing a second blocking GC. This change fixes the behavior so that only a single blocking GC is performed in this case. Bug: 36851903 Test: 004-NativeAllocations run test. Change-Id: I1e178b9ee7bb68703bdc9a09b1041a982de8b2ce
Loading
Please sign in to comment