When enqueuing references check whether the j.l.r.Reference has already been enqeued or removed in the lock. Do not enqueue them again. This occurs because multiple threads may try to enqueue the same j.l.r.Reference at the same time.
Reviewed-by: mchung, dholmes, plevart, shade
4268317: (ref) Reference.isEnqueued() can return true when instance not enqueued
The reference handler now declares, and assumes, that the discovered field, rather than the next field, is (to be) used to link the entries in the pending list, thus allowing a reference object to be safely enqueued even while it is in the pending state. Also added slightly modified regression tests from the two bug reports.
Reviewed-by: mchung, alanb, jcoomes