Removes clinits from very common core classes Boolean&Throwable.
[Boolean]
Earlier TRUE/FALSE fields were created with constructor. The constructor
requires to call clinit so TRUE/FALSE field initializations wasn't
inlined. As a result it caused TRUE/FALSE fields to be not hoistable via
constant hoisting pass; and as the fields were not hoisted; the clinit
was still required. Basically it was a chicken-egg problem. This CL uses
true/false primitives directly to initialize the fields so they are
hoisted and clinit is gone.
The Boolean.valueOf is also updated to not use the TRUE/FALSE fields to
avoid recursion in GWT (when primitive is assigned to boxed type in
TRUE/FALSE fields it would normally call Boolean.valueOf. Note that J2CL
takes the shortcut and not generates Boolean.valueOf calls).
[Throwable]
UNINITIALIZED marker object is upgraded to a compile time constant so
clinit is no longer needed.
Change-Id: Ic117889a5505f59b0e8c073e1d6523227fd921dd
diff --git a/user/super/com/google/gwt/emul/java/lang/Boolean.java b/user/super/com/google/gwt/emul/java/lang/Boolean.java
index d031414..68bcbc2 100644
--- a/user/super/com/google/gwt/emul/java/lang/Boolean.java
+++ b/user/super/com/google/gwt/emul/java/lang/Boolean.java
@@ -27,15 +27,9 @@
* Wraps native <code>boolean</code> as an object.
*/
public final class Boolean implements Comparable<Boolean>, Serializable {
- /*
- * TODO: figure out how to not clinit this class on direct field access.
- */
- // CHECKSTYLE_OFF: These have to be created somewhere.
- public static final Boolean FALSE = new Boolean(false);
- public static final Boolean TRUE = new Boolean(true);
-
- // CHECKSTYLE_ON
+ public static final Boolean FALSE = false;
+ public static final Boolean TRUE = true;
public static final Class<Boolean> TYPE = boolean.class;
@@ -69,7 +63,7 @@
}
public static Boolean valueOf(boolean b) {
- return b ? TRUE : FALSE;
+ return b ? $createBoolean(true) : $createBoolean(false);
}
public static Boolean valueOf(String s) {
diff --git a/user/super/com/google/gwt/emul/java/lang/Throwable.java b/user/super/com/google/gwt/emul/java/lang/Throwable.java
index 3d27af4..94623cb 100644
--- a/user/super/com/google/gwt/emul/java/lang/Throwable.java
+++ b/user/super/com/google/gwt/emul/java/lang/Throwable.java
@@ -33,7 +33,7 @@
*/
public class Throwable implements Serializable {
- private static final Object UNITIALIZED = new Object();
+ private static final Object UNINITIALIZED = "__noinit__";
/*
* NOTE: We cannot use custom field serializers because we need the client and
@@ -55,7 +55,7 @@
private transient boolean writetableStackTrace = true;
@JsProperty
- private transient Object backingJsObject = UNITIALIZED;
+ private transient Object backingJsObject = UNINITIALIZED;
public Throwable() {
fillInStackTrace();
@@ -176,7 +176,7 @@
// If this is the first run, let constructor initialize it.
// (We need to initialize the backingJsObject from constructor as our own implementation of
// fillInStackTrace is not guaranteed to be executed.)
- if (backingJsObject != UNITIALIZED) {
+ if (backingJsObject != UNINITIALIZED) {
initializeBackingError();
}