Merge

Thu, 16 May 2013 21:19:49 -0400

author
dholmes
date
Thu, 16 May 2013 21:19:49 -0400
changeset 5136
b334821dad92
parent 5134
78332b46e604
parent 5135
205dd30230e1
child 5139
1ba508fcd3e2

Merge

     1.1 --- a/src/share/vm/classfile/classFileParser.cpp	Thu May 16 12:40:27 2013 +0100
     1.2 +++ b/src/share/vm/classfile/classFileParser.cpp	Thu May 16 21:19:49 2013 -0400
     1.3 @@ -3165,13 +3165,13 @@
     1.4    first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() +
     1.5                                   nonstatic_field_size * heapOopSize;
     1.6  
     1.7 +  next_nonstatic_field_offset = first_nonstatic_field_offset;
     1.8 +
     1.9    // class is contended, pad before all the fields
    1.10    if (parsed_annotations->is_contended()) {
    1.11 -    first_nonstatic_field_offset += pad_size;
    1.12 +    next_nonstatic_field_offset += pad_size;
    1.13    }
    1.14  
    1.15 -  next_nonstatic_field_offset = first_nonstatic_field_offset;
    1.16 -
    1.17    unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE];
    1.18    unsigned int nonstatic_word_count   = fac->count[NONSTATIC_WORD]   - fac_contended.count[NONSTATIC_WORD];
    1.19    unsigned int nonstatic_short_count  = fac->count[NONSTATIC_SHORT]  - fac_contended.count[NONSTATIC_SHORT];
    1.20 @@ -3562,7 +3562,7 @@
    1.21    int instance_size = align_object_size(next_nonstatic_type_offset / wordSize);
    1.22  
    1.23    assert(instance_size == align_object_size(align_size_up(
    1.24 -         (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations->is_contended()) ? pad_size : 0)),
    1.25 +         (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize),
    1.26            wordSize) / wordSize), "consistent layout helper value");
    1.27  
    1.28    // Number of non-static oop map blocks allocated at end of klass.
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/runtime/contended/Inheritance1.java	Thu May 16 21:19:49 2013 -0400
     2.3 @@ -0,0 +1,248 @@
     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     8012939
    2.47 + * @summary \@Contended doesn't work correctly with inheritance
    2.48 + *
    2.49 + * @run main/othervm -XX:-RestrictContended Inheritance1
    2.50 + */
    2.51 +public class Inheritance1 {
    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.getField(field1);
    2.87 +        Field f2 = klass.getField(field2);
    2.88 +
    2.89 +        int diff = offset(f1) - offset(f2);
    2.90 +        if (diff < 0) {
    2.91 +            // f1 is first
    2.92 +            return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    2.93 +        } else {
    2.94 +            // f2 is first
    2.95 +            return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    2.96 +        }
    2.97 +    }
    2.98 +
    2.99 +    public static boolean sameLayout(Class klass1, Class klass2) throws Exception {
   2.100 +        for (Field f1 : klass1.getDeclaredFields()) {
   2.101 +            Field f2 = klass2.getDeclaredField(f1.getName());
   2.102 +            if (offset(f1) != offset(f2)) {
   2.103 +                return false;
   2.104 +            }
   2.105 +        }
   2.106 +
   2.107 +        for (Field f2 : klass1.getDeclaredFields()) {
   2.108 +            Field f1 = klass2.getDeclaredField(f2.getName());
   2.109 +            if (offset(f1) != offset(f2)) {
   2.110 +                return false;
   2.111 +            }
   2.112 +        }
   2.113 +
   2.114 +        return true;
   2.115 +    }
   2.116 +
   2.117 +    public static boolean isStatic(Field field) {
   2.118 +        return Modifier.isStatic(field.getModifiers());
   2.119 +    }
   2.120 +
   2.121 +    public static int offset(Field field) {
   2.122 +        if (isStatic(field)) {
   2.123 +            return (int) U.staticFieldOffset(field);
   2.124 +        } else {
   2.125 +            return (int) U.objectFieldOffset(field);
   2.126 +        }
   2.127 +    }
   2.128 +
   2.129 +    public static int getSize(Field field) {
   2.130 +        Class type = field.getType();
   2.131 +        if (type == byte.class)    { return 1; }
   2.132 +        if (type == boolean.class) { return 1; }
   2.133 +        if (type == short.class)   { return 2; }
   2.134 +        if (type == char.class)    { return 2; }
   2.135 +        if (type == int.class)     { return 4; }
   2.136 +        if (type == float.class)   { return 4; }
   2.137 +        if (type == long.class)    { return 8; }
   2.138 +        if (type == double.class)  { return 8; }
   2.139 +        return ADDRESS_SIZE;
   2.140 +    }
   2.141 +
   2.142 +    public static void main(String[] args) throws Exception {
   2.143 +        boolean endResult = true;
   2.144 +
   2.145 +        // --------------- INSTANCE FIELDS ---------------------
   2.146 +
   2.147 +        if (!arePaddedPairwise(A2_R1.class, "int1", "int2")) {
   2.148 +            System.err.println("A2_R1 failed");
   2.149 +            endResult &= false;
   2.150 +        }
   2.151 +
   2.152 +        if (!arePaddedPairwise(A3_R1.class, "int1", "int2")) {
   2.153 +            System.err.println("A3_R1 failed");
   2.154 +            endResult &= false;
   2.155 +        }
   2.156 +
   2.157 +        if (!arePaddedPairwise(A1_R2.class, "int1", "int2")) {
   2.158 +            System.err.println("A1_R2 failed");
   2.159 +            endResult &= false;
   2.160 +        }
   2.161 +
   2.162 +        if (!arePaddedPairwise(A2_R2.class, "int1", "int2")) {
   2.163 +            System.err.println("A2_R2 failed");
   2.164 +            endResult &= false;
   2.165 +        }
   2.166 +
   2.167 +        if (!arePaddedPairwise(A3_R2.class, "int1", "int2")) {
   2.168 +            System.err.println("A3_R2 failed");
   2.169 +            endResult &= false;
   2.170 +        }
   2.171 +
   2.172 +        if (!arePaddedPairwise(A1_R3.class, "int1", "int2")) {
   2.173 +            System.err.println("A1_R3 failed");
   2.174 +            endResult &= false;
   2.175 +        }
   2.176 +
   2.177 +        if (!arePaddedPairwise(A2_R3.class, "int1", "int2")) {
   2.178 +            System.err.println("A2_R3 failed");
   2.179 +            endResult &= false;
   2.180 +        }
   2.181 +
   2.182 +        if (!arePaddedPairwise(A3_R3.class, "int1", "int2")) {
   2.183 +            System.err.println("A3_R3 failed");
   2.184 +            endResult &= false;
   2.185 +        }
   2.186 +
   2.187 +        System.out.println(endResult ? "Test PASSES" : "Test FAILS");
   2.188 +        if (!endResult) {
   2.189 +           throw new Error("Test failed");
   2.190 +        }
   2.191 +    }
   2.192 +
   2.193 +    public static class R1 {
   2.194 +        public int int1;
   2.195 +    }
   2.196 +
   2.197 +    public static class R2 {
   2.198 +        @Contended
   2.199 +        public int int1;
   2.200 +    }
   2.201 +
   2.202 +    @Contended
   2.203 +    public static class R3 {
   2.204 +        public int int1;
   2.205 +    }
   2.206 +
   2.207 +    public static class A1_R1 extends R1 {
   2.208 +        public int int2;
   2.209 +    }
   2.210 +
   2.211 +    public static class A2_R1 extends R1 {
   2.212 +        @Contended
   2.213 +        public int int2;
   2.214 +    }
   2.215 +
   2.216 +    @Contended
   2.217 +    public static class A3_R1 extends R1 {
   2.218 +        public int int2;
   2.219 +    }
   2.220 +
   2.221 +    public static class A1_R2 extends R2 {
   2.222 +        public int int2;
   2.223 +    }
   2.224 +
   2.225 +    public static class A2_R2 extends R2 {
   2.226 +        @Contended
   2.227 +        public int int2;
   2.228 +    }
   2.229 +
   2.230 +    @Contended
   2.231 +    public static class A3_R2 extends R2 {
   2.232 +        public int int2;
   2.233 +    }
   2.234 +
   2.235 +    public static class A1_R3 extends R3 {
   2.236 +        public int int2;
   2.237 +    }
   2.238 +
   2.239 +    public static class A2_R3 extends R3 {
   2.240 +        @Contended
   2.241 +        public int int2;
   2.242 +    }
   2.243 +
   2.244 +    @Contended
   2.245 +    public static class A3_R3 extends R3 {
   2.246 +        public int int2;
   2.247 +    }
   2.248 +
   2.249 +
   2.250 +}
   2.251 +

mercurial