Lines 46-51
Link Here
|
46 |
import java.lang.ref.ReferenceQueue; |
46 |
import java.lang.ref.ReferenceQueue; |
47 |
import java.lang.ref.WeakReference; |
47 |
import java.lang.ref.WeakReference; |
48 |
import java.lang.reflect.Field; |
48 |
import java.lang.reflect.Field; |
|
|
49 |
import java.lang.reflect.Method; |
49 |
import java.util.logging.Level; |
50 |
import java.util.logging.Level; |
50 |
import java.util.logging.Logger; |
51 |
import java.util.logging.Logger; |
51 |
|
52 |
|
Lines 171-181
Link Here
|
171 |
return; |
172 |
return; |
172 |
} |
173 |
} |
173 |
Reference<?> ref; |
174 |
Reference<?> ref; |
174 |
synchronized (impl.lock()) { |
175 |
Object lck = impl.lock(); |
|
|
176 |
synchronized (lck) { |
175 |
ref = impl.pollSuper(); |
177 |
ref = impl.pollSuper(); |
176 |
impl = null; |
178 |
impl = null; |
177 |
if (ref == null) { |
179 |
if (ref == null) { |
178 |
ACTIVE.remove(Integer.MAX_VALUE); |
180 |
Reference<?> res = removeBetter(ACTIVE, lck); |
|
|
181 |
LOGGER.log(Level.FINE, "Got {0} with {1}", new Object[]{res, res == null ? null : res.get()}); |
179 |
continue; |
182 |
continue; |
180 |
} |
183 |
} |
181 |
} |
184 |
} |
Lines 208-211
Link Here
|
208 |
LOGGER.log(Level.WARNING, "Cannot hack ReferenceQueue to fix bug #206621!", ex); |
211 |
LOGGER.log(Level.WARNING, "Cannot hack ReferenceQueue to fix bug #206621!", ex); |
209 |
return ex; |
212 |
return ex; |
210 |
} |
213 |
} |
|
|
214 |
|
215 |
private static Reference<?> removeBetter(ReferenceQueue<?> q, Object lock) { |
216 |
try { |
217 |
Method m = q.getClass().getDeclaredMethod("reallyPoll"); // NOI18N |
218 |
m.setAccessible(true); |
219 |
|
220 |
Reference<?> r = (Reference<?>) m.invoke(q); |
221 |
if (r != null) { |
222 |
return r; |
223 |
} |
224 |
for (;;) { |
225 |
lock.wait(); |
226 |
r = (Reference<?>) m.invoke(q); |
227 |
if (r != null) { |
228 |
return r; |
229 |
} |
230 |
return null; |
231 |
} |
232 |
} catch (Exception ex) { |
233 |
return null; |
234 |
} |
235 |
} |
211 |
} |
236 |
} |