Author: sco...@google.com Date: Thu Apr 2 17:54:48 2009 New Revision: 5177
Modified: changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java Log: First pass at storing clinit state in classes. Modified: changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java ============================================================================== --- changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java (original) +++ changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JArrayType.java Thu Apr 2 17:54:48 2009 @@ -29,8 +29,8 @@ } private int dims; - private JType leafType; private JType elementType; + private JType leafType; /** * These are only supposed to be constructed by JProgram. @@ -71,9 +71,14 @@ } return s; } - + public JType getLeafType() { return leafType; + } + + @Override + public boolean hasClinit() { + return false; } public boolean isAbstract() { Modified: changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java ============================================================================== --- changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java (original) +++ changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JNullType.java Thu Apr 2 17:54:48 2009 @@ -44,6 +44,11 @@ return "N"; } + @Override + public boolean hasClinit() { + return false; + } + public boolean isAbstract() { return false; } Modified: changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java ============================================================================== --- changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java (original) +++ changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/ast/JReferenceType.java Thu Apr 2 17:54:48 2009 @@ -25,10 +25,16 @@ */ public abstract class JReferenceType extends JType implements CanBeAbstract { - public List<JField> fields = new ArrayList<JField>(); - public List<JMethod> methods = new ArrayList<JMethod>(); public JClassType extnds; + public List<JField> fields = new ArrayList<JField>(); public List<JInterfaceType> implments = new ArrayList<JInterfaceType>(); + public List<JMethod> methods = new ArrayList<JMethod>(); + + /** + * Tracks whether this class has a dynamic clinit. Defaults to true until + * shown otherwise. + */ + private boolean hasClinit = true; public JReferenceType(SourceInfo info, String name) { super(info, name, JNullLiteral.INSTANCE); @@ -49,4 +55,21 @@ return name.substring(dotpos + 1); } + /** + * Returns <code>true</code> when this method's clinit must be run + * dynamically. + */ + public boolean hasClinit() { + return hasClinit; + } + + /** + * Called when this class's clinit is empty or can be run at the top level. + */ + void removeClinit() { + assert hasClinit(); + JMethod clinitMethod = methods.get(0); + assert JProgram.isClinit(clinitMethod); + hasClinit = false; + } } 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:54:48 2009 @@ -208,7 +208,7 @@ private final Set<JInterfaceType> dualImpl = new IdentityHashSet<JInterfaceType>(); - private final Set<JReferenceType> hasClinitSet = new IdentityHashSet<JReferenceType>(); + private Set<JReferenceType> hasClinitSet; private final Map<JClassType, Set<JInterfaceType>> implementsMap = new IdentityHashMap<JClassType, Set<JInterfaceType>>(); @@ -510,7 +510,8 @@ } public boolean hasClinit(JReferenceType type) { - return hasClinitSet.contains(type); + assert type.hasClinit() == hasClinitSet.contains(type); + return type.hasClinit(); } /** @@ -544,11 +545,15 @@ * associated JProgram. */ public void recomputeAfterOptimizations() { - hasClinitSet.clear(); + hasClinitSet = new IdentityHashSet<JReferenceType>(); Set<JReferenceType> computed = new IdentityHashSet<JReferenceType>(); for (int i = 0; i < program.getDeclaredTypes().size(); ++i) { JReferenceType type = program.getDeclaredTypes().get(i); - computeHasClinit(type, computed); + if (type.hasClinit()) { + computeHasClinit(type, computed); + } else { + computed.add(type); + } } computeSingleJsoImplData(); @@ -618,6 +623,8 @@ if (computeHasClinitRecursive(type, computed, new IdentityHashSet<JReferenceType>())) { hasClinitSet.add(type); + } else { + type.removeClinit(); } computed.add(type); } @@ -629,7 +636,8 @@ // If we've been computed, hasClinitSet is accurate for me. if (computed.contains(type)) { - return hasClinitSet.contains(type); + assert type.hasClinit() == hasClinitSet.contains(type); + return type.hasClinit(); } JMethod method = type.methods.get(0); --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---