< prev index next >

src/java.base/share/classes/java/util/Objects.java

Print this page
@@ -25,10 +25,11 @@
  
  package java.util;
  
  import jdk.internal.util.Preconditions;
  import jdk.internal.vm.annotation.ForceInline;
+ import jdk.internal.misc.Unsafe;
  
  import java.util.function.Supplier;
  
  /**
   * This class consists of {@code static} utility methods for operating

@@ -435,10 +436,21 @@
      public static
      int checkFromIndexSize(int fromIndex, int size, int length) {
          return Preconditions.checkFromIndexSize(fromIndex, size, length, null);
      }
  
+     /**
+      * Return the size of the object in the heap.
+      *
+      * @param o an object
+      * @return the objects's size
+      * @since Valhalla
+      */
+     public static long getObjectSize(Object o) {
+         return Unsafe.getUnsafe().getObjectSize(o);
+     }
+ 
      /**
       * Checks if the {@code index} is within the bounds of the range from
       * {@code 0} (inclusive) to {@code length} (exclusive).
       *
       * <p>The {@code index} is defined to be out of bounds if any of the
< prev index next >