Roberto Lublinerman has posted comments on this change.

Change subject: Optimize initializing fields at the top scope.
......................................................................


Patch Set 1:

(1 comment)

....................................................
File dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
Line 2234:           // method. For now, assume that they might.
I was think of a visitor like this one (incomplete) that only checks whether any of the class constructors have a dynamic call.

  /**
* Classes that could potentially see uninitialized values for fields that are ininitialized
   * in the declaration.
   */
final Set<JClassType> canObserveSubclassUninitializedFieldsSet = new HashSet<JClassType>();

  /**
* Determines which classes can potentially see uninitialized values for fields that
   * are assigned literals in the declaration from subclasses.
   *
* If a class can not observe subclass uninitialized fieds then the initialization of those
   * could be hoisted to the prototype.
   */
private class CanObserveSubclassUninitializedFieldsVisitor extends JVisitor {

    private JClassType currentClass;
    @Override
    public boolean visit(JConstructor x, Context ctx) {
      // Only look at constructor bodies.
      assert currentClass == null;
      currentClass = x.getEnclosingType();
      return true;
    }

    @Override
    public boolean visit(JMethod x, Context ctx) {
      // Do not traverse the method body if it is not a constructor.
      return false;
    }

    @Override
    public void endVisit(JMethodCall x, Context ctx) {
      // this is a method call inside a constructor.
      assert currentClass != null;
      // static dispatch can not observe subclass fields.
      if (!x.isStaticDispatchOnly())
        return;


      if (x.canBePolymorphic()) {
        // only potentially dynamic calls could observe uninitialized
        // subclass fields.
        canObserveSubclassUninitializedFieldsSet.add(currentClass);
      }
    }
  }

After you run this visitor (which should probably be the first thing in execImpl) the information need to be propagated from classes to subclasses. That can be done in the visitor by querying the type oracle for subclasses or by another visitor pass, your choice.


--
To view, visit https://gwt-review.googlesource.com/3440
To unsubscribe, visit https://gwt-review.googlesource.com/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I97a06eb36396a8b8659ce9a025b21a9cf93d0500
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Stephen Haberman <stephen.haber...@gmail.com>
Gerrit-Reviewer: Brian Slesinsky <skybr...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jenk...@gwtproject.org>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Stephen Haberman <stephen.haber...@gmail.com>
Gerrit-HasComments: Yes

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to