Fix race between finalizeAllEnqueued and GC

Problem: GC uses pendingNext field for its internal references. This
causes a race where the GC can see the sentinel finalizer reference
through the internal doubly linked list and scan it before the
referent is marked, resulting in the pendingNext being part of a GC
internal reference queue. Then when we updated the pendingNext to
make a circular list it broke the list since the node never reached
the head.

The solution is to use native code so that we can use the same lock
that the GC uses when enqueing references and retry if the GC
changed the pendingNext.

Bug: 17462553

(cherry picked from commit e928a238e5e7f7b9fd74ed460f7e7943484d96af)

Change-Id: I6b68ca210bdda3c2468c5519d423f0bb1f00fc14
Merge "Fix race between finalizeAllEnqueued and GC"