Mercurial > hg > truffle
annotate test/compiler/unsafe/GetUnsafeObjectG1PreBarrier.java @ 20363:36c9011aaead
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
Summary: Dynamic allocate _reserved_regions instead of static object to avoid racing during process exit
Reviewed-by: dholmes, coleenp
author | zgu |
---|---|
date | Thu, 14 Aug 2014 09:02:51 -0400 |
parents | 71526a36ebb4 |
children |
rev | line source |
---|---|
12000
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
1 /* |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
4 * |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
8 * |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
13 * accompanied this code). |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
14 * |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
18 * |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
21 * questions. |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
22 */ |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
23 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
24 /* |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
25 * @test |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
26 * @bug 8016474 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
27 * @summary The bug only happens with C1 and G1 using a different ObjectAlignmentInBytes than KlassAlignmentInBytes (which is 8) |
12004
71526a36ebb4
8022029: GetUnsafeObjectG1PreBarrier fails on 32-bit with: Unrecognized VM option 'ObjectAlignmentInBytes=32'
twisti
parents:
12000
diff
changeset
|
28 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=32 GetUnsafeObjectG1PreBarrier |
12000
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
29 */ |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
30 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
31 import java.lang.reflect.Field; |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
32 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
33 import sun.misc.Unsafe; |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
34 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
35 public class GetUnsafeObjectG1PreBarrier { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
36 private static final Unsafe unsafe; |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
37 private static final int N = 100_000; |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
38 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
39 static { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
40 try { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
41 Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
42 theUnsafe.setAccessible(true); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
43 unsafe = (Unsafe) theUnsafe.get(null); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
44 } catch (NoSuchFieldException | IllegalAccessException e) { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
45 throw new IllegalStateException(e); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
46 } |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
47 } |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
48 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
49 public Object a; |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
50 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
51 public static void main(String[] args) throws Throwable { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
52 new GetUnsafeObjectG1PreBarrier(); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
53 } |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
54 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
55 public GetUnsafeObjectG1PreBarrier() throws Throwable { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
56 doit(); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
57 } |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
58 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
59 private void doit() throws Throwable { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
60 Field field = GetUnsafeObjectG1PreBarrier.class.getField("a"); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
61 long fieldOffset = unsafe.objectFieldOffset(field); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
62 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
63 for (int i = 0; i < N; i++) { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
64 readField(this, fieldOffset); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
65 } |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
66 } |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
67 |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
68 private void readField(Object o, long fieldOffset) { |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
69 unsafe.getObject(o, fieldOffset); |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
70 } |
8d77d02828d9
8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff
changeset
|
71 } |