Changeset 2738

Show
Ignore:
Timestamp:
08/25/08 07:18:20 (10 months ago)
Author:
chf
Message:

Some cleanups and refactorings. More to come

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/ReferenceCell.java

    r2700 r2738  
    4444    public ReferenceCell() { 
    4545        super(); 
    46         node = new ValueNode(); 
     46        node = ValueNode.nullValueNode; 
     47        id = counter.getAndIncrement(); 
     48    } 
     49 
     50    public ReferenceCell(FType t) { 
     51        super(); 
     52        theType = t; 
     53        node = ValueNode.nullValueNode; 
    4754        id = counter.getAndIncrement(); 
    4855    } 
     
    5158        super(); 
    5259        theType = t; 
    53         node = new ValueNode(v); 
    54         id = counter.getAndIncrement(); 
    55     } 
    56  
    57     public ReferenceCell(FType t) { 
    58         super(); 
    59         theType = t; 
    60         node = new ValueNode(); 
     60        node = new ValueNode(v, FortressTaskRunner.getTransaction(), null, null); 
    6161        id = counter.getAndIncrement(); 
    6262    } 
     
    6464    public FType getType() { return theType;} 
    6565    public String toString() { return "ReferenceCell" + id;} 
    66  
    6766 
    6867    private boolean transactionIsCommitted(Transaction w) { 
     
    9089    private synchronized void cleanup() { 
    9190        Transaction w = node.getWriter(); 
     91        if (Transaction.debug) 
     92            FortressTaskRunner.debugPrintln("Cleanup:" + this + " start with node = " + node); 
    9293        while (w != null && transactionIsNotActive(w)) { 
    9394            if (transactionIsAbortedOrOrphaned(w)) { 
     
    9697                assert(transactionIsCommitted(w)); 
    9798                Transaction p = w.getParent(); 
    98                 if (p == null) { 
    99                     node = new ValueNode(node.getValue(), node.getOld().getReaders()); 
    100                 } else  { 
    101                     node = new ValueNode(node.getValue(), p, node.getOld()); 
     99                ValueNode old = node.getOld(); 
     100                if (p == null && old == null) { 
     101                    // Committed to top level, with no previous value. 
     102                    node = new ValueNode(node.getValue(), null, null, null); 
     103                } else if (p == null) { 
     104                    // Committed to top level.  Any readers of the committed transaction 
     105                    // must be preserved. 
     106                    node = new ValueNode(node.getValue(), null, old.getReaders(), null); 
     107                } else  if (old != null) { 
     108                    // Committed to a parent transaction, must preserve readers and  
     109                    // old transaction. 
     110                    node = new ValueNode(node.getValue(), p, old.getReaders(), old); 
     111                } else { 
     112                    node = new ValueNode(node.getValue(), p, null, null); 
    102113                } 
    103114            } 
     
    105116                w = node.getWriter(); 
    106117            } else { 
    107                 node = new ValueNode(); 
     118                node = ValueNode.nullValueNode; 
     119                if (Transaction.debug) 
     120                    FortressTaskRunner.debugPrintln("Cleanup:" + this + " end with " + node); 
    108121                return; 
    109122            } 
    110123        } 
     124        if (Transaction.debug) 
     125            FortressTaskRunner.debugPrintln("Cleanup:" + this + " end with " + node); 
    111126    } 
    112127 
     
    114129        Transaction me  = FortressTaskRunner.getTransaction(); 
    115130        cleanup(); 
     131        if (Transaction.debug)  
     132            FortressTaskRunner.debugPrintln(this + " assignValue start = " + node + " value = " + f2); 
     133 
     134        if (node == ValueNode.nullValueNode) { 
     135            node = new ValueNode(f2, me, null, null); 
     136        } 
     137 
    116138        // writer is either active, or null 
    117139        if (me == null) { // top level assignment 
    118             ValueNode temp = node; 
    119             node = new ValueNode(f2); 
    120             temp.AbortAllReadersAndWriters(); 
     140            if (node == ValueNode.nullValueNode)  
     141                node = new ValueNode(f2, me, null, null); 
     142            else { 
     143                ValueNode temp = node; 
     144                node = new ValueNode(f2, null, null, null); 
     145                temp.AbortAllReadersAndWriters(); 
     146            } 
    121147        } else if (!me.isActive()) { 
    122148            throw new AbortedException(me, "Somebody killed me "); 
     
    128154 
    129155            Transaction w = node.getWriter(); 
     156            ValueNode old = node.getOld(); 
    130157 
    131158            if (w == null || w.isAncestorOf(me)) { 
    132                 node = new ValueNode(f2, me, node); 
     159                node = new ValueNode(f2, me, node.getReaders(), node); 
    133160                if (Transaction.debug) me.addWrite(this, f2); 
     161 
    134162            } else if (w.isActive()) { 
    135163                                // Cleanup got us to a parent node with an active writer 
     
    137165            } 
    138166        } 
     167        if (Transaction.debug) 
     168            FortressTaskRunner.debugPrintln(this + " assignValue finish = " + node); 
    139169    } 
    140170 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/ValueNode.java

    r2649 r2738  
    3232    Transaction writer; 
    3333    ReadSet readers; 
    34      
     34 
     35    public  ValueNode(FValue v, Transaction w, ReadSet r, ValueNode o) { 
     36        old = o; 
     37        value = v; 
     38        writer = w; 
     39        readers = new ReadSet(r); 
     40    } 
     41 
    3542    ValueNode() { 
    3643        old = null; 
    3744        value = null; 
    38         writer = FortressTaskRunner.getTransaction()
     45        writer = null
    3946        readers = new ReadSet(); 
    4047    } 
    4148 
    42     ValueNode(FValue val) { 
    43         old = null; 
    44         value = val; 
    45         writer = FortressTaskRunner.getTransaction(); 
    46         readers = new ReadSet(); 
    47     } 
    48  
    49     ValueNode(FValue val, Transaction w, ValueNode o) { 
    50         old = o; 
    51         value = val; 
    52         writer = w; 
    53         if (o != null) 
    54             readers = new ReadSet(o.readers); 
    55         else readers = new ReadSet(); 
    56     } 
    57  
    58     ValueNode(FValue val, ReadSet r) { 
    59         old = null; 
    60         value = val; 
    61         readers = new ReadSet(r); 
    62     } 
     49    public static final ValueNode nullValueNode = new ValueNode(); 
    6350 
    6451    public String toString() { 
    65         return "ValueNode[" + value +  ":" + writer + "]" ; 
     52        if (this == nullValueNode) 
     53            return "nullValueNode"; 
     54        else return "ValueNode[" + value +  ":" + writer +  "::" + readers + "]" ; 
    6655    } 
    6756 
     
    8069             
    8170    public void AbortAllReaders() { 
     71        if (this == nullValueNode) 
     72            throw new RuntimeException(Thread.currentThread().getName() + "Trying to abort all the readers of the null value node"); 
     73 
    8274                readers.seal(); 
    8375                for (Transaction r : readers) { 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/transactions/ReadSet.java

    r2649 r2738  
    3737      // out from underneath me, I get a NoSuchElementException, so I'm writing 
    3838      // my own add function. 
    39       myAdd(r); 
     39      if (r != null) 
     40          myAdd(r); 
    4041  } 
    4142 
     
    7273      if (sealed) { 
    7374                  FortressTaskRunner.debugPrintln("add of " + t + " to readset " + toString() + " failed because readset was sealed"); 
     75          Thread.dumpStack(); 
    7476                  return false; 
    7577      } else {