package edu.lsu.cct.MCSMPGC; public class Mutator extends Thread { public Memory memory; public int testcase; public Mutator(Memory memory,int testcase){ super(); this.memory = memory; this.testcase = testcase; } public void run(){ switch(testcase){ case TestCases.SIMPLE_CYCLE_1_ANCHOR: simpleCycle1Anchor(10); break; case TestCases.SIMPLE_CYCLE_2_ANCHOR: simpleCycle2AnchorRecover(10); break; } } private void simpleCycle2AnchorRecover(int n) { Node no = null; Node prev = null; Node current; for(int i = 0 ; i < n; i++){ if(i==0){ no = memory.alloc(); no.value = String.valueOf(i); no.anchored(memory); prev = no; } else{ current = memory.alloc(); current.value = String.valueOf(i); prev.refs.add(current.address); prev = current; } } prev.refs.add(no.address); prev.anchored(memory); System.out.println("free "+memory.free.size()+" allocated "+memory.allocated.size()); traversal(no.address); if(no.removeanchor()){ memory.anchors.remove(no); Collector c = new Collector(no.address); c.start(); } } private void simpleCycle1Anchor(int n) { // TODO Auto-generated method stub Node no = null; Node prev = null; Node current; for(int i = 0 ; i < n; i++){ if(i==0){ no = memory.alloc(); no.value = String.valueOf(i); no.anchored(memory); prev = no; } else{ current = memory.alloc(); current.value = String.valueOf(i); prev.refs.add(current.address); prev = current; } } prev.refs.add(no.address); System.out.println("free "+memory.free.size()+" allocated "+memory.allocated.size()); traversal(no.address); if(no.removeanchor()){ memory.anchors.remove(no); Collector c = new Collector(no.address); c.start(); } } private void traversal(int address) { // TODO Auto-generated method stub if(memory.anchors.contains(address)){ System.out.println("The object at address "+ address + " is an anchor"); Node first = memory.allocated.get(address); Node next =first; while(true){ System.out.print(next.value +" -> "+((Reference)next.refs.links.get(0)).type()+" "); next = memory.allocated.get(next.refs.links.get(0).to); if(next==first){ System.out.print(first.address); break; } } } } }