changeset 24728:cb8b23db71ec

8038223: Symbol trace debug output takes time Reviewed-by: hannesw, lagergren
author attila
date Mon, 24 Mar 2014 18:40:11 +0100
parents 611ba7e2101f
children 2b13051f2122
files nashorn/src/jdk/nashorn/internal/ir/Symbol.java
diffstat 1 files changed, 25 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/nashorn/src/jdk/nashorn/internal/ir/Symbol.java	Fri Mar 21 17:52:03 2014 +0100
+++ b/nashorn/src/jdk/nashorn/internal/ir/Symbol.java	Mon Mar 24 18:40:11 2014 +0100
@@ -31,7 +31,6 @@
 import java.util.HashSet;
 import java.util.Set;
 import java.util.StringTokenizer;
-
 import jdk.nashorn.internal.codegen.types.Range;
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.runtime.Context;
@@ -143,7 +142,9 @@
         this.slot       = slot;
         this.fieldIndex = -1;
         this.range      = Range.createUnknownRange();
-        trace("CREATE SYMBOL " + type);
+        if(shouldTrace()) {
+            trace("CREATE SYMBOL " + type);
+        }
     }
 
     /**
@@ -388,7 +389,9 @@
      */
      public Symbol setIsScope() {
         if (!isScope()) {
-            trace("SET IS SCOPE");
+            if(shouldTrace()) {
+                trace("SET IS SCOPE");
+            }
             assert !isShared();
             flags |= IS_SCOPE;
         }
@@ -402,7 +405,9 @@
      public Symbol setIsShared() {
          if (!isShared()) {
              assert isTemp();
-             trace("SET IS SHARED");
+             if(shouldTrace()) {
+                 trace("SET IS SHARED");
+             }
              flags |= IS_SHARED;
          }
          return this;
@@ -414,7 +419,9 @@
      */
     public void setIsFunctionDeclaration() {
         if (!isFunctionDeclaration()) {
-            trace("SET IS FUNCTION DECLARATION");
+            if(shouldTrace()) {
+                trace("SET IS FUNCTION DECLARATION");
+            }
             flags |= IS_FUNCTION_DECLARATION;
         }
     }
@@ -681,7 +688,9 @@
     public Symbol setSlot(final int slot) {
         if (slot != this.slot) {
             assert !isShared();
-            trace("SET SLOT " + slot);
+            if(shouldTrace()) {
+                trace("SET SLOT " + slot);
+            }
             this.slot = slot;
         }
         return this;
@@ -731,7 +740,9 @@
         final Type old = this.type;
         if (old != type) {
             assert !isShared() : this + " is a shared symbol and cannot have its type overridden to " + type;
-            trace("TYPE CHANGE: " + old + "=>" + type + " == " + type);
+            if(shouldTrace()) {
+                trace("TYPE CHANGE: " + old + "=>" + type + " == " + type);
+            }
             this.type = type;
         }
         return this;
@@ -776,12 +787,14 @@
         return symbol;
     }
 
+    private boolean shouldTrace() {
+        return TRACE_SYMBOLS != null && (TRACE_SYMBOLS.isEmpty() || TRACE_SYMBOLS.contains(name));
+    }
+
     private void trace(final String desc) {
-        if (TRACE_SYMBOLS != null && (TRACE_SYMBOLS.isEmpty() || TRACE_SYMBOLS.contains(name))) {
-            Context.err(Debug.id(this) + " SYMBOL: '" + name + "' " + desc);
-            if (TRACE_SYMBOLS_STACKTRACE != null && (TRACE_SYMBOLS_STACKTRACE.isEmpty() || TRACE_SYMBOLS_STACKTRACE.contains(name))) {
-                new Throwable().printStackTrace(Context.getCurrentErr());
-            }
+        Context.err(Debug.id(this) + " SYMBOL: '" + name + "' " + desc);
+        if (TRACE_SYMBOLS_STACKTRACE != null && (TRACE_SYMBOLS_STACKTRACE.isEmpty() || TRACE_SYMBOLS_STACKTRACE.contains(name))) {
+            new Throwable().printStackTrace(Context.getCurrentErr());
         }
     }
 }