hotspot/test/runtime/contended/Basic.java
author mgerdin
Mon, 11 Aug 2014 17:12:41 +0400
changeset 25958 8dc85547d6d6
parent 17611 5b5a5ad4c222
child 29678 dd2f3932c21e
permissions -rw-r--r--
8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot Reviewed-by: kvn, iignatyev, mgerdin Contributed-by: andrey.x.zakharov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17611
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     1
/*
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     4
 *
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     8
 *
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    13
 * accompanied this code).
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    14
 *
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    18
 *
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    21
 * questions.
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    22
 */
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    23
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    24
import java.io.BufferedReader;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    25
import java.io.InputStreamReader;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    26
import java.lang.Class;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    27
import java.lang.String;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    28
import java.lang.System;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    29
import java.lang.management.ManagementFactory;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    30
import java.lang.management.RuntimeMXBean;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    31
import java.util.ArrayList;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    32
import java.util.List;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    33
import java.util.concurrent.CyclicBarrier;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    34
import java.util.regex.Matcher;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    35
import java.util.regex.Pattern;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    36
import java.lang.reflect.Field;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    37
import java.lang.reflect.Modifier;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    38
import sun.misc.Unsafe;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    39
import sun.misc.Contended;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    40
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    41
/*
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    42
 * @test
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    43
 * @bug     8003985
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    44
 * @summary Support Contended Annotation - JEP 142
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    45
 *
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    46
 * @run main/othervm -XX:-RestrictContended Basic
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    47
 */
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    48
public class Basic {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    49
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    50
    private static final Unsafe U;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    51
    private static int ADDRESS_SIZE;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    52
    private static int HEADER_SIZE;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    53
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    54
    static {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    55
        // steal Unsafe
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    56
        try {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    57
            Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    58
            unsafe.setAccessible(true);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    59
            U = (Unsafe) unsafe.get(null);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    60
        } catch (NoSuchFieldException | IllegalAccessException e) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    61
            throw new IllegalStateException(e);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    62
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    63
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    64
        // When running with CompressedOops on 64-bit platform, the address size
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    65
        // reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    66
        // Try to guess the reference field size with this naive trick.
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    67
        try {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    68
            long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1"));
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    69
            long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2"));
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    70
            ADDRESS_SIZE = (int) Math.abs(off2 - off1);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    71
            HEADER_SIZE = (int) Math.min(off1, off2);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    72
        } catch (NoSuchFieldException e) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    73
            ADDRESS_SIZE = -1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    74
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    75
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    76
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    77
    static class CompressedOopsClass {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    78
        public Object obj1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    79
        public Object obj2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    80
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    81
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    82
    public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    83
        Field f1 = klass.getDeclaredField(field1);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    84
        Field f2 = klass.getDeclaredField(field2);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    85
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    86
        if (isStatic(f1) != isStatic(f2)) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    87
            return true; // these guys are in naturally disjoint locations
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    88
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    89
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    90
        int diff = offset(f1) - offset(f2);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    91
        if (diff < 0) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    92
            // f1 is first
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    93
            return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    94
        } else {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    95
            // f2 is first
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    96
            return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    97
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    98
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
    99
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   100
    public static boolean isPadded(Class klass, String field1) throws Exception {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   101
        Field f1 = klass.getDeclaredField(field1);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   102
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   103
        if (isStatic(f1)) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   104
            return offset(f1) > 128 + 64;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   105
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   106
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   107
        return offset(f1) > 64;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   108
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   109
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   110
    public static boolean sameLayout(Class klass1, Class klass2) throws Exception {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   111
        for (Field f1 : klass1.getDeclaredFields()) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   112
            Field f2 = klass2.getDeclaredField(f1.getName());
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   113
            if (offset(f1) != offset(f2)) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   114
                return false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   115
            }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   116
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   117
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   118
        for (Field f2 : klass1.getDeclaredFields()) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   119
            Field f1 = klass2.getDeclaredField(f2.getName());
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   120
            if (offset(f1) != offset(f2)) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   121
                return false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   122
            }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   123
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   124
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   125
        return true;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   126
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   127
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   128
    public static boolean isStatic(Field field) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   129
        return Modifier.isStatic(field.getModifiers());
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   130
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   131
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   132
    public static int offset(Field field) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   133
        if (isStatic(field)) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   134
            return (int) U.staticFieldOffset(field);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   135
        } else {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   136
            return (int) U.objectFieldOffset(field);
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   137
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   138
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   139
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   140
    public static int getSize(Field field) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   141
        Class type = field.getType();
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   142
        if (type == byte.class)    { return 1; }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   143
        if (type == boolean.class) { return 1; }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   144
        if (type == short.class)   { return 2; }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   145
        if (type == char.class)    { return 2; }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   146
        if (type == int.class)     { return 4; }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   147
        if (type == float.class)   { return 4; }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   148
        if (type == long.class)    { return 8; }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   149
        if (type == double.class)  { return 8; }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   150
        return ADDRESS_SIZE;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   151
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   152
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   153
    public static void main(String[] args) throws Exception {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   154
        boolean endResult = true;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   155
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   156
        // --------------- INSTANCE FIELDS ---------------------
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   157
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   158
        if (arePaddedPairwise(Test1.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   159
                isPadded(Test1.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   160
                isPadded(Test1.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   161
            System.err.println("Test1 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   162
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   163
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   164
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   165
        if (!arePaddedPairwise(Test2.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   166
                !isPadded(Test2.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   167
                isPadded(Test2.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   168
            System.err.println("Test2 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   169
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   170
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   171
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   172
        if (!arePaddedPairwise(Test3.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   173
                !isPadded(Test3.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   174
                !isPadded(Test3.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   175
            System.err.println("Test3 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   176
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   177
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   178
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   179
        if (arePaddedPairwise(Test4.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   180
                !isPadded(Test4.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   181
                !isPadded(Test4.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   182
            System.err.println("Test4 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   183
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   184
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   185
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   186
        if (!arePaddedPairwise(Test5.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   187
                !isPadded(Test5.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   188
                !isPadded(Test5.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   189
            System.err.println("Test5 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   190
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   191
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   192
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   193
        if (!arePaddedPairwise(Test6.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   194
                !isPadded(Test6.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   195
                !isPadded(Test6.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   196
            System.err.println("Test6 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   197
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   198
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   199
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   200
        if (arePaddedPairwise(Test7.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   201
                !isPadded(Test7.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   202
                !isPadded(Test7.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   203
            System.err.println("Test7 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   204
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   205
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   206
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   207
        if (!arePaddedPairwise(Test8.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   208
                !isPadded(Test8.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   209
                !isPadded(Test8.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   210
            System.err.println("Test8 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   211
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   212
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   213
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   214
        if (!arePaddedPairwise(Test9.class, "int1", "int2") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   215
                !isPadded(Test9.class, "int1") ||
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   216
                !isPadded(Test9.class, "int2")) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   217
            System.err.println("Test9 failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   218
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   219
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   220
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   221
        if (!sameLayout(Test4.class, Test7.class)) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   222
            System.err.println("Test4 and Test7 have different layouts");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   223
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   224
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   225
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   226
        if (!sameLayout(Test5.class, Test6.class)) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   227
            System.err.println("Test5 and Test6 have different layouts");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   228
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   229
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   230
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   231
        if (!sameLayout(Test8.class, Test9.class)) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   232
            System.err.println("Test8 and Test9 have different layouts");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   233
            endResult &= false;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   234
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   235
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   236
        System.out.println(endResult ? "Test PASSES" : "Test FAILS");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   237
        if (!endResult) {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   238
           throw new Error("Test failed");
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   239
        }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   240
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   241
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   242
    // ----------------------------------- INSTANCE FIELDS -----------------------------------------
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   243
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   244
    // naturally packed
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   245
    public static class Test1 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   246
                                 private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   247
                                 private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   248
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   249
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   250
    // int1 is padded
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   251
    public static class Test2 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   252
        @Contended               private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   253
                                 private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   254
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   255
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   256
    // both fields are padded
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   257
    public static class Test3 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   258
        @Contended               private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   259
        @Contended               private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   260
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   261
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   262
    // fields are padded in the singular group
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   263
    public static class Test4 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   264
        @Contended("sameGroup")  private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   265
        @Contended("sameGroup")  private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   266
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   267
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   268
    // fields are padded in disjoint groups
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   269
    public static class Test5 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   270
        @Contended("diffGroup1") private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   271
        @Contended("diffGroup2") private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   272
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   273
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   274
    // fields are padded in disjoint groups
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   275
    public static class Test6 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   276
        @Contended               private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   277
        @Contended("diffGroup2") private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   278
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   279
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   280
    // fields are padded in the singular group
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   281
    @Contended
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   282
    public static class Test7 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   283
                                 private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   284
                                 private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   285
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   286
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   287
    // all fields are padded as the group, and one field is padded specifically
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   288
    @Contended
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   289
    public static class Test8 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   290
        @Contended               private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   291
                                 private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   292
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   293
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   294
    // all fields are padded as the group, and one field is padded specifically
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   295
    @Contended
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   296
    public static class Test9 {
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   297
        @Contended("group")      private int int1;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   298
                                 private int int2;
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   299
    }
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   300
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   301
}
5b5a5ad4c222 8014871: Move @Contended regression tests to the same place
shade
parents:
diff changeset
   302