[armedbear-cvs] r12061 - trunk/abcl/src/org/armedbear/lisp

Erik Huelsmann ehuelsmann at common-lisp.net
Sun Jul 26 08:34:15 UTC 2009


Author: ehuelsmann
Date: Sun Jul 26 04:34:00 2009
New Revision: 12061

Log:
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.

Modified:
   trunk/abcl/src/org/armedbear/lisp/Lisp.java
   trunk/abcl/src/org/armedbear/lisp/LispThread.java

Modified: trunk/abcl/src/org/armedbear/lisp/Lisp.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Lisp.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Lisp.java	Sun Jul 26 04:34:00 2009
@@ -140,7 +140,6 @@
                                          LispThread thread)
     throws ConditionThrowable
   {
-    LispObject stack = thread.getStack();
     thread.pushStackFrame(fun, args);
     thread._values = null;
     LispObject result;
@@ -189,7 +188,7 @@
       }
     finally
       {
-        thread.setStack(stack);
+        thread.popStackFrame();
       }
     return result;
   }

Modified: trunk/abcl/src/org/armedbear/lisp/LispThread.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/LispThread.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/LispThread.java	Sun Jul 26 04:34:00 2009
@@ -34,6 +34,7 @@
 package org.armedbear.lisp;
 
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.concurrent.ConcurrentHashMap;
 
 public final class LispThread extends LispObject
@@ -447,7 +448,7 @@
                                 tag.writeToString() + "."));
     }
 
-    private static class StackFrame extends LispObject
+    private static class StackFrame
     {
         public final LispObject operator;
         private final LispObject first;
@@ -534,16 +535,17 @@
         }
     }
 
-    private LispObject stack = NIL;
+    private LinkedList<StackFrame> stack = new LinkedList<StackFrame>();
 
+    @Deprecated
     public LispObject getStack()
     {
-        return stack;
+        return NIL;
     }
 
+    @Deprecated
     public void setStack(LispObject stack)
     {
-        this.stack = stack;
     }
 
     private void doProfiling()
@@ -558,14 +560,14 @@
     public final void pushStackFrame(LispObject operator)
         throws ConditionThrowable
     {
-        stack = new Cons((new StackFrame(operator)), stack);
+        stack.addLast(new StackFrame(operator));
         doProfiling();
     }
 
     public final void pushStackFrame(LispObject operator, LispObject arg)
         throws ConditionThrowable
     {
-        stack = new Cons((new StackFrame(operator, arg)), stack);
+        stack.addLast(new StackFrame(operator, arg));
         doProfiling();
     }
 
@@ -573,7 +575,7 @@
                                LispObject second)
         throws ConditionThrowable
     {
-        stack = new Cons((new StackFrame(operator, first, second)), stack);
+        stack.addLast(new StackFrame(operator, first, second));
         doProfiling();
     }
 
@@ -581,21 +583,25 @@
                                LispObject second, LispObject third)
         throws ConditionThrowable
     {
-        stack = new Cons((new StackFrame(operator, first, second, third)),
-                         stack);
+        stack.addLast(new StackFrame(operator, first, second, third));
         doProfiling();
     }
 
     public final void pushStackFrame(LispObject operator, LispObject... args)
         throws ConditionThrowable
     {
-        stack = new Cons((new StackFrame(operator, args)), stack);
+        stack.addLast(new StackFrame(operator, args));
         doProfiling();
     }
 
+    public final void popStackFrame()
+    {
+        stack.removeLast();
+    }
+
     public void resetStack()
     {
-        stack = NIL;
+        stack.clear();
     }
 
     @Override
@@ -604,14 +610,13 @@
         if (use_fast_calls)
             return function.execute();
 
-        LispObject oldStack = stack;
         pushStackFrame(function);
         try {
             return function.execute();
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -622,14 +627,13 @@
         if (use_fast_calls)
             return function.execute(arg);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, arg);
         try {
             return function.execute(arg);
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -641,14 +645,13 @@
         if (use_fast_calls)
             return function.execute(first, second);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, first, second);
         try {
             return function.execute(first, second);
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -660,14 +663,13 @@
         if (use_fast_calls)
             return function.execute(first, second, third);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, first, second, third);
         try {
             return function.execute(first, second, third);
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -680,14 +682,13 @@
         if (use_fast_calls)
             return function.execute(first, second, third, fourth);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, first, second, third, fourth);
         try {
             return function.execute(first, second, third, fourth);
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -700,14 +701,13 @@
         if (use_fast_calls)
             return function.execute(first, second, third, fourth, fifth);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, first, second, third, fourth, fifth);
         try {
             return function.execute(first, second, third, fourth, fifth);
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -721,14 +721,13 @@
         if (use_fast_calls)
             return function.execute(first, second, third, fourth, fifth, sixth);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, first, second, third, fourth, fifth, sixth);
         try {
             return function.execute(first, second, third, fourth, fifth, sixth);
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -743,7 +742,6 @@
             return function.execute(first, second, third, fourth, fifth, sixth,
                                     seventh);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, first, second, third, fourth, fifth, sixth,
                                     seventh);
         try {
@@ -752,7 +750,7 @@
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -767,7 +765,6 @@
             return function.execute(first, second, third, fourth, fifth, sixth,
                                     seventh, eighth);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, first, second, third, fourth, fifth, sixth,
                                     seventh, eighth);
         try {
@@ -776,7 +773,7 @@
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -786,14 +783,13 @@
         if (use_fast_calls)
             return function.execute(args);
 
-        LispObject oldStack = stack;
         pushStackFrame(function, args);
         try {
             return function.execute(args);
         }
         finally {
             doProfiling();
-            stack = oldStack;
+            popStackFrame();
         }
     }
 
@@ -804,24 +800,24 @@
 
     public void backtrace(int limit)
     {
-        if (stack != NIL) {
+        if (! stack.isEmpty()) {
             try {
                 int count = 0;
                 Stream out =
                     checkCharacterOutputStream(Symbol.TRACE_OUTPUT.symbolValue());
                 out._writeLine("Evaluation stack:");
                 out._finishOutput();
-                while (stack != NIL) {
+                Iterator<StackFrame> i = stack.iterator();
+                while (i.hasNext()) {
                     out._writeString("  ");
                     out._writeString(String.valueOf(count));
                     out._writeString(": ");
-                    StackFrame frame = (StackFrame) stack.car();
+                    StackFrame frame = i.next();
                     pprint(frame.toList(), out.getCharPos(), out);
                     out.terpri();
                     out._finishOutput();
                     if (limit > 0 && ++count == limit)
                         break;
-                    stack = stack.cdr();
                 }
             }
             catch (Throwable t) {
@@ -833,18 +829,17 @@
     public LispObject backtraceAsList(int limit) throws ConditionThrowable
     {
         LispObject result = NIL;
-        if (stack != NIL) {
+        if (! stack.isEmpty()) {
             int count = 0;
             try {
-                LispObject s = stack;
-                while (s != NIL) {
-                    StackFrame frame = (StackFrame) s.car();
+                Iterator<StackFrame> i = stack.iterator();
+                while (i.hasNext()) {
+                    StackFrame frame = i.next();
                     if (frame != null) {
                         result = result.push(frame.toList());
                         if (limit > 0 && ++count == limit)
                             break;
                     }
-                    s = s.cdr();
                 }
             }
             catch (Throwable t) {
@@ -856,15 +851,14 @@
 
     public void incrementCallCounts() throws ConditionThrowable
     {
-        LispObject s = stack;
-        while (s != NIL) {
-            StackFrame frame = (StackFrame) s.car();
+        Iterator<StackFrame> i = stack.iterator();
+        while (i.hasNext()) {
+            StackFrame frame = i.next();
             if (frame != null) {
                 LispObject operator = frame.operator;
                 if (operator != null)
                     operator.incrementCallCount();
             }
-            s = s.cdr();
         }
     }
 




More information about the armedbear-cvs mailing list