Add VMDebug.countInstancesOfClasses

countInstancesOfClasses allows passing multiple classes unlike
countInstanceOfClass instead of needing to do one at a time.

This is going to be used to speed up string mode checking.

Also changed the logic to not do a GC, this was the old Dalvik
behavior. It is the job of the caller to do this.

Added test.

https://code.google.com/p/android/issues/detail?id=177552

Change-Id: Ia85684f40cf59a52aa71a8479c711a994651209b
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 26a45d3..0ae9cdf 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1704,11 +1704,12 @@
     mirror::Class* instance_class = obj->GetClass();
     CHECK(instance_class != nullptr);
     for (size_t i = 0; i < instance_counter->classes_.size(); ++i) {
+      mirror::Class* klass = instance_counter->classes_[i];
       if (instance_counter->use_is_assignable_from_) {
-        if (instance_counter->classes_[i]->IsAssignableFrom(instance_class)) {
+        if (klass != nullptr && klass->IsAssignableFrom(instance_class)) {
           ++instance_counter->counts_[i];
         }
-      } else if (instance_class == instance_counter->classes_[i]) {
+      } else if (instance_class == klass) {
         ++instance_counter->counts_[i];
       }
     }