Changeset 3040

Show
Ignore:
Timestamp:
11/07/08 14:29:25 (13 months ago)
Author:
dr2chase
Message:

Trimmed memory consumption

Location:
trunk/ProjectFortress
Files:
1 added
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/src/com/sun/fortress/Shell.java

    r3017 r3040  
    5050import com.sun.fortress.nodes_util.ASTIO; 
    5151import com.sun.fortress.interpreter.Driver; 
     52import com.sun.fortress.interpreter.evaluator.Init; 
    5253import com.sun.fortress.interpreter.evaluator.values.FValue; 
    5354import com.sun.fortress.syntax_abstractions.parser.PreParser; 
     
    231232        } 
    232233 
     234        int return_code = 0; 
     235             
    233236        // Now match the assembled string. 
    234237        try { 
     
    277280 
    278281            } else { printUsageMessage(); } 
    279         } 
    280         catch (UserError error) { 
     282        } catch (UserError error) { 
    281283            System.err.println(error.getMessage()); 
    282             System.exit(-1); 
     284            return_code = -1; 
    283285        } 
    284286        catch (IOException error) { 
    285287            System.err.println(error.getMessage()); 
    286             System.exit(-2); 
    287         } 
     288            return_code = -2; 
     289        } 
     290         
     291        Init.allowForLeakChecks(); 
     292         
     293         
     294        if (return_code != 0) 
     295            System.exit(return_code); 
    288296    } 
    289297 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/ComponentWrapper.java

    r2942 r3040  
    9595    } 
    9696 
     97    /** 
     98     * Reads a "command line" component; do not leave in the cache. 
     99     * @param comp 
     100     * @param api_list 
     101     * @param linker 
     102     * @param implicitLibs 
     103     */ 
    97104    public ComponentWrapper(ComponentIndex comp, List<APIWrapper> api_list, 
    98105            HashMap<String, ComponentWrapper> linker, String[] implicitLibs) { 
     
    100107        cacheDisabled = noCache; 
    101108        transformed = getCached(comp); 
    102         // TODO Auto-generated constructor stub 
     109        componentCache.forget(comp.ast().getName()); 
    103110    } 
    104111 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BaseEnv.java

    r2973 r3040  
    746746            int negative_object_depth) { 
    747747        if (-negative_object_depth > 0) { 
     748            // This assumes $self can be found in the current environment. 
     749            // Next statement maps -1 to zero, -2 to one, -3 to two, etc. 
    748750            negative_object_depth = -1 - negative_object_depth; 
    749751            FObject obj = (FObject) e.getLeafValue(WellKnownNames.secretSelfName); 
     
    754756                e = obj.getSelfEnv(); 
    755757            } 
    756         } else if (negative_object_depth == 0) 
    757             e = e.getTopLevel(); 
     758        } else if (negative_object_depth == 0) { 
     759            e = e.getTopLevel();  
     760        } else if (negative_object_depth < 0) { 
     761            // True only for MIN_VALUE 
     762            return e; 
     763        } 
    758764        return e; 
    759765    } 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java

    r3028 r3040  
    16611661 
    16621662    public FValue forVarRef(VarRef x) { 
    1663  
     1663//        Id id = x.getVar(); 
     1664//        String s= id.getText(); 
     1665//        if (s.contains("$self")) { 
     1666//            id = x.getVar(); 
     1667//        } 
    16641668        FValue res = BaseEnv.toContainingObjectEnv(e, x.getLexicalDepth()).getValueNull(x); 
    16651669        if (res == null) { 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Init.java

    r2842 r3040  
    3030import com.sun.fortress.interpreter.evaluator.values.GenericFunctionOrMethod; 
    3131import com.sun.fortress.interpreter.glue.NativeApp; 
     32import com.sun.fortress.repository.ProjectProperties; 
     33import com.sun.fortress.useful.Useful; 
    3234 
    3335 
     
    4042 
    4143    // For leak detection. 
    42     static int countdown=4; 
    43  
     44    static int countdown=16; 
     45     
    4446    public static void initializeEverything() { 
    4547        FTypeArrow.reset(); 
     
    6062        NativeApp.reset(); 
    6163 
    62         // For leak detection; runs 4 tests, then cleans the heap, and hangs. 
    63         if (false && countdown-- == 0) { 
    64             for (int i = 0; i < 10; i++) 
    65                 System.gc(); 
    66             try { 
    67                 Thread.sleep(1000000000); 
    68             } catch (InterruptedException ex) { 
    69  
    70             } 
    71         } 
     64         
    7265 
    7366    } 
    7467 
     68    public static void allowForLeakChecks() { 
     69        if (ProjectProperties.leakCheck) { 
     70            // Clean the heap up nicely before a heap snapshot 
     71            // (is the GC really necessary?) 
     72            // note that if we snapshotting the heap,the Nth call to 
     73            // initializeEverything will do its own GC and sleep, to catch 
     74            // leaks in a seres of running tests. 
     75            initializeEverything(); 
     76            for (int i = 0; i < 10; i++) 
     77                System.gc(); 
     78            /* Hang for jmap probe */ 
     79            try { 
     80                String pid = Useful.getPid(); 
     81                if (pid == null) 
     82                    pid = "<this process id>"; 
     83                System.err.println("Now is a good time to attach to this process with \"jmap -heap:format=b " + pid + "\"\n" + 
     84                        "Now sleeping for a very long time..."); 
     85                 Thread.sleep(1000000000); 
     86             } catch (InterruptedException ex) { 
     87     
     88             } 
     89         } 
     90    } 
     91 
    7592} 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java

    r3026 r3040  
    722722    @Override 
    723723    public Node forVarType(VarType vre) { 
    724         String s = NodeUtil.nameString(vre.getName()); 
    725         StaticParam tp = visibleGenericParameters.get(s); 
    726         if (tp != null) { 
    727             usedGenericParameters.put(s, tp); 
    728         } 
    729         Node node = newType(vre, s); 
     724        Id id = vre.getName(); 
     725        Node node = vre; 
     726        if (id.getApi().isNone()) { 
     727            String s = NodeUtil.nameString(id); 
     728            StaticParam tp = visibleGenericParameters.get(s); 
     729            if (tp != null) { 
     730                usedGenericParameters.put(s, tp); 
     731            } 
     732            node = newType(vre, s); 
     733        } else { 
     734            // Rewrite lexical nesting depth to zero if api-qualified. 
     735            node = NodeFactory.makeVarType(vre, 0); 
     736        } 
     737         
    730738        return visitNode(node); 
    731739 
     
    11221130        return s; 
    11231131    } 
    1124  
     1132    
    11251133    /** 
    11261134     * Given List<Id>, generate tuple of corresponding VarRef 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java

    r3026 r3040  
    7878 
    7979    public static APIName makeAPINameSkipLast(Id first, Id rest) { 
    80         List<Id> ids = new ArrayList<Id>(); 
     80        ArrayList<Id> ids = new ArrayList<Id>(); 
    8181        Id last = first; 
    8282        ids.add(first); 
     
    8686            if (!IterUtil.isEmpty(apiNames)) last = IterUtil.last(apiNames); 
    8787        } 
     88        ids.trimToSize(); 
    8889        return new APIName(FortressUtil.spanTwo(first, last), ids); 
    8990    } 
    9091 
    9192    public static APIName makeAPIName(Id first, Id rest) { 
    92         List<Id> ids = new ArrayList<Id>(); 
     93        ArrayList<Id> ids = new ArrayList<Id>(); 
    9394        ids.add(first); 
    9495        if (rest.getApi().isSome()) { 
     
    9697        } 
    9798        ids.add(new Id(rest.getSpan(), rest.getText())); 
     99        ids.trimToSize(); 
    98100        return new APIName(FortressUtil.spanTwo(first, rest), ids); 
    99101    } 
     
    431433 
    432434    private static List<Id> stringToIds(String path) { 
    433         List<Id> ids = new ArrayList<Id>(); 
     435        ArrayList<Id> ids = new ArrayList<Id>(); 
    434436 
    435437        StringTokenizer st = new StringTokenizer(path, "."); 
     
    438440            ids.add(makeId(e)); 
    439441        } 
     442        ids.trimToSize(); 
    440443        return ids; 
    441444    } 
     
    473476 
    474477    public static APIName makeAPINameFromPath(Span span, String path, String delimiter) { 
    475         List<Id> ids = new ArrayList<Id>(); 
     478        ArrayList<Id> ids = new ArrayList<Id>(); 
    476479        String file = new File(path).getName(); 
    477480        if (file.length() <= 4) { 
     
    481484            ids.add(new Id(span, n)); 
    482485        } 
     486        ids.trimToSize(); 
    483487        return new APIName(span, ids); 
    484488    } 
     
    516520 
    517521    public static Id makeId(Span span, String api, String name) { 
    518         List<Id> apis = new ArrayList<Id>(); 
     522        ArrayList<Id> apis = new ArrayList<Id>(); 
    519523        apis.add(makeId(span, api)); 
     524        apis.trimToSize(); 
    520525        return new Id(span, Option.some(new APIName(span, apis)), name); 
    521526    } 
     
    636641                              name, 
    637642                              Option.some((Type)makeVarType(type.getSpan(),type)), 
    638                               new ArrayList<Modifier>(), 
     643                              Collections.<Modifier>emptyList(), 
    639644                              false); 
    640645    } 
     
    644649                name, 
    645650                Option.some(type), 
    646                 new ArrayList<Modifier>(), 
     651                Collections.<Modifier>emptyList(), 
    647652                false); 
    648653    } 
     
    652657                name, 
    653658                type, 
    654                 new ArrayList<Modifier>(), 
     659                Collections.<Modifier>emptyList(), 
    655660                false); 
    656661    } 
     
    658663    public static LValueBind makeLValue(String name, Type type) { 
    659664        return new LValueBind(type.getSpan(), makeId(name), Option.some(type), 
    660                 new ArrayList<Modifier>(), false); 
     665                Collections.<Modifier>emptyList(), false); 
    661666    } 
    662667 
     
    722727    public static MatrixType makeMatrixType(Span span, Type element, 
    723728                                            ExtentRange dimension) { 
    724         List<ExtentRange> dims = new ArrayList<ExtentRange>(); 
     729        ArrayList<ExtentRange> dims = new ArrayList<ExtentRange>(); 
    725730        dims.add(dimension); 
     731        dims.trimToSize(); 
    726732        return new MatrixType(span, element, dims); 
    727733    } 
     
    730736                                            ExtentRange dimension, 
    731737                                            List<ExtentRange> dimensions) { 
    732         List<ExtentRange> dims = new ArrayList<ExtentRange>(); 
     738        ArrayList<ExtentRange> dims = new ArrayList<ExtentRange>(); 
    733739        dims.add(dimension); 
    734740        dims.addAll(dimensions); 
     741        dims.trimToSize(); 
    735742        return new MatrixType(span, element, dims); 
    736743    } 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/Unprinter.java

    r2941 r3040  
    2525import java.math.BigInteger; 
    2626import java.util.ArrayList; 
     27import java.util.Collections; 
    2728import java.util.List; 
    2829import java.util.Map; 
     
    323324                    if (fcl == List.class) { 
    324325                        // empty list 
    325                         f.set(node, new ArrayList()); 
     326                        f.set(node, Collections.EMPTY_LIST); 
    326327                    } else if (fcl == String.class) { 
    327328                        // empty string 
     
    630631                x = deQuote(s).intern(); // Intermediate form is quoted. 
    631632            } else if (s.startsWith("]")) { 
     633                a.trimToSize(); 
    632634                return a; 
    633635            } else { 
  • trunk/ProjectFortress/src/com/sun/fortress/repository/DerivedFiles.java

    r3002 r3040  
    6767        } 
    6868    } 
     69     
     70    public void forget(APIName name) { 
     71        cached.remove(name); 
     72    } 
    6973 
    7074} 
  • trunk/ProjectFortress/src/com/sun/fortress/repository/ProjectProperties.java

    r2941 r3040  
    288288    public final static String API_TREE_SUFFIX = "tfi"; 
    289289 
     290    public final static boolean leakCheck = getBoolean("fortress.test.leaks", false); 
     291 
    290292 
    291293    /** Creates a new instance of ProjectProperties */ 
  • trunk/ProjectFortress/src/com/sun/fortress/tests/unit_tests/FileTests.java

    r2927 r3040  
    2626import junit.framework.Test; 
    2727import junit.framework.TestCase; 
     28import junit.framework.TestResult; 
    2829import junit.framework.TestSuite; 
    2930 
     
    3132import com.sun.fortress.Shell; 
    3233import com.sun.fortress.interpreter.Driver; 
     34import com.sun.fortress.interpreter.evaluator.Init; 
    3335import com.sun.fortress.nodes.APIName; 
    3436import com.sun.fortress.nodes.CompilationUnit; 
     
    203205    } 
    204206 
    205     public static Test suite(String dirname, boolean failsOnly, boolean expect_failure) throws IOException { 
    206         TestSuite suite = new TestSuite("Test for default package"); 
    207         // $JUnit-BEGIN$ 
    208         dirname = ProjectProperties.backslashToSlash(dirname); 
     207    public static TestSuite suite(String dir_name, boolean failsOnly, boolean expect_failure) throws IOException { 
     208        TestSuite suite = new TestSuite("Runs all tests in " + dir_name) { 
     209            public void run(TestResult result) { 
     210                super.run(result); 
     211                Init.allowForLeakChecks(); 
     212            } 
     213        }; 
     214        String dirname = ProjectProperties.backslashToSlash(dir_name); 
    209215        File dir = new File(dirname); 
    210216        String[] files = dir.list(); 
  • trunk/ProjectFortress/src/com/sun/fortress/tests/unit_tests/SystemJUTest.java

    r2449 r3040  
    3838            testDir = s; 
    3939        } 
    40         TestSuite suite = new TestSuite("Test all .fss files in 'tests'."); 
     40       // TestSuite suite = new TestSuite("Test all .fss files in 'tests'."); 
    4141        //$JUnit-BEGIN$ 
    42         suite.addTest(FileTests.suite(testDir, failsOnly, false)); 
     42       // suite.addTest(FileTests.suite(testDir, failsOnly, false)); 
    4343        //$JUnit-END$ 
    44         return suite; 
     44        return FileTests.suite(testDir, failsOnly, false); 
    4545    } 
    4646 
  • trunk/ProjectFortress/src/com/sun/fortress/useful/Useful.java

    r2715 r3040  
    10561056        } 
    10571057 
     1058        /** 
     1059         * Gets a string representing the pid of this program - Java VM 
     1060         */ 
     1061    public static String getPid() { 
     1062        ArrayList<String> commands = new ArrayList<String>(); 
     1063        commands.add("/bin/bash"); 
     1064        commands.add("-c"); 
     1065        commands.add("echo $PPID"); 
     1066        ProcessBuilder pb = new ProcessBuilder(commands); 
     1067 
     1068        try { 
     1069 
     1070            Process pr = pb.start(); 
     1071            pr.waitFor(); 
     1072            if (pr.exitValue() == 0) { 
     1073                BufferedReader outReader = new BufferedReader( 
     1074                        new InputStreamReader(pr.getInputStream())); 
     1075                return outReader.readLine().trim(); 
     1076            } else { 
     1077                return null; 
     1078            } 
     1079        } catch (IOException x) { 
     1080            return null; 
     1081        } catch (InterruptedException x) { 
     1082            return null; 
     1083        } 
     1084    } 
    10581085 
    10591086}