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 8012939
44 * @summary \@Contended doesn't work correctly with inheritance
45 *
46 * @modules java.base/jdk.internal.misc
47 * @modules java.base/jdk.internal.vm.annotation
48 * @run main/othervm -XX:-RestrictContended Inheritance1
49 */
50 public class Inheritance1 {
51
52 private static final Unsafe U;
53 private static int ADDRESS_SIZE;
54 private static int HEADER_SIZE;
55
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
67 // 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.
69 try {
70 long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));
71 long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2"));
72 ADDRESS_SIZE = (int) Math.abs(off2 - off1);
73 HEADER_SIZE = (int) Math.min(off1, off2);
74 } catch (NoSuchFieldException e) {
75 ADDRESS_SIZE = -1;
76 }
77 }
78
79 static class CompressedOopsClass {
80 public Object obj1;
81 public Object obj2;
82 }
83
84 public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
85 Field f1 = klass.getField(field1);
|
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 8012939
44 * @summary \@Contended doesn't work correctly with inheritance
45 *
46 * @modules java.base/jdk.internal.misc
47 * @modules java.base/jdk.internal.vm.annotation
48 * @run main/othervm -XX:-RestrictContended Inheritance1
49 */
50 public class Inheritance1 {
51
52 private static final Unsafe U = Unsafe.getUnsafe();
53 private static int ADDRESS_SIZE;
54 private static int HEADER_SIZE;
55
56 static {
57 // When running with CompressedOops on 64-bit platform, the address size
58 // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
59 // Try to guess the reference field size with this naive trick.
60 try {
61 long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));
62 long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2"));
63 ADDRESS_SIZE = (int) Math.abs(off2 - off1);
64 HEADER_SIZE = (int) Math.min(off1, off2);
65 } catch (NoSuchFieldException e) {
66 ADDRESS_SIZE = -1;
67 }
68 }
69
70 static class CompressedOopsClass {
71 public Object obj1;
72 public Object obj2;
73 }
74
75 public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
76 Field f1 = klass.getField(field1);
|