< prev index next >

test/runtime/contended/Basic.java

Print this page




  31 import java.util.ArrayList;
  32 import java.util.List;
  33 import java.util.concurrent.CyclicBarrier;
  34 import java.util.regex.Matcher;
  35 import java.util.regex.Pattern;
  36 import java.lang.reflect.Field;
  37 import java.lang.reflect.Modifier;
  38 import jdk.internal.misc.Unsafe;
  39 import jdk.internal.vm.annotation.Contended;
  40 
  41 /*
  42  * @test
  43  * @bug     8003985
  44  * @summary Support Contended Annotation - JEP 142
  45  * @modules java.base/jdk.internal.misc
  46  * @modules java.base/jdk.internal.vm.annotation
  47  * @run main/othervm -XX:-RestrictContended Basic
  48  */
  49 public class Basic {
  50 
  51     private static final Unsafe U;
  52     private static int ADDRESS_SIZE;
  53     private static int HEADER_SIZE;
  54 
  55     static {
  56         // steal Unsafe
  57         try {
  58             Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
  59             unsafe.setAccessible(true);
  60             U = (Unsafe) unsafe.get(null);
  61         } catch (NoSuchFieldException | IllegalAccessException e) {
  62             throw new IllegalStateException(e);
  63         }
  64 
  65         // When running with CompressedOops on 64-bit platform, the address size
  66         // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
  67         // Try to guess the reference field size with this naive trick.
  68         try {
  69             long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));
  70             long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2"));
  71             ADDRESS_SIZE = (int) Math.abs(off2 - off1);
  72             HEADER_SIZE = (int) Math.min(off1, off2);
  73         } catch (NoSuchFieldException e) {
  74             ADDRESS_SIZE = -1;
  75         }
  76     }
  77 
  78     static class CompressedOopsClass {
  79         public Object obj1;
  80         public Object obj2;
  81     }
  82 
  83     public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
  84         Field f1 = klass.getDeclaredField(field1);




  31 import java.util.ArrayList;
  32 import java.util.List;
  33 import java.util.concurrent.CyclicBarrier;
  34 import java.util.regex.Matcher;
  35 import java.util.regex.Pattern;
  36 import java.lang.reflect.Field;
  37 import java.lang.reflect.Modifier;
  38 import jdk.internal.misc.Unsafe;
  39 import jdk.internal.vm.annotation.Contended;
  40 
  41 /*
  42  * @test
  43  * @bug     8003985
  44  * @summary Support Contended Annotation - JEP 142
  45  * @modules java.base/jdk.internal.misc
  46  * @modules java.base/jdk.internal.vm.annotation
  47  * @run main/othervm -XX:-RestrictContended Basic
  48  */
  49 public class Basic {
  50 
  51     private static final Unsafe U = Unsafe.getUnsafe();
  52     private static int ADDRESS_SIZE;
  53     private static int HEADER_SIZE;
  54 
  55     static {









  56         // When running with CompressedOops on 64-bit platform, the address size
  57         // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
  58         // Try to guess the reference field size with this naive trick.
  59         try {
  60             long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));
  61             long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2"));
  62             ADDRESS_SIZE = (int) Math.abs(off2 - off1);
  63             HEADER_SIZE = (int) Math.min(off1, off2);
  64         } catch (NoSuchFieldException e) {
  65             ADDRESS_SIZE = -1;
  66         }
  67     }
  68 
  69     static class CompressedOopsClass {
  70         public Object obj1;
  71         public Object obj2;
  72     }
  73 
  74     public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
  75         Field f1 = klass.getDeclaredField(field1);


< prev index next >