fix demos to work with new assertAllocated() lines in writeMem
authorAdam Megacz <adam@megacz.com>
Sat, 1 Aug 2009 02:24:51 +0000 (19:24 -0700)
committerAdam Megacz <adam@megacz.com>
Sat, 1 Aug 2009 02:24:51 +0000 (19:24 -0700)
src/edu/berkeley/fleet/dataflow/MergeSort.java
src/edu/berkeley/fleet/loops/Program.java
src/edu/berkeley/fleet/loops/ShipPool.java

index b478462..876cf91 100644 (file)
@@ -318,7 +318,8 @@ public class MergeSort {
 
         MemoryUtils.writeMem(fp, pool, mem1, offset, bvs);
 
-        Program program = new Program(pool.allocateShip("Memory"));
+        Ship mem = pool.allocateShip("Memory");
+        Program program = new Program(mem);
         long ret = new MergeSort(fleet, program, pool, 2, mem1, mem1).main(fp, vals_length);
 
         //long ret = 0;
@@ -327,6 +328,7 @@ public class MergeSort {
         //MemoryUtils.readMem(fp, new ShipPool(fp.getFleet()), mem1, 0, bvs);
 
         BitVector[] bvx = new BitVector[1024];
+        pool.allocateShip(mem);
         MemoryUtils.readMem(fp, new ShipPool(fp.getFleet()), mem1, 0, bvx);
         for(int i=0; i<bvx.length; i++)
             System.out.println(bvx[i]);
@@ -391,8 +393,12 @@ public class MergeSort {
         lf.sendWord(program.getCBDDestination());
         cb.seal();
 
+        ShipPool pool = new ShipPool(fp.getFleet());
+        pool.allocateShip(program.memoryShip);
         // FIXME
-        return program.run(fp, cb, new ShipPool(fp.getFleet()));
+        long ret = program.run(fp, cb, pool);
+        pool.releaseShip(program.memoryShip);
+        return ret;
     }
 
     public static void randomizeMemory(FleetProcess fp, ShipPool pool_, Ship memory, long start, long length, boolean randomize) {
index bd30f30..8cd4b01 100644 (file)
@@ -34,7 +34,8 @@ public class Program {
         return memoryShip.getDock("inCBD").getDataDestination();
     }
 
-    public long run(FleetProcess fp, CodeBag run, ShipPool pool) {
+    public long run(FleetProcess fp, CodeBag run, ShipPool pool_) {
+        ShipPool pool = new ShipPool(pool_);
         Ship timer    = pool.allocateShip("Timer");
         Ship debug    = pool.allocateShip("Debug");
         Dock debugIn  = debug.getDock("in");
@@ -60,7 +61,9 @@ public class Program {
         start.seal();
         done.seal();
         
-        install(fp, pool);
+        pool.setParent(null);
+        install(fp, pool_);
+        pool.setParent(pool_);
         
         MemoryUtils.putMemoryShipInDispatchMode(fp, memoryShip);
         fp.sendWord(getCBDDestination(), start.getDescriptor().getBitVector());
index 27dbff1..60bd121 100644 (file)
@@ -26,7 +26,7 @@ public class ShipPool implements Iterable<Ship> {
 
     public void allocateShip(Ship ship) {
         if (allocatedShips.contains(ship))
-            throw new RuntimeException("already allocated!");
+            throw new RuntimeException("ship " + ship + " is already allocated!");
         if (parent != null)
             parent.allocateShip(ship);
         allocatedShips.add(ship);