1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.BufferedReader; 25 import java.io.InputStreamReader; 26 import java.lang.Class; 27 import java.lang.String; 28 import java.lang.System; 29 import java.lang.management.ManagementFactory; 30 import java.lang.management.RuntimeMXBean; 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 sun.misc.Unsafe; 39 import jdk.internal.vm.annotation.Contended; 40 41 /* 42 * @test 43 * @bug 8015272 44 * @summary \@Contended within the same group to use the same oop map 45 * 46 * @modules java.base/sun.misc 47 * @run main/othervm -XX:-RestrictContended -XX:ContendedPaddingWidth=128 -Xmx128m OopMapsSameGroup 48 */ 49 public class OopMapsSameGroup { 50 51 public static final int COUNT = 10000; 52 53 public static void main(String[] args) throws Exception { 54 Object o01 = new Object(); 55 Object o02 = new Object(); 56 Object o03 = new Object(); 57 Object o04 = new Object(); 58 59 R[] rs = new R[COUNT]; 60 61 for (int i = 0; i < COUNT; i++) { 62 R r = new R(); 63 r.o01 = o01; 64 r.o02 = o02; 65 r.o03 = o03; 66 r.o04 = o04; 67 rs[i] = r; 68 } 69 70 System.gc(); 71 72 for (int i = 0; i < COUNT; i++) { 73 R r = rs[i]; 74 if (r.o01 != o01) throw new Error("Test Error: o01"); 75 if (r.o02 != o02) throw new Error("Test Error: o02"); 76 if (r.o03 != o03) throw new Error("Test Error: o03"); 77 if (r.o04 != o04) throw new Error("Test Error: o04"); 78 } 79 } 80 81 public static class R { 82 @Contended("group1") 83 Object o01; 84 85 @Contended("group1") 86 Object o02; 87 88 @Contended("group2") 89 Object o03; 90 91 @Contended("group2") 92 Object o04; 93 } 94 95 } 96