hotspot/test/runtime/contended/DefaultValue.java
changeset 41092 c388d897472d
parent 38152 80e5da81fb2c
equal deleted inserted replaced
41091:de3789bb384e 41092:c388d897472d
    47  * @modules java.base/jdk.internal.vm.annotation
    47  * @modules java.base/jdk.internal.vm.annotation
    48  * @run main/othervm -XX:-RestrictContended DefaultValue
    48  * @run main/othervm -XX:-RestrictContended DefaultValue
    49  */
    49  */
    50 public class DefaultValue {
    50 public class DefaultValue {
    51 
    51 
    52     private static final Unsafe U;
    52     private static final Unsafe U = Unsafe.getUnsafe();
    53     private static int ADDRESS_SIZE;
    53     private static int ADDRESS_SIZE;
    54     private static int HEADER_SIZE;
    54     private static int HEADER_SIZE;
    55 
    55 
    56     static {
    56     static {
    57         // steal Unsafe
       
    58         try {
       
    59             Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
       
    60             unsafe.setAccessible(true);
       
    61             U = (Unsafe) unsafe.get(null);
       
    62         } catch (NoSuchFieldException | IllegalAccessException e) {
       
    63             throw new IllegalStateException(e);
       
    64         }
       
    65 
       
    66         // When running with CompressedOops on 64-bit platform, the address size
    57         // When running with CompressedOops on 64-bit platform, the address size
    67         // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
    58         // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
    68         // Try to guess the reference field size with this naive trick.
    59         // Try to guess the reference field size with this naive trick.
    69         try {
    60         try {
    70             long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));
    61             long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));