8014871: Move @Contended regression tests to the same place

Mon, 20 May 2013 15:43:50 +0400

author
shade
date
Mon, 20 May 2013 15:43:50 +0400
changeset 5145
5e3573e08a83
parent 5144
a5d6f0c3585f
child 5146
bbddfb08190f

8014871: Move @Contended regression tests to the same place
Summary: Move the missing test to appropriate location.
Reviewed-by: dholmes, sla

test/runtime/8003985/Test8003985.java file | annotate | diff | comparison | revisions
test/runtime/contended/Basic.java file | annotate | diff | comparison | revisions
     1.1 --- a/test/runtime/8003985/Test8003985.java	Sat May 18 20:41:01 2013 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,302 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.
    1.11 - *
    1.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 - * version 2 for more details (a copy is included in the LICENSE file that
    1.16 - * accompanied this code).
    1.17 - *
    1.18 - * You should have received a copy of the GNU General Public License version
    1.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 - *
    1.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 - * or visit www.oracle.com if you need additional information or have any
    1.24 - * questions.
    1.25 - */
    1.26 -
    1.27 -import java.io.BufferedReader;
    1.28 -import java.io.InputStreamReader;
    1.29 -import java.lang.Class;
    1.30 -import java.lang.String;
    1.31 -import java.lang.System;
    1.32 -import java.lang.management.ManagementFactory;
    1.33 -import java.lang.management.RuntimeMXBean;
    1.34 -import java.util.ArrayList;
    1.35 -import java.util.List;
    1.36 -import java.util.concurrent.CyclicBarrier;
    1.37 -import java.util.regex.Matcher;
    1.38 -import java.util.regex.Pattern;
    1.39 -import java.lang.reflect.Field;
    1.40 -import java.lang.reflect.Modifier;
    1.41 -import sun.misc.Unsafe;
    1.42 -import sun.misc.Contended;
    1.43 -
    1.44 -/*
    1.45 - * @test
    1.46 - * @bug     8003985
    1.47 - * @summary Support Contended Annotation - JEP 142
    1.48 - *
    1.49 - * @run main/othervm -XX:-RestrictContended Test8003985
    1.50 - */
    1.51 -public class Test8003985 {
    1.52 -
    1.53 -    private static final Unsafe U;
    1.54 -    private static int ADDRESS_SIZE;
    1.55 -    private static int HEADER_SIZE;
    1.56 -
    1.57 -    static {
    1.58 -        // steal Unsafe
    1.59 -        try {
    1.60 -            Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
    1.61 -            unsafe.setAccessible(true);
    1.62 -            U = (Unsafe) unsafe.get(null);
    1.63 -        } catch (NoSuchFieldException | IllegalAccessException e) {
    1.64 -            throw new IllegalStateException(e);
    1.65 -        }
    1.66 -
    1.67 -        // When running with CompressedOops on 64-bit platform, the address size
    1.68 -        // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
    1.69 -        // Try to guess the reference field size with this naive trick.
    1.70 -        try {
    1.71 -            long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));
    1.72 -            long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2"));
    1.73 -            ADDRESS_SIZE = (int) Math.abs(off2 - off1);
    1.74 -            HEADER_SIZE = (int) Math.min(off1, off2);
    1.75 -        } catch (NoSuchFieldException e) {
    1.76 -            ADDRESS_SIZE = -1;
    1.77 -        }
    1.78 -    }
    1.79 -
    1.80 -    static class CompressedOopsClass {
    1.81 -        public Object obj1;
    1.82 -        public Object obj2;
    1.83 -    }
    1.84 -
    1.85 -    public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    1.86 -        Field f1 = klass.getDeclaredField(field1);
    1.87 -        Field f2 = klass.getDeclaredField(field2);
    1.88 -
    1.89 -        if (isStatic(f1) != isStatic(f2)) {
    1.90 -            return true; // these guys are in naturally disjoint locations
    1.91 -        }
    1.92 -
    1.93 -        int diff = offset(f1) - offset(f2);
    1.94 -        if (diff < 0) {
    1.95 -            // f1 is first
    1.96 -            return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    1.97 -        } else {
    1.98 -            // f2 is first
    1.99 -            return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
   1.100 -        }
   1.101 -    }
   1.102 -
   1.103 -    public static boolean isPadded(Class klass, String field1) throws Exception {
   1.104 -        Field f1 = klass.getDeclaredField(field1);
   1.105 -
   1.106 -        if (isStatic(f1)) {
   1.107 -            return offset(f1) > 128 + 64;
   1.108 -        }
   1.109 -
   1.110 -        return offset(f1) > 64;
   1.111 -    }
   1.112 -
   1.113 -    public static boolean sameLayout(Class klass1, Class klass2) throws Exception {
   1.114 -        for (Field f1 : klass1.getDeclaredFields()) {
   1.115 -            Field f2 = klass2.getDeclaredField(f1.getName());
   1.116 -            if (offset(f1) != offset(f2)) {
   1.117 -                return false;
   1.118 -            }
   1.119 -        }
   1.120 -
   1.121 -        for (Field f2 : klass1.getDeclaredFields()) {
   1.122 -            Field f1 = klass2.getDeclaredField(f2.getName());
   1.123 -            if (offset(f1) != offset(f2)) {
   1.124 -                return false;
   1.125 -            }
   1.126 -        }
   1.127 -
   1.128 -        return true;
   1.129 -    }
   1.130 -
   1.131 -    public static boolean isStatic(Field field) {
   1.132 -        return Modifier.isStatic(field.getModifiers());
   1.133 -    }
   1.134 -
   1.135 -    public static int offset(Field field) {
   1.136 -        if (isStatic(field)) {
   1.137 -            return (int) U.staticFieldOffset(field);
   1.138 -        } else {
   1.139 -            return (int) U.objectFieldOffset(field);
   1.140 -        }
   1.141 -    }
   1.142 -
   1.143 -    public static int getSize(Field field) {
   1.144 -        Class type = field.getType();
   1.145 -        if (type == byte.class)    { return 1; }
   1.146 -        if (type == boolean.class) { return 1; }
   1.147 -        if (type == short.class)   { return 2; }
   1.148 -        if (type == char.class)    { return 2; }
   1.149 -        if (type == int.class)     { return 4; }
   1.150 -        if (type == float.class)   { return 4; }
   1.151 -        if (type == long.class)    { return 8; }
   1.152 -        if (type == double.class)  { return 8; }
   1.153 -        return ADDRESS_SIZE;
   1.154 -    }
   1.155 -
   1.156 -    public static void main(String[] args) throws Exception {
   1.157 -        boolean endResult = true;
   1.158 -
   1.159 -        // --------------- INSTANCE FIELDS ---------------------
   1.160 -
   1.161 -        if (arePaddedPairwise(Test1.class, "int1", "int2") ||
   1.162 -                isPadded(Test1.class, "int1") ||
   1.163 -                isPadded(Test1.class, "int2")) {
   1.164 -            System.err.println("Test1 failed");
   1.165 -            endResult &= false;
   1.166 -        }
   1.167 -
   1.168 -        if (!arePaddedPairwise(Test2.class, "int1", "int2") ||
   1.169 -                !isPadded(Test2.class, "int1") ||
   1.170 -                isPadded(Test2.class, "int2")) {
   1.171 -            System.err.println("Test2 failed");
   1.172 -            endResult &= false;
   1.173 -        }
   1.174 -
   1.175 -        if (!arePaddedPairwise(Test3.class, "int1", "int2") ||
   1.176 -                !isPadded(Test3.class, "int1") ||
   1.177 -                !isPadded(Test3.class, "int2")) {
   1.178 -            System.err.println("Test3 failed");
   1.179 -            endResult &= false;
   1.180 -        }
   1.181 -
   1.182 -        if (arePaddedPairwise(Test4.class, "int1", "int2") ||
   1.183 -                !isPadded(Test4.class, "int1") ||
   1.184 -                !isPadded(Test4.class, "int2")) {
   1.185 -            System.err.println("Test4 failed");
   1.186 -            endResult &= false;
   1.187 -        }
   1.188 -
   1.189 -        if (!arePaddedPairwise(Test5.class, "int1", "int2") ||
   1.190 -                !isPadded(Test5.class, "int1") ||
   1.191 -                !isPadded(Test5.class, "int2")) {
   1.192 -            System.err.println("Test5 failed");
   1.193 -            endResult &= false;
   1.194 -        }
   1.195 -
   1.196 -        if (!arePaddedPairwise(Test6.class, "int1", "int2") ||
   1.197 -                !isPadded(Test6.class, "int1") ||
   1.198 -                !isPadded(Test6.class, "int2")) {
   1.199 -            System.err.println("Test6 failed");
   1.200 -            endResult &= false;
   1.201 -        }
   1.202 -
   1.203 -        if (arePaddedPairwise(Test7.class, "int1", "int2") ||
   1.204 -                !isPadded(Test7.class, "int1") ||
   1.205 -                !isPadded(Test7.class, "int2")) {
   1.206 -            System.err.println("Test7 failed");
   1.207 -            endResult &= false;
   1.208 -        }
   1.209 -
   1.210 -        if (!arePaddedPairwise(Test8.class, "int1", "int2") ||
   1.211 -                !isPadded(Test8.class, "int1") ||
   1.212 -                !isPadded(Test8.class, "int2")) {
   1.213 -            System.err.println("Test8 failed");
   1.214 -            endResult &= false;
   1.215 -        }
   1.216 -
   1.217 -        if (!arePaddedPairwise(Test9.class, "int1", "int2") ||
   1.218 -                !isPadded(Test9.class, "int1") ||
   1.219 -                !isPadded(Test9.class, "int2")) {
   1.220 -            System.err.println("Test9 failed");
   1.221 -            endResult &= false;
   1.222 -        }
   1.223 -
   1.224 -        if (!sameLayout(Test4.class, Test7.class)) {
   1.225 -            System.err.println("Test4 and Test7 have different layouts");
   1.226 -            endResult &= false;
   1.227 -        }
   1.228 -
   1.229 -        if (!sameLayout(Test5.class, Test6.class)) {
   1.230 -            System.err.println("Test5 and Test6 have different layouts");
   1.231 -            endResult &= false;
   1.232 -        }
   1.233 -
   1.234 -        if (!sameLayout(Test8.class, Test9.class)) {
   1.235 -            System.err.println("Test8 and Test9 have different layouts");
   1.236 -            endResult &= false;
   1.237 -        }
   1.238 -
   1.239 -        System.out.println(endResult ? "Test PASSES" : "Test FAILS");
   1.240 -        if (!endResult) {
   1.241 -           throw new Error("Test failed");
   1.242 -        }
   1.243 -    }
   1.244 -
   1.245 -    // ----------------------------------- INSTANCE FIELDS -----------------------------------------
   1.246 -
   1.247 -    // naturally packed
   1.248 -    public static class Test1 {
   1.249 -                                 private int int1;
   1.250 -                                 private int int2;
   1.251 -    }
   1.252 -
   1.253 -    // int1 is padded
   1.254 -    public static class Test2 {
   1.255 -        @Contended               private int int1;
   1.256 -                                 private int int2;
   1.257 -    }
   1.258 -
   1.259 -    // both fields are padded
   1.260 -    public static class Test3 {
   1.261 -        @Contended               private int int1;
   1.262 -        @Contended               private int int2;
   1.263 -    }
   1.264 -
   1.265 -    // fields are padded in the singular group
   1.266 -    public static class Test4 {
   1.267 -        @Contended("sameGroup")  private int int1;
   1.268 -        @Contended("sameGroup")  private int int2;
   1.269 -    }
   1.270 -
   1.271 -    // fields are padded in disjoint groups
   1.272 -    public static class Test5 {
   1.273 -        @Contended("diffGroup1") private int int1;
   1.274 -        @Contended("diffGroup2") private int int2;
   1.275 -    }
   1.276 -
   1.277 -    // fields are padded in disjoint groups
   1.278 -    public static class Test6 {
   1.279 -        @Contended               private int int1;
   1.280 -        @Contended("diffGroup2") private int int2;
   1.281 -    }
   1.282 -
   1.283 -    // fields are padded in the singular group
   1.284 -    @Contended
   1.285 -    public static class Test7 {
   1.286 -                                 private int int1;
   1.287 -                                 private int int2;
   1.288 -    }
   1.289 -
   1.290 -    // all fields are padded as the group, and one field is padded specifically
   1.291 -    @Contended
   1.292 -    public static class Test8 {
   1.293 -        @Contended               private int int1;
   1.294 -                                 private int int2;
   1.295 -    }
   1.296 -
   1.297 -    // all fields are padded as the group, and one field is padded specifically
   1.298 -    @Contended
   1.299 -    public static class Test9 {
   1.300 -        @Contended("group")      private int int1;
   1.301 -                                 private int int2;
   1.302 -    }
   1.303 -
   1.304 -}
   1.305 -
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/runtime/contended/Basic.java	Mon May 20 15:43:50 2013 +0400
     2.3 @@ -0,0 +1,302 @@
     2.4 +/*
     2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +import java.io.BufferedReader;
    2.28 +import java.io.InputStreamReader;
    2.29 +import java.lang.Class;
    2.30 +import java.lang.String;
    2.31 +import java.lang.System;
    2.32 +import java.lang.management.ManagementFactory;
    2.33 +import java.lang.management.RuntimeMXBean;
    2.34 +import java.util.ArrayList;
    2.35 +import java.util.List;
    2.36 +import java.util.concurrent.CyclicBarrier;
    2.37 +import java.util.regex.Matcher;
    2.38 +import java.util.regex.Pattern;
    2.39 +import java.lang.reflect.Field;
    2.40 +import java.lang.reflect.Modifier;
    2.41 +import sun.misc.Unsafe;
    2.42 +import sun.misc.Contended;
    2.43 +
    2.44 +/*
    2.45 + * @test
    2.46 + * @bug     8003985
    2.47 + * @summary Support Contended Annotation - JEP 142
    2.48 + *
    2.49 + * @run main/othervm -XX:-RestrictContended Basic
    2.50 + */
    2.51 +public class Basic {
    2.52 +
    2.53 +    private static final Unsafe U;
    2.54 +    private static int ADDRESS_SIZE;
    2.55 +    private static int HEADER_SIZE;
    2.56 +
    2.57 +    static {
    2.58 +        // steal Unsafe
    2.59 +        try {
    2.60 +            Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
    2.61 +            unsafe.setAccessible(true);
    2.62 +            U = (Unsafe) unsafe.get(null);
    2.63 +        } catch (NoSuchFieldException | IllegalAccessException e) {
    2.64 +            throw new IllegalStateException(e);
    2.65 +        }
    2.66 +
    2.67 +        // When running with CompressedOops on 64-bit platform, the address size
    2.68 +        // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
    2.69 +        // Try to guess the reference field size with this naive trick.
    2.70 +        try {
    2.71 +            long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));
    2.72 +            long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2"));
    2.73 +            ADDRESS_SIZE = (int) Math.abs(off2 - off1);
    2.74 +            HEADER_SIZE = (int) Math.min(off1, off2);
    2.75 +        } catch (NoSuchFieldException e) {
    2.76 +            ADDRESS_SIZE = -1;
    2.77 +        }
    2.78 +    }
    2.79 +
    2.80 +    static class CompressedOopsClass {
    2.81 +        public Object obj1;
    2.82 +        public Object obj2;
    2.83 +    }
    2.84 +
    2.85 +    public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    2.86 +        Field f1 = klass.getDeclaredField(field1);
    2.87 +        Field f2 = klass.getDeclaredField(field2);
    2.88 +
    2.89 +        if (isStatic(f1) != isStatic(f2)) {
    2.90 +            return true; // these guys are in naturally disjoint locations
    2.91 +        }
    2.92 +
    2.93 +        int diff = offset(f1) - offset(f2);
    2.94 +        if (diff < 0) {
    2.95 +            // f1 is first
    2.96 +            return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    2.97 +        } else {
    2.98 +            // f2 is first
    2.99 +            return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
   2.100 +        }
   2.101 +    }
   2.102 +
   2.103 +    public static boolean isPadded(Class klass, String field1) throws Exception {
   2.104 +        Field f1 = klass.getDeclaredField(field1);
   2.105 +
   2.106 +        if (isStatic(f1)) {
   2.107 +            return offset(f1) > 128 + 64;
   2.108 +        }
   2.109 +
   2.110 +        return offset(f1) > 64;
   2.111 +    }
   2.112 +
   2.113 +    public static boolean sameLayout(Class klass1, Class klass2) throws Exception {
   2.114 +        for (Field f1 : klass1.getDeclaredFields()) {
   2.115 +            Field f2 = klass2.getDeclaredField(f1.getName());
   2.116 +            if (offset(f1) != offset(f2)) {
   2.117 +                return false;
   2.118 +            }
   2.119 +        }
   2.120 +
   2.121 +        for (Field f2 : klass1.getDeclaredFields()) {
   2.122 +            Field f1 = klass2.getDeclaredField(f2.getName());
   2.123 +            if (offset(f1) != offset(f2)) {
   2.124 +                return false;
   2.125 +            }
   2.126 +        }
   2.127 +
   2.128 +        return true;
   2.129 +    }
   2.130 +
   2.131 +    public static boolean isStatic(Field field) {
   2.132 +        return Modifier.isStatic(field.getModifiers());
   2.133 +    }
   2.134 +
   2.135 +    public static int offset(Field field) {
   2.136 +        if (isStatic(field)) {
   2.137 +            return (int) U.staticFieldOffset(field);
   2.138 +        } else {
   2.139 +            return (int) U.objectFieldOffset(field);
   2.140 +        }
   2.141 +    }
   2.142 +
   2.143 +    public static int getSize(Field field) {
   2.144 +        Class type = field.getType();
   2.145 +        if (type == byte.class)    { return 1; }
   2.146 +        if (type == boolean.class) { return 1; }
   2.147 +        if (type == short.class)   { return 2; }
   2.148 +        if (type == char.class)    { return 2; }
   2.149 +        if (type == int.class)     { return 4; }
   2.150 +        if (type == float.class)   { return 4; }
   2.151 +        if (type == long.class)    { return 8; }
   2.152 +        if (type == double.class)  { return 8; }
   2.153 +        return ADDRESS_SIZE;
   2.154 +    }
   2.155 +
   2.156 +    public static void main(String[] args) throws Exception {
   2.157 +        boolean endResult = true;
   2.158 +
   2.159 +        // --------------- INSTANCE FIELDS ---------------------
   2.160 +
   2.161 +        if (arePaddedPairwise(Test1.class, "int1", "int2") ||
   2.162 +                isPadded(Test1.class, "int1") ||
   2.163 +                isPadded(Test1.class, "int2")) {
   2.164 +            System.err.println("Test1 failed");
   2.165 +            endResult &= false;
   2.166 +        }
   2.167 +
   2.168 +        if (!arePaddedPairwise(Test2.class, "int1", "int2") ||
   2.169 +                !isPadded(Test2.class, "int1") ||
   2.170 +                isPadded(Test2.class, "int2")) {
   2.171 +            System.err.println("Test2 failed");
   2.172 +            endResult &= false;
   2.173 +        }
   2.174 +
   2.175 +        if (!arePaddedPairwise(Test3.class, "int1", "int2") ||
   2.176 +                !isPadded(Test3.class, "int1") ||
   2.177 +                !isPadded(Test3.class, "int2")) {
   2.178 +            System.err.println("Test3 failed");
   2.179 +            endResult &= false;
   2.180 +        }
   2.181 +
   2.182 +        if (arePaddedPairwise(Test4.class, "int1", "int2") ||
   2.183 +                !isPadded(Test4.class, "int1") ||
   2.184 +                !isPadded(Test4.class, "int2")) {
   2.185 +            System.err.println("Test4 failed");
   2.186 +            endResult &= false;
   2.187 +        }
   2.188 +
   2.189 +        if (!arePaddedPairwise(Test5.class, "int1", "int2") ||
   2.190 +                !isPadded(Test5.class, "int1") ||
   2.191 +                !isPadded(Test5.class, "int2")) {
   2.192 +            System.err.println("Test5 failed");
   2.193 +            endResult &= false;
   2.194 +        }
   2.195 +
   2.196 +        if (!arePaddedPairwise(Test6.class, "int1", "int2") ||
   2.197 +                !isPadded(Test6.class, "int1") ||
   2.198 +                !isPadded(Test6.class, "int2")) {
   2.199 +            System.err.println("Test6 failed");
   2.200 +            endResult &= false;
   2.201 +        }
   2.202 +
   2.203 +        if (arePaddedPairwise(Test7.class, "int1", "int2") ||
   2.204 +                !isPadded(Test7.class, "int1") ||
   2.205 +                !isPadded(Test7.class, "int2")) {
   2.206 +            System.err.println("Test7 failed");
   2.207 +            endResult &= false;
   2.208 +        }
   2.209 +
   2.210 +        if (!arePaddedPairwise(Test8.class, "int1", "int2") ||
   2.211 +                !isPadded(Test8.class, "int1") ||
   2.212 +                !isPadded(Test8.class, "int2")) {
   2.213 +            System.err.println("Test8 failed");
   2.214 +            endResult &= false;
   2.215 +        }
   2.216 +
   2.217 +        if (!arePaddedPairwise(Test9.class, "int1", "int2") ||
   2.218 +                !isPadded(Test9.class, "int1") ||
   2.219 +                !isPadded(Test9.class, "int2")) {
   2.220 +            System.err.println("Test9 failed");
   2.221 +            endResult &= false;
   2.222 +        }
   2.223 +
   2.224 +        if (!sameLayout(Test4.class, Test7.class)) {
   2.225 +            System.err.println("Test4 and Test7 have different layouts");
   2.226 +            endResult &= false;
   2.227 +        }
   2.228 +
   2.229 +        if (!sameLayout(Test5.class, Test6.class)) {
   2.230 +            System.err.println("Test5 and Test6 have different layouts");
   2.231 +            endResult &= false;
   2.232 +        }
   2.233 +
   2.234 +        if (!sameLayout(Test8.class, Test9.class)) {
   2.235 +            System.err.println("Test8 and Test9 have different layouts");
   2.236 +            endResult &= false;
   2.237 +        }
   2.238 +
   2.239 +        System.out.println(endResult ? "Test PASSES" : "Test FAILS");
   2.240 +        if (!endResult) {
   2.241 +           throw new Error("Test failed");
   2.242 +        }
   2.243 +    }
   2.244 +
   2.245 +    // ----------------------------------- INSTANCE FIELDS -----------------------------------------
   2.246 +
   2.247 +    // naturally packed
   2.248 +    public static class Test1 {
   2.249 +                                 private int int1;
   2.250 +                                 private int int2;
   2.251 +    }
   2.252 +
   2.253 +    // int1 is padded
   2.254 +    public static class Test2 {
   2.255 +        @Contended               private int int1;
   2.256 +                                 private int int2;
   2.257 +    }
   2.258 +
   2.259 +    // both fields are padded
   2.260 +    public static class Test3 {
   2.261 +        @Contended               private int int1;
   2.262 +        @Contended               private int int2;
   2.263 +    }
   2.264 +
   2.265 +    // fields are padded in the singular group
   2.266 +    public static class Test4 {
   2.267 +        @Contended("sameGroup")  private int int1;
   2.268 +        @Contended("sameGroup")  private int int2;
   2.269 +    }
   2.270 +
   2.271 +    // fields are padded in disjoint groups
   2.272 +    public static class Test5 {
   2.273 +        @Contended("diffGroup1") private int int1;
   2.274 +        @Contended("diffGroup2") private int int2;
   2.275 +    }
   2.276 +
   2.277 +    // fields are padded in disjoint groups
   2.278 +    public static class Test6 {
   2.279 +        @Contended               private int int1;
   2.280 +        @Contended("diffGroup2") private int int2;
   2.281 +    }
   2.282 +
   2.283 +    // fields are padded in the singular group
   2.284 +    @Contended
   2.285 +    public static class Test7 {
   2.286 +                                 private int int1;
   2.287 +                                 private int int2;
   2.288 +    }
   2.289 +
   2.290 +    // all fields are padded as the group, and one field is padded specifically
   2.291 +    @Contended
   2.292 +    public static class Test8 {
   2.293 +        @Contended               private int int1;
   2.294 +                                 private int int2;
   2.295 +    }
   2.296 +
   2.297 +    // all fields are padded as the group, and one field is padded specifically
   2.298 +    @Contended
   2.299 +    public static class Test9 {
   2.300 +        @Contended("group")      private int int1;
   2.301 +                                 private int int2;
   2.302 +    }
   2.303 +
   2.304 +}
   2.305 +

mercurial