1 /*
2  * Copyright (c) 2013, 2016, 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 jdk.internal.vm.annotation.Contended;
39 
40 /*
41  * @test
42  * @bug     8015270
43  * @bug     8015493
44  * @summary \@Contended: fix multiple issues in the layout code
45  *
46  * @modules java.base/jdk.internal.vm.annotation
47  * @run main/othervm -XX:-RestrictContended -XX:ContendedPaddingWidth=128 -Xmx128m OopMaps
48  */
49 public class OopMaps {
50 
51     public static final int COUNT = 10000;
52 
main(String[] args)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         Object o05 = new Object();
59         Object o06 = new Object();
60         Object o07 = new Object();
61         Object o08 = new Object();
62         Object o09 = new Object();
63         Object o10 = new Object();
64         Object o11 = new Object();
65         Object o12 = new Object();
66         Object o13 = new Object();
67         Object o14 = new Object();
68 
69         R1[] rs = new R1[COUNT];
70 
71         for (int i = 0; i < COUNT; i++) {
72            R1 r1 = new R1();
73            r1.o01 = o01;
74            r1.o02 = o02;
75            r1.o03 = o03;
76            r1.o04 = o04;
77            r1.o05 = o05;
78            r1.o06 = o06;
79            r1.o07 = o07;
80            r1.o08 = o08;
81            r1.o09 = o09;
82            r1.o10 = o10;
83            r1.o11 = o11;
84            r1.o12 = o12;
85            r1.o13 = o13;
86            r1.o14 = o14;
87            r1.i1 = 1;
88            r1.i2 = 2;
89            r1.i3 = 3;
90            r1.i4 = 4;
91            rs[i] = r1;
92         }
93 
94         System.gc();
95 
96         for (int i = 0; i < COUNT; i++) {
97            R1 r1 = rs[i];
98            if (r1.o01 != o01) throw new Error("Test Error: o01");
99            if (r1.o02 != o02) throw new Error("Test Error: o02");
100            if (r1.o03 != o03) throw new Error("Test Error: o03");
101            if (r1.o04 != o04) throw new Error("Test Error: o04");
102            if (r1.o05 != o05) throw new Error("Test Error: o05");
103            if (r1.o06 != o06) throw new Error("Test Error: o06");
104            if (r1.o07 != o07) throw new Error("Test Error: o07");
105            if (r1.o08 != o08) throw new Error("Test Error: o08");
106            if (r1.o09 != o09) throw new Error("Test Error: o09");
107            if (r1.o10 != o10) throw new Error("Test Error: o10");
108            if (r1.o11 != o11) throw new Error("Test Error: o11");
109            if (r1.o12 != o12) throw new Error("Test Error: o12");
110            if (r1.o13 != o13) throw new Error("Test Error: o13");
111            if (r1.o14 != o14) throw new Error("Test Error: o14");
112            if (r1.i1 != 1)    throw new Error("Test Error: i1");
113            if (r1.i2 != 2)    throw new Error("Test Error: i2");
114            if (r1.i3 != 3)    throw new Error("Test Error: i3");
115            if (r1.i4 != 4)    throw new Error("Test Error: i4");
116         }
117     }
118 
119     public static class R0 {
120         int i1;
121         int i2;
122 
123         Object o01;
124         Object o02;
125 
126         @Contended
127         Object o03;
128 
129         @Contended
130         Object o04;
131 
132         @Contended
133         Object o05;
134 
135         @Contended
136         Object o06;
137 
138         @Contended
139         Object o07;
140    }
141 
142    public static class R1 extends R0 {
143         int i3;
144         int i4;
145 
146         Object o08;
147         Object o09;
148 
149         @Contended
150         Object o10;
151 
152         @Contended
153         Object o11;
154 
155         @Contended
156         Object o12;
157 
158         @Contended
159         Object o13;
160 
161         @Contended
162         Object o14;
163    }
164 
165 }
166 
167