Colin Alworth has uploaded a new change for review.

  https://gwt-review.googlesource.com/3361


Change subject: Ensure clinits get called for JSO instance methods.
......................................................................

Ensure clinits get called for JSO instance methods.

In following Java semantics, any static initialization code in a class
(collectively a clinit) should be run before any part of that class is used. To
achieve this, GWT ensures that this clinit was invoked before any (actually)
static method, and as part of any constructor. This way, instance methods are
sure to have already run the clinit, so it doesn't need to be run again.

However, JSO constructors don't exist, so instance methods are not guaranteed to have had the clinit already run. This is the bug that this patch is trying to
fix.

Two locations are changed, both with the effect of ensuring that a clinit is
emitted for JSOs. First, the MethodInliner must not skip adding a call to the clinit when the jso body is inlined and the method invocation (and ref to the
class) is dropped, and second, GenerateJavaScriptAST must likewise write out
explicit clinits for any static method or jso instance method.

Bug: issue 3192
Change-Id: If09885382bcf2d6c149cd8e48bfdd3ae527d67cb
---
M dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
M dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
2 files changed, 4 insertions(+), 4 deletions(-)



diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
index 240f6a0..1c7944a 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -2189,10 +2189,10 @@
       if (!crossClassTargets.contains(x)) {
         return null;
       }
-      if (x.canBePolymorphic() || program.isStaticImpl(x)) {
+      JDeclaredType enclosingType = x.getEnclosingType();
+ if (x.canBePolymorphic() || (program.isStaticImpl(x) && !program.isJavaScriptObject(enclosingType))) {
         return null;
       }
-      JDeclaredType enclosingType = x.getEnclosingType();
       if (enclosingType == null || !enclosingType.hasClinit()) {
         return null;
       }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
index d2b05ae..6acbb49 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
@@ -169,8 +169,8 @@
// Access from this class to the target class won't trigger a clinit
         return null;
       }
-      if (program.isStaticImpl(x.getTarget())) {
-        // No clinit needed; target is really an instance method.
+ if (program.isStaticImpl(x.getTarget()) && !program.isJavaScriptObject(x.getTarget().getEnclosingType())) {
+        // No clinit needed; target is really a non-jso instance method.
         return null;
       }
       if (JProgram.isClinit(x.getTarget())) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If09885382bcf2d6c149cd8e48bfdd3ae527d67cb
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Colin Alworth <[email protected]>

--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to