Author: [email protected]
Date: Thu Apr 2 17:56:32 2009
New Revision: 5180
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/JReferenceType.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/GenerateJavaAST.java
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
Log:
Reimplement TypeOracle.checkClinit() in JReferenceType; inlined
JTypeOracle.hasClinit()
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:56:32 2009
@@ -58,6 +58,7 @@
JReferenceType enclosingType, JType overriddenType) {
super(info, field);
assert (instance != null || field.isStatic());
+ assert (enclosingType != null);
this.instance = instance;
this.field = field;
this.enclosingType = enclosingType;
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:56:32 2009
@@ -40,6 +40,41 @@
super(info, name, JNullLiteral.INSTANCE);
}
+ /**
+ * Returns <code>true</code> if a static field access of
+ * <code>targetType</code> from within this type should generate a clinit
+ * call. This will be true in cases where <code>targetType</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>this == targetType</code></li>
+ * <li><code>this</code> is a subclass of <code>targetType</code>,
+ * because my clinit would have already run this
<code>targetType</code>'s
+ * clinit; see JLS 12.4</li>
+ * </ol>
+ */
+ public boolean checkClinitTo(JReferenceType targetType) {
+ if (this == targetType) {
+ // Call to self (very common case).
+ return false;
+ }
+ if (targetType == null || !targetType.hasClinit()) {
+ // Target has no clinit (common case).
+ return false;
+ }
+
+ // See if I'm a subclass.
+ JClassType checkType = this.extnds;
+ while (checkType != null) {
+ if (checkType == targetType) {
+ // I am a subclass.
+ return false;
+ }
+ checkType = checkType.extnds;
+ }
+ return true;
+ }
+
@Override
public String getJavahSignatureName() {
return "L" + name.replaceAll("_", "_1").replace('.', '_') + "_2";
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:56:32 2009
@@ -387,17 +387,7 @@
* </ol>
*/
public boolean checkClinit(JReferenceType fromType, JReferenceType
toType) {
- if (fromType == toType) {
- return false;
- }
- if (toType == null || !hasClinit(toType)) {
- return false;
- }
- if (fromType instanceof JClassType && toType instanceof JClassType
- && isSuperClass((JClassType) fromType, (JClassType) toType)) {
- return false;
- }
- return true;
+ return fromType.checkClinitTo(toType);
}
public void computeBeforeAST() {
@@ -505,10 +495,6 @@
public Map<JInterfaceType, JClassType> getSingleJsoImpls() {
return Collections.unmodifiableMap(jsoSingleImpls);
- }
-
- public boolean hasClinit(JReferenceType type) {
- return type.hasClinit();
}
/**
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:56:32 2009
@@ -403,7 +403,7 @@
tryOptimizeStringCall(x, ctx, target);
} else if (JProgram.isClinit(target)) {
// Eliminate the call if the target is now empty.
- if (!program.typeOracle.hasClinit(targetType)) {
+ if (!targetType.hasClinit()) {
ctx.replaceMe(program.getLiteralNull());
}
}
Modified:
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
==============================================================================
---
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
(original)
+++
changes/scottb/memory/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
Thu Apr 2 17:56:32 2009
@@ -2936,6 +2936,12 @@
public void endVisit(JsniMethodBody x, Context ctx) {
new JsniRefResolver(jsniMethodMap.get(x), x).accept(x.getFunc());
}
+
+ @Override
+ public boolean visit(JClassType x, Context ctx) {
+ currentClass = x;
+ return true;
+ }
}
/**
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:56:32 2009
@@ -565,7 +565,7 @@
List<JsFunction> jsFuncs = popList(x.methods.size()); // methods
List<JsNode> jsFields = popList(x.fields.size()); // fields
- if (typeOracle.hasClinit(x)) {
+ if (x.hasClinit()) {
JsFunction superClinit = clinitMap.get(x.extnds);
JsFunction myClinit = jsFuncs.get(0);
handleClinit(myClinit, superClinit);
@@ -818,7 +818,7 @@
List<JsVar> jsFields = popList(x.fields.size()); // fields
List<JsStatement> globalStmts =
jsProgram.getGlobalBlock().getStatements();
- if (typeOracle.hasClinit(x)) {
+ if (x.hasClinit()) {
JsFunction clinitFunc = jsFuncs.get(0);
handleClinit(clinitFunc, null);
globalStmts.add(clinitFunc.makeStmt());
@@ -1665,7 +1665,7 @@
return null;
}
JReferenceType enclosingType = x.getEnclosingType();
- if (enclosingType == null || !typeOracle.hasClinit(enclosingType)) {
+ if (enclosingType == null || !enclosingType.hasClinit()) {
return null;
}
// avoid recursion sickness
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---