8211270: GC abstraction to get real object and headers size
authorrkennke
Wed, 10 Oct 2018 10:58:48 +0200
changeset 52071 c4a39588a075
parent 52070 e4d72440d60e
child 52072 3be7d098f4a6
8211270: GC abstraction to get real object and headers size Reviewed-by: shade, zgu, eosterlund
src/hotspot/share/gc/shared/collectedHeap.cpp
src/hotspot/share/gc/shared/collectedHeap.hpp
src/hotspot/share/prims/jvmtiEnv.cpp
src/hotspot/share/prims/whitebox.cpp
--- a/src/hotspot/share/gc/shared/collectedHeap.cpp	Wed Oct 03 15:22:16 2018 +0200
+++ b/src/hotspot/share/gc/shared/collectedHeap.cpp	Wed Oct 10 10:58:48 2018 +0200
@@ -586,3 +586,7 @@
 void CollectedHeap::deduplicate_string(oop str) {
   // Do nothing, unless overridden in subclass.
 }
+
+size_t CollectedHeap::obj_size(oop obj) const {
+  return obj->size();
+}
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp	Wed Oct 03 15:22:16 2018 +0200
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp	Wed Oct 10 10:58:48 2018 +0200
@@ -576,6 +576,8 @@
 
   virtual bool is_oop(oop object) const;
 
+  virtual size_t obj_size(oop obj) const;
+
   // Non product verification and debugging.
 #ifndef PRODUCT
   // Support for PromotionFailureALot.  Return true if it's time to cause a
--- a/src/hotspot/share/prims/jvmtiEnv.cpp	Wed Oct 03 15:22:16 2018 +0200
+++ b/src/hotspot/share/prims/jvmtiEnv.cpp	Wed Oct 10 10:58:48 2018 +0200
@@ -470,7 +470,7 @@
 JvmtiEnv::GetObjectSize(jobject object, jlong* size_ptr) {
   oop mirror = JNIHandles::resolve_external_guard(object);
   NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
-  *size_ptr = (jlong)mirror->size() * wordSize;
+  *size_ptr = (jlong)Universe::heap()->obj_size(mirror) * wordSize;
   return JVMTI_ERROR_NONE;
 } /* end GetObjectSize */
 
--- a/src/hotspot/share/prims/whitebox.cpp	Wed Oct 03 15:22:16 2018 +0200
+++ b/src/hotspot/share/prims/whitebox.cpp	Wed Oct 10 10:58:48 2018 +0200
@@ -372,7 +372,7 @@
 
 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj))
   oop p = JNIHandles::resolve(obj);
-  return p->size() * HeapWordSize;
+  return Universe::heap()->obj_size(p) * HeapWordSize;
 WB_END
 
 WB_ENTRY(jlong, WB_GetHeapSpaceAlignment(JNIEnv* env, jobject o))