MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / gc

Method gc

src/main/java/wycc/util/AbstractHeap.java:194–215  ·  view source on GitHub ↗

Force a garbage collection event. This removes all items which are unreachable from the root, and compacts those remaining down. @return

()

Source from the content-addressed store, hash-verified

192 * @return
193 */
194 @Override
195 public boolean gc() {
196 // Mark all reachable items
197 BitSet reachable = findReachable(getRootItem(), new BitSet());
198 // Sweep all unreachable items away
199 int count = 0;
200 for(int i=0;i!=syntacticItems.size();++i) {
201 if(reachable.get(i)) {
202 Item item = syntacticItems.get(i);
203 // Reset the index of this item
204 item.allocate(this, count);
205 // Move the item down
206 syntacticItems.set(count++, item);
207 }
208 }
209 // Remove all unreachable items.
210 for (int i = syntacticItems.size(); i > count; i = i - 1) {
211 syntacticItems.remove(i - 1);
212 }
213 // Indicate whether anything changed
214 return count < syntacticItems.size();
215 }
216
217 public void print(PrintWriter out) {
218 String lenStr = Integer.toString(syntacticItems.size());

Callers

nothing calls this directly

Calls 7

findReachableMethod · 0.95
getRootItemMethod · 0.95
allocateMethod · 0.95
removeMethod · 0.80
sizeMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected