[J2Objc] Use ObjC-compatible integer hash code for better interoperability.

PiperOrigin-RevId: 933681491
diff --git a/jre_emul/Classes/com/google/j2objc/util/ReflectionUtil.java b/jre_emul/Classes/com/google/j2objc/util/ReflectionUtil.java
index 7f6b483..fe2652a 100644
--- a/jre_emul/Classes/com/google/j2objc/util/ReflectionUtil.java
+++ b/jre_emul/Classes/com/google/j2objc/util/ReflectionUtil.java
@@ -66,4 +66,12 @@
     // For more details about this behavior see {@link #matchClassNamePrefix}.
     return Boolean.TRUE.getClass().getName().equals("JavaLangBoolean");
   }
+
+  /**
+   * Checks if the given object is a NSNumber originating from ObjC by checking that it doesn't have
+   * class metadata. We use this for cross-language equality support, primarily for hashtable keys.
+   */
+  public static native boolean isObjCNumber(Object obj) /*-[
+    return [obj isKindOfClass:[NSNumber class]] && [[obj java_getClass] getMetadata] == NULL;
+  ]-*/;
 }
diff --git a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ByteTest.java b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ByteTest.java
index bbff653..61c9ffe 100644
--- a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ByteTest.java
+++ b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ByteTest.java
@@ -40,10 +40,10 @@
      * java.lang.Byte#hashCode()
      */
     public void test_hashCode() {
-        assertEquals(1, new Byte((byte) 1).hashCode());
-        assertEquals(2, new Byte((byte) 2).hashCode());
+    assertEquals(-1640531535, new Byte((byte) 1).hashCode());
+    assertEquals(1013871474, new Byte((byte) 2).hashCode());
         assertEquals(0, new Byte((byte) 0).hashCode());
-        assertEquals(-1, new Byte((byte) -1).hashCode());
+    assertEquals(-1640531535, new Byte((byte) -1).hashCode());
     }
 
     /**
@@ -510,8 +510,8 @@
      * java.lang.Byte#hashCode()
      */
     public void test_hashCode2() {
-        // Test for method int java.lang.Byte.hashCode()
-        assertEquals("Incorrect hash returned", 127, new Byte((byte) 127).hashCode());
+    // Test for method int java.lang.Byte.hashCode()
+    assertEquals("Incorrect hash returned", 2118337775, new Byte((byte) 127).hashCode());
     }
 
     /**
diff --git a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/FloatTest.java b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/FloatTest.java
index 0353068..7a49441 100644
--- a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/FloatTest.java
+++ b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/FloatTest.java
@@ -207,16 +207,13 @@
     public void test_hashCode() {
         // Test for method int java.lang.Float.hashCode()
         Float f = new Float(1908.8786f);
-        assertTrue("Returned invalid hash code for 1908.8786f", f.hashCode() == Float
-                .floatToIntBits(1908.8786f));
+    assertEquals("Returned invalid hash code for 1908.8786f", 397309157, f.hashCode());
 
         f = new Float(-1.112f);
-        assertTrue("Returned invalid hash code for -1.112", f.hashCode() == Float
-                .floatToIntBits(-1.112f));
+    assertEquals("Returned invalid hash code for -1.112", -987694671, f.hashCode());
 
         f = new Float(0f);
-        assertTrue("Returned invalid hash code for 0", f.hashCode() == Float.floatToIntBits(0f));
-
+    assertEquals("Returned invalid hash code for 0", 0, f.hashCode());
     }
 
     /**
@@ -315,12 +312,14 @@
         assertEquals("Incorrect float returned, expected minimum float.", Float.MIN_VALUE,
                 Float.parseFloat("7.0064923216240853546186479164496e-46"), 0.0);
 
-        doTestCompareRawBits(
-                "0.000000000000000000000000000000000000011754942807573642917278829910357665133228589927589904276829631184250030649651730385585324256680905818939208984375",
-                0x800000, "1.17549435E-38");
-        doTestCompareRawBits(
-                "0.00000000000000000000000000000000000001175494280757364291727882991035766513322858992758990427682963118425003064965173038558532425668090581893920898437499999f",
-                0x7fffff, "1.1754942E-38");
+    doTestCompareRawBits(
+        "0.000000000000000000000000000000000000011754942807573642917278829910357665133228589927589904276829631184250030649651730385585324256680905818939208984375",
+        0x800000,
+        "1.17549435E-38");
+    doTestCompareRawBits(
+        "0.00000000000000000000000000000000000001175494280757364291727882991035766513322858992758990427682963118425003064965173038558532425668090581893920898437499999f",
+        0x7fffff,
+        "1.1754942E-38");
 
         /* Test a set of regular floats with exponents from -38 to +38 */
         for (int i = 38; i > 3; i--) {
@@ -432,7 +431,9 @@
     public void test_parseFloat_LString_Unusual() {
         float actual;
 
-        actual = Float.parseFloat("0x00000000000000000000000000000000000000000.0000000000000000000000000000000000000p0000000000000000000000000000000000");
+    actual =
+        Float.parseFloat(
+            "0x00000000000000000000000000000000000000000.0000000000000000000000000000000000000p0000000000000000000000000000000000");
         assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
 
         actual = Float.parseFloat("+0Xfffff.fffffffffffffffffffffffffffffffp+99F");
@@ -444,10 +445,14 @@
         actual = Float.parseFloat("-0X123456789abcdef.p+1f");
         assertEquals("Returned incorrect value", -1.63971062E17f, actual, 0.0F);
 
-        actual = Float.parseFloat("-0X000000000000000000000000000001abcdef.0000000000000000000000000001abefp00000000000000000000000000000000000000000004f");
+    actual =
+        Float.parseFloat(
+            "-0X000000000000000000000000000001abcdef.0000000000000000000000000001abefp00000000000000000000000000000000000000000004f");
         assertEquals("Returned incorrect value", -4.48585472E8f, actual, 0.0F);
 
-        actual = Float.parseFloat("0X0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001234p600f");
+    actual =
+        Float.parseFloat(
+            "0X0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001234p600f");
         assertEquals("Returned incorrect value", 5.907252E33f, actual, 0.0F);
 
         actual = Float.parseFloat("0x1.p9223372036854775807");
@@ -574,21 +579,20 @@
                 0xff800000,
         };
 
-        String[] inputs = {
-                "0x1.fffffep127",
-                "0x1.fffffe000000000000000000000000000000000000000000000001p127",
-                "0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
-                "0x1.ffffffp127",
-                "0x1.ffffff000000000000000000000000000000000000000000000001p127",
-                "0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
-
-                "-0x1.fffffep127",
-                "-0x1.fffffe000000000000000000000000000000000000000000000001p127",
-                "-0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
-                "-0x1.ffffffp127",
-                "-0x1.ffffff000000000000000000000000000000000000000000000001p127",
-                "-0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
-        };
+    String[] inputs = {
+      "0x1.fffffep127",
+      "0x1.fffffe000000000000000000000000000000000000000000000001p127",
+      "0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
+      "0x1.ffffffp127",
+      "0x1.ffffff000000000000000000000000000000000000000000000001p127",
+      "0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
+      "-0x1.fffffep127",
+      "-0x1.fffffe000000000000000000000000000000000000000000000001p127",
+      "-0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
+      "-0x1.ffffffp127",
+      "-0x1.ffffff000000000000000000000000000000000000000000000001p127",
+      "-0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
+    };
 
         for (int i = 0; i < inputs.length; i++) {
             float actual = Float.parseFloat(inputs[i]);
@@ -624,21 +628,20 @@
                 0x80800001,
         };
 
-        String inputs[] = {
-                "0x1.0p-126",
-                "0x1.00000000000000000000000000000000000000000000001p-126",
-                "0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-                "0x1.000001p-126",
-                "0x1.000001000000000000000000000000000000000000000001p-126",
-                "0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-
-                "-0x1.0p-126",
-                "-0x1.00000000000000000000000000000000000000000000001p-126",
-                "-0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-                "-0x1.000001p-126",
-                "-0x1.000001000000000000000000000000000000000000000001p-126",
-                "-0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-        };
+    String inputs[] = {
+      "0x1.0p-126",
+      "0x1.00000000000000000000000000000000000000000000001p-126",
+      "0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "0x1.000001p-126",
+      "0x1.000001000000000000000000000000000000000000000001p-126",
+      "0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "-0x1.0p-126",
+      "-0x1.00000000000000000000000000000000000000000000001p-126",
+      "-0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "-0x1.000001p-126",
+      "-0x1.000001000000000000000000000000000000000000000001p-126",
+      "-0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+    };
 
         for (int i = 0; i < inputs.length; i++) {
             float actual = Float.parseFloat(inputs[i]);
@@ -674,21 +677,20 @@
                 0x80800000,
         };
 
-        String inputs[] = {
-                "0x0.fffffep-126",
-                "0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
-                "0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-                "0x0.ffffffp-126",
-                "0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
-                "0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-
-                "-0x0.fffffep-126",
-                "-0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
-                "-0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-                "-0x0.ffffffp-126",
-                "-0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
-                "-0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-        };
+    String inputs[] = {
+      "0x0.fffffep-126",
+      "0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
+      "0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "0x0.ffffffp-126",
+      "0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
+      "0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "-0x0.fffffep-126",
+      "-0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
+      "-0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "-0x0.ffffffp-126",
+      "-0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
+      "-0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+    };
 
         for (int i = 0; i < inputs.length; i++) {
             float actual = Float.parseFloat(inputs[i]);
@@ -724,21 +726,20 @@
                 0x80000002,
         };
 
-        String inputs[] = {
-                "0x0.000002p-126",
-                "0x0.00000200000000000000000000000000000000000001p-126",
-                "0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-                "0x0.000003p-126",
-                "0x0.000003000000000000000000000000000000000000001p-126",
-                "0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-
-                "-0x0.000002p-126",
-                "-0x0.00000200000000000000000000000000000000000001p-126",
-                "-0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-                "-0x0.000003p-126",
-                "-0x0.000003000000000000000000000000000000000000001p-126",
-                "-0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-        };
+    String inputs[] = {
+      "0x0.000002p-126",
+      "0x0.00000200000000000000000000000000000000000001p-126",
+      "0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "0x0.000003p-126",
+      "0x0.000003000000000000000000000000000000000000001p-126",
+      "0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "-0x0.000002p-126",
+      "-0x0.00000200000000000000000000000000000000000001p-126",
+      "-0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "-0x0.000003p-126",
+      "-0x0.000003000000000000000000000000000000000000001p-126",
+      "-0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+    };
 
         for (int i = 0; i < inputs.length; i++) {
             float actual = Float.parseFloat(inputs[i]);
@@ -774,21 +775,20 @@
                 0x80000001,
         };
 
-        String inputs[] = {
-                "0x0.000000000000000p-126",
-                "0x0.000000000000000000000000000000000000000000000001p-126",
-                "0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-                "0x0.000001p-126",
-                "0x0.000001000000000000000000000000000000000000000001p-126",
-                "0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-
-                "-0x0.000000000000000p-126",
-                "-0x0.000000000000000000000000000000000000000000000001p-126",
-                "-0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-                "-0x0.000001p-126",
-                "-0x0.000001000000000000000000000000000000000000000001p-126",
-                "-0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-        };
+    String inputs[] = {
+      "0x0.000000000000000p-126",
+      "0x0.000000000000000000000000000000000000000000000001p-126",
+      "0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "0x0.000001p-126",
+      "0x0.000001000000000000000000000000000000000000000001p-126",
+      "0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "-0x0.000000000000000p-126",
+      "-0x0.000000000000000000000000000000000000000000000001p-126",
+      "-0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+      "-0x0.000001p-126",
+      "-0x0.000001000000000000000000000000000000000000000001p-126",
+      "-0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
+    };
 
         for (int i = 0; i < inputs.length; i++) {
             float actual = Float.parseFloat(inputs[i]);
diff --git a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/IntegerTest.java b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/IntegerTest.java
index 3c7faa3..7057cfb 100644
--- a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/IntegerTest.java
+++ b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/IntegerTest.java
@@ -17,7 +17,6 @@
 package org.apache.harmony.tests.java.lang;
 
 import java.util.Properties;
-
 import junit.framework.TestCase;
 
 public class IntegerTest extends TestCase {
@@ -283,8 +282,8 @@
 
         Integer i1 = new Integer(1000);
         Integer i2 = new Integer(-1000);
-        assertTrue("Returned incorrect hashcode", i1.hashCode() == 1000
-                && (i2.hashCode() == -1000));
+    assertTrue(
+        "Returned incorrect hashcode", i1.hashCode() == 145972072 && (i2.hashCode() == 145972072));
     }
 
     /**
@@ -442,12 +441,16 @@
      * java.lang.Integer#toBinaryString(int)
      */
     public void test_toBinaryStringI() {
-        // Test for method java.lang.String
-        // java.lang.Integer.toBinaryString(int)
-        assertEquals("Incorrect string returned", "1111111111111111111111111111111", Integer.toBinaryString(
-                Integer.MAX_VALUE));
-        assertEquals("Incorrect string returned", "10000000000000000000000000000000", Integer.toBinaryString(
-                Integer.MIN_VALUE));
+    // Test for method java.lang.String
+    // java.lang.Integer.toBinaryString(int)
+    assertEquals(
+        "Incorrect string returned",
+        "1111111111111111111111111111111",
+        Integer.toBinaryString(Integer.MAX_VALUE));
+    assertEquals(
+        "Incorrect string returned",
+        "10000000000000000000000000000000",
+        Integer.toBinaryString(Integer.MIN_VALUE));
     }
 
     /**
@@ -516,7 +519,7 @@
         assertEquals("Returned incorrect octal String", "0", Integer.toString(0));
         assertEquals("Returned incorrect octal String", "708", Integer.toString(708));
         assertEquals("Returned incorrect octal String", "-100", Integer.toString(-100));
-        assertEquals("Returned incorrect octal String", "-1000000008", Integer.toString(-1000000008));
+    assertEquals("Returned incorrect octal String", "-1000000008", Integer.toString(-1000000008));
         assertEquals("Returned incorrect octal String", "2000000008", Integer.toString(2000000008));
     }
 
@@ -530,8 +533,10 @@
         assertTrue("Returned incorrect hex string--wanted 7fffffff but got: "
                 + Integer.toString(2147483647, 16), Integer.toString(
                 2147483647, 16).equals("7fffffff"));
-        assertEquals("Incorrect string returned", "1111111111111111111111111111111", Integer.toString(2147483647, 2)
-        );
+    assertEquals(
+        "Incorrect string returned",
+        "1111111111111111111111111111111",
+        Integer.toString(2147483647, 2));
         assertEquals("Incorrect string returned", "2147483647", Integer
                 .toString(2147483647, 10));
 
@@ -688,10 +693,10 @@
      * java.lang.Integer#hashCode()
      */
     public void test_hashCode() {
-        assertEquals(1, new Integer(1).hashCode());
-        assertEquals(2, new Integer(2).hashCode());
+    assertEquals(-1640531535, new Integer(1).hashCode());
+    assertEquals(1013871474, new Integer(2).hashCode());
         assertEquals(0, new Integer(0).hashCode());
-        assertEquals(-1, new Integer(-1).hashCode());
+    assertEquals(-1640531535, new Integer(-1).hashCode());
     }
 
     /**
diff --git a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/LongTest.java b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/LongTest.java
index 9da75cf..f62148a 100644
--- a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/LongTest.java
+++ b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/LongTest.java
@@ -17,7 +17,6 @@
 package org.apache.harmony.tests.java.lang;
 
 import java.util.Properties;
-
 import junit.framework.TestCase;
 
 public class LongTest extends TestCase {
@@ -315,9 +314,9 @@
      * java.lang.Long#toBinaryString(long)
      */
     public void test_toBinaryStringJ() {
-        // Test for method java.lang.String java.lang.Long.toBinaryString(long)
-        assertEquals("Incorrect binary string returned", "11011001010010010000", Long.toBinaryString(
-                890000L));
+    // Test for method java.lang.String java.lang.Long.toBinaryString(long)
+    assertEquals(
+        "Incorrect binary string returned", "11011001010010010000", Long.toBinaryString(890000L));
         assertEquals("Incorrect binary string returned",
 
                 "1000000000000000000000000000000000000000000000000000000000000000", Long
@@ -378,10 +377,9 @@
 
         assertEquals("Returned incorrect String", "89000000005", Long.toString(89000000005L)
         );
-        assertEquals("Returned incorrect String", "-9223372036854775808", Long.toString(Long.MIN_VALUE)
-        );
-        assertEquals("Returned incorrect String", "9223372036854775807", Long.toString(Long.MAX_VALUE)
-        );
+    assertEquals(
+        "Returned incorrect String", "-9223372036854775808", Long.toString(Long.MIN_VALUE));
+    assertEquals("Returned incorrect String", "9223372036854775807", Long.toString(Long.MAX_VALUE));
     }
 
     /**
@@ -526,10 +524,10 @@
      * java.lang.Long#hashCode()
      */
     public void test_hashCode() {
-        assertEquals((int) (1L ^ (1L >>> 32)), new Long(1).hashCode());
-        assertEquals((int) (2L ^ (2L >>> 32)), new Long(2).hashCode());
-        assertEquals((int) (0L ^ (0L >>> 32)), new Long(0).hashCode());
-        assertEquals((int) (-1L ^ (-1L >>> 32)), new Long(-1).hashCode());
+    assertEquals(-1640531535, new Long(1).hashCode());
+    assertEquals(1013871474, new Long(2).hashCode());
+    assertEquals(0, new Long(0).hashCode());
+    assertEquals(-1640531535, new Long(-1).hashCode());
     }
 
     /**
diff --git a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ShortTest.java b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ShortTest.java
index bf747e7..12c90ca 100644
--- a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ShortTest.java
+++ b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ShortTest.java
@@ -361,10 +361,10 @@
      * java.lang.Short#hashCode()
      */
     public void test_hashCode() {
-        assertEquals(1, new Short((short) 1).hashCode());
-        assertEquals(2, new Short((short) 2).hashCode());
+    assertEquals(-1640531535, new Short((short) 1).hashCode());
+    assertEquals(1013871474, new Short((short) 2).hashCode());
         assertEquals(0, new Short((short) 0).hashCode());
-        assertEquals(-1, new Short((short) -1).hashCode());
+    assertEquals(-1640531535, new Short((short) -1).hashCode());
     }
 
     /**
diff --git a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/FormatterTest.java b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/FormatterTest.java
index b3f9452..f2cac1f 100644
--- a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/FormatterTest.java
+++ b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/FormatterTest.java
@@ -775,7 +775,7 @@
         formatter.format(
                 "xx%1$s22%2$s%s%<s%5$s%<s&%7$h%2$s%8$s%<s%s%s%<ssuffix", "1",
                 "2", "3", "4", "5", "6", 7, "8", "9", "10", "11");
-        assertEquals("xx12221155&7288233suffix", formatter.toString());
+        assertEquals("xx12221155&538453d7288233suffix", formatter.toString());
 
         try {
             formatter.format("%<s", "hello");
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Byte.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Byte.java
index be1fa4e..4b5012d 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Byte.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Byte.java
@@ -25,6 +25,8 @@
 
 package java.lang;
 
+import com.google.j2objc.util.ReflectionUtil;
+
 /* J2ObjC removed
 import jdk.internal.vm.annotation.IntrinsicCandidate;
 import libcore.util.HexEncoding;
@@ -475,17 +477,16 @@
         return Byte.hashCode(value);
     }
 
-    /**
-     * Returns a hash code for a {@code byte} value; compatible with
-     * {@code Byte.hashCode()}.
-     *
-     * @param value the value to hash
-     * @return a hash code value for a {@code byte} value.
-     * @since 1.8
-     */
-    public static int hashCode(byte value) {
-        return (int)value;
-    }
+//   /*
+//    * Returns a hash code for a {@code byte} value; compatible with {@code Byte.hashCode()}.
+//    *
+//    * @param value the value to hash
+//    * @return a hash code value for a {@code byte} value.
+//    * @since 1.8
+//    */
+//   public static native int hashCode(byte value) /*-[
+//         return (jint)[@(value) hash];
+//     ]-*/;
 
     /**
      * Compares this object to the specified object.  The result is
@@ -498,8 +499,8 @@
      *                  {@code false} otherwise.
      */
     public boolean equals(Object obj) {
-        if (obj instanceof Byte) {
-            return value == ((Byte)obj).byteValue();
+    if (obj instanceof Byte || ReflectionUtil.isObjCNumber(obj)) {
+      return value == ((Number) obj).byteValue();
         }
         return false;
     }
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Double.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Double.java
index da23f99..c432f96 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Double.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Double.java
@@ -31,6 +31,7 @@
 import jdk.internal.vm.annotation.IntrinsicCandidate;
 */
 
+import com.google.j2objc.util.ReflectionUtil;
 import sun.misc.FloatingDecimal;
 import sun.misc.DoubleConsts;
 
@@ -889,18 +890,17 @@
         return Double.hashCode(value);
     }
 
-    /**
-     * Returns a hash code for a {@code double} value; compatible with
-     * {@code Double.hashCode()}.
-     *
-     * @param value the value to hash
-     * @return a hash code value for a {@code double} value.
-     * @since 1.8
-     */
-    public static int hashCode(double value) {
-        long bits = doubleToLongBits(value);
-        return (int)(bits ^ (bits >>> 32));
-    }
+    // /**
+    //  * Returns a hash code for a {@code double} value; compatible with
+    //  * {@code Double.hashCode()}.
+    //  *
+    //  * @param value the value to hash
+    //  * @return a hash code value for a {@code double} value.
+    //  * @since 1.8
+    //  */
+    // public static native int hashCode(double value) /*-[
+    //     return (jint)[@(value) hash];
+    // ]-*/;
 
     /**
      * Compares this object against the specified object.  The result
@@ -927,8 +927,8 @@
      * @jls 15.21.1 Numerical Equality Operators == and !=
      */
     public boolean equals(Object obj) {
-        return (obj instanceof Double)
-               && (doubleToLongBits(((Double)obj).value) ==
+        return (obj instanceof Double || ReflectionUtil.isObjCNumber(obj))
+               && (doubleToLongBits(((Number) obj).doubleValue()) ==
                       doubleToLongBits(value));
     }
 
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Float.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Float.java
index 65a828c..59d8377 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Float.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Float.java
@@ -34,6 +34,7 @@
 */
 // END Android-removed: dynamic constants not supported on Android.
 
+import com.google.j2objc.util.ReflectionUtil;
 import sun.misc.FloatingDecimal;
 
 /**
@@ -712,17 +713,17 @@
         return Float.hashCode(value);
     }
 
-    /**
-     * Returns a hash code for a {@code float} value; compatible with
-     * {@code Float.hashCode()}.
-     *
-     * @param value the value to hash
-     * @return a hash code value for a {@code float} value.
-     * @since 1.8
-     */
-    public static int hashCode(float value) {
-        return floatToIntBits(value);
-    }
+    // /**
+    //  * Returns a hash code for a {@code float} value; compatible with
+    //  * {@code Float.hashCode()}.
+    //  *
+    //  * @param value the value to hash
+    //  * @return a hash code value for a {@code float} value.
+    //  * @since 1.8
+    //  */
+    // public static native int hashCode(float value) /*-[
+    //     return (jint)[@(value) hash];
+    // ]-*/;
 
     /**
      * Compares this object against the specified object.  The result
@@ -752,8 +753,8 @@
      * @jls 15.21.1 Numerical Equality Operators == and !=
      */
     public boolean equals(Object obj) {
-        return (obj instanceof Float)
-               && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
+        return (obj instanceof Float || ReflectionUtil.isObjCNumber(obj))
+               && (floatToIntBits(((Number) obj).floatValue()) == floatToIntBits(value));
     }
 
     /**
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Integer.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Integer.java
index c80daca..0d019b5 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Integer.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Integer.java
@@ -25,6 +25,8 @@
 
 package java.lang;
 
+import com.google.j2objc.util.ReflectionUtil;
+
 /* J2ObjC removed
 import jdk.internal.vm.annotation.IntrinsicCandidate;
 */
@@ -1030,18 +1032,18 @@
         return Integer.hashCode(value);
     }
 
-    /**
-     * Returns a hash code for an {@code int} value; compatible with
-     * {@code Integer.hashCode()}.
-     *
-     * @param value the value to hash
-     * @since 1.8
-     *
-     * @return a hash code value for an {@code int} value.
-     */
-    public static int hashCode(int value) {
-        return value;
-    }
+    // /**
+    //  * Returns a hash code for an {@code int} value; compatible with
+    //  * {@code Integer.hashCode()}.
+    //  *
+    //  * @param value the value to hash
+    //  * @since 1.8
+    //  *
+    //  * @return a hash code value for an {@code int} value.
+    //  */
+    // public static native int hashCode(int value) /*-[
+    //     return (jint)[@(value) hash];
+    // ]-*/;
 
     /**
      * Compares this object to the specified object.  The result is
@@ -1054,8 +1056,8 @@
      *          {@code false} otherwise.
      */
     public boolean equals(Object obj) {
-        if (obj instanceof Integer) {
-            return value == ((Integer)obj).intValue();
+        if (obj instanceof Integer || ReflectionUtil.isObjCNumber(obj)) {
+            return value == ((Number) obj).intValue();
         }
         return false;
     }
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Long.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Long.java
index ea619a5..6314a3f 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Long.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Long.java
@@ -25,6 +25,8 @@
 
 package java.lang;
 
+import com.google.j2objc.util.ReflectionUtil;
+
 /* J2ObjC removed
 import jdk.internal.vm.annotation.IntrinsicCandidate;
 */
@@ -1257,17 +1259,17 @@
         return Long.hashCode(value);
     }
 
-    /**
-     * Returns a hash code for a {@code long} value; compatible with
-     * {@code Long.hashCode()}.
-     *
-     * @param value the value to hash
-     * @return a hash code value for a {@code long} value.
-     * @since 1.8
-     */
-    public static int hashCode(long value) {
-        return (int)(value ^ (value >>> 32));
-    }
+    // /**
+    //  * Returns a hash code for a {@code long} value; compatible with
+    //  * {@code Long.hashCode()}.
+    //  *
+    //  * @param value the value to hash
+    //  * @return a hash code value for a {@code long} value.
+    //  * @since 1.8
+    //  */
+    // public static native int hashCode(long value) /*-[
+    //     return (jint)[@(value) hash];
+    // ]-*/;
 
     /**
      * Compares this object to the specified object.  The result is
@@ -1280,8 +1282,8 @@
      *          {@code false} otherwise.
      */
     public boolean equals(Object obj) {
-        if (obj instanceof Long) {
-            return value == ((Long)obj).longValue();
+        if (obj instanceof Long || ReflectionUtil.isObjCNumber(obj)) {
+            return value == ((Number) obj).longValue();
         }
         return false;
     }
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Short.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Short.java
index 4be3273..3fcf56a 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Short.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/lang/Short.java
@@ -25,6 +25,8 @@
 
 package java.lang;
 
+import com.google.j2objc.util.ReflectionUtil;
+
 /* J2ObjC removed
 import jdk.internal.vm.annotation.IntrinsicCandidate;
 */
@@ -479,17 +481,16 @@
         return Short.hashCode(value);
     }
 
-    /**
-     * Returns a hash code for a {@code short} value; compatible with
-     * {@code Short.hashCode()}.
-     *
-     * @param value the value to hash
-     * @return a hash code value for a {@code short} value.
-     * @since 1.8
-     */
-    public static int hashCode(short value) {
-        return (int)value;
-    }
+//   /**
+//    * Returns a hash code for a {@code short} value; compatible with {@code Short.hashCode()}.
+//    *
+//    * @param value the value to hash
+//    * @return a hash code value for a {@code short} value.
+//    * @since 1.8
+//    */
+//   public static native int hashCode(short value) /*-[
+//         return (jint)[@(value) hash];
+//     ]-*/;
 
     /**
      * Compares this object to the specified object.  The result is
@@ -502,8 +503,8 @@
      *                  {@code false} otherwise.
      */
     public boolean equals(Object obj) {
-        if (obj instanceof Short) {
-            return value == ((Short)obj).shortValue();
+    if (obj instanceof Short || ReflectionUtil.isObjCNumber(obj)) {
+      return value == ((Number) obj).shortValue();
         }
         return false;
     }
diff --git a/jre_emul/misc_tests/com/google/j2objc/ReflectionTest.java b/jre_emul/misc_tests/com/google/j2objc/ReflectionTest.java
index cd9fb13..60f2d6b 100644
--- a/jre_emul/misc_tests/com/google/j2objc/ReflectionTest.java
+++ b/jre_emul/misc_tests/com/google/j2objc/ReflectionTest.java
@@ -201,4 +201,58 @@
     assertEquals("hello", a.annotationValue().value());
     assertEquals(Iterable.class, a.classValue());
   }
+
+  private static native Object getNativeNumber(long val) /*-[
+    return [NSNumber numberWithLongLong:(long long)val];
+  ]-*/;
+
+  private static native Object getNativeUnsignedByte(int val) /*-[
+    return [NSNumber numberWithUnsignedChar:(unsigned char)val];
+  ]-*/;
+
+  private static native Object getNativeUnsignedShort(int val) /*-[
+    return [NSNumber numberWithUnsignedShort:(unsigned short)val];
+  ]-*/;
+
+  public void testIsObjCNumber() {
+    Object nativeNum = getNativeNumber(42);
+    Object javaNum = Integer.valueOf(42);
+    Object decimalNum = new java.math.BigDecimal("1.23");
+
+    assertTrue(com.google.j2objc.util.ReflectionUtil.isObjCNumber(nativeNum));
+    assertFalse(com.google.j2objc.util.ReflectionUtil.isObjCNumber(javaNum));
+    assertFalse(com.google.j2objc.util.ReflectionUtil.isObjCNumber(decimalNum));
+    assertFalse(com.google.j2objc.util.ReflectionUtil.isObjCNumber("not a number"));
+    assertFalse(com.google.j2objc.util.ReflectionUtil.isObjCNumber(null));
+  }
+
+  public void testNumberHashMapCompatibility() {
+    java.util.HashMap<Number, String> map = new java.util.HashMap<>();
+
+    Object javaInt = Integer.valueOf(42);
+    Object objcInt = getNativeNumber(42);
+
+    map.put((Number) javaInt, "success");
+    assertEquals("success", map.get(objcInt));
+
+    map.clear();
+    map.put((Number) objcInt, "success_reverse");
+    assertEquals("success_reverse", map.get(javaInt));
+  }
+
+  public void testSignedUnsignedMismatches() {
+    Object objcUnsignedByte = getNativeUnsignedByte(200);
+    Object javaByte = Byte.valueOf((byte) -56);
+
+    if (javaByte.equals(objcUnsignedByte)) {
+      assertEquals(javaByte.hashCode(), objcUnsignedByte.hashCode());
+    }
+
+    Object objcUnsignedShort = getNativeUnsignedShort(45000);
+    Object javaShort = Short.valueOf((short) -20536);
+
+    if (javaShort.equals(objcUnsignedShort)) {
+      assertEquals(javaShort.hashCode(), objcUnsignedShort.hashCode());
+    }
+  }
 }