Revert "Encapsulate boxing caches and mark them side-effect free."
This reverts commit ab22c15c5af313311cb0cfff010dadd70fa0d3c2.
Reason for revert: Annotating the Byte cache with @HasNoSideEffect hits a cornercase bug in the GWT optimizer and makes a test fail.
Change-Id: I7b2db9b689ab9190e01eabea3636ae39a15b5a21
diff --git a/user/super/com/google/gwt/emul/java/lang/Byte.java b/user/super/com/google/gwt/emul/java/lang/Byte.java
index 0d69c2d..bc87eed 100644
--- a/user/super/com/google/gwt/emul/java/lang/Byte.java
+++ b/user/super/com/google/gwt/emul/java/lang/Byte.java
@@ -15,8 +15,6 @@
*/
package java.lang;
-import javaemul.internal.annotations.HasNoSideEffects;
-
/**
* Wraps native <code>byte</code> as an object.
*/
@@ -34,16 +32,6 @@
private static class BoxedValues {
// Box all values according to JLS
private static Byte[] boxedValues = new Byte[256];
-
- @HasNoSideEffects
- private static Byte get(byte b) {
- int rebase = b + 128;
- Byte result = BoxedValues.boxedValues[rebase];
- if (result == null) {
- result = BoxedValues.boxedValues[rebase] = new Byte(b);
- }
- return result;
- }
}
public static int compare(byte x, byte y) {
@@ -72,7 +60,12 @@
}
public static Byte valueOf(byte b) {
- return BoxedValues.get(b);
+ int rebase = b + 128;
+ Byte result = BoxedValues.boxedValues[rebase];
+ if (result == null) {
+ result = BoxedValues.boxedValues[rebase] = new Byte(b);
+ }
+ return result;
}
public static Byte valueOf(String s) throws NumberFormatException {
diff --git a/user/super/com/google/gwt/emul/java/lang/Character.java b/user/super/com/google/gwt/emul/java/lang/Character.java
index 4b01e4d..3733f73 100644
--- a/user/super/com/google/gwt/emul/java/lang/Character.java
+++ b/user/super/com/google/gwt/emul/java/lang/Character.java
@@ -19,7 +19,6 @@
import java.io.Serializable;
import javaemul.internal.NativeRegExp;
-import javaemul.internal.annotations.HasNoSideEffects;
/**
* Wraps a native <code>char</code> as an object.
@@ -105,15 +104,6 @@
private static class BoxedValues {
// Box values according to JLS - from \u0000 to \u007f
private static Character[] boxedValues = new Character[128];
-
- @HasNoSideEffects
- private static Character get(char c) {
- Character result = BoxedValues.boxedValues[c];
- if (result == null) {
- result = BoxedValues.boxedValues[c] = new Character(c);
- }
- return result;
- }
}
public static final Class<Character> TYPE = Character.class;
@@ -436,7 +426,11 @@
public static Character valueOf(char c) {
if (c < 128) {
- return BoxedValues.get(c);
+ Character result = BoxedValues.boxedValues[c];
+ if (result == null) {
+ result = BoxedValues.boxedValues[c] = new Character(c);
+ }
+ return result;
}
return new Character(c);
}
diff --git a/user/super/com/google/gwt/emul/java/lang/Integer.java b/user/super/com/google/gwt/emul/java/lang/Integer.java
index a56e31e..1e2f584 100644
--- a/user/super/com/google/gwt/emul/java/lang/Integer.java
+++ b/user/super/com/google/gwt/emul/java/lang/Integer.java
@@ -16,7 +16,6 @@
package java.lang;
import javaemul.internal.JsUtils;
-import javaemul.internal.annotations.HasNoSideEffects;
/**
* Wraps a primitive <code>int</code> as an object.
@@ -35,16 +34,6 @@
private static class BoxedValues {
// Box values according to JLS - between -128 and 127
private static Integer[] boxedValues = new Integer[256];
-
- @HasNoSideEffects
- private static Integer get(int i) {
- int rebase = i + 128;
- Integer result = boxedValues[rebase];
- if (result == null) {
- result = boxedValues[rebase] = new Integer(i);
- }
- return result;
- }
}
/**
@@ -244,7 +233,12 @@
public static Integer valueOf(int i) {
if (i > -129 && i < 128) {
- return BoxedValues.get(i);
+ int rebase = i + 128;
+ Integer result = BoxedValues.boxedValues[rebase];
+ if (result == null) {
+ result = BoxedValues.boxedValues[rebase] = new Integer(i);
+ }
+ return result;
}
return new Integer(i);
}
diff --git a/user/super/com/google/gwt/emul/java/lang/Long.java b/user/super/com/google/gwt/emul/java/lang/Long.java
index 693efeb..da22734 100644
--- a/user/super/com/google/gwt/emul/java/lang/Long.java
+++ b/user/super/com/google/gwt/emul/java/lang/Long.java
@@ -16,7 +16,6 @@
package java.lang;
import javaemul.internal.LongUtils;
-import javaemul.internal.annotations.HasNoSideEffects;
/** Wraps a primitive <code>long</code> as an object. */
public final class Long extends Number implements Comparable<Long> {
@@ -25,16 +24,6 @@
static class BoxedValues {
// Box values according to JLS - between -128 and 127
static Long[] boxedValues = new Long[256];
-
- @HasNoSideEffects
- private static Long get(long l) {
- int rebase = (int) l + 128;
- Long result = BoxedValues.boxedValues[rebase];
- if (result == null) {
- result = BoxedValues.boxedValues[rebase] = new Long(l);
- }
- return result;
- }
}
public static final long MAX_VALUE = 0x7fffffffffffffffL;
@@ -217,11 +206,16 @@
return String.valueOf(buf, cursor, bufLen - cursor);
}
- public static Long valueOf(long l) {
- if (l > -129 && l < 128) {
- return BoxedValues.get(l);
+ public static Long valueOf(long i) {
+ if (i > -129 && i < 128) {
+ int rebase = (int) i + 128;
+ Long result = BoxedValues.boxedValues[rebase];
+ if (result == null) {
+ result = BoxedValues.boxedValues[rebase] = new Long(i);
+ }
+ return result;
}
- return new Long(l);
+ return new Long(i);
}
public static Long valueOf(String s) throws NumberFormatException {
diff --git a/user/super/com/google/gwt/emul/java/lang/Short.java b/user/super/com/google/gwt/emul/java/lang/Short.java
index 15e9b38..c42d03c 100644
--- a/user/super/com/google/gwt/emul/java/lang/Short.java
+++ b/user/super/com/google/gwt/emul/java/lang/Short.java
@@ -15,8 +15,6 @@
*/
package java.lang;
-import javaemul.internal.annotations.HasNoSideEffects;
-
/**
* Wraps a primitive <code>short</code> as an object.
*/
@@ -34,16 +32,6 @@
private static class BoxedValues {
// Box values according to JLS - between -128 and 127
private static Short[] boxedValues = new Short[256];
-
- @HasNoSideEffects
- private static Short get(short s) {
- int rebase = s + 128;
- Short result = BoxedValues.boxedValues[rebase];
- if (result == null) {
- result = BoxedValues.boxedValues[rebase] = new Short(s);
- }
- return result;
- }
}
public static int compare(short x, short y) {
@@ -77,7 +65,12 @@
public static Short valueOf(short s) {
if (s > -129 && s < 128) {
- return BoxedValues.get(s);
+ int rebase = s + 128;
+ Short result = BoxedValues.boxedValues[rebase];
+ if (result == null) {
+ result = BoxedValues.boxedValues[rebase] = new Short(s);
+ }
+ return result;
}
return new Short(s);
}