< prev index next >

src/java.base/share/classes/java/lang/ref/ReferenceQueue.java

Print this page
rev 50093 : [mq]: pp2_work

*** 1,7 **** /* ! * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 64,73 **** --- 64,74 ---- ReferenceQueue<?> queue = r.queue; if ((queue == NULL) || (queue == ENQUEUED)) { return false; } assert queue == this; + // Self-loop end, so if a FinalReference it remains inactive. r.next = (head == null) ? r : head; head = r; queueLength++; // Update r.queue *after* adding to list, to avoid race // with concurrent enqueued checks and fast-path poll().
*** 88,98 **** --- 89,102 ---- // Update r.queue *before* removing from list, to avoid // race with concurrent enqueued checks and fast-path // poll(). Volatiles ensure ordering. @SuppressWarnings("unchecked") Reference<? extends T> rn = r.next; + // Handle self-looped next as end of list designator. head = (rn == r) ? null : rn; + // Self-loop next rather than setting to null, so if a + // FinalReference it remains inactive. r.next = r; queueLength--; if (r instanceof FinalReference) { VM.addFinalRefCount(-1); }
< prev index next >