Track jvmti allocations related to object tagging

Object tagging overhead can be significant. We now surface that
overhead via the jvmti-extension for memory use.

Test: ./test.py --host -j40
Bug: 62065509

Change-Id: Id0b98e74d66a1a99ac89186176ade39c922569cd
diff --git a/runtime/openjdkjvmti/ti_allocator.cc b/runtime/openjdkjvmti/ti_allocator.cc
index b82c4f4..8a0237d 100644
--- a/runtime/openjdkjvmti/ti_allocator.cc
+++ b/runtime/openjdkjvmti/ti_allocator.cc
@@ -59,20 +59,31 @@
     *mem_ptr = nullptr;
     return OK;
   }
-  *mem_ptr = reinterpret_cast<unsigned char*>(malloc(size));
+  *mem_ptr = AllocateImpl(size);
   if (UNLIKELY(*mem_ptr == nullptr)) {
     return ERR(OUT_OF_MEMORY);
   }
-  allocated += malloc_usable_size(*mem_ptr);
   return OK;
 }
 
+unsigned char* AllocUtil::AllocateImpl(jlong size) {
+  unsigned char* ret = size != 0 ? reinterpret_cast<unsigned char*>(malloc(size)) : nullptr;
+  if (LIKELY(ret != nullptr)) {
+    allocated += malloc_usable_size(ret);
+  }
+  return ret;
+}
+
 jvmtiError AllocUtil::Deallocate(jvmtiEnv* env ATTRIBUTE_UNUSED, unsigned char* mem) {
+  DeallocateImpl(mem);
+  return OK;
+}
+
+void AllocUtil::DeallocateImpl(unsigned char* mem) {
   if (mem != nullptr) {
     allocated -= malloc_usable_size(mem);
     free(mem);
   }
-  return OK;
 }
 
 }  // namespace openjdkjvmti