Fix a DCHECK failure due to unmatching numbers of cards scanned.

- See the bug for details of the failure.
- After a discussion, we decided to get rid of the DCHECK as a simple
  solution would not detect corner failure cases and a full solution
  would add undesired complexity, and left a comment that explains
  what situation had caused a DCHECK failure.
- Fix a potential error of failing to scan the last card that the end
  of the image space falls on as a result of the image end being not
  necessarily aligned by the card size.
- Remove dead/unused MarkSweep::ScanRoot().
- Add AlignUp and AlignDown for aligning pointers.

Bug: 11465268
Change-Id: Iee3018a42c48a159feb0e9cf77b1a6b303f5d245
diff --git a/runtime/utils.h b/runtime/utils.h
index 0174b37..51035b6 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -119,6 +119,7 @@
   typedef B value;
 };
 
+// For rounding integers.
 template<typename T>
 static inline T RoundDown(T x, int n) {
   CHECK(IsPowerOfTwo(n));
@@ -130,6 +131,18 @@
   return RoundDown(x + n - 1, n);
 }
 
+// For aligning pointers.
+template<typename T>
+static inline T* AlignDown(T* x, int n) {
+  CHECK(IsPowerOfTwo(n));
+  return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(x) & -static_cast<uintptr_t>(n));
+}
+
+template<typename T>
+static inline T* AlignUp(T* x, int n) {
+  return AlignDown(reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(x) + static_cast<uintptr_t>(n - 1)), n);
+}
+
 // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr.,
 // figure 3-3, page 48, where the function is called clp2.
 static inline uint32_t RoundUpToPowerOfTwo(uint32_t x) {