Math/StrictMath JDK Tests

- Add JDK tests for Math/StrictMath
- Add support for multiplyExact,
  floorDiv, floorMod with longxint
  parameters.
- Add Java 9 tests for the 3 new methods
- Fix BackportedMethodRewriter to support
  Backported methods calling each other

Bug:136717060
Change-Id: I2ae7dad3fd9ddfde496203f08c81211bb68d17e6
diff --git a/src/test/examplesJava9/backport/StrictMathBackportJava9Main.java b/src/test/examplesJava9/backport/StrictMathBackportJava9Main.java
new file mode 100644
index 0000000..b711539
--- /dev/null
+++ b/src/test/examplesJava9/backport/StrictMathBackportJava9Main.java
@@ -0,0 +1,67 @@
+// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package backport;
+
+public class StrictMathBackportJava9Main {
+
+  public static void main(String[] args) {
+    testMultiplyExactLongInt();
+    testFloorDivLongInt();
+    testFloorModLongInt();
+  }
+
+  public static void testMultiplyExactLongInt() {
+    assertEquals(8L, StrictMath.multiplyExact(2L, 4));
+    assertEquals(Long.MAX_VALUE, StrictMath.multiplyExact(Long.MAX_VALUE, 1));
+    assertEquals(Long.MIN_VALUE, StrictMath.multiplyExact(Long.MIN_VALUE / 2L, 2));
+    try {
+      throw new AssertionError(StrictMath.multiplyExact(Long.MAX_VALUE, 2));
+    } catch (ArithmeticException expected) {
+    }
+    try {
+      throw new AssertionError(StrictMath.multiplyExact(Long.MIN_VALUE, 2));
+    } catch (ArithmeticException expected) {
+    }
+  }
+
+  public static void testFloorDivLongInt() {
+    assertEquals(1L, StrictMath.floorDiv(4L, 4));
+    assertEquals(1L, StrictMath.floorDiv(-4L, -4));
+    assertEquals(-1L, StrictMath.floorDiv(-4L, 4));
+    assertEquals(-1L, StrictMath.floorDiv(4L, -4));
+
+    assertEquals(1L, StrictMath.floorDiv(4L, 3));
+    assertEquals(1L, StrictMath.floorDiv(-4L, -3));
+    assertEquals(-2L, StrictMath.floorDiv(-4L, 3));
+    assertEquals(-2L, StrictMath.floorDiv(4L, -3));
+
+    // Spec edge case: result is actually MAX_VALUE+1 which becomes MIN_VALUE.
+    assertEquals(Long.MIN_VALUE, StrictMath.floorDiv(Long.MIN_VALUE, -1));
+  }
+
+  public static void testFloorModLongInt() {
+    assertEquals(0, StrictMath.floorMod(4L, 4));
+    assertEquals(0, StrictMath.floorMod(-4L, -4));
+    assertEquals(0, StrictMath.floorMod(-4L, 4));
+    assertEquals(0, StrictMath.floorMod(4L, -4));
+
+    assertEquals(1, StrictMath.floorMod(4L, 3));
+    assertEquals(-1, StrictMath.floorMod(-4L, -3));
+    assertEquals(2, StrictMath.floorMod(-4L, 3));
+    assertEquals(-2, StrictMath.floorMod(4L, -3));
+  }
+
+  private static void assertEquals(int expected, int actual) {
+    if (expected != actual) {
+      throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
+    }
+  }
+
+  private static void assertEquals(long expected, long actual) {
+    if (expected != actual) {
+      throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
+    }
+  }
+}