Author: [EMAIL PROTECTED] Date: Tue Sep 16 20:34:47 2008 New Revision: 3660
Modified: changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/ast/JVariable.java changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/JavaToJavaScriptMap.java Log: Allow tracking the liveness of class literals, and their associated allocation expressions, relative to which entry points to the program are traversed. Modified: changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java ============================================================================== --- changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java (original) +++ changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java Tue Sep 16 20:34:47 2008 @@ -25,6 +25,7 @@ import com.google.gwt.dev.jjs.ast.JBinaryOperator; import com.google.gwt.dev.jjs.ast.JClassType; import com.google.gwt.dev.jjs.ast.JExpression; +import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JGwtCreate; import com.google.gwt.dev.jjs.ast.JMethod; import com.google.gwt.dev.jjs.ast.JMethodBody; @@ -587,6 +588,10 @@ JavaToJavaScriptMap postStringInterningMap = new JavaToJavaScriptMap() { public JsName nameForType(JReferenceType type) { return map.nameForType(type); + } + + public JField nameToField(JsName name) { + return map.nameToField(name); } public JMethod nameToMethod(JsName name) { Modified: changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/ast/JVariable.java ============================================================================== --- changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/ast/JVariable.java (original) +++ changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/ast/JVariable.java Tue Sep 16 20:34:47 2008 @@ -44,6 +44,13 @@ return null; } + public JExpression getInitializer() { + if (declStmt != null) { + return declStmt.getInitializer(); + } + return null; + } + public String getName() { return name; } @@ -66,13 +73,6 @@ public void setType(JType newType) { type = newType; - } - - protected JExpression getInitializer() { - if (declStmt != null) { - return declStmt.getInitializer(); - } - return null; } } Modified: changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java ============================================================================== --- changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java (original) +++ changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java Tue Sep 16 20:34:47 2008 @@ -155,10 +155,19 @@ @Override public boolean visit(JClassLiteral x, Context ctx) { - // Works just like JFieldRef to a static field. + /* + * Rescue just slightly less than what would normally be rescued for + * a field reference to the literal's field. Rescue the field itself, + * and its initializer, but do NOT rescue the whole enclosing class. + * That would pull in the clinit of that class, which has initializers + * for all the class literals, which in turn have all of the strings + * of all of the class names. + */ JField field = x.getField(); - rescue(field.getEnclosingType(), true, false); rescue(field); + accept(field.getInitializer()); + referencedTypes.add(field.getEnclosingType()); + liveFieldsAndMethods.add(field.getEnclosingType().methods.get(0)); return true; } @@ -345,7 +354,7 @@ // JsniFieldRef rescues as JFieldRef return visit((JFieldRef) x, ctx); } - + @Override public boolean visit(JsniMethodBody body, Context ctx) { liveStrings.addAll(body.getUsedStrings()); @@ -382,7 +391,7 @@ @Override public boolean visit(JStringLiteral literal, Context ctx) { liveStrings.add(literal.getValue()); - + // rescue and instantiate java.lang.String rescue(program.getTypeJavaLangString(), true, true); return true; @@ -473,9 +482,7 @@ private void rescue(JVariable var) { if (var != null) { - if (!liveFieldsAndMethods.contains(var)) { - liveFieldsAndMethods.add(var); - } + liveFieldsAndMethods.add(var); } } Modified: changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java ============================================================================== --- changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java (original) +++ changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java Tue Sep 16 20:34:47 2008 @@ -1499,7 +1499,9 @@ // asg JsExpression asg = createAssignment(lhs, rhs); - globalStmts.add(new JsExprStmt(asg)); + JsExprStmt stmt = asg.makeStmt(); + globalStmts.add(stmt); + typeForStatMap.put(stmt, program.getTypeJavaLangObject()); } } @@ -1532,7 +1534,9 @@ JsNameRef fieldRef = typeMarkerName.makeRef(); fieldRef.setQualifier(globalTemp.makeRef()); JsExpression asg = createAssignment(fieldRef, nullMethodName.makeRef()); - globalStmts.add(new JsExprStmt(asg)); + JsExprStmt stmt = asg.makeStmt(); + globalStmts.add(stmt); + typeForStatMap.put(stmt, program.getTypeJavaLangObject()); } private JsExpression generateTypeTable() { @@ -1944,11 +1948,20 @@ for (JAbstractMethodBody body : methodBodyMap.keySet()) { nameToMethodMap.put(methodBodyMap.get(body).getName(), body.getMethod()); } + final HashMap<JsName, JField> nameToFieldMap = new HashMap<JsName, JField>(); final HashMap<JsName, JReferenceType> constructorNameToTypeMap = new HashMap<JsName, JReferenceType>(); for (JReferenceType type : program.getDeclaredTypes()) { - JsName name = names.get(type); - if (name != null) { - constructorNameToTypeMap.put(name, type); + JsName typeName = names.get(type); + if (typeName != null) { + constructorNameToTypeMap.put(typeName, type); + } + for (JField field : type.fields) { + if (field.isStatic()) { + JsName fieldName = names.get(field); + if (fieldName != null) { + nameToFieldMap.put(fieldName, field); + } + } } } @@ -1958,6 +1971,10 @@ public JsName nameForType(JReferenceType type) { // TODO(spoon): use a smaller map than this whole thing return names.get(type); + } + + public JField nameToField(JsName name) { + return nameToFieldMap.get(name); } public JMethod nameToMethod(JsName name) { Modified: changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/JavaToJavaScriptMap.java ============================================================================== --- changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/JavaToJavaScriptMap.java (original) +++ changes/spoon/runAsync/dev/core/src/com/google/gwt/dev/jjs/impl/JavaToJavaScriptMap.java Tue Sep 16 20:34:47 2008 @@ -15,6 +15,7 @@ */ package com.google.gwt.dev.jjs.impl; +import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JMethod; import com.google.gwt.dev.jjs.ast.JReferenceType; import com.google.gwt.dev.js.ast.JsName; @@ -28,6 +29,12 @@ * Return the JavaScript name corresponding to a Java type. */ JsName nameForType(JReferenceType type); + + /** + * If <code>name</code> is the name of a <code>var<code> that corresponds to a Java + * static field, then return that field. Otherwise, return null. + */ + JField nameToField(JsName name); /** * If <code>name</code> is the name of a function that corresponds to a Java --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---