Changeset 879

Show
Ignore:
Timestamp:
10/04/07 16:55:44 (2 years ago)
Author:
dr2chase
Message:

Fixes to overloading and instantiation deadlocks

Location:
trunk/ProjectFortress
Files:
8 added
12 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/EvalType.java

    r799 r879  
    313313 
    314314    public FType forOprArg(OprArg b) { 
    315         return new FTypeOpr(NodeUtil.nameString(b.getName())); 
     315        return FTypeOpr.make(NodeUtil.nameString(b.getName())); 
    316316    } 
    317317 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Init.java

    r358 r879  
    3030import com.sun.fortress.interpreter.evaluator.types.FTypeLong; 
    3131import com.sun.fortress.interpreter.evaluator.types.FTypeNumber; 
     32import com.sun.fortress.interpreter.evaluator.types.FTypeOpr; 
    3233import com.sun.fortress.interpreter.evaluator.types.FTypeOverloadedArrow; 
    3334import com.sun.fortress.interpreter.evaluator.types.FTypeRange; 
     
    5152        FTypeArrow.reset(); 
    5253        FTypeTuple.reset(); 
     54        FTypeOpr.reset(); 
    5355        FTypeRest.reset(); 
    5456        FTypeOverloadedArrow.reset(); 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/OverloadJUTest.java

    r744 r879  
    4343        super("OverloadJUTest"); 
    4444    } 
    45     private Overload simple_overload(List<FType> types) { 
    46         return new Overload(new Dummy_fcn(types)); 
     45    private Overload simple_overload(List<FType> types, OverloadedFunction olf) { 
     46        return new Overload(new Dummy_fcn(types), olf); 
    4747    } 
    4848 
     
    7777              NodeFactory.makeIdName("dummyOverloadName"), BetterEnv.primitive("Test overload dispatch")); 
    7878        for(List<FType> cl: clauses) { 
    79             fcn.addOverload(simple_overload(cl)); 
     79            fcn.addOverload(simple_overload(cl, fcn)); 
    8080        } 
    8181        fcn.finishInitializing(); 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTraitOrObjectOrGeneric.java

    r855 r879  
    8888                    // if (x.getStaticParams().isPresent()) { 
    8989                    if (x instanceof FTypeGeneric) { 
    90                         cl = new OverloadedFunction(fndod.getName(), topLevel); 
     90                         
     91                           cl = new OverloadedFunction(fndod.getName(), topLevel); 
     92                           topLevel.putValueNoShadowFn(fndodname, cl); 
     93                         
    9194                    } else { 
    9295                        // Note that the instantiation of a generic 
     
    9497                        // here too 
    9598                        cl = new FunctionalMethod(topLevel, fndod, spi, x); 
     99                        topLevel.putValueNoShadowFn(fndodname, cl); 
    96100                    } 
    97101 
    98102                    // TODO test and other modifiers 
    99103 
    100                     topLevel.putValueNoShadowFn(fndodname, cl); 
     104                     
    101105                } 
    102106            } 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FType.java

    r852 r879  
    3838import com.sun.fortress.useful.EmptyLatticeIntervalError; 
    3939import com.sun.fortress.useful.HasAt; 
     40import com.sun.fortress.useful.ListComparer; 
    4041import com.sun.fortress.useful.MagicNumbers; 
    4142import com.sun.fortress.useful.Pair; 
     
    5152    protected static final boolean DUMP_UNIFY = false; 
    5253 
    53     static Comparator<FType> comparator = new Comparator<FType>() { 
     54    static public Comparator<FType> comparator = new Comparator<FType>() { 
    5455 
    5556        public int compare(FType arg0, FType arg1) { 
     
    5960    }; 
    6061 
     62    static public ListComparer<FType> listComparer = new ListComparer<FType>(); 
     63     
    6164    // static Random random = new Random(0xd06f00d); 
    6265 
     
    248251        } 
    249252 
    250         for (FType t : getTransitiveExtends()) { 
     253        List<FType> extendsThis = getTransitiveExtends(); 
     254        for (FType t : extendsThis) { 
    251255            BASet t_excludes = t.excludes; 
    252             for (FType o : other.getTransitiveExtends()) { 
     256            if (t_excludes.isEmpty()) 
     257                continue; 
     258            List<FType> extendsOther = other.getTransitiveExtends(); 
     259            for (FType o : extendsOther) { 
    253260                if ( !(t == this && o == other) && t_excludes.contains(o)) { 
    254261                    // Short-circuit any future queries 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTypeGeneric.java

    r869 r879  
    1818package com.sun.fortress.interpreter.evaluator.types; 
    1919 
     20import static com.sun.fortress.interpreter.evaluator.InterpreterBug.bug; 
     21import static com.sun.fortress.interpreter.evaluator.ProgramError.error; 
     22import static com.sun.fortress.interpreter.evaluator.ProgramError.errorMsg; 
     23 
    2024import java.util.ArrayList; 
    2125import java.util.HashMap; 
    2226import java.util.List; 
    2327import java.util.Map; 
    24 import java.util.Set; 
    2528 
    2629import com.sun.fortress.interpreter.env.BetterEnv; 
    2730import com.sun.fortress.interpreter.evaluator.BuildEnvironments; 
    2831import com.sun.fortress.interpreter.evaluator.EvalType; 
     32import com.sun.fortress.interpreter.evaluator.InstantiationLock; 
    2933import com.sun.fortress.interpreter.rewrite.OprInstantiater; 
    3034import com.sun.fortress.nodes.AbsDeclOrDecl; 
     
    3236import com.sun.fortress.nodes.ObjectDecl; 
    3337import com.sun.fortress.nodes.OperatorParam; 
    34 import com.sun.fortress.nodes.TraitObjectAbsDeclOrDecl; 
    35 import com.sun.fortress.nodes._RewriteObjectExpr; 
    3638import com.sun.fortress.nodes.StaticArg; 
    3739import com.sun.fortress.nodes.StaticParam; 
    3840import com.sun.fortress.nodes.TraitAbsDeclOrDecl; 
     41import com.sun.fortress.nodes.TraitObjectAbsDeclOrDecl; 
     42import com.sun.fortress.nodes._RewriteObjectExpr; 
    3943import com.sun.fortress.nodes_util.NodeUtil; 
    4044import com.sun.fortress.useful.Factory1P; 
    4145import com.sun.fortress.useful.HasAt; 
    4246import com.sun.fortress.useful.LazyFactory1P; 
    43 import com.sun.fortress.useful.LazyMemo1P; 
     47import com.sun.fortress.useful.LazyMemo1PCL; 
    4448import com.sun.fortress.useful.Useful; 
    45  
    46 import static com.sun.fortress.interpreter.evaluator.ProgramError.error; 
    47 import static com.sun.fortress.interpreter.evaluator.ProgramError.errorMsg; 
    48 import static com.sun.fortress.interpreter.evaluator.InterpreterBug.bug; 
    4949 
    5050public class FTypeGeneric extends FTraitOrObjectOrGeneric implements Factory1P<List<FType>, FTraitOrObject, HasAt> { 
     
    231231 
    232232 
    233     LazyMemo1P<List<FType>, FTraitOrObject, HasAt> memo = 
    234         new LazyMemo1P<List<FType>, FTraitOrObject, HasAt>( 
    235             new Factory()); 
     233    LazyMemo1PCL<List<FType>, FTraitOrObject, HasAt> memo = 
     234        new LazyMemo1PCL<List<FType>, FTraitOrObject, HasAt>( 
     235            new Factory(), FType.listComparer, InstantiationLock.L); 
    236236 
    237237    public FTraitOrObject make(List<FType> l, HasAt within) { 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTypeOpr.java

    r829 r879  
    1818package com.sun.fortress.interpreter.evaluator.types; 
    1919 
     20import java.util.List; 
    2021import java.util.Set; 
    2122import com.sun.fortress.interpreter.env.BetterEnv; 
     
    2324import com.sun.fortress.nodes.Type; 
    2425import com.sun.fortress.useful.BoundingMap; 
     26import com.sun.fortress.useful.Factory1; 
     27import com.sun.fortress.useful.Memo1C; 
     28import com.sun.fortress.useful.StringComparer; 
    2529 
    2630import static com.sun.fortress.interpreter.evaluator.ProgramError.errorMsg; 
     
    2832 
    2933public class FTypeOpr extends FType { 
    30     public FTypeOpr(String s) { 
     34    private FTypeOpr(String s) { 
    3135        super(s); 
    3236    } 
    3337 
     38    static Memo1C<String, FType> memo = null; 
     39 
     40    private static class Factory implements Factory1<String, FType> { 
     41        public FType make(String part1) { 
     42            return new FTypeOpr(part1); 
     43        } 
     44    } 
     45     
     46    public static void reset() { 
     47        memo = new Memo1C<String, FType>( new Factory(), StringComparer.V); 
     48    } 
     49     
     50    static public FType make(String s) { 
     51        return memo.make(s); 
     52    } 
     53     
    3454    /* 
    3555     * @see com.sun.fortress.interpreter.evaluator.types.FType#unifyNonVar(java.util.Set, com.sun.fortress.interpreter.useful.ABoundingMap, 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTypeTuple.java

    r852 r879  
    4646public class FTypeTuple extends FType { 
    4747 
    48     static ListComparer<FType> listComparer = new ListComparer<FType>(); 
    4948    List<FType> l; 
    5049 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/GenericConstructor.java

    r869 r879  
    2525import com.sun.fortress.interpreter.evaluator.Environment; 
    2626import com.sun.fortress.interpreter.evaluator.EvalType; 
     27import com.sun.fortress.interpreter.evaluator.InstantiationLock; 
    2728import com.sun.fortress.interpreter.evaluator.types.FType; 
    2829import com.sun.fortress.interpreter.evaluator.types.FTypeGeneric; 
     
    3637import com.sun.fortress.useful.HasAt; 
    3738import com.sun.fortress.useful.Memo1P; 
     39import com.sun.fortress.useful.Memo1PCL; 
    3840import com.sun.fortress.useful.Useful; 
    3941 
     
    6466    } 
    6567 
    66      Memo1P<List<FType>, Constructor, HasAt> memo = 
    67          new Memo1P<List<FType>, Constructor, HasAt>(new Factory()); 
     68     Memo1PCL<List<FType>, Constructor, HasAt> memo = 
     69         new Memo1PCL<List<FType>, Constructor, HasAt>(new Factory(), FType.listComparer, InstantiationLock.L); 
    6870 
    6971     public Constructor make(List<FType> l, HasAt within) { 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/Overload.java

    r679 r879  
    2222import com.sun.fortress.interpreter.evaluator.InterpreterBug; 
    2323import com.sun.fortress.interpreter.evaluator.types.FType; 
     24import com.sun.fortress.useful.DebugletPrintStream; 
    2425import com.sun.fortress.useful.HasAt; 
    2526 
     
    4243    } 
    4344 
    44     public Overload(SingleFcn fn) { 
     45    public Overload(SingleFcn fn, OverloadedFunction olf) { 
    4546        this.fn = fn; 
    4647    } 
     
    7273 
    7374    private SingleFcn fn; 
     75     
     76    DebugletPrintStream ps; 
    7477 
    7578    /* (non-Javadoc) 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/OverloadedFunction.java

    r865 r879  
    1818package com.sun.fortress.interpreter.evaluator.values; 
    1919 
     20import java.io.PrintStream; 
    2021import java.util.ArrayList; 
    2122import java.util.List; 
     
    2627import com.sun.fortress.interpreter.evaluator.EvaluatorBase; 
    2728import com.sun.fortress.interpreter.evaluator.FortressError; 
     29import com.sun.fortress.interpreter.evaluator.InstantiationLock; 
    2830import com.sun.fortress.interpreter.evaluator.ProgramError; 
    2931import com.sun.fortress.interpreter.evaluator.types.FType; 
     
    3941import com.sun.fortress.nodes.FnRef; 
    4042import com.sun.fortress.useful.BATreeEC; 
     43import com.sun.fortress.useful.DebugletPrintStream; 
    4144import com.sun.fortress.useful.Factory1P; 
    4245import com.sun.fortress.useful.HasAt; 
     
    5255    implements Factory1P<List<FType>, Fcn, HasAt>{ 
    5356 
     57    private final boolean debug = false; 
     58    /** 
     59     * Disables ALL consistency checking of overloaded functions. 
     60     */ 
     61    private final boolean noCheck = false; 
     62     
    5463    protected volatile List<Overload> overloads = new ArrayList<Overload>(); 
    5564    private List<Overload> pendingOverloads = new ArrayList<Overload>(); 
    56     protected volatile boolean finishedFirst = false; 
    57     protected volatile boolean finishedSecond = false; 
     65    protected volatile boolean finishedFirst = true; // an empty overload is consistent 
     66    protected volatile boolean finishedSecond = true; 
    5867    protected SimpleName fnName; 
    5968     
    60     private Thread currentUpdater; 
    61  
    6269    static final boolean DUMP_EXCLUSION = false; 
    6370 
     
    124131            ol = pendingOverloads.get(i); 
    125132            SingleFcn sfcn = ol.getFn(); 
     133             
     134            String ps = ol.ps != null ? String.valueOf(ol.ps) + " " : ""; 
     135             
    126136            if (sfcn instanceof Closure)  { 
    127137                Closure cl = (Closure) sfcn; 
    128138                if (! cl.getFinished()) 
    129139                    cl.finishInitializing(); 
     140                 
     141                if (debug) { 
     142                    System.err.println("Overload " + ps  + cl); 
     143                } 
    130144 
    131145            } else if (sfcn instanceof Dummy_fcn) { 
    132                 // Primitives are all ready 
     146                if (debug) 
     147                    System.err.println("Overload primitive " + ps  + sfcn); 
    133148 
    134149            } else if (sfcn instanceof FGenericFunction) { 
    135                 // no finishInitializing for these guys, yet 
     150                if (debug) 
     151                    System.err.println("Overload generic " + ps  + sfcn); 
    136152 
    137153            } else { 
     
    139155                             sfcn)); 
    140156             } 
     157             
     158            if (ol.ps != null) 
     159                ol.ps.close(); 
    141160        } 
    142161        finishedFirst = true; 
     
    163182            ftalist.add(new_overloads.get(i).getFn().type()); 
    164183 
     184            if (!noCheck) { 
     185             
    165186            for (int j = i-1; j >= 0 ; j--) { 
    166187                Overload o1 = new_overloads.get(i); 
     
    320341                } 
    321342            } 
     343            } 
    322344        } 
    323345        FType ftoa = FTypeOverloadedArrow.make(ftalist); 
     
    405427//        if (finishedFirst && !fn.getFinished()) 
    406428//            throw new IllegalStateException("Any functions added after finishedFirst must have types assigned."); 
    407         addOverload(new Overload(fn)); 
     429        addOverload(new Overload(fn, this)); 
    408430    } 
    409431 
     
    427449     * @param overload 
    428450     */ 
    429     public synchronized void addOverload(Overload overload) { 
     451    public void addOverload(Overload overload) { 
    430452//        if (finishedSecond) 
    431453//            throw new IllegalStateException("Cannot add overloads after overloaded function is complete"); 
    432454         
    433         Thread me = Thread.currentThread(); 
     455//        Thread me = Thread.currentThread(); 
     456//         
     457//        if (currentUpdater == null) { 
     458//            currentUpdater = me; 
     459//        } 
     460//         
     461//        while (currentUpdater != me) { 
     462//            try { 
     463//                wait(); 
     464//            } catch (InterruptedException e) { 
     465//                // TODO Auto-generated catch block 
     466//                e.printStackTrace(); 
     467//            } 
     468//            if (currentUpdater == null) 
     469//                currentUpdater = me; 
     470//        } 
     471//         
    434472         
    435         if (currentUpdater == null) { 
    436             currentUpdater = me; 
     473        if (!finishedSecond) { 
     474            pendingOverloads.add(overload); 
     475            // InstantiationLock.lastOverload = this; 
     476            // InstantiationLock.lastOverloadThrowable = Useful.backtrace(0, 1000); 
     477        } else { 
     478            // InstantiationLock.L.lock(); 
     479            if (debug) 
     480                System.err.println("Lock " + fnName.stringName()); 
     481            finishedFirst = false; 
     482            finishedSecond = false; 
     483            pendingOverloads.add(overload); 
     484            // InstantiationLock.lastOverload = this; 
     485            // InstantiationLock.lastOverloadThrowable = Useful.backtrace(0, 1000); 
    437486        } 
    438487         
    439         while (currentUpdater != me) { 
    440             try { 
    441                 wait(); 
    442             } catch (InterruptedException e) { 
    443                 // TODO Auto-generated catch block 
    444                 e.printStackTrace(); 
    445             } 
    446             if (currentUpdater == null) 
    447                 currentUpdater = me; 
    448         } 
    449          
    450         finishedFirst = false; 
    451         finishedSecond = false; 
    452         pendingOverloads.add(overload); 
     488        if (debug) { 
     489            DebugletPrintStream ps = DebugletPrintStream.make("OVERLOADS"); 
     490            overload.ps = ps; 
     491            System.err.println("add " + ps + " " + overload); 
     492            ps.backtrace().flush(); 
     493        } 
    453494         
    454495    } 
     
    481522     */ 
    482523    public int bestMatchIndex(List<FValue> args, HasAt loc, BetterEnv envForInference) throws Error { 
    483         if (!finishedSecond) { 
    484             synchronized(this) { 
    485                 if (!finishedSecond && 
    486                         (currentUpdater == Thread.currentThread() || 
    487                          currentUpdater == null)) 
    488                     bug(loc,"Cannot call before 'setFinished()'"); 
    489             } 
    490         } 
     524       
     525        if (!finishedSecond && InstantiationLock.L.isHeldByCurrentThread()) 
     526            bug(loc, "Cannot call before 'setFinished()'"); 
    491527            
    492528        int best = -1; 
     
    567603     * very exciting overload consistency test. 
    568604     */ 
    569     public synchronized void bless() { 
     605    public void bless() { 
     606        if (finishedSecond) 
     607            return; 
    570608        this.overloads = pendingOverloads; 
    571609        this.pendingOverloads = new ArrayList<Overload>(); 
    572610        finishedSecond = true; 
    573611        finishedFirst = true; 
    574         notifyAll(); 
    575         currentUpdater = null; 
     612        if (debug) 
     613            System.err.println("Unlock " + fnName.stringName()); 
     614        // InstantiationLock.L.unlock(); 
    576615    } 
    577616 
  • trunk/ProjectFortress/test

    r723 r879  
    2424fi 
    2525 
    26 java -cp "$CP" -Xmx320m -Xms192m \ 
     26 
     27 
     28java -cp "$CP" -Xmx512m -Xms256m \ 
    2729junit.swingui.TestRunner \ 
    2830com.sun.fortress.interpreter.drivers.SystemJUTests >& test.log