Skip to content

Commit

Permalink
Removes clinits from very common core classes Boolean&Throwable.
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
gkdn committed May 8, 2016
1 parent 5be1d83 commit 6396a7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 3 additions & 9 deletions user/super/com/google/gwt/emul/java/lang/Boolean.java
Expand Up @@ -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;

Expand Down Expand Up @@ -69,7 +63,7 @@ public static String toString(boolean x) {
}

public static Boolean valueOf(boolean b) {
return b ? TRUE : FALSE;
return b ? $createBoolean(true) : $createBoolean(false);
}

public static Boolean valueOf(String s) {
Expand Down
6 changes: 3 additions & 3 deletions user/super/com/google/gwt/emul/java/lang/Throwable.java
Expand Up @@ -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
Expand All @@ -55,7 +55,7 @@ public class Throwable implements Serializable {
private transient boolean writetableStackTrace = true;

@JsProperty
private transient Object backingJsObject = UNITIALIZED;
private transient Object backingJsObject = UNINITIALIZED;

public Throwable() {
fillInStackTrace();
Expand Down Expand Up @@ -176,7 +176,7 @@ public Throwable fillInStackTrace() {
// 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();
}

Expand Down

0 comments on commit 6396a7b

Please sign in to comment.