MCPcopy Create free account
hub / github.com/antlr/codebuff / run

Method run

output/java_guava/1.4.13/Finalizer.java:115–200  ·  view source on GitHub ↗

Loops continuously, pulling references off the queue and cleaning them up.

()

Source from the content-addressed store, hash-verified

113 */
114
115 @SuppressWarnings("InfiniteLoopStatement")
116 @Override
117 public void run() {
118 while (true) {
119 try {
120 if (!cleanUp(queue.remove())) {
121 break;
122 }
123 } catch (InterruptedException e) {
124 // ignore}
125 }
126 }
127
128 /**
129 * Cleans up a single reference. Catches and logs all throwables.
130 *
131 * @return true if the caller should continue, false if the associated FinalizableReferenceQueue
132 * is no longer referenced.
133 */
134
135 private boolean cleanUp(Reference<?> reference) {
136 Method finalizeReferentMethod = getFinalizeReferentMethod();
137 if (finalizeReferentMethod == null) {
138 return false;
139 }
140 do {
141 /*
142 * This is for the benefit of phantom references. Weak and soft references will have already
143 * been cleared by this point.
144 */
145 reference.clear();
146 if (reference == frqReference) {
147 /*
148 * The client no longer has a reference to the FinalizableReferenceQueue. We can stop.
149 */
150 return false;
151 }
152 try {
153 finalizeReferentMethod.invoke(reference);
154 } catch (Throwable t) {
155 logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
156 }
157
158 /*
159 * Loop as long as we have references available so as not to waste CPU looking up the Method
160 * over and over again.
161 */
162 } while ((reference = queue.poll()) != null);
163 return true;
164 }
165
166 /**
167 * Looks up FinalizableReference.finalizeReferent() method.
168 */
169
170 private Method getFinalizeReferentMethod() {
171 Class<?> finalizableReferenceClass = finalizableReferenceClassReference.get();
172 if (finalizableReferenceClass == null) {

Callers

nothing calls this directly

Calls 9

cleanUpMethod · 0.95
logMethod · 0.80
removeMethod · 0.65
clearMethod · 0.65
getMethod · 0.65
invokeMethod · 0.45
pollMethod · 0.45
setAccessibleMethod · 0.45

Tested by

no test coverage detected