< 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

*** 409,10 ***
--- 410,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

*** 484,6 ***
--- 496,17 ---
       */
      public static
      long checkFromIndexSize(long fromIndex, long size, long length) {
          return Preconditions.checkFromIndexSize(fromIndex, size, length, null);
      }
+     /**
+      * {@return a new instance of an unspecified class}
+      * The object has a unique identity; no other references to it exist.
+      * It can be used for synchronization, or where a placeholder Object is needed.
+      * Use this method to avoid relying on the {@linkplain Object#Object() Object constructor}.
+      *
+      * @since 17
+      */
+     public static Object newIdentity() {
+         return new Object() {};
+     }
  }
< prev index next >