freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [20/23] incubator-freemarker git commit: Decreased guaranteed stack usage (which is the stack usage you see in exception stack traces) by 1 per visit(TemplateElement[]).
Date Tue, 15 Dec 2015 22:24:01 GMT
Decreased guaranteed stack usage (which is the stack usage you see in exception stack traces)
by 1 per visit(TemplateElement[]).


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/a97cf728
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/a97cf728
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/a97cf728

Branch: refs/heads/2.3
Commit: a97cf7289d53a69cf74cb3a9aa9f669e99e3949f
Parents: bc303ab
Author: ddekany <ddekany@apache.org>
Authored: Tue Dec 15 00:18:10 2015 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Tue Dec 15 00:18:10 2015 +0100

----------------------------------------------------------------------
 src/main/java/freemarker/core/Environment.java | 27 ++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a97cf728/src/main/java/freemarker/core/Environment.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/Environment.java b/src/main/java/freemarker/core/Environment.java
index a622e9b..ef7a301 100644
--- a/src/main/java/freemarker/core/Environment.java
+++ b/src/main/java/freemarker/core/Environment.java
@@ -320,6 +320,7 @@ public final class Environment extends Configurable {
      * "Visit" the template element.
      */
     void visit(TemplateElement element) throws IOException, TemplateException {
+        // ATTENTION: This method body is manually "inlined" into visit(TemplateElement[]);
keep them in sync!
         pushElement(element);
         try {
             TemplateElement[] templateElementsToVisit = element.accept(this);
@@ -336,6 +337,7 @@ public final class Environment extends Configurable {
         } finally {
             popElement();
         }
+        // ATTENTION: This method body above is manually "inlined" into visit(TemplateElement[]);
keep them in sync!
     }
     
     /**
@@ -348,11 +350,30 @@ public final class Environment extends Configurable {
         if (elementBuffer == null) {
             return;
         }
-        for (TemplateElement el : elementBuffer) {
-            if (el == null) {
+        for (TemplateElement element : elementBuffer) {
+            if (element == null) {
                 break;  // Skip unused trailing buffer capacity 
             }
-            visit(el);
+            
+            // ATTENTION: This part is the manually "inlining" of visit(TemplateElement[]);
keep them in sync!
+            // We don't just let Hotspot to do it, as we want a hard guarantee regarding
maximum stack usage. 
+            pushElement(element);
+            try {
+                TemplateElement[] templateElementsToVisit = element.accept(this);
+                if (templateElementsToVisit != null) {
+                    for (TemplateElement el : templateElementsToVisit) {
+                        if (el == null) {
+                            break;  // Skip unused trailing buffer capacity 
+                        }
+                        visit(el);
+                    }
+                }
+            } catch (TemplateException te) {
+                handleTemplateException(te);
+            } finally {
+                popElement();
+            }
+            // ATTENTION: This part above is the manually "inlining" of visit(TemplateElement[]);
keep them in sync!
         }
     }
 


Mime
View raw message