Changeset 12061


Ignore:
Timestamp:
07/26/09 08:34:00 (14 years ago)
Author:
ehuelsmann
Message:

Eliminate constructor execution time of Cons, LispObject and Lisp.

By removing inheritance of StackFrame? from LispObject and no longer storing
the stack as a list of Conses, a large number of calls to these constructors
have been removed.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Lisp.java

    r12053 r12061  
    141141    throws ConditionThrowable
    142142  {
    143     LispObject stack = thread.getStack();
    144143    thread.pushStackFrame(fun, args);
    145144    thread._values = null;
     
    190189    finally
    191190      {
    192         thread.setStack(stack);
     191        thread.popStackFrame();
    193192      }
    194193    return result;
  • trunk/abcl/src/org/armedbear/lisp/LispThread.java

    r12058 r12061  
    3535
    3636import java.util.Iterator;
     37import java.util.LinkedList;
    3738import java.util.concurrent.ConcurrentHashMap;
    3839
     
    448449    }
    449450
    450     private static class StackFrame extends LispObject
     451    private static class StackFrame
    451452    {
    452453        public final LispObject operator;
     
    535536    }
    536537
    537     private LispObject stack = NIL;
    538 
     538    private LinkedList<StackFrame> stack = new LinkedList<StackFrame>();
     539
     540    @Deprecated
    539541    public LispObject getStack()
    540542    {
    541         return stack;
    542     }
    543 
     543        return NIL;
     544    }
     545
     546    @Deprecated
    544547    public void setStack(LispObject stack)
    545548    {
    546         this.stack = stack;
    547549    }
    548550
     
    559561        throws ConditionThrowable
    560562    {
    561         stack = new Cons((new StackFrame(operator)), stack);
     563        stack.addLast(new StackFrame(operator));
    562564        doProfiling();
    563565    }
     
    566568        throws ConditionThrowable
    567569    {
    568         stack = new Cons((new StackFrame(operator, arg)), stack);
     570        stack.addLast(new StackFrame(operator, arg));
    569571        doProfiling();
    570572    }
     
    574576        throws ConditionThrowable
    575577    {
    576         stack = new Cons((new StackFrame(operator, first, second)), stack);
     578        stack.addLast(new StackFrame(operator, first, second));
    577579        doProfiling();
    578580    }
     
    582584        throws ConditionThrowable
    583585    {
    584         stack = new Cons((new StackFrame(operator, first, second, third)),
    585                          stack);
     586        stack.addLast(new StackFrame(operator, first, second, third));
    586587        doProfiling();
    587588    }
     
    590591        throws ConditionThrowable
    591592    {
    592         stack = new Cons((new StackFrame(operator, args)), stack);
     593        stack.addLast(new StackFrame(operator, args));
    593594        doProfiling();
    594595    }
    595596
     597    public final void popStackFrame()
     598    {
     599        stack.removeLast();
     600    }
     601
    596602    public void resetStack()
    597603    {
    598         stack = NIL;
     604        stack.clear();
    599605    }
    600606
     
    605611            return function.execute();
    606612
    607         LispObject oldStack = stack;
    608613        pushStackFrame(function);
    609614        try {
     
    612617        finally {
    613618            doProfiling();
    614             stack = oldStack;
     619            popStackFrame();
    615620        }
    616621    }
     
    623628            return function.execute(arg);
    624629
    625         LispObject oldStack = stack;
    626630        pushStackFrame(function, arg);
    627631        try {
     
    630634        finally {
    631635            doProfiling();
    632             stack = oldStack;
     636            popStackFrame();
    633637        }
    634638    }
     
    642646            return function.execute(first, second);
    643647
    644         LispObject oldStack = stack;
    645648        pushStackFrame(function, first, second);
    646649        try {
     
    649652        finally {
    650653            doProfiling();
    651             stack = oldStack;
     654            popStackFrame();
    652655        }
    653656    }
     
    661664            return function.execute(first, second, third);
    662665
    663         LispObject oldStack = stack;
    664666        pushStackFrame(function, first, second, third);
    665667        try {
     
    668670        finally {
    669671            doProfiling();
    670             stack = oldStack;
     672            popStackFrame();
    671673        }
    672674    }
     
    681683            return function.execute(first, second, third, fourth);
    682684
    683         LispObject oldStack = stack;
    684685        pushStackFrame(function, first, second, third, fourth);
    685686        try {
     
    688689        finally {
    689690            doProfiling();
    690             stack = oldStack;
     691            popStackFrame();
    691692        }
    692693    }
     
    701702            return function.execute(first, second, third, fourth, fifth);
    702703
    703         LispObject oldStack = stack;
    704704        pushStackFrame(function, first, second, third, fourth, fifth);
    705705        try {
     
    708708        finally {
    709709            doProfiling();
    710             stack = oldStack;
     710            popStackFrame();
    711711        }
    712712    }
     
    722722            return function.execute(first, second, third, fourth, fifth, sixth);
    723723
    724         LispObject oldStack = stack;
    725724        pushStackFrame(function, first, second, third, fourth, fifth, sixth);
    726725        try {
     
    729728        finally {
    730729            doProfiling();
    731             stack = oldStack;
     730            popStackFrame();
    732731        }
    733732    }
     
    744743                                    seventh);
    745744
    746         LispObject oldStack = stack;
    747745        pushStackFrame(function, first, second, third, fourth, fifth, sixth,
    748746                                    seventh);
     
    753751        finally {
    754752            doProfiling();
    755             stack = oldStack;
     753            popStackFrame();
    756754        }
    757755    }
     
    768766                                    seventh, eighth);
    769767
    770         LispObject oldStack = stack;
    771768        pushStackFrame(function, first, second, third, fourth, fifth, sixth,
    772769                                    seventh, eighth);
     
    777774        finally {
    778775            doProfiling();
    779             stack = oldStack;
     776            popStackFrame();
    780777        }
    781778    }
     
    787784            return function.execute(args);
    788785
    789         LispObject oldStack = stack;
    790786        pushStackFrame(function, args);
    791787        try {
     
    794790        finally {
    795791            doProfiling();
    796             stack = oldStack;
     792            popStackFrame();
    797793        }
    798794    }
     
    805801    public void backtrace(int limit)
    806802    {
    807         if (stack != NIL) {
     803        if (! stack.isEmpty()) {
    808804            try {
    809805                int count = 0;
     
    812808                out._writeLine("Evaluation stack:");
    813809                out._finishOutput();
    814                 while (stack != NIL) {
     810                Iterator<StackFrame> i = stack.iterator();
     811                while (i.hasNext()) {
    815812                    out._writeString("  ");
    816813                    out._writeString(String.valueOf(count));
    817814                    out._writeString(": ");
    818                     StackFrame frame = (StackFrame) stack.car();
     815                    StackFrame frame = i.next();
    819816                    pprint(frame.toList(), out.getCharPos(), out);
    820817                    out.terpri();
     
    822819                    if (limit > 0 && ++count == limit)
    823820                        break;
    824                     stack = stack.cdr();
    825821                }
    826822            }
     
    834830    {
    835831        LispObject result = NIL;
    836         if (stack != NIL) {
     832        if (! stack.isEmpty()) {
    837833            int count = 0;
    838834            try {
    839                 LispObject s = stack;
    840                 while (s != NIL) {
    841                     StackFrame frame = (StackFrame) s.car();
     835                Iterator<StackFrame> i = stack.iterator();
     836                while (i.hasNext()) {
     837                    StackFrame frame = i.next();
    842838                    if (frame != null) {
    843839                        result = result.push(frame.toList());
     
    845841                            break;
    846842                    }
    847                     s = s.cdr();
    848843                }
    849844            }
     
    857852    public void incrementCallCounts() throws ConditionThrowable
    858853    {
    859         LispObject s = stack;
    860         while (s != NIL) {
    861             StackFrame frame = (StackFrame) s.car();
     854        Iterator<StackFrame> i = stack.iterator();
     855        while (i.hasNext()) {
     856            StackFrame frame = i.next();
    862857            if (frame != null) {
    863858                LispObject operator = frame.operator;
     
    865860                    operator.incrementCallCount();
    866861            }
    867             s = s.cdr();
    868862        }
    869863    }
Note: See TracChangeset for help on using the changeset viewer.