Author: sco...@google.com
Date: Thu Apr  2 17:57:11 2009
New Revision: 5181

Modified:
     
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java
     
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
     
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
     
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
     
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java

Log:
JField compute clinit on demand; inlined JTypeOracle.checkClinit

Modified:  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java
==============================================================================
---  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java    
 
(original)
+++  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JFieldRef.java    
 
Thu Apr  2 17:57:11 2009
@@ -33,11 +33,6 @@
    private final JField field;

    /**
-   * If true, this field access forces a clinit.
-   */
-  private boolean hasClinit;
-
-  /**
     * This can only be null if the referenced field is static.
     */
    private JExpression instance;
@@ -85,9 +80,20 @@
      return super.getType();
    }

+  public boolean hasClinit() {
+    // A cross-class reference to a static, non constant field forces  
clinit
+    if (!field.isStatic()) {
+      return false;
+    }
+    if (field.isFinal() && field.isCompileTimeConstant()) {
+      return false;
+    }
+    return getEnclosingType().checkClinitTo(field.getEnclosingType());
+  }
+
    @Override
    public boolean hasSideEffects() {
-    if (hasClinit) {
+    if (hasClinit()) {
        return true;
      }
      JExpression expr = instance;
@@ -95,10 +101,6 @@
        return false;
      }
      return expr.hasSideEffects();
-  }
-
-  public void setHasClinit(boolean hasClinit) {
-    this.hasClinit = hasClinit;
    }

    public void traverse(JVisitor visitor, Context ctx) {

Modified:  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
==============================================================================
---  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java  
 
(original)
+++  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java  
 
Thu Apr  2 17:57:11 2009
@@ -16,7 +16,6 @@
  package com.google.gwt.dev.jjs.ast;

  import com.google.gwt.dev.jjs.ast.js.JMultiExpression;
-import com.google.gwt.dev.jjs.ast.js.JsniFieldRef;
  import com.google.gwt.dev.util.collect.IdentityHashMap;
  import com.google.gwt.dev.util.collect.IdentityHashSet;
  import com.google.gwt.dev.util.collect.IdentitySets;
@@ -373,23 +372,6 @@
      return false;
    }

-  /**
-   * Returns <code>true</code> if a static field access of  
<code>toType</code>
-   * from within <code>fromType</code> should generate a clinit call. This
-   * will be true in cases where <code>toType</code> has a live clinit  
method
-   * which we cannot statically know has already run. We can statically  
know the
-   * clinit method has already run when:
-   * <ol>
-   * <li><code>fromType == toType</code></li>
-   * <li><code>toType</code> is a superclass of <code>fromType</code>
-   * (because <code>toType</code>'s clinit would have already run
-   * <code>fromType</code>'s clinit; see JLS 12.4)</li>
-   * </ol>
-   */
-  public boolean checkClinit(JReferenceType fromType, JReferenceType  
toType) {
-    return fromType.checkClinitTo(toType);
-  }
-
    public void computeBeforeAST() {
      javaLangObject = program.getTypeJavaLangObject();
      superClassMap.clear();
@@ -537,30 +519,6 @@
      }

      computeSingleJsoImplData();
-
-    // Update JFieldRef's clinit info.
-    new JVisitor() {
-      @Override
-      public void endVisit(JsniFieldRef x, Context ctx) {
-        endVisit((JFieldRef) x, ctx);
-      }
-
-      @Override
-      public void endVisit(JFieldRef x, Context ctx) {
-        // A cross-class reference to a static, non constant field forces  
clinit
-        JField field = x.getField();
-        if (field.isStatic()
-            && (!field.isFinal() || !field.isCompileTimeConstant())) {
-          if (program.typeOracle.checkClinit(x.getEnclosingType(),
-              field.getEnclosingType())) {
-            // Therefore, we have side effects
-            x.setHasClinit(true);
-            return;
-          }
-        }
-        x.setHasClinit(false);
-      }
-    }.accept(program);
    }

    public void setInstantiatedTypes(Set<JReferenceType> instantiatedTypes) {

Modified:  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
==============================================================================
---  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
  
(original)
+++  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
  
Thu Apr  2 17:57:11 2009
@@ -32,7 +32,6 @@
  import com.google.gwt.dev.jjs.ast.JDoubleLiteral;
  import com.google.gwt.dev.jjs.ast.JExpression;
  import com.google.gwt.dev.jjs.ast.JExpressionStatement;
-import com.google.gwt.dev.jjs.ast.JField;
  import com.google.gwt.dev.jjs.ast.JFieldRef;
  import com.google.gwt.dev.jjs.ast.JForStatement;
  import com.google.gwt.dev.jjs.ast.JIfStatement;
@@ -1176,19 +1175,12 @@
      }

      private JMethodCall maybeCreateClinitCall(JFieldRef x) {
-      JMethodCall call;
-      JField field = x.getField();
-      if (field.isStatic()
-          && !field.isCompileTimeConstant()
-          && program.typeOracle.checkClinit(currentClass,
-              field.getEnclosingType())) {
-        JMethod clinit = field.getEnclosingType().methods.get(0);
+      if (x.hasClinit()) {
+        JMethod clinit = x.getField().getEnclosingType().methods.get(0);
          assert (JProgram.isClinit(clinit));
-        call = new JMethodCall(x.getSourceInfo(), null, clinit);
-      } else {
-        call = null;
+        return new JMethodCall(x.getSourceInfo(), null, clinit);
        }
-      return call;
+      return null;
      }

      private int numRemovableExpressions(JMultiExpression x) {

Modified:  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
==============================================================================
---  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
        
(original)
+++  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
        
Thu Apr  2 17:57:11 2009
@@ -1641,15 +1641,14 @@
          return null;
        }

-      JReferenceType enclosingType = x.getEnclosingType();
-      if (!typeOracle.checkClinit(currentMethod.getEnclosingType(),
-          enclosingType)) {
+      JReferenceType targetType = x.getEnclosingType();
+      if (!currentMethod.getEnclosingType().checkClinitTo(targetType)) {
          return null;
-      } else if  
(enclosingType.equals(program.getTypeClassLiteralHolder())) {
+      } else if (targetType.equals(program.getTypeClassLiteralHolder())) {
          return null;
        }

-      JMethod clinitMethod = enclosingType.methods.get(0);
+      JMethod clinitMethod = targetType.methods.get(0);
        SourceInfo sourceInfo = x.getSourceInfo().makeChild(
            GenerateJavaScriptVisitor.class, "clinit invocation");
        JsInvocation jsInvocation = new JsInvocation(sourceInfo);
@@ -1750,7 +1749,7 @@
      public void endVisit(JMethodCall x, Context ctx) {
        JReferenceType sourceType = currentMethod.getEnclosingType();
        JReferenceType targetType = x.getTarget().getEnclosingType();
-      if (typeOracle.checkClinit(sourceType, targetType)) {
+      if (sourceType.checkClinitTo(targetType)) {
          crossClassTargets.add(x.getTarget());
        }
      }

Modified:  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
==============================================================================
---  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
        
(original)
+++  
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
        
Thu Apr  2 17:57:11 2009
@@ -148,8 +148,7 @@

      private JMethodCall createClinitCall(JMethodCall x) {
        JReferenceType targetEnclosingType =  
x.getTarget().getEnclosingType();
-      if (!program.typeOracle.checkClinit(currentMethod.getEnclosingType(),
-          targetEnclosingType)) {
+      if  
(!currentMethod.getEnclosingType().checkClinitTo(targetEnclosingType)) {
          // Access from this class to the target class won't trigger a  
clinit
          return null;
        }

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to