Fix heap corruption and verification.

There was a faulty assumption that space End() was always aligned to
card boundaries. This was true for all spaces other than the image
and resulted in heap corruption when the last object of the image
space contained a reference to an object in another space.

Also fixed an error where we called the pre GC verification post GC.

Bug: 17080623

(cherry picked from commit 6724d8649ab73e4fb86c8014bda51b13bddf2f3f)

Change-Id: I931149421c738653863eb6105dfdf7ecd750601a
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 5d138d2..821d22f 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -2483,7 +2483,6 @@
 bool Heap::VerifyMissingCardMarks() {
   Thread* self = Thread::Current();
   Locks::mutator_lock_->AssertExclusiveHeld(self);
-
   // We need to sort the live stack since we binary search it.
   live_stack_->Sort();
   // Since we sorted the allocation stack content, need to revoke all
@@ -2491,7 +2490,6 @@
   RevokeAllThreadLocalAllocationStacks(self);
   VerifyLiveStackReferences visitor(this);
   GetLiveBitmap()->Visit(visitor);
-
   // We can verify objects in the live stack since none of these should reference dead objects.
   for (mirror::Object** it = live_stack_->Begin(); it != live_stack_->End(); ++it) {
     if (!kUseThreadLocalAllocationStack || *it != nullptr) {
@@ -2689,7 +2687,7 @@
 void Heap::PostGcVerification(collector::GarbageCollector* gc) {
   if (verify_system_weaks_ || verify_post_gc_rosalloc_ || verify_post_gc_heap_) {
     collector::GarbageCollector::ScopedPause pause(gc);
-    PreGcVerificationPaused(gc);
+    PostGcVerificationPaused(gc);
   }
 }