Merge "Add keptBy predicate and support for referencing a keep rule."
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/Java8MethodRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/Java8MethodRewriter.java
index ea1d2c6..c0a7569 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/Java8MethodRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/Java8MethodRewriter.java
@@ -142,6 +142,34 @@
         original.holder.descriptor, original.name, original.proto);
   }
 
+  private static final class ByteMethods extends TemplateMethodCode {
+    ByteMethods(InternalOptions options, DexMethod method, String methodName) {
+      super(options, method, methodName, method.proto.toDescriptorString());
+    }
+
+    public static ByteMethods hashCodeCode(InternalOptions options, DexMethod method) {
+      return new ByteMethods(options, method, "hashCodeImpl");
+    }
+
+    public static int hashCodeImpl(byte i) {
+      return Byte.valueOf(i).hashCode();
+    }
+  }
+
+
+  private static final class ShortMethods extends TemplateMethodCode {
+    ShortMethods(InternalOptions options, DexMethod method, String methodName) {
+      super(options, method, methodName, method.proto.toDescriptorString());
+    }
+
+    public static ShortMethods hashCodeCode(InternalOptions options, DexMethod method) {
+      return new ShortMethods(options, method, "hashCodeImpl");
+    }
+
+    public static int hashCodeImpl(short i) {
+      return Short.valueOf(i).hashCode();
+    }
+  }
 
   private static final class IntegerMethods extends TemplateMethodCode {
     IntegerMethods(InternalOptions options, DexMethod method, String methodName) {
@@ -320,12 +348,28 @@
 
     public RewritableMethods(DexItemFactory factory) {
       rewritable = new HashMap<>();
+      // Byte
+      DexString clazz = factory.boxedByteDescriptor;
+      // int Byte.hashCode(byte i)
+      DexString method = factory.createString("hashCode");
+      DexProto proto = factory.createProto(factory.intType, factory.byteType);
+      addOrGetMethod(clazz, method)
+          .put(proto, new MethodGenerator(ByteMethods::hashCodeCode, clazz, method, proto));
+
+      // Short
+      clazz = factory.boxedShortDescriptor;
+      // int Short.hashCode(short i)
+      method = factory.createString("hashCode");
+      proto = factory.createProto(factory.intType, factory.shortType);
+      addOrGetMethod(clazz, method)
+          .put(proto, new MethodGenerator(ShortMethods::hashCodeCode, clazz, method, proto));
+
       // Integer
-      DexString clazz = factory.boxedIntDescriptor;
+      clazz = factory.boxedIntDescriptor;
 
       // int Integer.hashCode(int i)
-      DexString method = factory.createString("hashCode");
-      DexProto proto = factory.createProto(factory.intType, factory.intType);
+      method = factory.createString("hashCode");
+      proto = factory.createProto(factory.intType, factory.intType);
       addOrGetMethod(clazz, method)
           .put(proto, new MethodGenerator(IntegerMethods::hashCodeCode, clazz, method, proto));
 
diff --git a/src/test/java/com/android/tools/r8/desugar/Java8MethodsTest.java b/src/test/java/com/android/tools/r8/desugar/Java8MethodsTest.java
index 8139694..f94d5a5 100644
--- a/src/test/java/com/android/tools/r8/desugar/Java8MethodsTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/Java8MethodsTest.java
@@ -28,6 +28,16 @@
 
   static class Java8Methods {
     public static void main(String[] args) {
+      byte[] aBytes = new byte[]{42, 1, -1, Byte.MAX_VALUE, Byte.MIN_VALUE};
+      for (byte aByte : aBytes) {
+        System.out.println(Byte.hashCode(aByte));
+      }
+
+      short[] aShorts = new short[]{42, 1, -1, Short.MAX_VALUE, Short.MIN_VALUE};
+      for (short aShort : aShorts) {
+        System.out.println(Short.hashCode(aShort));
+      }
+
       int[] aInts = new int[]{42, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE};
       int[] bInts = new int[]{43, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE};
       for (int aInt : aInts) {